rsanchez
2014-10-15 7686a892d556333194349f73fee3a268b6202d66
securis/src/main/resources/static/js/angular/chosen.js
....@@ -1,11 +1,12 @@
1
-// Generated by CoffeeScript 1.6.3
1
+// Generated by CoffeeScript 1.6.2
22 (function() {
33 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; };
44
55 angular.module('localytics.directives', []);
66
77 angular.module('localytics.directives').directive('chosen', function() {
8
- var CHOSEN_OPTION_WHITELIST, NG_OPTIONS_REGEXP, chosen, isEmpty, snakeCase;
8
+ var CHOSEN_OPTION_WHITELIST, NG_OPTIONS_REGEXP, isEmpty, snakeCase;
9
+
910 NG_OPTIONS_REGEXP = /^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/;
1011 CHOSEN_OPTION_WHITELIST = ['noResultsText', 'allowSingleDeselect', 'disableSearchThreshold', 'disableSearch', 'enableSplitWordSearch', 'inheritSelectClasses', 'maxSelectedOptions', 'placeholderTextMultiple', 'placeholderTextSingle', 'searchContains', 'singleBackstrokeDelete', 'displayDisabledOptions', 'displaySelectedOptions', 'width'];
1112 snakeCase = function(input) {
....@@ -15,6 +16,7 @@
1516 };
1617 isEmpty = function(value) {
1718 var key;
19
+
1820 if (angular.isArray(value)) {
1921 return value.length === 0;
2022 } else if (angular.isObject(value)) {
....@@ -26,12 +28,13 @@
2628 }
2729 return true;
2830 };
29
- return chosen = {
31
+ return {
3032 restrict: 'A',
3133 require: '?ngModel',
3234 terminal: true,
33
- link: function(scope, element, attr, ctrl) {
34
- var disableWithMessage, empty, initOrUpdate, initialized, match, options, origRender, removeEmptyMessage, startLoading, stopLoading, valuesExpr, viewWatch;
35
+ link: function(scope, element, attr, ngModel) {
36
+ var chosen, defaultText, disableWithMessage, empty, initOrUpdate, match, options, origRender, removeEmptyMessage, startLoading, stopLoading, valuesExpr, viewWatch;
37
+
3538 element.addClass('localytics-chosen');
3639 options = scope.$eval(attr.chosen) || {};
3740 angular.forEach(attr, function(value, key) {
....@@ -45,56 +48,56 @@
4548 stopLoading = function() {
4649 return element.removeClass('loading').attr('disabled', false).trigger('chosen:updated');
4750 };
48
- initialized = false;
51
+ chosen = null;
52
+ defaultText = null;
4953 empty = false;
5054 initOrUpdate = function() {
51
- if (initialized) {
55
+ if (chosen) {
5256 return element.trigger('chosen:updated');
5357 } else {
54
- element.chosen(options);
55
- return initialized = true;
58
+ chosen = element.chosen(options).data('chosen');
59
+ return defaultText = chosen.default_text;
5660 }
5761 };
5862 removeEmptyMessage = function() {
5963 empty = false;
60
- return element.find('option.empty').remove();
64
+ return element.attr('data-placeholder', defaultText);
6165 };
62
- disableWithMessage = function(message) {
66
+ disableWithMessage = function() {
6367 empty = true;
64
- return element.empty().append("<option selected class=\"empty\">" + message + "</option>").attr('disabled', true).trigger('chosen:updated');
68
+ return element.attr('data-placeholder', chosen.results_none_found).attr('disabled', true).trigger('chosen:updated');
6569 };
66
- if (ctrl) {
67
- origRender = ctrl.$render;
68
- ctrl.$render = function() {
70
+ if (ngModel) {
71
+ origRender = ngModel.$render;
72
+ ngModel.$render = function() {
6973 origRender();
7074 return initOrUpdate();
7175 };
7276 if (attr.multiple) {
7377 viewWatch = function() {
74
- return ctrl.$viewValue;
78
+ return ngModel.$viewValue;
7579 };
76
- scope.$watch(viewWatch, ctrl.$render, true);
80
+ scope.$watch(viewWatch, ngModel.$render, true);
7781 }
7882 } else {
7983 initOrUpdate();
8084 }
81
- attr.$observe('disabled', function(value) {
85
+ attr.$observe('disabled', function() {
8286 return element.trigger('chosen:updated');
8387 });
84
- if (attr.ngOptions) {
88
+ if (attr.ngOptions && ngModel) {
8589 match = attr.ngOptions.match(NG_OPTIONS_REGEXP);
8690 valuesExpr = match[7];
87
- if (angular.isUndefined(scope.$eval(valuesExpr))) {
88
- startLoading();
89
- }
9091 return scope.$watchCollection(valuesExpr, function(newVal, oldVal) {
91
- if (newVal !== oldVal) {
92
+ if (angular.isUndefined(newVal)) {
93
+ return startLoading();
94
+ } else {
9295 if (empty) {
9396 removeEmptyMessage();
9497 }
9598 stopLoading();
9699 if (isEmpty(newVal)) {
97
- return disableWithMessage(options.no_results_text || 'No values available');
100
+ return disableWithMessage();
98101 }
99102 }
100103 });
....@@ -103,4 +106,4 @@
103106 };
104107 });
105108
106
-}).call(this);
109
+}).call(this);