mirror of
https://github.com/wahyd4/cdnjs.git
synced 2026-08-27 21:56:06 +10:00
1 line
9.0 KiB
JavaScript
1 line
9.0 KiB
JavaScript
"use strict";void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr",function(e){var t=this;t.parse=function(t){var c=t.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!c)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",t);var l=c[1],s=c[2],i=c[3];if(c=l.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/),!c)throw e("iidexp","'_item_' in '_item_ in _collection_' should be an identifier or '(_key_, _value_)' expression, but got '{0}'.",l);c[3]||c[1],c[2];return{lhs:l,rhs:s,trackByExp:i}},t.getNgRepeatExpression=function(e,t,c){var l=e+" in "+t;return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(e,t,c,l,s){function i(){a.resetSearchInput&&(a.search=o)}function n(e){var t=!0;switch(e){case p.Down:a.activeIndex<a.items.length-1&&a.activeIndex++;break;case p.Up:a.activeIndex>0&&a.activeIndex--;break;case p.Tab:case p.Enter:a.select(a.items[a.activeIndex]);break;case p.Escape:a.close();break;default:t=!1}return t}function r(){var e=t.querySelectorAll(".ui-select-choices-content"),c=e.querySelectorAll(".ui-select-choices-row");if(c.length<1)throw s("rows","Expected multiple .ui-select-choices-row but got '{0}'.",c.length);var l=c[a.activeIndex],i=l.offsetTop+l.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;i>n?e[0].scrollTop+=i-n:i<l.clientHeight&&(e[0].scrollTop-=l.clientHeight-i)}var a=this,o="";a.placeholder=void 0,a.search=o,a.activeIndex=0,a.items=[],a.selected=void 0,a.open=!1,a.disabled=void 0,a.resetSearchInput=void 0,a.refreshDelay=void 0;var u=t.querySelectorAll("input.ui-select-search");if(1!==u.length)throw s("searchInput","Expected 1 input.ui-select-search but got '{0}'.",u.length);a.activate=function(){a.disabled||(i(),a.open=!0,c(function(){u[0].focus()}))},a.parseRepeatAttr=function(t){var c=l.parse(t);e.$watchCollection(c.rhs,function(e){if(void 0===e||null===e)a.items=[];else{if(!angular.isArray(e))throw s("items","Expected an array but got '{0}'.",e);a.items=e}})};var d=void 0;a.refresh=function(t){void 0!==t&&(d&&c.cancel(d),d=c(function(){e.$apply(t)},a.refreshDelay))},a.select=function(e){a.selected=e,a.close()},a.close=function(){a.open&&(i(),a.open=!1)};var p={Enter:13,Tab:9,Up:38,Down:40,Escape:27};u.on("keydown",function(t){if(a.items.length>0){var c=t.which;switch(e.$apply(function(){var e=n(c);e&&(t.preventDefault(),t.stopPropagation())}),c){case p.Down:case p.Up:r()}}}),e.$on("$destroy",function(){u.off("keydown")})}]).directive("uiSelect",["$document","uiSelectConfig",function(e,t){return{restrict:"EA",templateUrl:function(e,c){var l=c.theme||t.theme;return l+"/select.tpl.html"},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(t,c,l,s,i){var n=s[0],r=s[1];l.$observe("disabled",function(){n.disabled=void 0!==l.disabled?l.disabled:!1}),l.$observe("resetSearchInput",function(){var e=t.$eval(l.resetSearchInput);n.resetSearchInput=void 0!==e?e:!0}),t.$watch("$select.selected",function(e){r.$viewValue!==e&&r.$setViewValue(e)}),r.$render=function(){n.selected=r.$viewValue},e.on("mousedown",function(e){var l=!1;l=window.jQuery?window.jQuery.contains(c[0],e.target):c[0].contains(e.target),l||(n.close(),t.$digest())}),t.$on("$destroy",function(){e.off("mousedown")}),i(t,function(e){var t=angular.element("<div>").append(e),l=t.querySelectorAll(".ui-select-match");if(1!==l.length)throw uiSelectMinErr("transcluded","Expected 1 .ui-select-match but got '{0}'.",l.length);c.querySelectorAll(".ui-select-match").replaceWith(l);var s=t.querySelectorAll(".ui-select-choices");if(1!==s.length)throw uiSelectMinErr("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);c.querySelectorAll(".ui-select-choices").replaceWith(s)})}}}]).directive("choices",["uiSelectConfig","RepeatParser","uiSelectMinErr",function(e,t,c){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,s){var i=t.parse(s.repeat),n=l.querySelectorAll(".ui-select-choices-row");if(1!==n.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",n.length);return n.attr("ng-repeat",t.getNgRepeatExpression(i.lhs,"$select.items",i.trackByExp)).attr("ng-mouseenter","$select.activeIndex = $index").attr("ng-click","$select.select("+i.lhs+")"),function(t,c,l,s){s.parseRepeatAttr(l.repeat),t.$watch("$select.search",function(){s.activeIndex=0,s.refresh(l.refresh)}),l.$observe("refreshDelay",function(){var c=t.$eval(l.refreshDelay);s.refreshDelay=void 0!==c?c:e.refreshDelay})}}}}]).directive("match",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/match.tpl.html"},link:function(t,c,l,s){l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder})}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c?t.replace(new RegExp(e(c),"gi"),'<span class="ui-select-highlight">$&</span>'):t}}),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",'<ul class="ui-select-choices ui-select-choices-content dropdown-menu" role="menu" aria-labelledby="dLabel" ng-show="$select.items.length> 0"> <li class="ui-select-choices-row" ng-class="{active: $select.activeIndex===$index}"> <a href="javascript:void(0)" ng-transclude></a> </li> </ul> '),e.put("bootstrap/match.tpl.html",'<button class="btn btn-default form-control ui-select-match" ng-hide="$select.open" ng-disabled="$select.disabled" ng-click="$select.activate()"> <span ng-hide="$select.selected !==undefined" class="text-muted">{{$select.placeholder}}</span> <span ng-show="$select.selected !==undefined" ng-transclude></span> <span class="caret"></span> </button> '),e.put("bootstrap/select.tpl.html",'<div class="ui-select-bootstrap dropdown" ng-class="{open: $select.open}"> <div class="ui-select-match"></div> <input type="text" autocomplete="off" tabindex="" class="form-control ui-select-search" placeholder="{{$select.placeholder}}" ng-model="$select.search" ng-show="$select.open"> <div class="ui-select-choices"></div> </div> '),e.put("select2/choices.tpl.html",'<ul class="ui-select-choices ui-select-choices-content select2-results"> <li class="ui-select-choices-row" ng-class="{\'select2-highlighted\': $select.activeIndex===$index}"> <div class="select2-result-label" ng-transclude></div> </li> </ul> '),e.put("select2/match.tpl.html",'<a class="select2-choice ui-select-match" ng-class="{\'select2-default\': $select.selected === undefined}" ng-click="$select.activate()"> <span ng-hide="$select.selected !==undefined" class="select2-chosen">{{$select.placeholder}}</span> <span ng-show="$select.selected !==undefined" class="select2-chosen" ng-transclude></span> <span class="select2-arrow"><b></b></span> </a> '),e.put("select2/select.tpl.html",'<div class="select2 select2-container" ng-class="{\'select2-container-active select2-dropdown-open\': $select.open, \'select2-container-disabled\': $select.disabled}"> <div class="ui-select-match"></div> <div class="select2-drop select2-with-searchbox select2-drop-active" ng-class="{\'select2-display-none\': !$select.open}"> <div class="select2-search"> <input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="ui-select-search select2-input" ng-model="$select.search"> </div> <div class="ui-select-choices"></div> </div> </div> '),e.put("selectize/choices.tpl.html",'<div ng-show="$select.open" class="ui-select-choices selectize-dropdown single"> <div class="ui-select-choices-content selectize-dropdown-content"> <div class="ui-select-choices-row" ng-class="{\'active\': $select.activeIndex===$index}"> <div class="option" data-selectable ng-transclude></div> </div> </div> </div> '),e.put("selectize/match.tpl.html",'<div ng-hide="$select.open || $select.selected===undefined" class="ui-select-match" ng-transclude></div> '),e.put("selectize/select.tpl.html",'<div class="selectize-control single"> <div class="selectize-input" ng-class="{\'focus\': $select.open, \'disabled\': $select.disabled}" ng-click="$select.activate()"> <div class="ui-select-match"></div> <input type="text" autocomplete="off" tabindex="" class="ui-select-search" placeholder="{{$select.placeholder}}" ng-model="$select.search" ng-hide="$select.selected && !$select.open" ng-disabled="$select.disabled"> </div> <div class="ui-select-choices"></div> </div> ')}]); |