You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6 lines
18 KiB

  1. /*!
  2. * Angular Material Design
  3. * https://github.com/angular/material
  4. * @license MIT
  5. * v1.1.0-master-2b98560
  6. */
  7. function MdAutocompleteCtrl(e,t,n,o,i,l,r,a,c,u,m){function s(){n.initOptionalProperties(e,c,{searchText:"",selectedItem:null}),i(t),f(),n.nextTick(function(){x(),h(),e.autofocus&&t.on("focus",g)})}function d(){e.requireMatch&&Ie&&Ie.$setValidity("md-require-match",!!e.selectedItem)}function p(){function o(){var e=0,n=t.find("md-input-container");if(n.length){var o=n.find("input");e=n.prop("offsetHeight"),e-=o.prop("offsetTop"),e-=o.prop("offsetHeight"),e+=n.prop("offsetTop")}return e}function i(){var e=$e.scrollContainer.getBoundingClientRect(),t={};e.right>u.right-MENU_PADDING&&(t.left=r.right-e.width+"px"),$e.$.scrollContainer.css(t)}if(!$e)return n.nextTick(p,!1,e);var l,r=$e.wrap.getBoundingClientRect(),a=$e.snap.getBoundingClientRect(),u=$e.root.getBoundingClientRect(),m=a.bottom-u.top,s=u.bottom-a.top,d=r.left-u.left,h=r.width,g=o();c.mdFloatingLabel&&(d+=INPUT_PADDING,h-=2*INPUT_PADDING),l={left:d+"px",minWidth:h+"px",maxWidth:Math.max(r.right-u.left,u.right-r.left)-MENU_PADDING+"px"},m>s&&u.height-r.bottom-MENU_PADDING<MAX_HEIGHT?(l.top="auto",l.bottom=s+"px",l.maxHeight=Math.min(MAX_HEIGHT,r.top-u.top-MENU_PADDING)+"px"):(l.top=m-g+"px",l.bottom="auto",l.maxHeight=Math.min(MAX_HEIGHT,u.bottom+n.scrollTop()-r.bottom-MENU_PADDING)+"px"),$e.$.scrollContainer.css(l),n.nextTick(i,!1)}function h(){$e.$.root.length&&(i($e.$.scrollContainer),$e.$.scrollContainer.detach(),$e.$.root.append($e.$.scrollContainer),r.pin&&r.pin($e.$.scrollContainer,a))}function g(){$e.input.focus()}function f(){var t=parseInt(e.delay,10)||0;c.$observe("disabled",function(e){he.isDisabled=n.parseAttributeBoolean(e,!1)}),c.$observe("required",function(e){he.isRequired=n.parseAttributeBoolean(e,!1)}),c.$observe("readonly",function(e){he.isReadonly=n.parseAttributeBoolean(e,!1)}),e.$watch("searchText",t?n.debounce(R,t):R),e.$watch("selectedItem",w),angular.element(l).on("resize",p),e.$on("$destroy",$)}function $(){if(he.hidden||n.enableScrolling(),angular.element(l).off("resize",p),$e){var e=["ul","scroller","scrollContainer","input"];angular.forEach(e,function(e){$e.$[e].remove()})}}function x(){$e={main:t[0],scrollContainer:t[0].querySelector(".md-virtual-repeat-container"),scroller:t[0].querySelector(".md-virtual-repeat-scroller"),ul:t.find("ul")[0],input:t.find("input")[0],wrap:t.find("md-autocomplete-wrap")[0],root:document.body},$e.li=$e.ul.getElementsByTagName("li"),$e.snap=C(),$e.$=v($e),Ie=$e.$.input.controller("ngModel")}function C(){for(var e=t;e.length;e=e.parent())if(angular.isDefined(e.attr("md-autocomplete-snap")))return e[0];return $e.wrap}function v(e){var t={};for(var n in e)e.hasOwnProperty(n)&&(t[n]=angular.element(e[n]));return t}function b(e,t){!e&&t?(p(),$e&&(n.disableScrollAround($e.ul),Te=A(angular.element($e.wrap)))):e&&!t&&(n.enableScrolling(),Te&&(Te(),Te=null))}function A(e){function t(e){e.preventDefault()}return e.on("wheel",t),e.on("touchmove",t),function(){e.off("wheel",t),e.off("touchmove",t)}}function M(){Ce=!0}function T(){be||he.hidden||$e.input.focus(),Ce=!1,he.hidden=U()}function I(){$e.input.focus()}function w(t,n){d(),t?_(t).then(function(o){e.searchText=o,D(t,n)}):n&&e.searchText&&_(n).then(function(t){t.toString().toLowerCase()===e.searchText.toLowerCase()&&(e.searchText="")}),t!==n&&y()}function y(){angular.isFunction(e.itemChange)&&e.itemChange(F(e.selectedItem))}function E(){angular.isFunction(e.textChange)&&e.textChange()}function D(e,t){ve.forEach(function(n){n(e,t)})}function N(e){ve.indexOf(e)==-1&&ve.push(e)}function H(e){var t=ve.indexOf(e);t!=-1&&ve.splice(t,1)}function R(t,n){he.index=q(),t!==n&&(d(),_(e.selectedItem).then(function(o){t!==o&&(e.selectedItem=null,t!==n&&E(),J()?me():(he.matches=[],G(!1),ie()))}))}function k(e){be=!1,Ce||(he.hidden=U(),pe("ngBlur",{$event:e}))}function O(e){e&&(Ce=!1,be=!1),$e.input.blur()}function L(e){be=!0,B()&&J()&&me(),he.hidden=U(),pe("ngFocus",{$event:e})}function P(t){switch(t.keyCode){case o.KEY_CODE.DOWN_ARROW:if(he.loading)return;t.stopPropagation(),t.preventDefault(),he.index=Math.min(he.index+1,he.matches.length-1),re(),ie();break;case o.KEY_CODE.UP_ARROW:if(he.loading)return;t.stopPropagation(),t.preventDefault(),he.index=he.index<0?he.matches.length-1:Math.max(0,he.index-1),re(),ie();break;case o.KEY_CODE.TAB:if(T(),he.hidden||he.loading||he.index<0||he.matches.length<1)return;Z(he.index);break;case o.KEY_CODE.ENTER:if(he.hidden||he.loading||he.index<0||he.matches.length<1)return;if(K())return;t.stopPropagation(),t.preventDefault(),Z(he.index);break;case o.KEY_CODE.ESCAPE:if(t.preventDefault(),!V())return;t.stopPropagation(),te(),e.searchText&&W("clear")&&ne(),he.hidden=!0,W("blur")&&O(!0)}}function S(){return angular.isNumber(e.minLength)?e.minLength:1}function _(t){function n(t){return t&&e.itemText?e.itemText(F(t)):null}return u.when(n(t)||t).then(function(e){return e&&!angular.isString(e)&&m.warn("md-autocomplete: Could not resolve display value to a string. Please check the `md-item-text` attribute."),e})}function F(e){if(e){var t={};return he.itemName&&(t[he.itemName]=e),t}}function q(){return e.autoselect?0:-1}function G(e){he.loading!=e&&(he.loading=e),he.hidden=U()}function U(){return!B()||!j()}function B(){return!(he.loading&&!z())&&(!K()&&!!be)}function V(){return W("blur")||!he.hidden||he.loading||W("clear")&&e.searchText}function W(t){return!e.escapeOptions||e.escapeOptions.toLowerCase().indexOf(t)!==-1}function j(){return J()&&z()||ue()}function z(){return!!he.matches.length}function K(){return!!he.scope.selectedItem}function Y(){return he.loading&&!K()}function X(){return _(he.matches[he.index])}function J(){return(e.searchText||"").length>=S()}function Q(e,t,n){Object.defineProperty(he,e,{get:function(){return n},set:function(e){var o=n;n=e,t(e,o)}})}function Z(t){n.nextTick(function(){_(he.matches[t]).then(function(e){var t=$e.$.input.controller("ngModel");t.$setViewValue(e),t.$render()})["finally"](function(){e.selectedItem=he.matches[t],G(!1)})},!1)}function ee(){te(),ne()}function te(){he.index=0,he.matches=[]}function ne(){G(!0),e.searchText="";var t=document.createEvent("CustomEvent");t.initCustomEvent("change",!0,!0,{value:""}),$e.input.dispatchEvent(t),$e.input.blur(),e.searchText="",$e.input.focus()}function oe(t){function o(t){t&&(t=u.when(t),Me++,G(!0),n.nextTick(function(){t.then(i)["finally"](function(){0===--Me&&G(!1)})},!0,e))}function i(n){xe[r]=n,(t||"")===(e.searchText||"")&&se(n)}var l=e.$parent.$eval(fe),r=t.toLowerCase(),a=angular.isArray(l),c=!!l.then;a?i(l):c&&o(l)}function ie(){X().then(function(e){he.messages=[le(),e]})}function le(){if(Ae===he.matches.length)return"";switch(Ae=he.matches.length,he.matches.length){case 0:return"There are no matches available.";case 1:return"There is 1 match available.";default:return"There are "+he.matches.length+" matches available."}}function re(){if($e.li[0]){var e=$e.li[0].offsetHeight,t=e*he.index,n=t+e,o=$e.scroller.clientHeight,i=$e.scroller.scrollTop;t<i?ce(t):n>i+o&&ce(n-o)}}function ae(){return 0!==Me}function ce(e){$e.$.scrollContainer.controller("mdVirtualRepeatContainer").scrollTo(e)}function ue(){var e=(he.scope.searchText||"").length;return he.hasNotFound&&!z()&&(!he.loading||ae())&&e>=S()&&(be||Ce)&&!K()}function me(){var t=e.searchText||"",n=t.toLowerCase();!e.noCache&&xe[n]?se(xe[n]):oe(t),he.hidden=U()}function se(t){he.matches=t,he.hidden=U(),he.loading&&G(!1),e.selectOnMatch&&de(),ie(),p()}function de(){var t=e.searchText,n=he.matches,o=n[0];1===n.length&&_(o).then(function(n){var o=t==n;e.matchInsensitive&&!o&&(o=t.toLowerCase()==n.toLowerCase()),o&&Z(0)})}function pe(t,n){c[t]&&e.$parent.$eval(c[t],n||{})}var he=this,ge=e.itemsExpr.split(/ in /i),fe=ge[1],$e=null,xe={},Ce=!1,ve=[],be=!1,Ae=0,Me=0,Te=null,Ie=null;return Q("hidden",b,!0),he.scope=e,he.parent=e.$parent,he.itemName=ge[0],he.matches=[],he.loading=!1,he.hidden=!0,he.index=null,he.messages=[],he.id=n.nextUid(),he.isDisabled=null,he.isRequired=null,he.isReadonly=null,he.hasNotFound=!1,he.keydown=P,he.blur=k,he.focus=L,he.clear=ee,he.select=Z,he.listEnter=M,he.listLeave=T,he.mouseUp=I,he.getCurrentDisplayValue=X,he.registerSelectedItemWatcher=N,he.unregisterSelectedItemWatcher=H,he.notFoundVisible=ue,he.loadingIsVisible=Y,he.positionDropdown=p,s()}function MdAutocomplete(e){return{controller:"MdAutocompleteCtrl",controllerAs:"$mdAutocompleteCtrl",scope:{inputName:"@mdInputName",inputMinlength:"@mdInputMinlength",inputMaxlength:"@mdInputMaxlength",searchText:"=?mdSearchText",selectedItem:"=?mdSelectedItem",itemsExpr:"@mdItems",itemText:"&mdItemText",placeholder:"@placeholder",noCache:"=?mdNoCache",requireMatch:"=?mdRequireMatch",selectOnMatch:"=?mdSelectOnMatch",matchInsensitive:"=?mdMatchCaseInsensitive",itemChange:"&?mdSelectedItemChange",textChange:"&?mdSearchTextChange",minLength:"=?mdMinLength",delay:"=?mdDelay",autofocus:"=?mdAutofocus",floatingLabel:"@?mdFloatingLabel",autoselect:"=?mdAutoselect",menuClass:"@?mdMenuClass",inputId:"@?mdInputId",escapeOptions:"@?mdEscapeOptions"},link:function(e,t,n,o){o.hasNotFound=!!t.attr("md-has-not-found")},template:function(t,n){function o(){var e=t.find("md-item-template").detach(),n=e.length?e.html():t.html();return e.length||t.empty(),"<md-autocomplete-parent-scope md-autocomplete-replace>"+n+"</md-autocomplete-parent-scope>"}function i(){var e=t.find("md-not-found").detach(),n=e.length?e.html():"";return n?'<li ng-if="$mdAutocompleteCtrl.notFoundVisible()" md-autocomplete-parent-scope>'+n+"</li>":""}function l(){return n.mdFloatingLabel?' <md-input-container ng-if="floatingLabel"> <label>{{floatingLabel}}</label> <input type="search" '+(null!=u?'tabindex="'+u+'"':"")+' id="{{ inputId || \'fl-input-\' + $mdAutocompleteCtrl.id }}" name="{{inputName}}" autocomplete="off" ng-required="$mdAutocompleteCtrl.isRequired" ng-readonly="$mdAutocompleteCtrl.isReadonly" ng-minlength="inputMinlength" ng-maxlength="inputMaxlength" ng-disabled="$mdAutocompleteCtrl.isDisabled" ng-model="$mdAutocompleteCtrl.scope.searchText" ng-model-options="{ allowInvalid: true }" ng-keydown="$mdAutocompleteCtrl.keydown($event)" ng-blur="$mdAutocompleteCtrl.blur($event)" ng-focus="$mdAutocompleteCtrl.focus($event)" aria-owns="ul-{{$mdAutocompleteCtrl.id}}" '+(null!=n.mdNoAsterisk?'md-no-asterisk="'+n.mdNoAsterisk+'"':"")+" "+(null!=n.mdSelectOnFocus?'md-select-on-focus=""':"")+' aria-label="{{floatingLabel}}" aria-autocomplete="list" role="combobox" aria-haspopup="true" aria-activedescendant="" aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/> <div md-autocomplete-parent-scope md-autocomplete-replace>'+c+"</div> </md-input-container>":' <input type="search" '+(null!=u?'tabindex="'+u+'"':"")+' id="{{ inputId || \'input-\' + $mdAutocompleteCtrl.id }}" name="{{inputName}}" ng-if="!floatingLabel" autocomplete="off" ng-required="$mdAutocompleteCtrl.isRequired" ng-disabled="$mdAutocompleteCtrl.isDisabled" ng-readonly="$mdAutocompleteCtrl.isReadonly" ng-model="$mdAutocompleteCtrl.scope.searchText" ng-keydown="$mdAutocompleteCtrl.keydown($event)" ng-blur="$mdAutocompleteCtrl.blur($event)" ng-focus="$mdAutocompleteCtrl.focus($event)" placeholder="{{placeholder}}" aria-owns="ul-{{$mdAutocompleteCtrl.id}}" '+(null!=n.mdSelectOnFocus?'md-select-on-focus=""':"")+' aria-label="{{placeholder}}" aria-autocomplete="list" role="combobox" aria-haspopup="true" aria-activedescendant="" aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/> <button type="button" tabindex="-1" ng-if="$mdAutocompleteCtrl.scope.searchText && !$mdAutocompleteCtrl.isDisabled" ng-click="$mdAutocompleteCtrl.clear($event)"> <md-icon md-svg-src="'+e.mdClose+'"></md-icon> <span class="md-visually-hidden">Clear</span> </button> '}var r=i(),a=o(),c=t.html(),u=n.tabindex;return r&&t.attr("md-has-not-found",!0),t.attr("tabindex","-1")," <md-autocomplete-wrap ng-class=\"{ 'md-whiteframe-z1': !floatingLabel, 'md-menu-showing': !$mdAutocompleteCtrl.hidden }\"> "+l()+' <md-progress-linear class="'+(n.mdFloatingLabel?"md-inline":"")+'" ng-if="$mdAutocompleteCtrl.loadingIsVisible()" md-mode="indeterminate"></md-progress-linear> <md-virtual-repeat-container md-auto-shrink md-auto-shrink-min="1" ng-mouseenter="$mdAutocompleteCtrl.listEnter()" ng-mouseleave="$mdAutocompleteCtrl.listLeave()" ng-mouseup="$mdAutocompleteCtrl.mouseUp()" ng-hide="$mdAutocompleteCtrl.hidden" class="md-autocomplete-suggestions-container md-whiteframe-z1" ng-class="{ \'md-not-found\': $mdAutocompleteCtrl.notFoundVisible() }" role="presentation"> <ul class="md-autocomplete-suggestions" ng-class="::menuClass" id="ul-{{$mdAutocompleteCtrl.id}}"> <li md-virtual-repeat="item in $mdAutocompleteCtrl.matches" ng-class="{ selected: $index === $mdAutocompleteCtrl.index }" ng-click="$mdAutocompleteCtrl.select($index)" md-extra-name="$mdAutocompleteCtrl.itemName"> '+a+" </li>"+r+' </ul> </md-virtual-repeat-container> </md-autocomplete-wrap> <aria-status class="md-visually-hidden" role="status" aria-live="assertive"> <p ng-repeat="message in $mdAutocompleteCtrl.messages track by $index" ng-if="message">{{message}}</p> </aria-status>'}}}function MdAutocompleteItemScopeDirective(e,t){function n(e,n,o){return function(e,n,i){function l(n,o){c[o]=e[n],e.$watch(n,function(e){t.nextTick(function(){c[o]=e})})}function r(){var t=!1,n=!1;e.$watch(function(){n||t||(t=!0,e.$$postDigest(function(){n||c.$digest(),t=n=!1}))}),c.$watch(function(){n=!0})}var a=e.$mdAutocompleteCtrl,c=a.parent.$new(),u=a.itemName;l("$index","$index"),l("item",u),r(),o(c,function(e){n.after(e)})}}return{restrict:"AE",compile:n,terminal:!0,transclude:"element"}}function MdHighlightCtrl(e,t,n){this.$scope=e,this.$element=t,this.$attrs=n,this.regex=null}function MdHighlight(e,t){return{terminal:!0,controller:"MdHighlightCtrl",compile:function(n,o){var i=t(o.mdHighlightText),l=e(n.html());return function(e,t,n,o){o.init(i,l)}}}}goog.provide("ngmaterial.components.autocomplete"),goog.require("ngmaterial.components.icon"),goog.require("ngmaterial.components.virtualRepeat"),goog.require("ngmaterial.core"),angular.module("material.components.autocomplete",["material.core","material.components.icon","material.components.virtualRepeat"]),MdAutocompleteCtrl.$inject=["$scope","$element","$mdUtil","$mdConstant","$mdTheming","$window","$animate","$rootElement","$attrs","$q","$log"],angular.module("material.components.autocomplete").controller("MdAutocompleteCtrl",MdAutocompleteCtrl);var ITEM_HEIGHT=41,MAX_HEIGHT=5.5*ITEM_HEIGHT,MENU_PADDING=8,INPUT_PADDING=2;MdAutocomplete.$inject=["$$mdSvgRegistry"],angular.module("material.components.autocomplete").directive("mdAutocomplete",MdAutocomplete),MdAutocompleteItemScopeDirective.$inject=["$compile","$mdUtil"],angular.module("material.components.autocomplete").directive("mdAutocompleteParentScope",MdAutocompleteItemScopeDirective),MdHighlightCtrl.$inject=["$scope","$element","$attrs"],angular.module("material.components.autocomplete").controller("MdHighlightCtrl",MdHighlightCtrl),MdHighlightCtrl.prototype.init=function(e,t){this.flags=this.$attrs.mdHighlightFlags||"",this.unregisterFn=this.$scope.$watch(function(n){return{term:e(n),contentText:t(n)}}.bind(this),this.onRender.bind(this),!0),this.$element.on("$destroy",this.unregisterFn)},MdHighlightCtrl.prototype.onRender=function(e,t){var n=e.contentText;null!==this.regex&&e.term===t.term||(this.regex=this.createRegex(e.term,this.flags)),e.term?this.applyRegex(n):this.$element.text(n)},MdHighlightCtrl.prototype.applyRegex=function(e){var t=this.resolveTokens(e);this.$element.empty(),t.forEach(function(e){if(e.isMatch){var t=angular.element('<span class="highlight">').text(e.text);this.$element.append(t)}else this.$element.append(document.createTextNode(e))}.bind(this))},MdHighlightCtrl.prototype.resolveTokens=function(e){function t(t,o){var i=e.slice(t,o);i&&n.push(i)}var n=[],o=0;return e.replace(this.regex,function(e,i){t(o,i),n.push({text:e,isMatch:!0}),o=i+e.length}),t(o),n},MdHighlightCtrl.prototype.createRegex=function(e,t){var n="",o="",i=this.sanitizeRegex(e);return t.indexOf("^")>=0&&(n="^"),t.indexOf("$")>=0&&(o="$"),new RegExp(n+i+o,t.replace(/[$\^]/g,""))},MdHighlightCtrl.prototype.sanitizeRegex=function(e){return e&&e.toString().replace(/[\\\^\$\*\+\?\.\(\)\|\{}\[\]]/g,"\\$&")},MdHighlight.$inject=["$interpolate","$parse"],angular.module("material.components.autocomplete").directive("mdHighlightText",MdHighlight),ngmaterial.components.autocomplete=angular.module("material.components.autocomplete");