jquery.passwordbox.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * EasyUI for jQuery 1.9.4
  3. *
  4. * Copyright (c) 2009-2020 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the freeware license: http://www.jeasyui.com/license_freeware.php
  7. * To use it on other terms please contact us: info@jeasyui.com
  8. *
  9. */
  10. (function($){
  11. function _1(_2){
  12. var _3=$.data(_2,"passwordbox");
  13. var _4=_3.options;
  14. var _5=$.extend(true,[],_4.icons);
  15. if(_4.showEye){
  16. _5.push({iconCls:"passwordbox-open",handler:function(e){
  17. _4.revealed=!_4.revealed;
  18. _6(_2);
  19. }});
  20. }
  21. $(_2).addClass("passwordbox-f").textbox($.extend({},_4,{icons:_5}));
  22. _6(_2);
  23. };
  24. function _7(_8,_9,_a){
  25. var _b=$(_8).data("passwordbox");
  26. var t=$(_8);
  27. var _c=t.passwordbox("options");
  28. if(_c.revealed){
  29. t.textbox("setValue",_9);
  30. return;
  31. }
  32. _b.converting=true;
  33. var _d=unescape(_c.passwordChar);
  34. var cc=_9.split("");
  35. var vv=t.passwordbox("getValue").split("");
  36. for(var i=0;i<cc.length;i++){
  37. var c=cc[i];
  38. if(c!=vv[i]){
  39. if(c!=_d){
  40. vv.splice(i,0,c);
  41. }
  42. }
  43. }
  44. var _e=t.passwordbox("getSelectionStart");
  45. if(cc.length<vv.length){
  46. vv.splice(_e,vv.length-cc.length,"");
  47. }
  48. for(var i=0;i<cc.length;i++){
  49. if(_a||i!=_e-1){
  50. cc[i]=_d;
  51. }
  52. }
  53. t.textbox("setValue",vv.join(""));
  54. t.textbox("setText",cc.join(""));
  55. t.textbox("setSelectionRange",{start:_e,end:_e});
  56. setTimeout(function(){
  57. _b.converting=false;
  58. },0);
  59. };
  60. function _6(_f,_10){
  61. var t=$(_f);
  62. var _11=t.passwordbox("options");
  63. var _12=t.next().find(".passwordbox-open");
  64. var _13=unescape(_11.passwordChar);
  65. _10=_10==undefined?t.textbox("getValue"):_10;
  66. t.textbox("setValue",_10);
  67. t.textbox("setText",_11.revealed?_10:_10.replace(/./ig,_13));
  68. _11.revealed?_12.addClass("passwordbox-close"):_12.removeClass("passwordbox-close");
  69. };
  70. function _14(e){
  71. var _15=e.data.target;
  72. var t=$(e.data.target);
  73. var _16=t.data("passwordbox");
  74. var _17=t.data("passwordbox").options;
  75. _16.checking=true;
  76. _16.value=t.passwordbox("getText");
  77. (function(){
  78. if(_16.checking){
  79. var _18=t.passwordbox("getText");
  80. if(_16.value!=_18){
  81. _16.value=_18;
  82. if(_16.lastTimer){
  83. clearTimeout(_16.lastTimer);
  84. _16.lastTimer=undefined;
  85. }
  86. _7(_15,_18);
  87. _16.lastTimer=setTimeout(function(){
  88. _7(_15,t.passwordbox("getText"),true);
  89. _16.lastTimer=undefined;
  90. },_17.lastDelay);
  91. }
  92. setTimeout(arguments.callee,_17.checkInterval);
  93. }
  94. })();
  95. };
  96. function _19(e){
  97. var _1a=e.data.target;
  98. var _1b=$(_1a).data("passwordbox");
  99. _1b.checking=false;
  100. if(_1b.lastTimer){
  101. clearTimeout(_1b.lastTimer);
  102. _1b.lastTimer=undefined;
  103. }
  104. _6(_1a);
  105. };
  106. $.fn.passwordbox=function(_1c,_1d){
  107. if(typeof _1c=="string"){
  108. var _1e=$.fn.passwordbox.methods[_1c];
  109. if(_1e){
  110. return _1e(this,_1d);
  111. }else{
  112. return this.textbox(_1c,_1d);
  113. }
  114. }
  115. _1c=_1c||{};
  116. return this.each(function(){
  117. var _1f=$.data(this,"passwordbox");
  118. if(_1f){
  119. $.extend(_1f.options,_1c);
  120. }else{
  121. _1f=$.data(this,"passwordbox",{options:$.extend({},$.fn.passwordbox.defaults,$.fn.passwordbox.parseOptions(this),_1c)});
  122. }
  123. _1(this);
  124. });
  125. };
  126. $.fn.passwordbox.methods={options:function(jq){
  127. return $.data(jq[0],"passwordbox").options;
  128. },setValue:function(jq,_20){
  129. return jq.each(function(){
  130. _6(this,_20);
  131. });
  132. },clear:function(jq){
  133. return jq.each(function(){
  134. _6(this,"");
  135. });
  136. },reset:function(jq){
  137. return jq.each(function(){
  138. $(this).textbox("reset");
  139. _6(this);
  140. });
  141. },showPassword:function(jq){
  142. return jq.each(function(){
  143. var _21=$(this).passwordbox("options");
  144. _21.revealed=true;
  145. _6(this);
  146. });
  147. },hidePassword:function(jq){
  148. return jq.each(function(){
  149. var _22=$(this).passwordbox("options");
  150. _22.revealed=false;
  151. _6(this);
  152. });
  153. }};
  154. $.fn.passwordbox.parseOptions=function(_23){
  155. return $.extend({},$.fn.textbox.parseOptions(_23),$.parser.parseOptions(_23,["passwordChar",{checkInterval:"number",lastDelay:"number",revealed:"boolean",showEye:"boolean"}]));
  156. };
  157. $.fn.passwordbox.defaults=$.extend({},$.fn.textbox.defaults,{passwordChar:"%u25CF",checkInterval:200,lastDelay:500,revealed:false,showEye:true,inputEvents:{focus:_14,blur:_19,keydown:function(e){
  158. var _24=$(e.data.target).data("passwordbox");
  159. return !_24.converting;
  160. }},val:function(_25){
  161. return $(_25).parent().prev().passwordbox("getValue");
  162. }});
  163. })(jQuery);