jquery.filebox.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * jQuery EasyUI 1.4.1
  3. *
  4. * Copyright (c) 2009-2014 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the GPL license: http://www.gnu.org/licenses/gpl.txt
  7. * To use it on other terms please contact us at 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. var id="filebox_file_id_"+(++_1);
  16. $(_3).addClass("filebox-f").textbox($.extend({},_5,{buttonText:_5.buttonText?("<label for=\""+id+"\">"+_5.buttonText+"</label>"):""}));
  17. $(_3).textbox("textbox").attr("readonly","readonly");
  18. _4.filebox=$(_3).next().addClass("filebox");
  19. _4.filebox.find(".textbox-value").remove();
  20. _5.oldValue="";
  21. var _6=$("<input type=\"file\" class=\"textbox-value\">").appendTo(_4.filebox);
  22. _6.attr("id",id).attr("name",$(_3).attr("textboxName")||"");
  23. _6.change(function(){
  24. $(_3).filebox("setText",this.value);
  25. _5.onChange.call(_3,this.value,_5.oldValue);
  26. _5.oldValue=this.value;
  27. });
  28. var _7=$(_3).filebox("button");
  29. if(_7.length){
  30. if(_7.linkbutton("options").disabled){
  31. _6.attr("disabled","disabled");
  32. }else{
  33. _6.removeAttr("disabled");
  34. }
  35. }
  36. };
  37. $.fn.filebox=function(_8,_9){
  38. if(typeof _8=="string"){
  39. var _a=$.fn.filebox.methods[_8];
  40. if(_a){
  41. return _a(this,_9);
  42. }else{
  43. return this.textbox(_8,_9);
  44. }
  45. }
  46. _8=_8||{};
  47. return this.each(function(){
  48. var _b=$.data(this,"filebox");
  49. if(_b){
  50. $.extend(_b.options,_8);
  51. }else{
  52. $.data(this,"filebox",{options:$.extend({},$.fn.filebox.defaults,$.fn.filebox.parseOptions(this),_8)});
  53. }
  54. _2(this);
  55. });
  56. };
  57. $.fn.filebox.methods={options:function(jq){
  58. var _c=jq.textbox("options");
  59. return $.extend($.data(jq[0],"filebox").options,{width:_c.width,value:_c.value,originalValue:_c.originalValue,disabled:_c.disabled,readonly:_c.readonly});
  60. }};
  61. $.fn.filebox.parseOptions=function(_d){
  62. return $.extend({},$.fn.textbox.parseOptions(_d),{});
  63. };
  64. $.fn.filebox.defaults=$.extend({},$.fn.textbox.defaults,{buttonIcon:null,buttonText:"Choose File",buttonAlign:"right",inputEvents:{}});
  65. })(jQuery);