select.min.js 16 KB

1234567
  1. /*!
  2. * Angular Material Design
  3. * https://github.com/angular/material
  4. * @license MIT
  5. * v0.11.3-master-3fe7d76
  6. */
  7. !function(e,t,n){"use strict";function o(e,o,r,i,l,a){function d(d,s){var c=t.element("<md-select-value><span></span></md-select-value>");if(c.append('<span class="md-select-icon" aria-hidden="true"></span>'),c.addClass("md-select-value"),c[0].hasAttribute("id")||c.attr("id","select_value_label_"+o.nextUid()),d.find("md-content").length||d.append(t.element("<md-content>").append(d.contents())),s.mdOnOpen&&(d.find("md-content").prepend(t.element('<div> <md-progress-circular md-mode="{{progressMode}}" ng-hide="$$loadingAsyncDone"></md-progress-circular></div>')),d.find("md-option").attr("ng-show","$$loadingAsyncDone")),s.name){var u=t.element('<select class="md-visually-hidden">');u.attr({name:"."+s.name,"ng-model":s.ngModel,"aria-hidden":"true",tabindex:"-1"});var f=d.find("md-option");t.forEach(f,function(e){var n=t.element("<option>"+e.innerHTML+"</option>");e.hasAttribute("ng-value")?n.attr("ng-value",e.getAttribute("ng-value")):e.hasAttribute("value")&&n.attr("value",e.getAttribute("value")),u.append(n)}),d.parent().append(u)}var p=t.isDefined(s.multiple)?"multiple":"",m='<div class="md-select-menu-container"><md-select-menu {0}>{1}</md-select-menu></div>';return m=o.supplant(m,[p,d.html()]),d.empty().append(c),s.tabindex=s.tabindex||"0",function(d,s,c,u){function f(){var e=s.attr("placeholder");!e&&y&&y.label&&(e=y.label.text()),i.expect(s,"aria-label",e)}function p(){A&&(E=E||A.find("md-select-menu").controller("mdSelectMenu"),w.setLabelText(E.selectedLabels()))}function h(){y&&y.setHasValue(E.selectedLabels().length>0||(s[0].validity||{}).badInput)}function g(){A=t.element(m);var e=A.find("md-select-menu");if(e.data("$ngModelController",C),e.data("$mdSelectController",w),O=d.$new(),r.inherit(A,s),s.attr("md-container-class")){var n=A[0].getAttribute("class")+" "+s.attr("md-container-class");A[0].setAttribute("class",n)}A=l(A)(O),E=A.find("md-select-menu").controller("mdSelectMenu")}function v(e){var n=[32,13,38,40];if(-1!=n.indexOf(e.keyCode))e.preventDefault(),b(e);else if(e.keyCode<=90&&e.keyCode>=31){e.preventDefault();var o=E.optNodeForKeyboardSearch(e);if(!o)return;var r=t.element(o).controller("mdOption");E.isMultiple||E.deselect(Object.keys(E.selected)[0]),E.select(r.hashKey,r.value),E.refreshViewValue(),C.$render()}}function b(){O.isOpen=!0,e.show({scope:O,preserveScope:!0,skipCompile:!0,element:A,target:s[0],hasBackdrop:!0,loadingAsync:c.mdOnOpen?d.$eval(c.mdOnOpen)||!0:!1}).then(function(){O.isOpen=!1})}var $,y=u[0],w=u[1],C=u[2],k=u[3],M=s.find("md-select-value"),x=t.isDefined(c.readonly);if(y){var S=y.isErrorGetter||function(){return C.$invalid&&C.$touched};if(y.input)throw new Error("<md-input-container> can only have *one* child <input>, <textarea> or <select> element!");y.input=s,y.label||i.expect(s,"aria-label",s.attr("placeholder")),d.$watch(S,y.setInvalid)}var A,O,E;if(g(),r(s),c.name&&k){var D=s.parent()[0].querySelector('select[name=".'+c.name+'"]'),T=t.element(D).controller();T&&k.$removeControl(T)}k&&o.nextTick(function(){k.$setPristine()});var R=C.$render;C.$render=function(){R(),p(),h()},c.$observe("placeholder",C.$render),w.setLabelText=function(e){w.setIsPlaceholder(!e);var t=c.placeholder||(y&&y.label?y.label.text():"");e=e||t||"";var n=M.children().eq(0);n.text(e)},w.setIsPlaceholder=function(e){e?(M.addClass("md-select-placeholder"),y&&y.label&&y.label.addClass("md-placeholder md-static")):(M.removeClass("md-select-placeholder"),y&&y.label&&y.label.removeClass("md-placeholder"))},x||s.on("focus",function(e){y&&y.element.hasClass("md-input-has-value")&&y.setFocused(!0)}).on("blur",function(e){y&&y.setFocused(!1),h()}),w.triggerClose=function(){a(c.mdOnClose)(d)},d.$$postDigest(function(){f(),p()});var V;c.$observe("ngMultiple",function(e){V&&V();var t=a(e);V=d.$watch(function(){return t(d)},function(e,t){(e!==n||t!==n)&&(e?s.attr("multiple","multiple"):s.removeAttr("multiple"),A&&(E.setMultiple(e),R=C.$render,C.$render=function(){R(),p()},E.refreshViewValue(),C.$render()))})}),c.$observe("disabled",function(e){t.isString(e)&&(e=!0),($===n||$!==e)&&($=e,e?(s.attr({tabindex:-1,"aria-disabled":"true"}),s.off("click",b),s.off("keydown",v)):(s.attr({tabindex:c.tabindex,"aria-disabled":"false"}),s.on("click",b),s.on("keydown",v)))}),c.disabled||c.ngDisabled||(s.attr({tabindex:c.tabindex,"aria-disabled":"false"}),s.on("click",b),s.on("keydown",v));var B={role:"combobox","aria-expanded":"false"};s[0].hasAttribute("id")||(B.id="select_"+o.nextUid()),s.attr(B),d.$on("$destroy",function(){e.destroy()["finally"](function(){A&&A.remove(),y&&(y.setFocused(!1),y.setHasValue(!1),y.input=null)})})}}return{restrict:"E",require:["^?mdInputContainer","mdSelect","ngModel","?^form"],compile:d,controller:function(){}}}function r(e,o,r){function i(e,n,i,l){function a(){n.attr({id:"select_menu_"+o.nextUid(),role:"listbox","aria-multiselectable":c.isMultiple?"true":"false"})}function d(e){(13==e.keyCode||32==e.keyCode)&&s(e)}function s(n){var r=o.getClosest(n.target,"md-option"),i=r&&t.element(r).data("$mdOptionController");if(r&&i){if(r.hasAttribute("disabled"))return n.stopImmediatePropagation(),!1;var l=c.hashGetter(i.value),a=t.isDefined(c.selected[l]);e.$apply(function(){c.isMultiple?a?c.deselect(l):c.select(l,i.value):a||(c.deselect(Object.keys(c.selected)[0]),c.select(l,i.value)),c.refreshViewValue()})}}var c=l[0],u=l[1];r(n),n.on("click",s),n.on("keypress",d),u&&c.init(u),a()}function l(r,i,l){function a(){var e=c.ngModel.$modelValue||c.ngModel.$viewValue||[];if(t.isArray(e)){var n=Object.keys(c.selected),o=e.map(c.hashGetter),r=n.filter(function(e){return-1===o.indexOf(e)});r.forEach(c.deselect),o.forEach(function(t,n){c.select(t,e[n])})}}function d(){var e=c.ngModel.$viewValue||c.ngModel.$modelValue;Object.keys(c.selected).forEach(c.deselect),c.select(c.hashGetter(e),e)}var c=this;c.isMultiple=t.isDefined(i.multiple),c.selected={},c.options={},r.$watch(function(){return c.options},function(){c.ngModel.$render()},!0);var u;c.setMultiple=function(e){function n(e,n){return t.isArray(e||n||[])}var o=c.ngModel;c.isMultiple=e,u&&u(),c.isMultiple?(o.$validators["md-multiple"]=n,o.$render=a,r.$watchCollection(i.ngModel,function(e){n(e)&&a(e),c.ngModel.$setPristine()})):(delete o.$validators["md-multiple"],o.$render=d)};var f,p,m,h="",g=300;c.optNodeForKeyboardSearch=function(e){f&&clearTimeout(f),f=setTimeout(function(){f=n,h="",m=n,p=n},g),h+=String.fromCharCode(e.keyCode);var o=new RegExp("^"+h,"i");p||(p=l.find("md-option"),m=new Array(p.length),t.forEach(p,function(e,t){m[t]=e.textContent.trim()}));for(var r=0;r<m.length;++r)if(o.test(m[r]))return p[r]},c.init=function(n){if(c.ngModel=n,n.$options&&n.$options.trackBy){var o={},i=e(n.$options.trackBy);c.hashGetter=function(e,t){return o.$value=e,i(t||r,o)}}else c.hashGetter=function(e){return t.isObject(e)?"object_"+(e.$$mdSelectId||(e.$$mdSelectId=++s)):e};c.setMultiple(c.isMultiple)},c.selectedLabels=function(){var e=o.nodesToArray(l[0].querySelectorAll("md-option[selected]"));return e.length?e.map(function(e){return e.textContent}).join(", "):""},c.select=function(e,t){var n=c.options[e];n&&n.setSelected(!0),c.selected[e]=t},c.deselect=function(e){var t=c.options[e];t&&t.setSelected(!1),delete c.selected[e]},c.addOption=function(e,n){if(t.isDefined(c.options[e]))throw new Error('Duplicate md-option values are not allowed in a select. Duplicate value "'+n.value+'" found.');c.options[e]=n,t.isDefined(c.selected[e])&&(c.select(e,n.value),c.refreshViewValue())},c.removeOption=function(e){delete c.options[e]},c.refreshViewValue=function(){var e,t=[];for(var n in c.selected)(e=c.options[n])?t.push(e.value):t.push(c.selected[n]);c.ngModel.$setViewValue(c.isMultiple?t:t[0])}}return l.$inject=["$scope","$attrs","$element"],{restrict:"E",require:["mdSelectMenu","?ngModel"],controller:l,link:{pre:i}}}function i(e,n){function o(e,n){return e.append(t.element('<div class="md-text">').append(e.contents())),e.attr("tabindex",n.tabindex||"0"),r}function r(o,r,i,l){function a(e,t){var n=c.hashGetter(t,o),r=c.hashGetter(e,o);s.hashKey=r,s.value=e,c.removeOption(n,s),c.addOption(r,s)}function d(){var e={role:"option","aria-selected":"false"};r[0].hasAttribute("id")||(e.id="select_option_"+n.nextUid()),r.attr(e)}var s=l[0],c=l[1];t.isDefined(i.ngValue)?o.$watch(i.ngValue,a):t.isDefined(i.value)?a(i.value):o.$watch(function(){return r.text()},a),i.$observe("disabled",function(e){e?r.attr("tabindex","-1"):r.attr("tabindex","0")}),o.$$postDigest(function(){i.$observe("selected",function(e){t.isDefined(e)&&("string"==typeof e&&(e=!0),e?(c.isMultiple||c.deselect(Object.keys(c.selected)[0]),c.select(s.hashKey,s.value)):c.deselect(s.hashKey),c.refreshViewValue(),c.ngModel.$render())})}),e.attach(o,r),d(),o.$on("$destroy",function(){c.removeOption(s.hashKey,s)})}function i(e){this.selected=!1,this.setSelected=function(t){t&&!this.selected?e.attr({selected:"selected","aria-selected":"true"}):!t&&this.selected&&(e.removeAttr("selected"),e.attr("aria-selected","false")),this.selected=t}}return i.$inject=["$element"],{restrict:"E",require:["mdOption","^^mdSelectMenu"],controller:i,compile:o}}function l(){function e(e,n){var o=e.find("label");o.length||(o=t.element("<label>"),e.prepend(o)),n.label&&o.text(n.label)}return{restrict:"E",compile:e}}function a(e){function o(e,o,a,s,c,u,f,p){function m(e,t,n){function o(){return f(t,{addClass:"md-leave"}).start()}function r(){g(n.target,!1),t.attr("opacity",0),t.removeClass("md-active"),b(t,n),v(n),!n.$destroy&&n.restoreFocus&&n.target.focus()}return n=n||{},n.cleanupInteraction(),n.cleanupResizing(),n.hideBackdrop(),n.$destroy===!0?r():o().then(r)}function h(r,i,l){function d(e,t,n){return n.parent.append(t),c(function(e,n){try{f(t,{removeClass:"md-leave",duration:0}).start().then(m).then(e)}catch(o){n(o)}})}function m(){return c(function(e){if(l.isRemoved)return c.reject(!1);var t=$(r,i,l);t.container.element.css(w.toCss(t.container.styles)),t.dropDown.element.css(w.toCss(t.dropDown.styles)),u(function(){i.addClass("md-active"),t.dropDown.element.css(w.toCss({transform:""})),v(l.focusedNode),e()})})}function h(e,t,n){return n.disableParentScroll&&!a.getClosest(n.target,"MD-DIALOG")?n.restoreScroll=a.disableScrollAround(n.element,n.parent):n.disableParentScroll=!1,n.hasBackdrop&&(n.backdrop=a.createBackdrop(e,"md-select-backdrop md-click-catcher"),p.enter(n.backdrop,n.parent,null,{duration:0})),function(){n.backdrop&&n.backdrop.remove(),n.disableParentScroll&&n.restoreScroll(),delete n.restoreScroll}}function v(e){e&&!e.hasAttribute("disabled")&&e.focus()}function b(e,n){var o=i.find("md-select-menu");if(!n.target)throw new Error(a.supplant(y,[n.target]));t.extend(n,{isRemoved:!1,target:t.element(n.target),parent:t.element(n.parent),selectEl:o,contentEl:i.find("md-content"),optionNodes:o[0].getElementsByTagName("md-option")})}function C(){var e=function(e,t,n){return function(){if(!n.isRemoved){var o=$(e,t,n),r=o.container,i=o.dropDown;r.element.css(w.toCss(r.styles)),i.element.css(w.toCss(i.styles))}}}(r,i,l),n=t.element(s);return n.on("resize",e),n.on("orientationchange",e),function(){n.off("resize",e),n.off("orientationchange",e)}}function k(){l.loadingAsync&&!l.isRemoved&&(r.$$loadingAsyncDone=!1,r.progressMode="indeterminate",c.when(l.loadingAsync).then(function(){r.$$loadingAsyncDone=!0,r.progressMode="",delete l.loadingAsync}).then(function(){u(m)}))}function M(){function t(t){t.preventDefault(),t.stopPropagation(),l.restoreFocus=!1,a.nextTick(e.hide,!0)}function r(t){var n=o.KEY_CODE;switch(t.keyCode){case n.UP_ARROW:return c();case n.DOWN_ARROW:return s();case n.SPACE:case n.ENTER:var r=a.getClosest(t.target,"md-option");r&&(f.triggerHandler({type:"click",target:r}),t.preventDefault()),u(t);break;case n.TAB:case n.ESCAPE:t.preventDefault(),l.restoreFocus=!0,a.nextTick(e.hide,!0);break;default:if(t.keyCode>=31&&t.keyCode<=90){var i=f.controller("mdSelectMenu").optNodeForKeyboardSearch(t);l.focusedNode=i||l.focusedNode,i&&i.focus()}}}function d(e){var t,o=a.nodesToArray(l.optionNodes),r=o.indexOf(l.focusedNode);do-1===r?r=0:"next"===e&&r<o.length-1?r++:"prev"===e&&r>0&&r--,t=o[r],t.hasAttribute("disabled")&&(t=n);while(!t&&r<o.length-1&&r>0);t&&t.focus(),l.focusedNode=t}function s(){d("next")}function c(){d("prev")}function u(t){function n(){var e=!1;if(t&&t.currentTarget.children.length>0){var n=t.currentTarget.children[0],o=n.scrollHeight>n.clientHeight;if(o&&n.children.length>0){var r=t.pageX-t.currentTarget.getBoundingClientRect().left;r>n.querySelector("md-option").offsetWidth&&(e=!0)}}return e}t&&"mouseup"==t.type&&t.currentTarget!=f[0]||n()||p.isMultiple||(l.restoreFocus=!0,a.nextTick(function(){e.hide(p.ngModel.$viewValue)},!0))}if(!l.isRemoved){var f=l.selectEl,p=f.controller("mdSelectMenu")||{};return i.addClass("md-clickable"),l.backdrop&&l.backdrop.on("click",t),f.on("keydown",r),f.on("mouseup",u),function(){l.backdrop&&l.backdrop.off("click",t),f.off("keydown",r),f.off("mouseup",u),i.removeClass("md-clickable"),l.isRemoved=!0}}}return k(),b(r,l),g(l.target),l.hideBackdrop=h(r,i,l),d(r,i,l).then(function(e){return l.alreadyOpen=!0,l.cleanupInteraction=M(),l.cleanupResizing=C(),e},l.hideBackdrop)}function g(e,n){n=t.isUndefined(n)?"true":"false",e&&e.attr("aria-expanded",n)}function v(e){var t=e.selectEl.controller("mdSelect");if(t){var n=e.selectEl.controller("mdSelectMenu");t.setLabelText(n.selectedLabels()),t.triggerClose()}}function b(e,t){e[0].parentNode===t.parent[0]&&t.parent[0].removeChild(e[0])}function $(e,n,o){var c,u,f=n[0],p=o.target[0].firstElementChild,m=o.parent[0],h=o.selectEl[0],g=o.contentEl[0],v=m.getBoundingClientRect(),b=p.getBoundingClientRect(),$=!1,y={left:v.left+d,top:d,bottom:v.height-d,right:v.width-d-(a.floatingScrollbars()?16:0)},w={top:b.top-y.top,left:b.left-y.left,right:y.right-(b.left+b.width),bottom:y.bottom-(b.top+b.height)},C=v.width-2*d,k=g.scrollHeight>g.offsetHeight,M=h.querySelector("md-option[selected]"),c=h.getElementsByTagName("md-option"),x=h.getElementsByTagName("md-optgroup"),S=r(o.loadingAsync);u=S?g.firstElementChild||g:M?M:x.length?x[0]:c.length?c[0]:g.firstElementChild||g,g.offsetWidth>C&&(g.style["max-width"]=C+"px"),$&&(g.style["min-width"]=b.width+"px"),k&&h.classList.add("md-overflow");var A=u;"MD-OPTGROUP"===(A.tagName||"").toUpperCase()&&(A=c[0]||g.firstElementChild||g,u=A),o.focusedNode=A;var O=h.getBoundingClientRect(),E=l(u);if(u){var D=s.getComputedStyle(u);E.paddingLeft=parseInt(D.paddingLeft,10)||0,E.paddingRight=parseInt(D.paddingRight,10)||0}if(k){var T=g.offsetHeight/2;g.scrollTop=E.top+E.height/2-T,w.top<T?g.scrollTop=Math.min(E.top,g.scrollTop+T-w.top):w.bottom<T&&(g.scrollTop=Math.max(E.top+E.height-O.height,g.scrollTop-T+w.bottom))}var R,V,B,N;$?(R=b.left,V=b.top+b.height,B="50% 0",V+O.height>y.bottom&&(V=b.top-O.height,B="50% 100%")):(R=b.left+E.left-E.paddingLeft+2,V=Math.floor(b.top+b.height/2-E.height/2-E.top+g.scrollTop)+2,B=E.left+b.width/2+"px "+(E.top+E.height/2-g.scrollTop)+"px 0px",N=b.width+E.paddingLeft+E.paddingRight);var j=f.getBoundingClientRect(),P=Math.round(100*Math.min(b.width/O.width,1))/100,L=Math.round(100*Math.min(b.height/O.height,1))/100;return{container:{element:t.element(f),styles:{left:Math.floor(i(y.left,R,y.right-j.width)),top:Math.floor(i(y.top,V,y.bottom-j.height)),"min-width":N}},dropDown:{element:t.element(h),styles:{transformOrigin:B,transform:o.alreadyOpen?"":a.supplant("scale({0},{1})",[P,L])}}}}var y="$mdSelect.show() expected a target element in options.target but got '{0}'!",w=a.dom.animator;return{parent:"body",themable:!0,onShow:h,onRemove:m,hasBackdrop:!0,disableParentScroll:!0}}function r(e){return e&&t.isFunction(e.then)}function i(e,t,n){return Math.max(e,Math.min(t,n))}function l(e){return e?{left:e.offsetLeft,top:e.offsetTop,width:e.offsetWidth,height:e.offsetHeight}:{left:0,top:0,width:0,height:0}}return o.$inject=["$mdSelect","$mdConstant","$mdUtil","$window","$q","$$rAF","$animateCss","$animate"],e("$mdSelect").setDefaults({methods:["target"],options:o})}var d=8,s=0;t.module("material.components.select",["material.core","material.components.backdrop"]).directive("mdSelect",o).directive("mdSelectMenu",r).directive("mdOption",i).directive("mdOptgroup",l).provider("$mdSelect",a),o.$inject=["$mdSelect","$mdUtil","$mdTheming","$mdAria","$compile","$parse"],r.$inject=["$parse","$mdUtil","$mdTheming"],i.$inject=["$mdButtonInkRipple","$mdUtil"],a.$inject=["$$interimElementProvider"]}(window,window.angular);