www-thermferm/jqwidgets/jqxpasswordinput.js

changeset 511
2d1d43c3a2c2
parent 373
f6850e0b5d35
child 617
b216f9d4b917
equal deleted inserted replaced
510:2da3d3340403 511:2d1d43c3a2c2
1 /* 1 /*
2 jQWidgets v3.8.0 (2015-Apr) 2 jQWidgets v4.5.2 (2017-May)
3 Copyright (c) 2011-2015 jQWidgets. 3 Copyright (c) 2011-2017 jQWidgets.
4 License: http://jqwidgets.com/license/ 4 License: http://jqwidgets.com/license/
5 */ 5 */
6 !function(a){"use strict";a.jqx.jqxWidget("jqxPasswordInput","",{}),a.extend(a.jqx._jqxPasswordInput.prototype,{defineInstance:function(){var b={width:null,height:null,disabled:!1,rtl:!1,placeHolder:null,showStrength:!1,showStrengthPosition:"right",maxLength:null,minLength:null,showPasswordIcon:!0,strengthTypeRenderer:null,passwordStrength:null,changeType:null,localization:{passwordStrengthString:"Password strength",tooShort:"Too short",weak:"Weak",fair:"Fair",good:"Good",strong:"Strong",showPasswordString:"Show Password"},strengthColors:{tooShort:"rgb(170, 0, 51)",weak:"rgb(170, 0, 51)",fair:"rgb(255, 204, 51)",good:"rgb(45, 152, 243)",strong:"rgb(118, 194, 97)"}};return this===a.jqx._jqxPasswordInput.prototype?b:(a.extend(!0,this,b),b)},createInstance:function(){var a=this;a._inDOM=document.body.contains(a.element),a.render()},render:function(){var b=this,c=a.jqx.browser.browser,d=a.jqx.browser.version;this._browserCheck="msie"!=c||"7.0"!=d&&"8.0"!=d,this.widgetID=b.element.id;var e="Invalid input type. Please set the type attribute of the input element to password.";if("password"!=this.element.getAttribute("type"))throw e;b._hidden=!0,b._setTheme(),b._setAttributes(),b._showPassword(),b._showStrength(),a.jqx.utilities.resize(this.host,function(){if(!b._inDOM){var a=b.element.parentNode;return b.element.nextSibling?a.insertBefore(b.icon,b.element.nextSibling):a.appendChild(b.icon),void(b._inDOM=!0)}b.element===document.activeElement&&(b._positionIcon(),b.showStrength&&b.host.jqxTooltip("close"))})},refresh:function(b){var c=this;b||(c.removeHandler(c.host,"change.passwordinput"+c.widgetID),c.removeHandler(c.host,"focus.passwordinput"+c.widgetID),c.removeHandler(c.host,"blur.passwordinput"+c.widgetID),c.removeHandler(c.host,"click.passwordinput"+c.widgetID),c.removeHandler(c.host,"keyup.passwordinput"+c.widgetID),c.removeHandler(c.icon,"mousedown.passwordinput"+c.widgetID),c.removeHandler(a(document),"mouseup.passwordinput"+c.widgetID),c.removeHandler(a(document),"mousedown.passwordinput"+c.widgetID),c._setAttributes(),c._setTheme(),c._showPassword(),c._showStrength())},val:function(b){var c=this,d=c.element.value,e="placeholder"in c.element;if(a.isEmptyObject(b)&&""!==b)return e||d!==c.placeHolder||(d=""),d;if(!e||b!==d){if(!e){if(""===b)return void(d!==c.placeHolder&&(c.element.value=c.placeHolder,c.element.setAttribute("type","text")));c.element.setAttribute("type","password")}c.element.value=b,c.showStrength===!0&&c._evaluateStrength()}},propertyChangedHandler:function(b,c,d,e){return"theme"===c?void a.jqx.utilities.setTheme(d,e,b.host):"disabled"==c?void(b.disabled?(b.element.setAttribute("disabled","disabled"),b.element.className+=" "+b.toThemeProperty("jqx-fill-state-disabled")):(b.host.removeAttr("disabled"),b.host.removeClass(b.toThemeProperty("jqx-fill-state-disabled")))):void("placeHolder"==c?this._browserCheck&&("placeholder"in this.element?b.element.setAttribute("placeholder",b.placeHolder):""===b.element.value?(b.element.setAttribute("type","text"),b.element.value=e):b.element.value==d&&(b.element.value=e)):this.refresh())},resize:function(a,b){this.width=a,this.height=b,this.element.style.width=this._toPx(a),this.element.style.height=this._toPx(b)},_setAttributes:function(){var a=this,b=a.element;b.style.width=a._toPx(a.width),b.style.height=a._toPx(a.height),a.maxLength&&b.setAttribute("maxlength",a.maxLength),a.minLength&&b.setAttribute("minLength",a.minLength),a.placeHolder&&a._browserCheck&&("placeholder"in a.element?b.setAttribute("placeholder",a.placeHolder):""===b.value&&(b.setAttribute("type","text"),b.value=a.placeHolder)),a.disabled?(b.setAttribute("disabled","disabled"),b.className+=" "+this.toThemeProperty("jqx-fill-state-disabled")):(b.removeAttribute("disabled"),a.host.removeClass(a.toThemeProperty("jqx-fill-state-disabled")));var c=!1;a.addHandler(b,"change.passwordinput"+a.widgetID,function(b){c||(b.preventDefault(),b.stopPropagation(),c=!0,a._raiseEvent(),c=!1)}),a.addHandler(b,"click.passwordinput"+a.widgetID,function(){a.showPasswordIcon&&a.icon&&(a.icon.style.display="inline",a._positionIcon())}),a.interval=null,a.addHandler(b,"keydown.passwordinput"+a.widgetID,function(){if(a.changeType="keyboard",a.showPasswordIcon&&a.icon){a.interval&&clearInterval(a.interval);var b=0;a.interval=setInterval(function(){"none"!=a.icon.style.display?(a._positionIcon(),b++,b>5&&clearInterval(a.interval)):clearInterval(a.interval)},100)}}),a.addHandler(b,"focus.passwordinput"+a.widgetID,function(){if(a._focused=!0,b.className+=" "+a.toThemeProperty("jqx-fill-state-focus"),!a.placeHolder||!a._browserCheck||"placeholder"in a.element||b.value!=a.placeHolder||(b.value="",a._hidden&&b.setAttribute("type","password")),a.val().length>0&&a.showStrength){var c=a.host.jqxTooltip("content");c&&a.host.jqxTooltip("open")}a.showPasswordIcon&&a.icon&&(a.icon.style.display="inline",a._positionIcon())}),a.addHandler(b,"blur.passwordinput"+a.widgetID,function(){a._focused=!1,a.host.removeClass(a.toThemeProperty("jqx-fill-state-focus")),!a.placeHolder||!a._browserCheck||"placeholder"in a.element||""!==b.value||(a.element.value=a.placeHolder,a.element.setAttribute("type","text")),a.showPasswordIcon&&a._browserCheck&&(a.rtl===!1?a.host.removeClass(a.toThemeProperty("jqx-passwordinput-password-icon-ltr")):a.host.removeClass(a.toThemeProperty("jqx-passwordinput-password-icon-rtl"))),a.showStrength&&a.host.jqxTooltip("close"),a.showPasswordIcon&&a.icon&&(a.icon.style.display="none")})},destroy:function(){this.host.jqxTooltip&&this.host.jqxTooltip("destroy"),this.host.remove()},_setTheme:function(){var a=this,b="jqx-widget jqx-widget-content jqx-input jqx-rc-all";a.rtl?(b+=" jqx-rtl",a.element.style.direction="rtl"):(a.host.removeClass(a.toThemeProperty("jqx-rtl")),a.element.style.direction="ltr"),a.element.className+=" "+a.toThemeProperty(b)},_showPassword:function(){if(this.showPasswordIcon&&this._browserCheck){var b=this,c=document.createElement("span"),d=".passwordinput"+b.widgetID;c.setAttribute("tabindex",-1),c.setAttribute("hasfocus",!1),c.setAttribute("title",b.localization.showPasswordString),c.style.position="absolute",c.style.display="none",c.className=b.toThemeProperty("jqx-passwordinput-password-icon");var e=b.element.parentNode;e&&(b.element.nextSibling?e.insertBefore(c,b.element.nextSibling):e.appendChild(c)),b.icon=c,b._positionIcon();var f=function(){b.element.setAttribute("type","password"),b._hidden=!0},g=function(){b._hidden===!1?f():b._hidden&&(b.element.setAttribute("type","text"),b._hidden=!1)},h=a.jqx.mobile.isTouchDevice();h?b.addHandler(b.icon,"mousedown"+d,function(){return g(),!1}):(b.addHandler(b.icon,"mousedown"+d,function(){return g(),!1}),b.addHandler(a(document),"mouseup"+d,function(){return f(),!1}),b.addHandler(a(document),"mousedown"+d,function(){b._focused&&f()}))}},_positionIcon:function(){var b=this.host.offset(),c=this.element.offsetWidth,d=this.element.offsetHeight,e=a(this.icon);this.rtl?e.offset({top:parseInt(b.top+d/2-5,10),left:b.left+2}):e.offset({top:parseInt(b.top+d/2-5,10),left:b.left+c-18})},_showStrength:function(){var a=this;if(a.showStrength){if(!a.host.jqxTooltip)throw new Error("jqxPasswordInput: Missing reference to jqxtooltip.js");var b,c=a.widgetID+"Strength",d=c+"Value",e=c+"Indicator";if(a.strengthTypeRenderer){var f=a.element.value;"placeholder"in a.element||!a._browserCheck||f!=a.placeHolder||(f=""),a._countCharacters();var g=a.localization.tooShort,h=a.strengthTypeRenderer(f,{letters:a.letters,numbers:a.numbers,specialKeys:a.specials},g);b=h}else b='<div style="width: 220px;"><div><span style="font-weight: bold;">'+a.localization.passwordStrengthString+': </span><span id="'+d+'"></span></div><div id="'+e+'"></div></div>';if(a.host.jqxTooltip({theme:a.theme,position:a.showStrengthPosition,content:b,trigger:"none",autoHide:!1,rtl:a.rtl}),!a.strengthTypeRenderer){var i=document.getElementById(e);document.getElementById(d).innerHTML=a.localization.tooShort,i.className+=" jqx-passwordinput-password-strength-inicator",i.style.backgroundColor=a.strengthColors.tooShort,a.rtl===!1?i.style.float="left":i.style.float="right"}a._checkStrength()}},_checkStrength:function(){var a=this;a.addHandler(a.host,"keyup.passwordinput"+a.widgetID,function(){a._evaluateStrength()})},_raiseEvent:function(){var b=new a.Event("change");b.args={type:this.changeType},this.changeType=null,b.owner=this;var c=this.host.trigger(b);return c},_evaluateStrength:function(){var b=this,c=b.element.value,d=c.length;if(b._countCharacters(),d>0&&b.showStrength){var e=!b.host.jqxTooltip("opened");e&&b.host.jqxTooltip("open")}var f,g=b.letters+b.numbers+2*b.specials+b.letters*b.numbers/2+d;f=d<8?b.localization.tooShort:g<20?b.localization.weak:g<30?b.localization.fair:g<40?b.localization.good:b.localization.strong;var h;if(b.strengthTypeRenderer)h=b.strengthTypeRenderer(c,{letters:b.letters,numbers:b.numbers,specialKeys:b.specials},f),b.host.jqxTooltip({content:h});else{b.passwordStrength&&(h=b.passwordStrength(c,{letters:b.letters,numbers:b.numbers,specialKeys:b.specials},f),a.each(b.localization,function(){var a=this;if(h==a)return f=h,!1})),document.getElementById(b.widgetID+"StrengthValue").innerHTML=f;var i,j,k=document.getElementById(b.widgetID+"StrengthIndicator");switch(f){case b.localization.tooShort:i="20%",j=b.strengthColors.tooShort;break;case b.localization.weak:i="40%",j=b.strengthColors.weak;break;case b.localization.fair:i="60%",j=b.strengthColors.fair;break;case b.localization.good:i="80%",j=b.strengthColors.good;break;case b.localization.strong:i="100%",j=b.strengthColors.strong}k.style.width=i,k.style.backgroundColor=j}},_countCharacters:function(){var a=this;a.letters=0,a.numbers=0,a.specials=0;for(var b="<>@!#$%^&*()_+[]{}?:;|'\"\\,./~`-=",c=a.element.value,d=c.length,e=0;e<d;e++){var f=c.charAt(e),g=c.charCodeAt(e);g>64&&g<91||g>96&&g<123||g>127&&g<155||g>159&&g<166?a.letters+=1:isNaN(f)!==!1?b.indexOf(f)==-1||(a.specials+=1):a.numbers+=1}},_toPx:function(a){return"number"==typeof a?a+"px":a}})}(jqxBaseFramework);
6 7
7 (function(a){a.jqx.jqxWidget("jqxPasswordInput","",{});a.extend(a.jqx._jqxPasswordInput.prototype,{defineInstance:function(){var b={width:null,height:null,disabled:false,rtl:false,placeHolder:null,showStrength:false,showStrengthPosition:"right",maxLength:null,minLength:null,showPasswordIcon:true,strengthTypeRenderer:null,passwordStrength:null,localization:{passwordStrengthString:"Password strength",tooShort:"Too short",weak:"Weak",fair:"Fair",good:"Good",strong:"Strong",showPasswordString:"Show Password"},strengthColors:{tooShort:"rgb(170, 0, 51)",weak:"rgb(170, 0, 51)",fair:"rgb(255, 204, 51)",good:"rgb(45, 152, 243)",strong:"rgb(118, 194, 97)"}};a.extend(true,this,b);return b},createInstance:function(b){this.render()},render:function(){var e=this;var c=a.jqx.browser.browser;var b=a.jqx.browser.version;this._browserCheck=c!="msie"||(b!="7.0"&&b!="8.0");this.widgetID=e.element.id;var f=e.host;var d="Invalid input type. Please set the type attribute of the input element to password.";if(f.attr("type")!="password"){throw d}e._hidden=true;e._setTheme();e._setAttributes();e._showPassword();e._showStrength()},refresh:function(c){var b=this;if(c==true){return}b.removeHandler(b.host,"focus.passwordinput"+b.widgetID);b.removeHandler(b.host,"blur.passwordinput"+b.widgetID);b.removeHandler(b.host,"click.passwordinput"+b.widgetID);b.removeHandler(a(window),"resize.passwordinput"+b.widgetID);b.removeHandler(b.host,"keyup.passwordinput"+b.widgetID);b.removeHandler(b.icon,"mousedown.passwordinput"+b.iconID);b.removeHandler(b.icon,"mouseup.passwordinput"+b.iconID);b.removeHandler(a(document),"mousedown.passwordinput"+b.iconID);b._setAttributes();b._setTheme();b._showPassword();b._showStrength()},val:function(d){var c=this,e=c.element.value,b="placeholder" in c.element;if(a.isEmptyObject(d)&&d!=""){if(!b&&e===c.placeHolder){e=""}return e}else{if(b&&d===e){return}if(!b){if(d===""){if(e!==c.placeHolder){c.element.value=c.placeHolder;c.host.attr("type","text")}return}else{c.host.attr("type","password")}}c.element.value=d;if(c.showStrength===true){c._evaluateStrength()}}},propertyChangedHandler:function(b,c,f,e){var d=this.host;if(c=="disabled"){if(b.disabled==true){b.host.attr("disabled","disabled");b.host.addClass(b.toThemeProperty("jqx-fill-state-disabled"))}else{b.host.removeAttr("disabled");b.host.removeClass(b.toThemeProperty("jqx-fill-state-disabled"))}return}if(c=="placeHolder"){if(this._browserCheck){if("placeholder" in this.element){d.attr("placeholder",this.placeHolder)}else{if(d.val()==""){d.attr("type","text");b.element.value=e}else{if(d.val()==f){b.element.value=e}}}}}else{this.refresh()}},resize:function(c,b){this.width=c;this.height=b;this.host.width(this.width);this.host.height(this.height)},_setAttributes:function(){var b=this;var c=b.host;c.width(b.width);c.height(b.height);if(b.maxLength){c.attr("maxlength",b.maxLength)}if(b.minLength){c.attr("minLength",b.minLength)}if(b.placeHolder&&b._browserCheck){if("placeholder" in b.element){c.attr("placeholder",b.placeHolder)}else{if(c.val()==""){c.attr("type","text");b.element.value=b.placeHolder}}}if(b.disabled==true){c.attr("disabled","disabled");c.addClass(this.toThemeProperty("jqx-fill-state-disabled"))}else{c.removeAttr("disabled");c.removeClass(b.toThemeProperty("jqx-fill-state-disabled"))}b.addHandler(c,"click.passwordinput"+b.widgetID,function(){if(b.showPasswordIcon&&b.icon){b.icon.show();b._positionIcon()}});b.interval=null;b.addHandler(c,"keydown.passwordinput"+b.widgetID,function(){if(b.showPasswordIcon&&b.icon){if(b.interval){clearInterval(b.interval)}var d=0;b.interval=setInterval(function(){if(b.icon[0].style.display!="none"){b._positionIcon();d++;if(d>5){clearInterval(b.interval)}}else{clearInterval(b.interval)}},100)}});b.addHandler(c,"focus.passwordinput"+b.widgetID,function(){b._focused=true;b.host.addClass(b.toThemeProperty("jqx-fill-state-focus"));if(b.placeHolder&&b._browserCheck&&!("placeholder" in b.element)&&c.val()==b.placeHolder){c.val("");if(b._hidden==true){c.attr("type","password")}}if(b.val().length>0){if(b.showStrength==true){var d=c.jqxTooltip("content");if(d){c.jqxTooltip("open")}}}if(b.showPasswordIcon&&b.icon){b.icon.show();b._positionIcon()}});b.addHandler(c,"blur.passwordinput"+b.widgetID,function(){b._focused=false;b.host.removeClass(b.toThemeProperty("jqx-fill-state-focus"));if(b.placeHolder&&b._browserCheck&&!("placeholder" in b.element)&&c.val()==""){b.element.value=b.placeHolder;c.attr("type","text")}if(b.showPasswordIcon==true&&b._browserCheck){if(b.rtl==false){b.host.removeClass(b.toThemeProperty("jqx-passwordinput-password-icon-ltr"))}else{b.host.removeClass(b.toThemeProperty("jqx-passwordinput-password-icon-rtl"))}}if(b.showStrength==true){c.jqxTooltip("close")}if(b.showPasswordIcon&&b.icon){b.icon.hide()}})},destroy:function(){if(this.host.jqxTooltip){this.host.jqxTooltip("destroy")}this.host.remove()},_setTheme:function(){var c=this.host;var b=this;c.addClass(b.toThemeProperty("jqx-widget"));c.addClass(b.toThemeProperty("jqx-widget-content"));c.addClass(b.toThemeProperty("jqx-input"));c.addClass(b.toThemeProperty("jqx-rc-all"));if(b.rtl==true){c.addClass(b.toThemeProperty("jqx-rtl"));c.css("direction","rtl")}else{c.removeClass(b.toThemeProperty("jqx-rtl"));c.css("direction","ltr")}},_showPassword:function(){if(this.showPasswordIcon==true&&this._browserCheck){var f=this;this.iconID=this.widgetID+"-password-icon";a("<span tabindex='-1' hasfocus='false' style='position: absolute; display: none;' id='"+f.iconID+"'></span>").insertAfter(f.host);var e=a("#"+f.iconID);f.icon=e;e.addClass(f.toThemeProperty("jqx-passwordinput-password-icon"));e.attr("title",f.localization.showPasswordString);f._positionIcon();var d=function(){f.host.attr("type","password");f._hidden=true;e.attr("title",f.localization.showPasswordString)};var b=function(){if(f._hidden==false){d()}else{if(f._hidden==true){f.host.attr("type","text");f._hidden=false}}};var c=a.jqx.mobile.isTouchDevice();if(c){f.addHandler(f.icon,"mousedown.passwordinput"+f.iconID,function(g){b();return false})}else{f.addHandler(f.icon,"mousedown.passwordinput"+f.iconID,function(g){b();return false});f.addHandler(f.icon,"mouseup.passwordinput"+f.iconID,function(g){d();return false});f.addHandler(a(document),"mousedown.passwordinput"+f.iconID,function(g){if(f._focused){d()}})}}},_positionIcon:function(){var c=this.host.offset();var b=this.host.outerWidth();var d=this.host.outerHeight();if(this.rtl==true){this.icon.offset({top:parseInt(c.top+d/2-10/2),left:c.left+2})}else{this.icon.offset({top:parseInt(c.top+d/2-10/2),left:c.left+b-18})}},_showStrength:function(){var g=this;if(g.showStrength==true){if(g.host.jqxTooltip!=undefined){var e=g.widgetID+"Strength";var i=e+"Value";var c=e+"Indicator";var f;if(!g.strengthTypeRenderer){f="<div style='width: 220px;' id='"+e+"'><div><span style='font-weight: bold;'>"+g.localization.passwordStrengthString+": </span><span id='"+i+"'></span></div><div id='"+c+"'></div></div>"}else{var d=g.host.val();if(!("placeholder" in g.element)&&g._browserCheck&&d==g.placeHolder){d=""}g._countCharacters();var b=g.localization.tooShort;var h=g.strengthTypeRenderer(d,{letters:g.letters,numbers:g.numbers,specialKeys:g.specials},b);f=h}g.host.jqxTooltip({theme:g.theme,position:g.showStrengthPosition,content:f,trigger:"none",autoHide:false,rtl:g.rtl});if(!g.strengthTypeRenderer){a("#"+i).html(g.localization.tooShort);a("#"+c).addClass("jqx-passwordinput-password-strength-inicator").css("background-color",g.strengthColors.tooShort);if(g.rtl==false){a("#"+c).css("float","left")}else{a("#"+c).css("float","right")}}g._checkStrength()}else{throw new Error("jqxPasswordInput: Missing reference to jqxtooltip.js")}}},_checkStrength:function(){var b=this;b.addHandler(a(window),"resize.passwordinput"+b.widgetID,function(){if(b.icon){b.icon.hide()}});b.addHandler(b.host,"keyup.passwordinput"+b.widgetID,function(){b._evaluateStrength()})},_evaluateStrength:function(){var f=this;var d=f.host.val();var e=d.length;f._countCharacters();if(e>0){if(f.showStrength==true){var i=!f.host.jqxTooltip("opened");if(i){f.host.jqxTooltip("open")}}}var c=f.letters+f.numbers+2*f.specials+f.letters*f.numbers/2+e;var b;if(e<8){b=f.localization.tooShort}else{if(c<20){b=f.localization.weak}else{if(c<30){b=f.localization.fair}else{if(c<40){b=f.localization.good}else{b=f.localization.strong}}}}if(f.strengthTypeRenderer){var h=f.strengthTypeRenderer(d,{letters:f.letters,numbers:f.numbers,specialKeys:f.specials},b);f.host.jqxTooltip({content:h})}else{if(f.passwordStrength){var h=f.passwordStrength(d,{letters:f.letters,numbers:f.numbers,specialKeys:f.specials},b);a.each(f.localization,function(){var j=this;if(h==j){b=h;return false}})}a("#"+f.widgetID+"StrengthValue").html(b);var g=a("#"+f.widgetID+"StrengthIndicator");switch(b){case f.localization.tooShort:g.css({width:"20%","background-color":f.strengthColors.tooShort});break;case f.localization.weak:g.css({width:"40%","background-color":f.strengthColors.weak});break;case f.localization.fair:g.css({width:"60%","background-color":f.strengthColors.fair});break;case f.localization.good:g.css({width:"80%","background-color":f.strengthColors.good});break;case f.localization.strong:g.css({width:"100%","background-color":f.strengthColors.strong});break}}},_countCharacters:function(){var g=this;g.letters=0;g.numbers=0;g.specials=0;var d="<>@!#$%^&*()_+[]{}?:;|'\"\\,./~`-=";var b=g.host.val();var f=b.length;for(var c=0;c<f;c++){var h=b.charAt(c);var e=b.charCodeAt(c);if((e>64&&e<91)||(e>96&&e<123)||(e>127&&e<155)||(e>159&&e<166)){g.letters+=1;continue}if(isNaN(h)==false){g.numbers+=1;continue}if(d.indexOf(h)!=-1){g.specials+=1;continue}}}})})(jqxBaseFramework);

mercurial