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