jquery.filebox.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * jQuery EasyUI 1.4.4
  3. *
  4. * Copyright (c) 2009-2015 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. var _1=0;
  12. function _2(_3){
  13. var _4=$.data(_3,"filebox");
  14. var _5=_4.options;
  15. _5.fileboxId="filebox_file_id_"+(++_1);
  16. $(_3).addClass("filebox-f").textbox(_5);
  17. $(_3).textbox("textbox").attr("readonly","readonly");
  18. _4.filebox=$(_3).next().addClass("filebox");
  19. var _6=_7(_3);
  20. var _8=$(_3).filebox("button");
  21. if(_8.length){
  22. $("<label class=\"filebox-label\" for=\""+_5.fileboxId+"\"></label>").appendTo(_8);
  23. if(_8.linkbutton("options").disabled){
  24. _6.attr("disabled","disabled");
  25. }else{
  26. _6.removeAttr("disabled");
  27. }
  28. }
  29. };
  30. function _7(_9){
  31. var _a=$.data(_9,"filebox");
  32. var _b=_a.options;
  33. _a.filebox.find(".textbox-value").remove();
  34. _b.oldValue="";
  35. var _c=$("<input type=\"file\" class=\"textbox-value\">").appendTo(_a.filebox);
  36. _c.attr("id",_b.fileboxId).attr("name",$(_9).attr("textboxName")||"");
  37. _c.change(function(){
  38. $(_9).filebox("setText",this.value);
  39. _b.onChange.call(_9,this.value,_b.oldValue);
  40. _b.oldValue=this.value;
  41. });
  42. return _c;
  43. };
  44. $.fn.filebox=function(_d,_e){
  45. if(typeof _d=="string"){
  46. var _f=$.fn.filebox.methods[_d];
  47. if(_f){
  48. return _f(this,_e);
  49. }else{
  50. return this.textbox(_d,_e);
  51. }
  52. }
  53. _d=_d||{};
  54. return this.each(function(){
  55. var _10=$.data(this,"filebox");
  56. if(_10){
  57. $.extend(_10.options,_d);
  58. }else{
  59. $.data(this,"filebox",{options:$.extend({},$.fn.filebox.defaults,$.fn.filebox.parseOptions(this),_d)});
  60. }
  61. _2(this);
  62. });
  63. };
  64. $.fn.filebox.methods={options:function(jq){
  65. var _11=jq.textbox("options");
  66. return $.extend($.data(jq[0],"filebox").options,{width:_11.width,value:_11.value,originalValue:_11.originalValue,disabled:_11.disabled,readonly:_11.readonly});
  67. },clear:function(jq){
  68. return jq.each(function(){
  69. $(this).textbox("clear");
  70. _7(this);
  71. });
  72. },reset:function(jq){
  73. return jq.each(function(){
  74. $(this).filebox("clear");
  75. });
  76. }};
  77. $.fn.filebox.parseOptions=function(_12){
  78. return $.extend({},$.fn.textbox.parseOptions(_12),{});
  79. };
  80. $.fn.filebox.defaults=$.extend({},$.fn.textbox.defaults,{buttonIcon:null,buttonText:"Choose File",buttonAlign:"right",inputEvents:{}});
  81. })(jQuery);