|
|
/*! * Angular Material Design * https://github.com/angular/material
* @license MIT * v1.1.0-master-2b98560 */ !function(e,t,n){"use strict";function o(e,o,i,l,r,a,c,d,p,h,f){function g(){i.initOptionalProperties(e,p,{searchText:"",selectedItem:null}),r(o),b(),i.nextTick(function(){w(),v(),e.autofocus&&o.on("focus",C)})}function $(){e.requireMatch&&Me&&Me.$setValidity("md-require-match",!!e.selectedItem)}function x(){function t(){var e=0,t=o.find("md-input-container");if(t.length){var n=t.find("input");e=t.prop("offsetHeight"),e-=n.prop("offsetTop"),e-=n.prop("offsetHeight"),e+=t.prop("offsetTop")}return e}function n(){var e=Ae.scrollContainer.getBoundingClientRect(),t={};e.right>c.right-s&&(t.left=r.right-e.width+"px"),Ae.$.scrollContainer.css(t)}if(!Ae)return i.nextTick(x,!1,e);var l,r=Ae.wrap.getBoundingClientRect(),a=Ae.snap.getBoundingClientRect(),c=Ae.root.getBoundingClientRect(),d=a.bottom-c.top,h=c.bottom-a.top,f=r.left-c.left,g=r.width,$=t();p.mdFloatingLabel&&(f+=m,g-=2*m),l={left:f+"px",minWidth:g+"px",maxWidth:Math.max(r.right-c.left,c.right-r.left)-s+"px"},d>h&&c.height-r.bottom-s<u?(l.top="auto",l.bottom=h+"px",l.maxHeight=Math.min(u,r.top-c.top-s)+"px"):(l.top=d-$+"px",l.bottom="auto",l.maxHeight=Math.min(u,c.bottom+i.scrollTop()-r.bottom-s)+"px"),Ae.$.scrollContainer.css(l),i.nextTick(n,!1)}function v(){Ae.$.root.length&&(r(Ae.$.scrollContainer),Ae.$.scrollContainer.detach(),Ae.$.root.append(Ae.$.scrollContainer),c.pin&&c.pin(Ae.$.scrollContainer,d))}function C(){Ae.input.focus()}function b(){var n=parseInt(e.delay,10)||0;p.$observe("disabled",function(e){ve.isDisabled=i.parseAttributeBoolean(e,!1)}),p.$observe("required",function(e){ve.isRequired=i.parseAttributeBoolean(e,!1)}),p.$observe("readonly",function(e){ve.isReadonly=i.parseAttributeBoolean(e,!1)}),e.$watch("searchText",n?i.debounce(q,n):q),e.$watch("selectedItem",O),t.element(a).on("resize",x),e.$on("$destroy",A)}function A(){if(ve.hidden||i.enableScrolling(),t.element(a).off("resize",x),Ae){var e=["ul","scroller","scrollContainer","input"];t.forEach(e,function(e){Ae.$[e].remove()})}}function w(){Ae={main:o[0],scrollContainer:o[0].querySelector(".md-virtual-repeat-container"),scroller:o[0].querySelector(".md-virtual-repeat-scroller"),ul:o.find("ul")[0],input:o.find("input")[0],wrap:o.find("md-autocomplete-wrap")[0],root:document.body},Ae.li=Ae.ul.getElementsByTagName("li"),Ae.snap=T(),Ae.$=y(Ae),Me=Ae.$.input.controller("ngModel")}function T(){for(var e=o;e.length;e=e.parent())if(t.isDefined(e.attr("md-autocomplete-snap")))return e[0];return Ae.wrap}function y(e){var n={};for(var o in e)e.hasOwnProperty(o)&&(n[o]=t.element(e[o]));return n}function E(e,n){!e&&n?(x(),Ae&&(i.disableScrollAround(Ae.ul),ke=I(t.element(Ae.wrap)))):e&&!n&&(i.enableScrolling(),ke&&(ke(),ke=null))}function I(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 R(){Te=!0}function k(){Ee||ve.hidden||Ae.input.focus(),Te=!1,ve.hidden=K()}function M(){Ae.input.focus()}function O(t,n){$(),t?_(t).then(function(o){e.searchText=o,N(t,n)}):n&&e.searchText&&_(n).then(function(t){t.toString().toLowerCase()===e.searchText.toLowerCase()&&(e.searchText="")}),t!==n&&L()}function L(){t.isFunction(e.itemChange)&&e.itemChange(j(e.selectedItem))}function D(){t.isFunction(e.textChange)&&e.textChange()}function N(e,t){ye.forEach(function(n){n(e,t)})}function S(e){ye.indexOf(e)==-1&&ye.push(e)}function F(e){var t=ye.indexOf(e);t!=-1&&ye.splice(t,1)}function q(t,n){ve.index=z(),t!==n&&($(),_(e.selectedItem).then(function(o){t!==o&&(e.selectedItem=null,t!==n&&D(),ne()?fe():(ve.matches=[],U(!1),ue()))}))}function H(e){Ee=!1,Te||(ve.hidden=K(),xe("ngBlur",{$event:e}))}function P(e){e&&(Te=!1,Ee=!1),Ae.input.blur()}function B(e){Ee=!0,Y()&&ne()&&fe(),ve.hidden=K(),xe("ngFocus",{$event:e})}function V(t){switch(t.keyCode){case l.KEY_CODE.DOWN_ARROW:if(ve.loading)return;t.stopPropagation(),t.preventDefault(),ve.index=Math.min(ve.index+1,ve.matches.length-1),me(),ue();break;case l.KEY_CODE.UP_ARROW:if(ve.loading)return;t.stopPropagation(),t.preventDefault(),ve.index=ve.index<0?ve.matches.length-1:Math.max(0,ve.index-1),me(),ue();break;case l.KEY_CODE.TAB:if(k(),ve.hidden||ve.loading||ve.index<0||ve.matches.length<1)return;ie(ve.index);break;case l.KEY_CODE.ENTER:if(ve.hidden||ve.loading||ve.index<0||ve.matches.length<1)return;if(Z())return;t.stopPropagation(),t.preventDefault(),ie(ve.index);break;case l.KEY_CODE.ESCAPE:if(t.preventDefault(),!G())return;t.stopPropagation(),re(),e.searchText&&J("clear")&&ae(),ve.hidden=!0,J("blur")&&P(!0)}}function W(){return t.isNumber(e.minLength)?e.minLength:1}function _(n){function o(t){return t&&e.itemText?e.itemText(j(t)):null}return h.when(o(n)||n).then(function(e){return e&&!t.isString(e)&&f.warn("md-autocomplete: Could not resolve display value to a string. Please check the `md-item-text` attribute."),e})}function j(e){if(!e)return n;var t={};return ve.itemName&&(t[ve.itemName]=e),t}function z(){return e.autoselect?0:-1}function U(e){ve.loading!=e&&(ve.loading=e),ve.hidden=K()}function K(){return!Y()||!Q()}function Y(){return!(ve.loading&&!X())&&(!Z()&&!!Ee)}function G(){return J("blur")||!ve.hidden||ve.loading||J("clear")&&e.searchText}function J(t){return!e.escapeOptions||e.escapeOptions.toLowerCase().indexOf(t)!==-1}function Q(){return ne()&&X()||he()}function X(){return!!ve.matches.length}function Z(){return!!ve.scope.selectedItem}function ee(){return ve.loading&&!Z()}function te(){return _(ve.matches[ve.index])}function ne(){return(e.searchText||"").length>=W()}function oe(e,t,n){Object.defineProperty(ve,e,{get:function(){return n},set:function(e){var o=n;n=e,t(e,o)}})}function ie(t){i.nextTick(function(){_(ve.matches[t]).then(function(e){var t=Ae.$.input.controller("ngModel");t.$setViewValue(e),t.$render()})["finally"](function(){e.selectedItem=ve.matches[t],U(!1)})},!1)}function le(){re(),ae()}function re(){ve.index=0,ve.matches=[]}function ae(){U(!0),e.searchText="";var t=document.createEvent("CustomEvent");t.initCustomEvent("change",!0,!0,{value:""}),Ae.input.dispatchEvent(t),Ae.input.blur(),e.searchText="",Ae.input.focus()}function ce(n){function o(t){t&&(t=h.when(t),Re++,U(!0),i.nextTick(function(){t.then(l)["finally"](function(){0===--Re&&U(!1)})},!0,e))}function l(t){we[a]=t,(n||"")===(e.searchText||"")&&ge(t)}var r=e.$parent.$eval(be),a=n.toLowerCase(),c=t.isArray(r),u=!!r.then;c?l(r):u&&o(r)}function ue(){te().then(function(e){ve.messages=[se(),e]})}function se(){if(Ie===ve.matches.length)return"";switch(Ie=ve.matches.length,ve.matches.length){case 0:return"There are no matches available.";case 1:return"There is 1 match available.";default:return"There are "+ve.matches.length+" matches available."}}function me(){if(Ae.li[0]){var e=Ae.li[0].offsetHeight,t=e*ve.index,n=t+e,o=Ae.scroller.clientHeight,i=Ae.scroller.scrollTop;t<i?pe(t):n>i+o&&pe(n-o)}}function de(){return 0!==Re}function pe(e){Ae.$.scrollContainer.controller("mdVirtualRepeatContainer").scrollTo(e)}function he(){var e=(ve.scope.searchText||"").length;return ve.hasNotFound&&!X()&&(!ve.loading||de())&&e>=W()&&(Ee||Te)&&!Z()}function fe(){var t=e.searchText||"",n=t.toLowerCase();!e.noCache&&we[n]?ge(we[n]):ce(t),ve.hidden=K()}function ge(t){ve.matches=t,ve.hidden=K(),ve.loading&&U(!1),e.selectOnMatch&&$e(),ue(),x()}function $e(){var t=e.searchText,n=ve.matches,o=n[0];1===n.length&&_(o).then(function(n){var o=t==n;e.matchInsensitive&&!o&&(o=t.toLowerCase()==n.toLowerCase()),o&&ie(0)})}function xe(t,n){p[t]&&e.$parent.$eval(p[t],n||{})}var ve=this,Ce=e.itemsExpr.split(/ in /i),be=Ce[1],Ae=null,we={},Te=!1,ye=[],Ee=!1,Ie=0,Re=0,ke=null,Me=null;return oe("hidden",E,!0),ve.scope=e,ve.parent=e.$parent,ve.itemName=Ce[0],ve.matches=[],ve.loading=!1,ve.hidden=!0,ve.index=null,ve.messages=[],ve.id=i.nextUid(),ve.isDisabled=null,ve.isRequired=null,ve.isReadonly=null,ve.hasNotFound=!1,ve.keydown=V,ve.blur=H,ve.focus=B,ve.clear=le,ve.select=ie,ve.listEnter=R,ve.listLeave=k,ve.mouseUp=M,ve.getCurrentDisplayValue=te,ve.registerSelectedItemWatcher=S,ve.unregisterSelectedItemWatcher=F,ve.notFoundVisible=he,ve.loadingIsVisible=ee,ve.positionDropdown=x,g()}function i(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 l(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 r(e,t,n){this.$scope=e,this.$element=t,this.$attrs=n,this.regex=null}function a(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)}}}}t.module("material.components.autocomplete",["material.core","material.components.icon","material.components.virtualRepeat"]),o.$inject=["$scope","$element","$mdUtil","$mdConstant","$mdTheming","$window","$animate","$rootElement","$attrs","$q","$log"],t.module("material.components.autocomplete").controller("MdAutocompleteCtrl",o);var c=41,u=5.5*c,s=8,m=2;i.$inject=["$$mdSvgRegistry"],t.module("material.components.autocomplete").directive("mdAutocomplete",i),l.$inject=["$compile","$mdUtil"],t.module("material.components.autocomplete").directive("mdAutocompleteParentScope",l),r.$inject=["$scope","$element","$attrs"],t.module("material.components.autocomplete").controller("MdHighlightCtrl",r),r.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)},r.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)},r.prototype.applyRegex=function(e){var n=this.resolveTokens(e);this.$element.empty(),n.forEach(function(e){if(e.isMatch){var n=t.element('<span class="highlight">').text(e.text);this.$element.append(n)}else this.$element.append(document.createTextNode(e))}.bind(this))},r.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},r.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,""))},r.prototype.sanitizeRegex=function(e){return e&&e.toString().replace(/[\\\^\$\*\+\?\.\(\)\|\{}\[\]]/g,"\\$&")},a.$inject=["$interpolate","$parse"],t.module("material.components.autocomplete").directive("mdHighlightText",a)}(window,window.angular);
|