Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bower_components/
node_modules/
node_modules/
28 changes: 23 additions & 5 deletions dist/angular-chosen.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,28 @@
* @license MIT
*/
(function() {
var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
var chosen,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

angular.module('localytics.directives', []);

angular.module('localytics.directives').directive('chosen', [
'$timeout', function($timeout) {
chosen = angular.module('localytics.directives');

chosen.provider('chosen', function() {
var options;
options = {};
return {
setOption: function(newOpts) {
angular.extend(options, newOpts);
},
$get: function() {
return options;
}
};
});

chosen.directive('chosen', [
'chosen', '$timeout', function(config, $timeout) {
var CHOSEN_OPTION_WHITELIST, NG_OPTIONS_REGEXP, isEmpty, snakeCase;
NG_OPTIONS_REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/;
CHOSEN_OPTION_WHITELIST = ['persistentCreateOption', 'createOptionText', 'createOption', 'skipNoResults', 'noResultsText', 'allowSingleDeselect', 'disableSearchThreshold', 'disableSearch', 'enableSplitWordSearch', 'inheritSelectClasses', 'maxSelectedOptions', 'placeholderTextMultiple', 'placeholderTextSingle', 'searchContains', 'singleBackstrokeDelete', 'displayDisabledOptions', 'displaySelectedOptions', 'width', 'includeGroupLabelInSelected', 'maxShownResults'];
Expand All @@ -37,11 +53,13 @@
require: '?ngModel',
priority: 1,
link: function(scope, element, attr, ngModel) {
var chosen, empty, initOrUpdate, match, options, origRender, startLoading, stopLoading, updateMessage, valuesExpr, viewWatch;
var directiveOptions, empty, initOrUpdate, match, options, origRender, startLoading, stopLoading, updateMessage, valuesExpr, viewWatch;
scope.disabledValuesHistory = scope.disabledValuesHistory ? scope.disabledValuesHistory : [];
element = $(element);
element.addClass('localytics-chosen');
options = scope.$eval(attr.chosen) || {};
directiveOptions = scope.$eval(attr.chosen) || {};
options = angular.copy(config);
angular.extend(options, directiveOptions);
angular.forEach(attr, function(value, key) {
if (indexOf.call(CHOSEN_OPTION_WHITELIST, key) >= 0) {
return attr.$observe(key, function(value) {
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-chosen.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion example/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions src/chosen.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
angular.module('localytics.directives', [])

angular.module('localytics.directives').directive 'chosen', ['$timeout', ($timeout) ->

chosen = angular.module('localytics.directives')

chosen.provider 'chosen', ->
options = {}
{
setOption: (newOpts) ->
angular.extend options, newOpts
return
$get: ->
options
}

chosen.directive 'chosen', ['chosen', '$timeout', (config, $timeout) ->
# coffeelint: disable=max_line_length
# This is stolen from Angular...
NG_OPTIONS_REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/
Expand Down Expand Up @@ -48,7 +59,13 @@ angular.module('localytics.directives').directive 'chosen', ['$timeout', ($timeo
element.addClass('localytics-chosen')

# Take a hash of options from the chosen directive
options = scope.$eval(attr.chosen) or {}
directiveOptions = scope.$eval(attr.chosen) or {}

# Clone options from configProvider
options = angular.copy(config)

# Merge options from directive with options from configProvider
angular.extend(options, directiveOptions)

# Options defined as attributes take precedence
angular.forEach attr, (value, key) ->
Expand Down