jquery.filebox.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * jQuery EasyUI 1.4.3
  3. *
  4. * Copyright (c) 2009-2015 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(_5);
  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. $("<label class=\"filebox-label\" for=\""+id+"\"></label>").appendTo(_7);
  31. if(_7.linkbutton("options").disabled){
  32. _6.attr("disabled","disabled");
  33. }else{
  34. _6.removeAttr("disabled");
  35. }
  36. }
  37. };
  38. $.fn.filebox=function(_8,_9){
  39. if(typeof _8=="string"){
  40. var _a=$.fn.filebox.methods[_8];
  41. if(_a){
  42. return _a(this,_9);
  43. }else{
  44. return this.textbox(_8,_9);
  45. }
  46. }
  47. _8=_8||{};
  48. return this.each(function(){
  49. var _b=$.data(this,"filebox");
  50. if(_b){
  51. $.extend(_b.options,_8);
  52. }else{
  53. $.data(this,"filebox",{options:$.extend({},$.fn.filebox.defaults,$.fn.filebox.parseOptions(this),_8)});
  54. }
  55. _2(this);
  56. });
  57. };
  58. $.fn.filebox.methods={options:function(jq){
  59. var _c=jq.textbox("options");
  60. return $.extend($.data(jq[0],"filebox").options,{width:_c.width,value:_c.value,originalValue:_c.originalValue,disabled:_c.disabled,readonly:_c.readonly});
  61. }};
  62. $.fn.filebox.parseOptions=function(_d){
  63. return $.extend({},$.fn.textbox.parseOptions(_d),{});
  64. };
  65. $.fn.filebox.defaults=$.extend({},$.fn.textbox.defaults,{buttonIcon:null,buttonText:"Choose File",buttonAlign:"right",inputEvents:{}});
  66. })(jQuery);