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
11 KiB

  1. /*!
  2. * Angular Material Design
  3. * https://github.com/angular/material
  4. * @license MIT
  5. * v1.1.0-master-2b98560
  6. */
  7. function mdInputContainerDirective(e,n){function t(n){var t=n[0].querySelector(r),i=n[0].querySelector(s);return t&&n.addClass("md-icon-left"),i&&n.addClass("md-icon-right"),function(n,t){e(t)}}function i(e,t,i,a){var r=this;r.isErrorGetter=i.mdIsError&&n(i.mdIsError),r.delegateClick=function(){r.input.focus()},r.element=t,r.setFocused=function(e){t.toggleClass("md-input-focused",!!e)},r.setHasValue=function(e){t.toggleClass("md-input-has-value",!!e)},r.setHasPlaceholder=function(e){t.toggleClass("md-input-has-placeholder",!!e)},r.setInvalid=function(e){e?a.addClass(t,"md-input-invalid"):a.removeClass(t,"md-input-invalid")},e.$watch(function(){return r.label&&r.input},function(e){e&&!r.label.attr("for")&&r.label.attr("for",r.input.attr("id"))})}i.$inject=["$scope","$element","$attrs","$animate"];var a=["INPUT","TEXTAREA","SELECT","MD-SELECT"],r=a.reduce(function(e,n){return e.concat(["md-icon ~ "+n,".md-icon ~ "+n])},[]).join(","),s=a.reduce(function(e,n){return e.concat([n+" ~ md-icon",n+" ~ .md-icon"])},[]).join(",");return{restrict:"E",compile:t,controller:i}}function labelDirective(){return{restrict:"E",require:"^?mdInputContainer",link:function(e,n,t,i){!i||t.mdNoFloat||n.hasClass("md-container-ignore")||(i.label=n,e.$on("$destroy",function(){i.label=null}))}}}function inputTextareaDirective(e,n,t,i,a){function r(r,s,o,u){function l(e){return g.setHasValue(!p.$isEmpty(e)),e}function c(){g.label&&o.$observe("required",function(e){g.label.toggleClass("md-required",e&&!$)})}function d(){g.setHasValue(s.val().length>0||(s[0].validity||{}).badInput)}function m(){function t(){s.attr("rows",1).css("height","auto").addClass("md-no-flex");var e=u();if(!C){var n=s[0].style.padding||"";C=s.css("padding",0).prop("offsetHeight"),s[0].style.padding=n}if(v&&C&&(e=Math.max(e,C*v)),h&&C){var t=C*h;t<e?(s.attr("md-no-autogrow",""),e=t):s.removeAttr("md-no-autogrow")}C&&s.attr("rows",Math.round(e/C)),s.css("height",e+"px").removeClass("md-no-flex")}function u(){var e=M.offsetHeight,n=M.scrollHeight-e;return e+Math.max(n,0)}function l(n){return e.nextTick(t),n}function c(){if(m&&(m=!1,angular.element(n).off("resize",t),$&&$(),s.attr("md-no-autogrow","").off("input",t),f)){var e=p.$formatters.indexOf(l);e>-1&&p.$formatters.splice(e,1)}}function d(){function n(e){e.preventDefault(),d=!0,m=e.clientY,f=parseFloat(s.css("height"))||s.prop("offsetHeight")}function t(e){d&&(e.preventDefault(),c(),p.addClass("md-input-resized"))}function i(n){d&&s.css("height",f+(n.pointer.y-m)-e.scrollTop()+"px")}function u(e){d&&(d=!1,p.removeClass("md-input-resized"))}if(!o.hasOwnProperty("mdNoResize")){var l=angular.element('<div class="md-resize-handle"></div>'),d=!1,m=null,f=0,p=g.element,v=a.register(l,"drag",{horizontal:!1});s.wrap('<div class="md-resize-wrapper">').after(l),l.on("mousedown",n),p.on("$md.dragstart",t).on("$md.drag",i).on("$md.dragend",u),r.$on("$destroy",function(){l.off("mousedown",n).remove(),p.off("$md.dragstart",t).off("$md.drag",i).off("$md.dragend",u),v(),l=null,p=null,v=null})}}var m=!o.hasOwnProperty("mdNoAutogrow");if(d(),m){var v=o.hasOwnProperty("rows")?parseInt(o.rows):NaN,h=o.hasOwnProperty("maxRows")?parseInt(o.maxRows):NaN,$=r.$on("md-resize-textarea",t),C=null,M=s[0];if(i(function(){e.nextTick(t)},10,!1),s.on("input",t),f&&p.$formatters.push(l),v||s.attr("rows",1),angular.element(n).on("resize",t),r.$on("$destroy",c),o.hasOwnProperty("mdDetectHidden")){var w=function(){var e=!1;return function(){var n=0===M.offsetHeight;n===!1&&e===!0&&t(),e=n}}();r.$watch(function(){return e.nextTick(w,!1),!0})}}}var g=u[0],f=!!u[1],p=u[1]||e.fakeNgModel(),v=u[2],h=angular.isDefined(o.readonly),$=e.parseAttributeBoolean(o.mdNoAsterisk),C=s[0].tagName.toLowerCase();if(g){if("hidden"===o.type)return void s.attr("aria-hidden","true");if(g.input){if(g.input[0].contains(s[0]))return;throw new Error("<md-input-container> can only have *one* <input>, <textarea> or <md-select> child element!")}g.input=s,c();var M=angular.element('<div class="md-errors-spacer">');s.after(M),g.label||t.expect(s,"aria-label",o.placeholder),s.addClass("md-input"),s.attr("id")||s.attr("id","input_"+e.nextUid()),"input"===C&&"number"===o.type&&o.min&&o.max&&!o.step?s.attr("step","any"):"textarea"===C&&m(),f||d();var w=g.isErrorGetter||function(){return p.$invalid&&(p.$touched||v&&v.$submitted)};r.$watch(w,g.setInvalid),o.ngValue&&o.$observe("value",d),p.$parsers.push(l),p.$formatters.push(l),s.on("input",d),h||s.on("focus",function(n){e.nextTick(function(){g.setFocused(!0)})}).on("blur",function(n){e.nextTick(function(){g.setFocused(!1),d()})}),r.$on("$destroy",function(){g.setFocused(!1),g.setHasValue(!1),g.input=null})}}return{restrict:"E",require:["^?mdInputContainer","?ngModel","?^form"],link:r}}function mdMaxlengthDirective(e,n){function t(t,i,a,r){function s(e){return u.parent?(u.text(String(i.val()||e||"").length+" / "+o),e):e}var o,u,l,c=r[0],d=r[1];n.nextTick(function(){l=angular.element(d.element[0].querySelector(".md-errors-spacer")),u=angular.element('<div class="md-char-counter">'),l.append(u),a.$set("ngTrim","false"),c.$formatters.push(s),c.$viewChangeListeners.push(s),i.on("input keydown keyup",function(){s()}),t.$watch(a.mdMaxlength,function(n){o=n,angular.isNumber(n)&&n>0?(u.parent().length||e.enter(u,l),s()):e.leave(u)}),c.$validators["md-maxlength"]=function(e,n){return!angular.isNumber(o)||o<0||(e||i.val()||n||"").length<=o}})}return{restrict:"A",require:["ngModel","^mdInputContainer"],link:t}}function placeholderDirective(e){function n(n,t,i,a){if(a){var r=a.element.find("label"),s=a.element.attr("md-no-float");if(r&&r.length||""===s||n.$eval(s))return void a.setHasPlaceholder(!0);if("MD-SELECT"!=t[0].nodeName){var o=angular.element('<label ng-click="delegateClick()" tabindex="-1">'+i.placeholder+"</label>");i.$set("placeholder",null),a.element.addClass("md-icon-float").prepend(o),e(o)(n)}}}return{restrict:"A",require:"^^?mdInputContainer",priority:200,link:{pre:n}}}function mdSelectOnFocusDirective(e){function n(n,t,i){function a(){s=!0,e(function(){t[0].select(),s=!1},1,!1)}function r(e){s&&e.preventDefault()}if("INPUT"===t[0].nodeName||"TEXTAREA"===t[0].nodeName){var s=!1;t.on("focus",a).on("mouseup",r),n.$on("$destroy",function(){t.off("focus",a).off("mouseup",r)})}}return{restrict:"A",link:n}}function ngMessagesDirective(){function e(e,t,i,a){a&&(t.toggleClass("md-input-messages-animation",!0),t.toggleClass("md-auto-hide",!0),("false"==i.mdAutoHide||n(i))&&t.toggleClass("md-auto-hide",!1))}function n(e){return visibilityDirectives.some(function(n){return e[n]})}return{restrict:"EA",link:e,require:"^^?mdInputContainer"}}function ngMessageDirective(e){function n(n){function t(){for(var e=n[0];e=e.parentNode;)if(e.nodeType===Node.DOCUMENT_FRAGMENT_NODE)return!0;return!1}function i(n){return!!e.getClosest(n,"md-input-container")}function a(e){e.toggleClass("md-input-message-animation",!0)}if(i(n))a(n);else if(t())return function(e,t){i(t)&&a(n)}}return{restrict:"EA",compile:n,priority:100}}function mdInputInvalidMessagesAnimation(e,n,t){return saveSharedServices(e,n,t),{addClass:function(e,n,t){showInputMessages(e,t)}}}function ngMessagesAnimation(e,n,t){return saveSharedServices(e,n,t),{enter:function(e,n){showInputMessages(e,n)},leave:function(e,n){hideInputMessages(e,n)},addClass:function(e,n,t){"ng-hide"==n?hideInputMessages(e,t):t()},removeClass:function(e,n,t){"ng-hide"==n?showInputMessages(e,t):t()}}}function ngMessageAnimation(e,n,t){return saveSharedServices(e,n,t),{enter:function(e,n){var t=showMessage(e);t.start().done(n)},leave:function(e,n){var t=hideMessage(e);t.start().done(n)}}}function showInputMessages(e,n){var t,i=[],a=getMessagesElement(e);angular.forEach(a.children(),function(e){t=showMessage(angular.element(e)),i.push(t.start())}),$$AnimateRunner.all(i,n)}function hideInputMessages(e,n){var t,i=[],a=getMessagesElement(e);angular.forEach(a.children(),function(e){t=hideMessage(angular.element(e)),i.push(t.start())}),$$AnimateRunner.all(i,n)}function showMessage(e){var n=parseInt(window.getComputedStyle(e[0]).height),t=parseInt(window.getComputedStyle(e[0]).marginTop),i=getMessagesElement(e),a=getInputElement(e),r=t>-n;return r||i.hasClass("md-auto-hide")&&!a.hasClass("md-input-invalid")?$animateCss(e,{}):$animateCss(e,{event:"enter",structural:!0,from:{opacity:0,"margin-top":-n+"px"},to:{opacity:1,"margin-top":"0"},duration:.3})}function hideMessage(e){var n=e[0].offsetHeight,t=window.getComputedStyle(e[0]);return 0==t.opacity?$animateCss(e,{}):$animateCss(e,{event:"leave",structural:!0,from:{opacity:1,"margin-top":0},to:{opacity:0,"margin-top":-n+"px"},duration:.3})}function getInputElement(e){var n=e.controller("mdInputContainer");return n.element}function getMessagesElement(e){return e.hasClass("md-input-message-animation")?angular.element($mdUtil.getClosest(e,function(e){return e.classList.contains("md-input-messages-animation")})):angular.element(e[0].querySelector(".md-input-messages-animation"))}function saveSharedServices(e,n,t){$$AnimateRunner=e,$animateCss=n,$mdUtil=t}goog.provide("ngmaterial.components.input"),goog.require("ngmaterial.core"),mdInputContainerDirective.$inject=["$mdTheming","$parse"],inputTextareaDirective.$inject=["$mdUtil","$window","$mdAria","$timeout","$mdGesture"],mdMaxlengthDirective.$inject=["$animate","$mdUtil"],placeholderDirective.$inject=["$compile"],ngMessageDirective.$inject=["$mdUtil"],mdSelectOnFocusDirective.$inject=["$timeout"],mdInputInvalidMessagesAnimation.$inject=["$$AnimateRunner","$animateCss","$mdUtil"],ngMessagesAnimation.$inject=["$$AnimateRunner","$animateCss","$mdUtil"],ngMessageAnimation.$inject=["$$AnimateRunner","$animateCss","$mdUtil"],angular.module("material.components.input",["material.core"]).directive("mdInputContainer",mdInputContainerDirective).directive("label",labelDirective).directive("input",inputTextareaDirective).directive("textarea",inputTextareaDirective).directive("mdMaxlength",mdMaxlengthDirective).directive("placeholder",placeholderDirective).directive("ngMessages",ngMessagesDirective).directive("ngMessage",ngMessageDirective).directive("ngMessageExp",ngMessageDirective).directive("mdSelectOnFocus",mdSelectOnFocusDirective).animation(".md-input-invalid",mdInputInvalidMessagesAnimation).animation(".md-input-messages-animation",ngMessagesAnimation).animation(".md-input-message-animation",ngMessageAnimation).service("mdInputInvalidAnimation",mdInputInvalidMessagesAnimation).service("mdInputMessagesAnimation",ngMessagesAnimation).service("mdInputMessageAnimation",ngMessageAnimation);var visibilityDirectives=["ngIf","ngShow","ngHide","ngSwitchWhen","ngSwitchDefault"],$$AnimateRunner,$animateCss,$mdUtil;ngmaterial.components.input=angular.module("material.components.input");