jquery.passwordbox.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * EasyUI for jQuery 1.6.10
  3. *
  4. * Copyright (c) 2009-2018 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 t=$(_8);
  26. var _b=t.passwordbox("options");
  27. if(_b.revealed){
  28. t.textbox("setValue",_9);
  29. return;
  30. }
  31. var _c=unescape(_b.passwordChar);
  32. var cc=_9.split("");
  33. var vv=t.passwordbox("getValue").split("");
  34. for(var i=0;i<cc.length;i++){
  35. var c=cc[i];
  36. if(c!=vv[i]){
  37. if(c!=_c){
  38. vv.splice(i,0,c);
  39. }
  40. }
  41. }
  42. var _d=t.passwordbox("getSelectionStart");
  43. if(cc.length<vv.length){
  44. vv.splice(_d,vv.length-cc.length,"");
  45. }
  46. for(var i=0;i<cc.length;i++){
  47. if(_a||i!=_d-1){
  48. cc[i]=_c;
  49. }
  50. }
  51. t.textbox("setValue",vv.join(""));
  52. t.textbox("setText",cc.join(""));
  53. t.textbox("setSelectionRange",{start:_d,end:_d});
  54. };
  55. function _6(_e,_f){
  56. var t=$(_e);
  57. var _10=t.passwordbox("options");
  58. var _11=t.next().find(".passwordbox-open");
  59. var _12=unescape(_10.passwordChar);
  60. _f=_f==undefined?t.textbox("getValue"):_f;
  61. t.textbox("setValue",_f);
  62. t.textbox("setText",_10.revealed?_f:_f.replace(/./ig,_12));
  63. _10.revealed?_11.addClass("passwordbox-close"):_11.removeClass("passwordbox-close");
  64. };
  65. function _13(e){
  66. var _14=e.data.target;
  67. var t=$(e.data.target);
  68. var _15=t.data("passwordbox");
  69. var _16=t.data("passwordbox").options;
  70. _15.checking=true;
  71. _15.value=t.passwordbox("getText");
  72. (function(){
  73. if(_15.checking){
  74. var _17=t.passwordbox("getText");
  75. if(_15.value!=_17){
  76. _15.value=_17;
  77. if(_15.lastTimer){
  78. clearTimeout(_15.lastTimer);
  79. _15.lastTimer=undefined;
  80. }
  81. _7(_14,_17);
  82. _15.lastTimer=setTimeout(function(){
  83. _7(_14,t.passwordbox("getText"),true);
  84. _15.lastTimer=undefined;
  85. },_16.lastDelay);
  86. }
  87. setTimeout(arguments.callee,_16.checkInterval);
  88. }
  89. })();
  90. };
  91. function _18(e){
  92. var _19=e.data.target;
  93. var _1a=$(_19).data("passwordbox");
  94. _1a.checking=false;
  95. if(_1a.lastTimer){
  96. clearTimeout(_1a.lastTimer);
  97. _1a.lastTimer=undefined;
  98. }
  99. _6(_19);
  100. };
  101. $.fn.passwordbox=function(_1b,_1c){
  102. if(typeof _1b=="string"){
  103. var _1d=$.fn.passwordbox.methods[_1b];
  104. if(_1d){
  105. return _1d(this,_1c);
  106. }else{
  107. return this.textbox(_1b,_1c);
  108. }
  109. }
  110. _1b=_1b||{};
  111. return this.each(function(){
  112. var _1e=$.data(this,"passwordbox");
  113. if(_1e){
  114. $.extend(_1e.options,_1b);
  115. }else{
  116. _1e=$.data(this,"passwordbox",{options:$.extend({},$.fn.passwordbox.defaults,$.fn.passwordbox.parseOptions(this),_1b)});
  117. }
  118. _1(this);
  119. });
  120. };
  121. $.fn.passwordbox.methods={options:function(jq){
  122. return $.data(jq[0],"passwordbox").options;
  123. },setValue:function(jq,_1f){
  124. return jq.each(function(){
  125. _6(this,_1f);
  126. });
  127. },clear:function(jq){
  128. return jq.each(function(){
  129. _6(this,"");
  130. });
  131. },reset:function(jq){
  132. return jq.each(function(){
  133. $(this).textbox("reset");
  134. _6(this);
  135. });
  136. },showPassword:function(jq){
  137. return jq.each(function(){
  138. var _20=$(this).passwordbox("options");
  139. _20.revealed=true;
  140. _6(this);
  141. });
  142. },hidePassword:function(jq){
  143. return jq.each(function(){
  144. var _21=$(this).passwordbox("options");
  145. _21.revealed=false;
  146. _6(this);
  147. });
  148. }};
  149. $.fn.passwordbox.parseOptions=function(_22){
  150. return $.extend({},$.fn.textbox.parseOptions(_22),$.parser.parseOptions(_22,["passwordChar",{checkInterval:"number",lastDelay:"number",revealed:"boolean",showEye:"boolean"}]));
  151. };
  152. $.fn.passwordbox.defaults=$.extend({},$.fn.textbox.defaults,{passwordChar:"%u25CF",checkInterval:200,lastDelay:500,revealed:false,showEye:true,inputEvents:{focus:_13,blur:_18},val:function(_23){
  153. return $(_23).parent().prev().passwordbox("getValue");
  154. }});
  155. })(jQuery);