/** * @author zhixin wen * https://github.com/wenzhixin/bootstrap-show-password * version: 1.0.3 */ !function(e){"use strict";var t=function(e){var t=arguments,s=!0,i=1;return e=e.replace(/%s/g,function(){var e=t[i++];return"undefined"==typeof e?(s=!1,""):e}),s?e:""},s=function(t,s){this.options=s,this.$element=e(t),this.isshown=!1,this.init()};s.defaults={placement:"after",white:!1,message:"click here to show/hide password",eyeclass:"glyphicon",eyeopenclass:"glyphicon-eye-open",eyecloseclass:"glyphicon-eye-close"},s.prototype.init=function(){var s,i;"before"===this.options.placement?(s="insertbefore",i="input-prepend"):(this.options.placement="after",s="insertafter",i="input-append"),this.$element.wrap(t('
',i)),this.$text=e('')[s](this.$element).attr("class",this.$element.attr("class")).attr("style",this.$element.attr("style")).attr("placeholder",this.$element.attr("placeholder")).css("display",this.$element.css("display")).val(this.$element.val()).hide(),this.$element.prop("readonly")&&this.$text.prop("readonly",!0),this.$icon=e(['','',""].join(""))[s](this.$text).css("cursor","pointer"),this.$text.off("keyup").on("keyup",e.proxy(function(){this.isshown&&this.$element.val(this.$text.val()).trigger("change")},this)),this.$icon.off("click").on("click",e.proxy(function(){this.$text.val(this.$element.val()).trigger("change"),this.toggle()},this))},s.prototype.toggle=function(e){this[this.isshown?"hide":"show"](e)},s.prototype.show=function(t){var s=e.event("show.bs.password",{relatedtarget:t});this.$element.trigger(s),this.isshown=!0,this.$element.hide(),this.$text.show(),this.$icon.find("i").removeclass("icon-eye-open "+this.options.eyeopenclass).addclass("icon-eye-close "+this.options.eyecloseclass),this.$text[this.options.placement](this.$element)},s.prototype.hide=function(t){var s=e.event("hide.bs.password",{relatedtarget:t});this.$element.trigger(s),this.isshown=!1,this.$element.show(),this.$text.hide(),this.$icon.find("i").removeclass("icon-eye-close "+this.options.eyecloseclass).addclass("icon-eye-open "+this.options.eyeopenclass),this.$element[this.options.placement](this.$text)},s.prototype.val=function(e){return"undefined"==typeof e?this.$element.val():(this.$element.val(e).trigger("change"),this.$text.val(e),void 0)};var i=e.fn.password;e.fn.password=function(){var t,i=arguments[0],n=arguments,o=["show","hide","toggle","val"];return this.each(function(){var a=e(this),h=a.data("bs.password"),r=e.extend({},s.defaults,a.data(),"object"==typeof i&&i);if("string"==typeof i){if(e.inarray(i,o)<0)throw"unknown method: "+i;t=h[i](n[1])}else h?h.init(r):(h=new s(a,r),a.data("bs.password",h))}),t?t:this},e.fn.password.constructor=s,e.fn.password.noconflict=function(){return e.fn.password=i,this},e(function(){e('[data-toggle="password"]').password()})}(window.jquery);