Skip to content

Commit 166ab0a

Browse files
committedAug 27, 2014
stop using coffee; switch to gulp
1 parent 05cfea3 commit 166ab0a

22 files changed

+686
-17631
lines changed
 

‎.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# 2 space indentation
7+
[*.js]
8+
indent_style = space
9+
indent_size = 2

‎.jshintrc

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"node": true,
3+
"browser": true,
4+
"bitwise": true,
5+
"camelcase": true,
6+
"curly": true,
7+
"eqeqeq": true,
8+
"immed": true,
9+
"indent": 2,
10+
"latedef": true,
11+
"newcap": true,
12+
"noarg": true,
13+
"quotmark": false,
14+
"regexp": true,
15+
"undef": true,
16+
"unused": true,
17+
"strict": true,
18+
"trailing": false,
19+
"smarttabs": true,
20+
"white": false,
21+
"globals": {
22+
"angular": false
23+
}
24+
}

‎Gruntfile.coffee

+1-23
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@ path = require 'path'
22

33
# Build configurations.
44
module.exports = (grunt) ->
5-
grunt.initConfig
6-
# Deletes Compiled script directory
7-
# These directories should be deleted before subsequent builds.
8-
# These directories are not committed to source control.
9-
clean:
10-
working:
11-
scripts: [
12-
'./scripts/*'
13-
]
14-
5+
grunt.initConfig
156
# Compile CoffeeScript (.coffee) files to JavaScript (.js).
167
coffee:
178
src:
@@ -71,8 +62,6 @@ module.exports = (grunt) ->
7162
# Register grunt tasks supplied by grunt-contrib-*.
7263
# Referenced in package.json.
7364
# https://github.com/gruntjs/grunt-contrib
74-
grunt.loadNpmTasks 'grunt-contrib-clean'
75-
grunt.loadNpmTasks 'grunt-contrib-coffee'
7665
grunt.loadNpmTasks 'grunt-contrib-watch'
7766
grunt.loadNpmTasks 'grunt-contrib-copy'
7867
grunt.loadNpmTasks 'grunt-contrib-uglify'
@@ -86,7 +75,6 @@ module.exports = (grunt) ->
8675
# Enter the following command at the command line to execute this build task:
8776
# grunt test
8877
grunt.registerTask 'test', [
89-
'clean:working'
9078
'default'
9179
'karma'
9280
]
@@ -95,16 +83,6 @@ module.exports = (grunt) ->
9583
# Enter the following command at the command line to execute this build task:
9684
# grunt
9785
grunt.registerTask 'default', [
98-
'coffee:src'
9986
'copy:dist'
10087
'uglify:dist'
10188
]
102-
103-
104-
# Compiles the app with non-optimized build settings and watches changes.
105-
# Enter the following command at the command line to execute this build task:
106-
# grunt dev
107-
grunt.registerTask 'dev', [
108-
'coffee:src'
109-
'watch'
110-
]

‎README.md

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
angular-dropdowns
2-
=================
1+
# angular-dropdowns
32

4-
Dropdown directives for AngularJS (1.1.5, 1.2.x).
3+
Dropdown directives for AngularJS (1.1.5+, 1.2.x).
54

65
Includes both a select-style dropdown and a menu-style dropdown. The menu-style dropdown attaches to an existing element (button, link, div, etc), whereas the select-style dropdown replaces the element it is attached to.
76

87
See examples: http://jsfiddle.net/jseppi/cTzun/3/embedded/result/
98

10-
Usage
11-
-----
9+
## Usage
1210

1311
Include `ngDropdowns` in your module dependencies:
1412

@@ -96,19 +94,17 @@ You can specify a function to call upon dropdown value change by specifying the
9694
</div>
9795
```
9896

99-
Contributors
100-
---------
97+
## Contributors
98+
10199
* [@jseppi](http://github.com/jseppi)
102100
* [@alexisbg](http://github.com/alexisbg)
103101
* [@elishacook](http://github.com/elishacook)
104102
* [@dinodsaurus](https://github.com/dinodsaurus)
105103

106-
License
107-
---------
104+
## License
105+
108106
[MIT](http://jseppi.mit-license.org/license.html)
109107

108+
## Credits
110109

111-
Credits
112-
-------------
113110
Styling based on http://tympanus.net/codrops/2012/10/04/custom-drop-down-list-styling/
114-
File renamed without changes.

‎angular-dropdowns.js

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
/**
2+
* @license MIT http://jseppi.mit-license.org/license.html
3+
*/
4+
'use strict';
5+
var dd = angular.module('ngDropdowns', []);
6+
7+
dd.directive('dropdownSelect', ['DropdownService', '$window',
8+
function (DropdownService, $window) {
9+
return {
10+
restrict: 'A',
11+
replace: true,
12+
scope: {
13+
dropdownSelect: '=',
14+
dropdownModel: '=',
15+
dropdownOnchange: '&'
16+
},
17+
18+
controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
19+
$scope.labelField = $attrs.dropdownItemLabel || 'text';
20+
21+
DropdownService.register($element);
22+
23+
this.select = function (selected) {
24+
if (selected !== $scope.dropdownModel) {
25+
angular.copy(selected, $scope.dropdownModel);
26+
}
27+
$scope.dropdownOnchange({
28+
selected: selected
29+
});
30+
};
31+
32+
var $clickEvent = ('ontouchstart' in $window ? 'touchend' : 'click');
33+
$element.bind($clickEvent, function (event) {
34+
event.stopPropagation();
35+
DropdownService.toggleActive($element);
36+
});
37+
38+
$scope.$on('$destroy', function () {
39+
DropdownService.unregister($element);
40+
});
41+
}],
42+
43+
template: "<div class='wrap-dd-select'>" +
44+
" <span class='selected'>{{dropdownModel[labelField]}}</span>" +
45+
" <ul class='dropdown'>" +
46+
" <li ng-repeat='item in dropdownSelect'" +
47+
" class='dropdown-item'" +
48+
" dropdown-select-item='item'" +
49+
" dropdown-item-label='labelField'>" +
50+
" </li>" +
51+
" </ul>" +
52+
"</div>"
53+
};
54+
}
55+
]);
56+
57+
dd.directive('dropdownSelectItem', [
58+
function () {
59+
return {
60+
require: '^dropdownSelect',
61+
replace: true,
62+
scope: {
63+
dropdownItemLabel: '=',
64+
dropdownSelectItem: '='
65+
},
66+
67+
link: function (scope, element, attrs, dropdownSelectCtrl) {
68+
scope.selectItem = function () {
69+
if (scope.dropdownSelectItem.href) {
70+
return;
71+
}
72+
dropdownSelectCtrl.select(scope.dropdownSelectItem);
73+
};
74+
},
75+
76+
template: "<li ng-class='{divider: dropdownSelectItem.divider}'>" +
77+
" <a href='' class='dropdown-item'" +
78+
" ng-if='!dropdownSelectItem.divider'" +
79+
" ng-href='{{dropdownSelectItem.href}}'" +
80+
" ng-click='selectItem()'>" +
81+
" {{dropdownSelectItem[dropdownItemLabel]}}" +
82+
" </a>" +
83+
"</li>"
84+
};
85+
}
86+
]);
87+
88+
dd.directive('dropdownMenu', ['$parse', '$compile', 'DropdownService', '$window',
89+
function ($parse, $compile, DropdownService, $window) {
90+
91+
var template = "<ul class='dropdown'>" +
92+
" <li ng-repeat='item in dropdownMenu'" +
93+
" class='dropdown-item'" +
94+
" dropdown-item-label='labelField'" +
95+
" dropdown-menu-item='item'>" +
96+
" </li>" +
97+
"</ul>";
98+
99+
return {
100+
restrict: 'A',
101+
replace: false,
102+
scope: {
103+
dropdownMenu: '=',
104+
dropdownModel: '=',
105+
dropdownOnchange: '&'
106+
},
107+
108+
controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
109+
$scope.labelField = $attrs.dropdownItemLabel || 'text';
110+
111+
var $clickEvent = ('ontouchstart' in $window ? 'touchend' : 'click');
112+
var $template = angular.element(template);
113+
// Attach this controller to the element's data
114+
$template.data('$dropdownMenuController', this);
115+
116+
var tpl = $compile($template)($scope);
117+
var $wrap = angular.element("<div class='wrap-dd-menu'></div>");
118+
119+
$element.replaceWith($wrap);
120+
$wrap.append($element);
121+
$wrap.append(tpl);
122+
123+
DropdownService.register(tpl);
124+
125+
this.select = function (selected) {
126+
if (selected !== $scope.dropdownModel) {
127+
angular.copy(selected, $scope.dropdownModel);
128+
}
129+
$scope.dropdownOnchange({
130+
selected: selected
131+
});
132+
};
133+
134+
$element.bind($clickEvent, function (event) {
135+
event.stopPropagation();
136+
DropdownService.toggleActive(tpl);
137+
});
138+
139+
$scope.$on('$destroy', function () {
140+
DropdownService.unregister(tpl);
141+
});
142+
}]
143+
};
144+
}
145+
]);
146+
147+
dd.directive('dropdownMenuItem', [
148+
function () {
149+
return {
150+
require: '^dropdownMenu',
151+
replace: true,
152+
scope: {
153+
dropdownMenuItem: '=',
154+
dropdownItemLabel: '='
155+
},
156+
157+
link: function (scope, element, attrs, dropdownMenuCtrl) {
158+
scope.selectItem = function () {
159+
if (scope.dropdownMenuItem.href) {
160+
return;
161+
}
162+
dropdownMenuCtrl.select(scope.dropdownMenuItem);
163+
};
164+
},
165+
166+
template: "<li ng-class='{divider: dropdownMenuItem.divider}'>" +
167+
" <a href='' class='dropdown-item'" +
168+
" ng-if='!dropdownMenuItem.divider'" +
169+
" ng-href='{{dropdownMenuItem.href}}'" +
170+
" ng-click='selectItem()'>" +
171+
" {{dropdownMenuItem[dropdownItemLabel]}}" +
172+
" </a>" +
173+
"</li>"
174+
};
175+
}
176+
]);
177+
178+
dd.factory('DropdownService', ['$document',
179+
function ($document) {
180+
var body = $document.find('body'),
181+
service = {},
182+
_dropdowns = [];
183+
184+
body.bind('click', function () {
185+
return angular.forEach(_dropdowns, function (el) {
186+
el.removeClass('active');
187+
});
188+
});
189+
190+
service.register = function (ddEl) {
191+
_dropdowns.push(ddEl);
192+
};
193+
194+
service.unregister = function (ddEl) {
195+
var index;
196+
index = _dropdowns.indexOf(ddEl);
197+
if (index > -1) {
198+
_dropdowns.splice(index, 1);
199+
}
200+
};
201+
202+
service.toggleActive = function (ddEl) {
203+
angular.forEach(_dropdowns, function (el) {
204+
if (el !== ddEl) {
205+
el.removeClass('active');
206+
}
207+
});
208+
209+
ddEl.toggleClass('active');
210+
};
211+
212+
return service;
213+
}
214+
]);

‎bower.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "angular-dropdowns",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"homepage": "https://github.com/jseppi/angular-dropdowns",
55
"authors": [
66
"James Seppi"
77
],
88
"description": "AngularJS Dropdown Directives",
99
"main": [
1010
"dist/angular-dropdowns.js",
11-
"css/dropdowns.css"
11+
"dist/angular-dropdowns.css"
1212
],
1313
"keywords": [
1414
"angular",

0 commit comments

Comments
 (0)
Please sign in to comment.