mirror of https://github.com/apache/lucene.git
revert any changes to chosen.
This commit is contained in:
parent
3086040feb
commit
4d0a8ccaf1
|
@ -1,14 +1,18 @@
|
||||||
/*
|
/*
|
||||||
The MIT License
|
The MIT License
|
||||||
|
|
||||||
Copyright (c) 2013 Localytics http://www.localytics.com
|
Copyright (c) 2013 Localytics http://www.localytics.com
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
@ -19,117 +23,117 @@ THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
// Generated by CoffeeScript 1.8.0
|
// Generated by CoffeeScript 1.8.0
|
||||||
(function() {
|
(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 __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', []);
|
||||||
|
|
||||||
angular.module('localytics.directives').directive('chosen', [
|
angular.module('localytics.directives').directive('chosen', [
|
||||||
'$timeout', function($timeout) {
|
'$timeout', function($timeout) {
|
||||||
var CHOSEN_OPTION_WHITELIST, NG_OPTIONS_REGEXP, isEmpty, snakeCase;
|
var CHOSEN_OPTION_WHITELIST, NG_OPTIONS_REGEXP, isEmpty, snakeCase;
|
||||||
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+(.*?))?$/;
|
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+(.*?))?$/;
|
||||||
CHOSEN_OPTION_WHITELIST = ['noResultsText', 'allowSingleDeselect', 'disableSearchThreshold', 'disableSearch', 'enableSplitWordSearch', 'inheritSelectClasses', 'maxSelectedOptions', 'placeholderTextMultiple', 'placeholderTextSingle', 'searchContains', 'singleBackstrokeDelete', 'displayDisabledOptions', 'displaySelectedOptions', 'width'];
|
CHOSEN_OPTION_WHITELIST = ['noResultsText', 'allowSingleDeselect', 'disableSearchThreshold', 'disableSearch', 'enableSplitWordSearch', 'inheritSelectClasses', 'maxSelectedOptions', 'placeholderTextMultiple', 'placeholderTextSingle', 'searchContains', 'singleBackstrokeDelete', 'displayDisabledOptions', 'displaySelectedOptions', 'width'];
|
||||||
snakeCase = function(input) {
|
snakeCase = function(input) {
|
||||||
return input.replace(/[A-Z]/g, function($1) {
|
return input.replace(/[A-Z]/g, function($1) {
|
||||||
return "_" + ($1.toLowerCase());
|
return "_" + ($1.toLowerCase());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
isEmpty = function(value) {
|
isEmpty = function(value) {
|
||||||
var key;
|
var key;
|
||||||
if (angular.isArray(value)) {
|
if (angular.isArray(value)) {
|
||||||
return value.length === 0;
|
return value.length === 0;
|
||||||
} else if (angular.isObject(value)) {
|
} else if (angular.isObject(value)) {
|
||||||
for (key in value) {
|
for (key in value) {
|
||||||
if (value.hasOwnProperty(key)) {
|
if (value.hasOwnProperty(key)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
};
|
return true;
|
||||||
return {
|
};
|
||||||
restrict: 'A',
|
return {
|
||||||
require: '?ngModel',
|
restrict: 'A',
|
||||||
terminal: true,
|
require: '?ngModel',
|
||||||
link: function(scope, element, attr, ngModel) {
|
terminal: true,
|
||||||
var chosen, defaultText, disableWithMessage, empty, initOrUpdate, match, options, origRender, removeEmptyMessage, startLoading, stopLoading, valuesExpr, viewWatch;
|
link: function(scope, element, attr, ngModel) {
|
||||||
element.addClass('localytics-chosen');
|
var chosen, defaultText, disableWithMessage, empty, initOrUpdate, match, options, origRender, removeEmptyMessage, startLoading, stopLoading, valuesExpr, viewWatch;
|
||||||
options = scope.$eval(attr.chosen) || {};
|
element.addClass('localytics-chosen');
|
||||||
angular.forEach(attr, function(value, key) {
|
options = scope.$eval(attr.chosen) || {};
|
||||||
if (__indexOf.call(CHOSEN_OPTION_WHITELIST, key) >= 0) {
|
angular.forEach(attr, function(value, key) {
|
||||||
return options[snakeCase(key)] = scope.$eval(value);
|
if (__indexOf.call(CHOSEN_OPTION_WHITELIST, key) >= 0) {
|
||||||
}
|
return options[snakeCase(key)] = scope.$eval(value);
|
||||||
});
|
|
||||||
startLoading = function() {
|
|
||||||
return element.addClass('loading').attr('disabled', true).trigger('chosen:updated');
|
|
||||||
};
|
|
||||||
stopLoading = function() {
|
|
||||||
return element.removeClass('loading').attr('disabled', false).trigger('chosen:updated');
|
|
||||||
};
|
|
||||||
chosen = null;
|
|
||||||
defaultText = null;
|
|
||||||
empty = false;
|
|
||||||
initOrUpdate = function() {
|
|
||||||
if (chosen) {
|
|
||||||
return element.trigger('chosen:updated');
|
|
||||||
} else {
|
|
||||||
chosen = element.chosen(options).data('chosen');
|
|
||||||
return defaultText = chosen.default_text;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
removeEmptyMessage = function() {
|
|
||||||
empty = false;
|
|
||||||
return element.attr('data-placeholder', defaultText);
|
|
||||||
};
|
|
||||||
disableWithMessage = function() {
|
|
||||||
empty = true;
|
|
||||||
return element.attr('data-placeholder', chosen.results_none_found).attr('disabled', true).trigger('chosen:updated');
|
|
||||||
};
|
|
||||||
if (ngModel) {
|
|
||||||
origRender = ngModel.$render;
|
|
||||||
ngModel.$render = function() {
|
|
||||||
origRender();
|
|
||||||
return initOrUpdate();
|
|
||||||
};
|
|
||||||
if (attr.multiple) {
|
|
||||||
viewWatch = function() {
|
|
||||||
return ngModel.$viewValue;
|
|
||||||
};
|
|
||||||
scope.$watch(viewWatch, ngModel.$render, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
initOrUpdate();
|
|
||||||
}
|
}
|
||||||
attr.$observe('disabled', function() {
|
});
|
||||||
|
startLoading = function() {
|
||||||
|
return element.addClass('loading').attr('disabled', true).trigger('chosen:updated');
|
||||||
|
};
|
||||||
|
stopLoading = function() {
|
||||||
|
return element.removeClass('loading').attr('disabled', false).trigger('chosen:updated');
|
||||||
|
};
|
||||||
|
chosen = null;
|
||||||
|
defaultText = null;
|
||||||
|
empty = false;
|
||||||
|
initOrUpdate = function() {
|
||||||
|
if (chosen) {
|
||||||
return element.trigger('chosen:updated');
|
return element.trigger('chosen:updated');
|
||||||
});
|
} else {
|
||||||
if (attr.ngOptions && ngModel) {
|
chosen = element.chosen(options).data('chosen');
|
||||||
match = attr.ngOptions.match(NG_OPTIONS_REGEXP);
|
return defaultText = chosen.default_text;
|
||||||
valuesExpr = match[7];
|
}
|
||||||
scope.$watchCollection(valuesExpr, function(newVal, oldVal) {
|
};
|
||||||
var timer;
|
removeEmptyMessage = function() {
|
||||||
return timer = $timeout(function() {
|
empty = false;
|
||||||
if (angular.isUndefined(newVal)) {
|
return element.attr('data-placeholder', defaultText);
|
||||||
return startLoading();
|
};
|
||||||
} else {
|
disableWithMessage = function() {
|
||||||
if (empty) {
|
empty = true;
|
||||||
removeEmptyMessage();
|
return element.attr('data-placeholder', chosen.results_none_found).attr('disabled', true).trigger('chosen:updated');
|
||||||
}
|
};
|
||||||
stopLoading();
|
if (ngModel) {
|
||||||
if (isEmpty(newVal)) {
|
origRender = ngModel.$render;
|
||||||
return disableWithMessage();
|
ngModel.$render = function() {
|
||||||
}
|
origRender();
|
||||||
|
return initOrUpdate();
|
||||||
|
};
|
||||||
|
if (attr.multiple) {
|
||||||
|
viewWatch = function() {
|
||||||
|
return ngModel.$viewValue;
|
||||||
|
};
|
||||||
|
scope.$watch(viewWatch, ngModel.$render, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
initOrUpdate();
|
||||||
|
}
|
||||||
|
attr.$observe('disabled', function() {
|
||||||
|
return element.trigger('chosen:updated');
|
||||||
|
});
|
||||||
|
if (attr.ngOptions && ngModel) {
|
||||||
|
match = attr.ngOptions.match(NG_OPTIONS_REGEXP);
|
||||||
|
valuesExpr = match[7];
|
||||||
|
scope.$watchCollection(valuesExpr, function(newVal, oldVal) {
|
||||||
|
var timer;
|
||||||
|
return timer = $timeout(function() {
|
||||||
|
if (angular.isUndefined(newVal)) {
|
||||||
|
return startLoading();
|
||||||
|
} else {
|
||||||
|
if (empty) {
|
||||||
|
removeEmptyMessage();
|
||||||
|
}
|
||||||
|
stopLoading();
|
||||||
|
if (isEmpty(newVal)) {
|
||||||
|
return disableWithMessage();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
return scope.$on('$destroy', function(event) {
|
|
||||||
if (typeof timer !== "undefined" && timer !== null) {
|
|
||||||
return $timeout.cancel(timer);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
return scope.$on('$destroy', function(event) {
|
||||||
|
if (typeof timer !== "undefined" && timer !== null) {
|
||||||
|
return $timeout.cancel(timer);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
};
|
||||||
]);
|
}
|
||||||
|
]);
|
||||||
}).call(this);
|
|
||||||
|
}).call(this);
|
||||||
|
|
Loading…
Reference in New Issue