jquery.filebox.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. 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._propAttr("disabled",true);
  25. }else{
  26. _6._propAttr("disabled",false);
  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.attr("accept",_b.accept);
  38. _c.attr("capture",_b.capture);
  39. if(_b.multiple){
  40. _c.attr("multiple","multiple");
  41. }
  42. _c.change(function(){
  43. var _d=this.value;
  44. if(this.files){
  45. _d=$.map(this.files,function(_e){
  46. return _e.name;
  47. }).join(_b.separator);
  48. }
  49. $(_9).filebox("setText",_d);
  50. _b.onChange.call(_9,_d,_b.oldValue);
  51. _b.oldValue=_d;
  52. });
  53. return _c;
  54. };
  55. $.fn.filebox=function(_f,_10){
  56. if(typeof _f=="string"){
  57. var _11=$.fn.filebox.methods[_f];
  58. if(_11){
  59. return _11(this,_10);
  60. }else{
  61. return this.textbox(_f,_10);
  62. }
  63. }
  64. _f=_f||{};
  65. return this.each(function(){
  66. var _12=$.data(this,"filebox");
  67. if(_12){
  68. $.extend(_12.options,_f);
  69. }else{
  70. $.data(this,"filebox",{options:$.extend({},$.fn.filebox.defaults,$.fn.filebox.parseOptions(this),_f)});
  71. }
  72. _2(this);
  73. });
  74. };
  75. $.fn.filebox.methods={options:function(jq){
  76. var _13=jq.textbox("options");
  77. return $.extend($.data(jq[0],"filebox").options,{width:_13.width,value:_13.value,originalValue:_13.originalValue,disabled:_13.disabled,readonly:_13.readonly});
  78. },clear:function(jq){
  79. return jq.each(function(){
  80. $(this).textbox("clear");
  81. _7(this);
  82. });
  83. },reset:function(jq){
  84. return jq.each(function(){
  85. $(this).filebox("clear");
  86. });
  87. },setValue:function(jq){
  88. return jq;
  89. },setValues:function(jq){
  90. return jq;
  91. },files:function(jq){
  92. return jq.next().find(".textbox-value")[0].files;
  93. }};
  94. $.fn.filebox.parseOptions=function(_14){
  95. var t=$(_14);
  96. return $.extend({},$.fn.textbox.parseOptions(_14),$.parser.parseOptions(_14,["accept","capture","separator"]),{multiple:(t.attr("multiple")?true:undefined)});
  97. };
  98. $.fn.filebox.defaults=$.extend({},$.fn.textbox.defaults,{buttonIcon:null,buttonText:"Choose File",buttonAlign:"right",inputEvents:{},accept:"",capture:"",separator:",",multiple:false});
  99. })(jQuery);