-
Notifications
You must be signed in to change notification settings - Fork 2
/
v-textfield.min.js
executable file
·9 lines (8 loc) · 2.57 KB
/
v-textfield.min.js
1
2
3
4
5
6
7
8
9
/**
* User-friendly text fields in AngularJS
* @version v0.1.4
* @link http://lukaszwatroba.github.io/v-textfield
* @author Łukasz Wątroba <[email protected]>
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
!function(e){"use strict";function i(){return{restrict:"A",require:["^vTextfield","ngModel"],scope:{ngRequired:"=?ngRequired"},link:function(i,t,s,n){function l(){a.setHasValue(d())}function o(){a.setIsFocused(!0)}function u(){a.setIsFocused(!1)}function d(i){return i=e.isUndefined(i)?t.val():i,e.isDefined(i)&&null!==i&&""!==i.toString().trim()}if(n[0]||n[1]){var a=n[0],r=n[1];r.$formatters.push(function(e){return a.setHasValue(d(e)),e}),e.isDefined(s.required)?a.setIsRequired(!0):e.isDefined(i.ngRequired)?i.$watch("ngRequired",function(e){a.setIsRequired(e)}):a.setIsRequired(!1),a.setHasPlaceholder(e.isDefined(s.placeholder)),i.$watch(function(){return r.$valid},function(e){a.setIsValid(e)}),i.$watch(function(){return r.$dirty},function(e){a.setIsDirty(e)}),a.setIsFocused(!1),t.bind("input",l).bind("focus",o).bind("blur",u),i.$on("$destroy",function(){a.setIsFocused(!1),a.setHasValue(!1),t.unbind("input",l).unbind("focus",o).unbind("blur",u)})}}}}function t(){return{restrict:"E",replace:!0,transclude:!0,controller:s,scope:{},link:function(e,i,t,s,n){n(e.$parent,function(e){i.append(e)})}}}function s(e,i,t){var s=t.states;this.setIsFocused=function(e){i.toggleClass(s.focused,e).toggleClass(s.blured,!e)},this.setHasValue=function(e){i.toggleClass(s.hasValue,e).toggleClass(s.hasNoValue,!e)},this.setHasPlaceholder=function(e){i.toggleClass(s.hasPlaceholder,e).toggleClass(s.hasNoPlaceholder,!e)},this.setIsRequired=function(e){i.toggleClass(s.required,e).toggleClass(s.optional,!e)},this.setIsValid=function(e){i.toggleClass(s.valid,e).toggleClass(s.invalid,!e)},this.setIsDirty=function(e){i.toggleClass(s.dirty,e).toggleClass(s.pristine,!e)},this.setIsTouched=function(e){i.toggleClass(s.touched,e).toggleClass(s.untouched,!e)}}e.module("vTextfield.config",[]).constant("textfieldConfig",{states:{focused:"is-focused",blured:"is-blured",valid:"is-valid",invalid:"is-invalid",dirty:"is-dirty",pristine:"is-pristine",required:"is-required",optional:"is-optional",hasValue:"has-value",hasNoValue:"has-noValue",hasPlaceholder:"has-placeholder",hasNoPlaceholder:"has-noPlaceholder"}}),e.module("vTextfield.directives",[]),e.module("vTextfield",["vTextfield.config","vTextfield.directives"]),e.module("vTextfield.directives").directive("vTextfieldInput",i),e.module("vTextfield.directives").directive("vTextfield",t),s.$inject=["$scope","$element","textfieldConfig"]}(angular);