(function(n){typeof define=="function"&&define.amd?define(["jquery"],n):typeof exports=="object"?n(require("jquery")):n(jQuery)})(function(n,t){function f(t,i){this.element=n(t);this.wrapperElement=n();this.toggleElement=n();this.init(i)}var i="plugin_hideShowPassword",r=["show","innerToggle"],u=32,e=13,o=function(){var n=document.body,t=document.createElement("input"),i=!0;n||(n=document.createElement("body"));t=n.appendChild(t);try{t.setAttribute("type","text")}catch(r){i=!1}return n.removeChild(t),i}(),s={show:"infer",innerToggle:!1,enable:o,triggerOnToggle:!1,className:"hideShowPassword-field",initEvent:"hideShowPasswordInit",changeEvent:"passwordVisibilityChange",props:{autocapitalize:"off",autocomplete:"off",autocorrect:"off",spellcheck:"false"},toggle:{element:'<button type="button">',className:"hideShowPassword-toggle",touchSupport:typeof Modernizr=="undefined"?!1:Modernizr.touchevents,attachToEvent:"click.hideShowPassword",attachToTouchEvent:"touchstart.hideShowPassword mousedown.hideShowPassword",attachToKeyEvent:"keyup",attachToKeyCodes:!0,styles:{position:"absolute"},touchStyles:{pointerEvents:"none"},position:"infer",verticalAlign:"middle",offset:0,attr:{role:"button","aria-label":"Show Password",title:"Show Password",tabIndex:0}},wrapper:{element:"<div>",className:"hideShowPassword-wrapper",enforceWidth:!0,styles:{position:"relative"},inheritStyles:["display","verticalAlign","marginTop","marginRight","marginBottom","marginLeft"],innerElementStyles:{marginTop:0,marginRight:0,marginBottom:0,marginLeft:0}},states:{shown:{className:"hideShowPassword-shown",changeEvent:"passwordShown",props:{type:"text"},toggle:{className:"hideShowPassword-toggle-hide",content:"Hide",attr:{"aria-pressed":"true",title:"Hide Password"}}},hidden:{className:"hideShowPassword-hidden",changeEvent:"passwordHidden",props:{type:"password"},toggle:{className:"hideShowPassword-toggle-show",content:"Show",attr:{"aria-pressed":"false",title:"Show Password"}}}}};f.prototype={init:function(t){if(this.update(t,s)){if(this.element.addClass(this.options.className),this.options.innerToggle&&(this.wrapElement(this.options.wrapper),this.initToggle(this.options.toggle),typeof this.options.innerToggle=="string")){this.toggleElement.hide();this.element.one(this.options.innerToggle,n.proxy(function(){this.toggleElement.show()},this))}this.element.trigger(this.options.initEvent,[this])}},update:function(n,t){return this.options=this.prepareOptions(n,t),this.updateElement()&&this.element.trigger(this.options.changeEvent,[this]).trigger(this.state().changeEvent,[this]),this.options.enable},toggle:function(n){return n=n||"toggle",this.update({show:n})},prepareOptions:function(t,i){var r=t||{},f=[],o;if(i=i||this.options,t=n.extend(!0,{},i,t),r.hasOwnProperty("wrapper")&&r.wrapper.hasOwnProperty("inheritStyles")&&(t.wrapper.inheritStyles=r.wrapper.inheritStyles),t.enable&&(t.show==="toggle"?t.show=this.isType("hidden",t.states):t.show==="infer"&&(t.show=this.isType("shown",t.states)),t.toggle.position==="infer"&&(t.toggle.position=this.element.css("text-direction")==="rtl"?"left":"right"),!n.isArray(t.toggle.attachToKeyCodes))){if(t.toggle.attachToKeyCodes===!0){o=n(t.toggle.element);switch(o.prop("tagName").toLowerCase()){case"button":case"input":break;case"a":if(o.filter("[href]").length){f.push(u);break}default:f.push(u,e)}}t.toggle.attachToKeyCodes=f}return t},updateElement:function(){return!this.options.enable||this.isType()?!1:(this.element.prop(n.extend({},this.options.props,this.state().props)).addClass(this.state().className).removeClass(this.otherState().className),this.options.triggerOnToggle&&this.element.trigger(this.options.triggerOnToggle,[this]),this.updateToggle(),!0)},isType:function(n,i){return i=i||this.options.states,n=n||this.state(t,t,i).props.type,i[n]&&(n=i[n].props.type),this.element.prop("type")===n},state:function(n,i,r){return r=r||this.options.states,n===t&&(n=this.options.show),typeof n=="boolean"&&(n=n?"shown":"hidden"),i&&(n=n==="shown"?"hidden":"shown"),r[n]},otherState:function(n){return this.state(n,!0)},wrapElement:function(t){var i=t.enforceWidth,r;return this.wrapperElement.length||(r=this.element.outerWidth(),n.each(t.inheritStyles,n.proxy(function(n,i){t.styles[i]=this.element.css(i)},this)),this.element.css(t.innerElementStyles).wrap(n(t.element).addClass(t.className).css(t.styles)),this.wrapperElement=this.element.parent(),i===!0&&(i=this.wrapperElement.outerWidth()===r?!1:r),i!==!1&&this.wrapperElement.css("width",i)),this.wrapperElement},initToggle:function(t){if(!this.toggleElement.length){if(this.toggleElement=n(t.element).attr(t.attr).addClass(t.className).css(t.styles).appendTo(this.wrapperElement),this.updateToggle(),this.positionToggle(t.position,t.verticalAlign,t.offset),t.touchSupport){this.toggleElement.css(t.touchStyles);this.element.on(t.attachToTouchEvent,n.proxy(this.toggleTouchEvent,this))}else this.toggleElement.on(t.attachToEvent,n.proxy(this.toggleEvent,this));if(t.attachToKeyCodes.length)this.toggleElement.on(t.attachToKeyEvent,n.proxy(this.toggleKeyEvent,this))}return this.toggleElement},positionToggle:function(n,t,i){var r={};r[n]=i;switch(t){case"top":case"bottom":r[t]=i;break;case"middle":r.top="50%";r.marginTop=this.toggleElement.outerHeight()/-2}return this.toggleElement.css(r)},updateToggle:function(n,t){var i,r;return this.toggleElement.length&&(i="padding-"+this.options.toggle.position,n=n||this.state().toggle,t=t||this.otherState().toggle,this.toggleElement.attr(n.attr).addClass(n.className).removeClass(t.className).html(n.content),r=this.toggleElement.outerWidth()+this.options.toggle.offset*2,this.element.css(i)!==r&&this.element.css(i,r)),this.toggleElement},toggleEvent:function(n){n.preventDefault();this.toggle()},toggleKeyEvent:function(t){n.each(this.options.toggle.attachToKeyCodes,n.proxy(function(n,i){if(t.which===i)return this.toggleEvent(t),!1},this))},toggleTouchEvent:function(n){var t=this.toggleElement.offset().left,i,r,u;t&&(i=n.pageX||n.originalEvent.pageX,this.options.toggle.position==="left"?(t+=this.toggleElement.outerWidth(),r=i,u=t):(r=t,u=i),u>=r&&this.toggleEvent(n))}};n.fn.hideShowPassword=function(){var t={};return n.each(arguments,function(i,u){var f={};if(typeof u=="object")f=u;else if(r[i])f[r[i]]=u;else return!1;n.extend(!0,t,f)}),this.each(function(){var r=n(this),u=r.data(i);u?u.update(t):r.data(i,new f(this,t))})};n.each({show:!0,hide:!1,toggle:"toggle"},function(t,i){n.fn[t+"Password"]=function(n,t){return this.hideShowPassword(i,n,t)}})})