jquery.filebox.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * jQuery EasyUI 1.5.2
  3. *
  4. * Copyright (c) 2009-2017 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.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. }};
  92. $.fn.filebox.parseOptions=function(_14){
  93. var t=$(_14);
  94. return $.extend({},$.fn.textbox.parseOptions(_14),$.parser.parseOptions(_14,["accept","capture","separator"]),{multiple:(t.attr("multiple")?true:undefined)});
  95. };
  96. $.fn.filebox.defaults=$.extend({},$.fn.textbox.defaults,{buttonIcon:null,buttonText:"Choose File",buttonAlign:"right",inputEvents:{},accept:"",capture:"",separator:",",multiple:false});
  97. })(jQuery);