7 lines
No EOL
13 KiB
JavaScript
7 lines
No EOL
13 KiB
JavaScript
/*!
|
|
* Angular Material Design
|
|
* https://github.com/angular/material
|
|
* @license MIT
|
|
* v0.10.1
|
|
*/
|
|
!function(e,t,n){"use strict";function o(e,o,i,l,a,r,c,m,s,p){function h(){i.initOptionalProperties(e,s,{searchText:null,selectedItem:null}),a(o),x(),i.nextTick(function(){v(),$(),g()})}function f(){function e(){var e=ne.ul.getBoundingClientRect(),n={};e.right>o.right-d&&(n.left=t.right-e.width+"px"),ne.$.ul.css(n)}if(!ne)return i.nextTick(f,!1);var t=ne.wrap.getBoundingClientRect(),n=ne.snap.getBoundingClientRect(),o=ne.root.getBoundingClientRect(),l=n.bottom-o.top,a=o.bottom-n.top,r=t.left-o.left,c=t.width,m={left:r+"px",minWidth:c+"px",maxWidth:Math.max(t.right-o.left,o.right-t.left)-d+"px"};l>a&&o.height-t.bottom-d<u?(m.top="auto",m.bottom=a+"px",m.maxHeight=Math.min(u,t.top-o.top-d)+"px"):(m.top=l+"px",m.bottom="auto",m.maxHeight=Math.min(u,o.bottom-t.bottom-d)+"px"),ne.$.ul.css(m),i.nextTick(e,!1)}function g(){ne.$.root.length&&(a(ne.$.ul),ne.$.ul.detach(),ne.$.root.append(ne.$.ul),c.pin&&c.pin(ne.$.ul,m))}function $(){e.autofocus&&ne.input.focus()}function x(){var n=parseInt(e.delay,10)||0;s.$observe("disabled",function(e){Z.isDisabled=e}),s.$observe("required",function(e){Z.isRequired=null!==e}),e.$watch("searchText",n?i.debounce(R,n):R),e.$watch("selectedItem",I),t.element(r).on("resize",f),e.$on("$destroy",C)}function C(){t.element(r).off("resize",f),ne.$.ul.remove()}function v(){ne={main:o[0],ul:o.find("ul")[0],input:o.find("input")[0],wrap:o.find("md-autocomplete-wrap")[0],root:document.body},ne.li=ne.ul.getElementsByTagName("li"),ne.snap=A(),ne.$=b(ne)}function A(){for(var e=o;e.length;e=e.parent())if(t.isDefined(e.attr("md-autocomplete-snap")))return e[0];return ne.wrap}function b(e){var n={};for(var o in e)e.hasOwnProperty(o)&&(n[o]=t.element(e[o]));return n}function w(e,t){!e&&t?(f(),ne&&i.nextTick(function(){i.disableScrollAround(ne.ul)},!1)):e&&!t&&i.nextTick(function(){i.enableScrolling()},!1)}function T(){ie=!0}function y(){ie=!1,ae||(Z.hidden=!0)}function E(){ne.input.focus()}function I(t,n){t&&H(t).then(function(o){e.searchText=o,D(t,n)}),t!==n&&k()}function k(){t.isFunction(e.itemChange)&&e.itemChange(_(e.selectedItem))}function M(){t.isFunction(e.textChange)&&e.textChange()}function D(e,t){le.forEach(function(n){n(e,t)})}function L(e){-1==le.indexOf(e)&&le.push(e)}function O(e){var t=le.indexOf(e);-1!=t&&le.splice(t,1)}function R(t,n){Z.index=U(),t!==n&&H(e.selectedItem).then(function(o){t!==o&&(e.selectedItem=null,t!==n&&M(),j()?Q():(Z.loading=!1,Z.matches=[],Z.hidden=W(),V()))})}function N(){ae=!1,ie||(Z.hidden=!0)}function S(){ae=!0,t.isString(e.searchText)||(e.searchText=""),e.minLength>0||(Z.hidden=W(),Z.hidden||Q())}function P(e){switch(e.keyCode){case l.KEY_CODE.DOWN_ARROW:if(Z.loading)return;e.stopPropagation(),e.preventDefault(),Z.index=Math.min(Z.index+1,Z.matches.length-1),J(),V();break;case l.KEY_CODE.UP_ARROW:if(Z.loading)return;e.stopPropagation(),e.preventDefault(),Z.index=Z.index<0?Z.matches.length-1:Math.max(0,Z.index-1),J(),V();break;case l.KEY_CODE.TAB:case l.KEY_CODE.ENTER:if(Z.hidden||Z.loading||Z.index<0||Z.matches.length<1)return;e.stopPropagation(),e.preventDefault(),Y(Z.index);break;case l.KEY_CODE.ESCAPE:e.stopPropagation(),e.preventDefault(),z(),Z.matches=[],Z.hidden=!0,Z.index=U()}}function q(){return t.isNumber(e.minLength)?e.minLength:1}function H(t){function n(t){return t&&e.itemText?e.itemText(_(t)):null}return p.when(n(t)||t)}function _(e){if(!e)return n;var t={};return Z.itemName&&(t[Z.itemName]=e),t}function U(){return e.autoselect?0:-1}function W(){return j()&&Z.matches.length?void 0:!0}function B(){return H(Z.matches[Z.index])}function j(){return t.isDefined(e.searchText)&&e.searchText.length>=q()}function K(e,t,n){Object.defineProperty(Z,e,{get:function(){return n},set:function(e){var o=n;n=e,t(e,o)}})}function Y(t){i.nextTick(function(){H(Z.matches[t]).then(function(e){var t=ne.$.input.controller("ngModel");t.$setViewValue(e),t.$render()})["finally"](function(){e.selectedItem=Z.matches[t],Z.loading=!1,Z.hidden=!0,Z.index=0,Z.matches=[]})},!1)}function z(){e.searchText="",Y(-1);var t=document.createEvent("CustomEvent");t.initCustomEvent("input",!0,!0,{value:e.searchText}),ne.input.dispatchEvent(t),ne.input.focus()}function F(n){function o(t){oe[a]=t,n===e.searchText&&(Z.matches=t,Z.hidden=W(),e.selectOnMatch&&X(),V(),f())}var l=e.$parent.$eval(te),a=n.toLowerCase();t.isArray(l)?o(l):l&&i.nextTick(function(){Z.loading=!0,l.success&&l.success(o),l.then&&l.then(o),l["finally"]&&l["finally"](function(){Z.loading=!1})})}function V(){B().then(function(e){Z.messages=[G(),e]})}function G(){if(re===Z.matches.length)return"";switch(re=Z.matches.length,Z.matches.length){case 0:return"There are no matches available.";case 1:return"There is 1 match available.";default:return"There are "+Z.matches.length+" matches available."}}function J(){if(ne.li[Z.index]){var e=ne.li[Z.index],t=e.offsetTop,n=t+e.offsetHeight,o=ne.ul.clientHeight;t<ne.ul.scrollTop?ne.ul.scrollTop=t:n>ne.ul.scrollTop+o&&(ne.ul.scrollTop=n-o)}}function Q(){var t=e.searchText,n=t.toLowerCase();!e.noCache&&oe[n]?(Z.matches=oe[n],V()):F(t),ae&&(Z.hidden=W())}function X(){var t=e.searchText,n=Z.matches,o=n[0];1===n.length&&H(o).then(function(e){t==e&&Y(0)})}var Z=this,ee=e.itemsExpr.split(/ in /i),te=ee[1],ne=null,oe={},ie=!1,le=[],ae=!1,re=0;return K("hidden",w,!0),Z.scope=e,Z.parent=e.$parent,Z.itemName=ee[0],Z.matches=[],Z.loading=!1,Z.hidden=!0,Z.index=null,Z.messages=[],Z.id=i.nextUid(),Z.isDisabled=null,Z.isRequired=null,Z.keydown=P,Z.blur=N,Z.focus=S,Z.clear=z,Z.select=Y,Z.listEnter=T,Z.listLeave=y,Z.mouseUp=E,Z.getCurrentDisplayValue=B,Z.registerSelectedItemWatcher=L,Z.unregisterSelectedItemWatcher=O,h()}function i(){return{controller:"MdAutocompleteCtrl",controllerAs:"$mdAutocompleteCtrl",scope:{inputName:"@mdInputName",inputMinlength:"@mdInputMinlength",inputMaxlength:"@mdInputMaxlength",searchText:"=?mdSearchText",selectedItem:"=?mdSelectedItem",itemsExpr:"@mdItems",itemText:"&mdItemText",placeholder:"@placeholder",noCache:"=?mdNoCache",selectOnMatch:"=?mdSelectOnMatch",itemChange:"&?mdSelectedItemChange",textChange:"&?mdSearchTextChange",minLength:"=?mdMinLength",delay:"=?mdDelay",autofocus:"=?mdAutofocus",floatingLabel:"@?mdFloatingLabel",autoselect:"=?mdAutoselect",menuClass:"@?mdMenuClass",inputId:"@?mdInputId"},template:function(e,t){function n(){var t=e.find("md-item-template").remove(),n=t.length?t.html():e.html();return t.length||e.empty(),n}function o(){var t=e.find("md-not-found").remove(),n=t.length?t.html():"";return n?'<li ng-if="!$mdAutocompleteCtrl.matches.length && !$mdAutocompleteCtrl.loading && !$mdAutocompleteCtrl.hidden" ng-hide="$mdAutocompleteCtrl.hidden" md-autocomplete-parent-scope>'+n+"</li>":""}function i(){return t.mdFloatingLabel?' <md-input-container flex ng-if="floatingLabel"> <label>{{floatingLabel}}</label> <input type="search" id="{{ inputId || \'fl-input-\' + $mdAutocompleteCtrl.id }}" name="{{inputName}}" autocomplete="off" ng-required="$mdAutocompleteCtrl.isRequired" ng-minlength="inputMinlength" ng-maxlength="inputMaxlength" ng-disabled="$mdAutocompleteCtrl.isDisabled" ng-model="$mdAutocompleteCtrl.scope.searchText" ng-keydown="$mdAutocompleteCtrl.keydown($event)" ng-blur="$mdAutocompleteCtrl.blur()" ng-focus="$mdAutocompleteCtrl.focus()" aria-owns="ul-{{$mdAutocompleteCtrl.id}}" aria-label="{{floatingLabel}}" aria-autocomplete="list" aria-haspopup="true" aria-activedescendant="" aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/> <div md-autocomplete-parent-scope md-autocomplete-replace>'+r+"</div> </md-input-container>":' <input flex type="search" id="{{ inputId || \'input-\' + $mdAutocompleteCtrl.id }}" name="{{inputName}}" ng-if="!floatingLabel" autocomplete="off" ng-required="$mdAutocompleteCtrl.isRequired" ng-disabled="$mdAutocompleteCtrl.isDisabled" ng-model="$mdAutocompleteCtrl.scope.searchText" ng-keydown="$mdAutocompleteCtrl.keydown($event)" ng-blur="$mdAutocompleteCtrl.blur()" ng-focus="$mdAutocompleteCtrl.focus()" placeholder="{{placeholder}}" aria-owns="ul-{{$mdAutocompleteCtrl.id}}" aria-label="{{placeholder}}" aria-autocomplete="list" 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()"> <md-icon md-svg-icon="md-close"></md-icon> <span class="md-visually-hidden">Clear</span> </button> '}var l=o(),a=n(),r=e.html();return' <md-autocomplete-wrap layout="row" ng-class="{ \'md-whiteframe-z1\': !floatingLabel, \'md-menu-showing\': !$mdAutocompleteCtrl.hidden }" role="listbox"> '+i()+' <md-progress-linear ng-if="$mdAutocompleteCtrl.loading && !$mdAutocompleteCtrl.hidden" md-mode="indeterminate"></md-progress-linear> <ul role="presentation" class="md-autocomplete-suggestions md-whiteframe-z1 {{menuClass || \'\'}}" id="ul-{{$mdAutocompleteCtrl.id}}" ng-hide="$mdAutocompleteCtrl.hidden" ng-mouseenter="$mdAutocompleteCtrl.listEnter()" ng-mouseleave="$mdAutocompleteCtrl.listLeave()" ng-mouseup="$mdAutocompleteCtrl.mouseUp()"> <li ng-repeat="(index, item) in $mdAutocompleteCtrl.matches" ng-class="{ selected: index === $mdAutocompleteCtrl.index }" ng-click="$mdAutocompleteCtrl.select(index)" md-autocomplete-list-item="$mdAutocompleteCtrl.itemName"> '+a+" </li> "+l+' </ul> </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,n,o){function i(e,t){l(e,t),n.on("$destroy",a)}function l(t,n){function i(){return o(n)(e)}u.watchers.push(e.$watch(t,function(e){u.term=e,r(e,u.template)})),u.watchers.push(e.$watch(i,function(e){u.template=e,r(u.term,e)}))}function a(){u.watchers.forEach(function(e){e()})}function r(){if(null!==u.term&&null!==u.template){var i=o(u.template)(e),l=t.element("<div>").text(i).html(),a=n.attr("md-highlight-flags")||"",r=m(u.term,a),c=l.replace(r,'<span class="highlight">$&</span>');n.html(c)}}function c(e){return e?e.replace(/[\\\^\$\*\+\?\.\(\)\|\{}\[\]]/g,"\\$&"):e}function m(e,t){var n="";return t.indexOf("^")>=1&&(n+="^"),n+=e,t.indexOf("$")>=1&&(n+="$"),new RegExp(c(n),t.replace(/[\$\^]/g,""))}var u=this;u.term=null,u.template=null,u.watchers=[],u.init=i}function a(){return{terminal:!0,scope:!1,controller:"MdHighlightCtrl",compile:function(e,t){var n=e.html();return function(e,t,o,i){i.init(o.mdHighlightText,n)}}}}function r(e,t){function n(n,o,i){var l=n.$parent.$mdAutocompleteCtrl,a=l.parent.$new(!1,l.parent),r=l.scope.$eval(i.mdAutocompleteListItem);a[r]=n.item,e(o.contents())(a),o.attr({role:"option",id:"item_"+t.nextUid()})}return{terminal:!0,link:n,scope:!1}}function c(e){function t(t,n,o){var i=t.$parent.$mdAutocompleteCtrl;e(n.contents())(i.parent),o.hasOwnProperty("mdAutocompleteReplace")&&(n.after(n.contents()),n.remove())}return{restrict:"A",terminal:!0,link:t,scope:!1}}t.module("material.components.autocomplete",["material.core","material.components.icon"]),t.module("material.components.autocomplete").controller("MdAutocompleteCtrl",o);var m=41,u=5.5*m,d=8;o.$inject=["$scope","$element","$mdUtil","$mdConstant","$mdTheming","$window","$animate","$rootElement","$attrs","$q"],t.module("material.components.autocomplete").directive("mdAutocomplete",i),t.module("material.components.autocomplete").controller("MdHighlightCtrl",l),l.$inject=["$scope","$element","$interpolate"],t.module("material.components.autocomplete").directive("mdHighlightText",a),t.module("material.components.autocomplete").directive("mdAutocompleteListItem",r),r.$inject=["$compile","$mdUtil"],t.module("material.components.autocomplete").directive("mdAutocompleteParentScope",c),c.$inject=["$compile"]}(window,window.angular); |