qscms2.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. *上传附件
  3. *form flie元素ID容
  4. *option 上传附件的参数
  5. *fun 上传成功回调函数
  6. *before 上传附件前回调函数
  7. *going 执行上传附件时显示内容(默认为"请稍后...")
  8. */
  9. /*(function($){
  10. $.isUp = 0;
  11. $.upload = function(form,option,fun,before,going){
  12. var settings = {
  13. type:'image'
  14. },
  15. upload = function(){
  16. $.isUp=1;
  17. $.ajaxFileUpload({
  18. url: qscms.root + '/?c=upload&a=attach',
  19. type: 'POST',
  20. data:settings,
  21. secureuri:false,
  22. fileElementId:form,
  23. dataType:'json',
  24. success:function(result){
  25. if(result.status==1){
  26. fun && fun(result);
  27. }else{
  28. alert(result.msg);
  29. if(result.dialog) location.reload();
  30. }
  31. $.isUp = 0;
  32. }
  33. });
  34. };
  35. if(option) $.extend(settings,option);
  36. $(form).die().live({
  37. 'click':function(){
  38. //if($.isUp) return !1;
  39. if(before && !1 == before()) return !1;
  40. },
  41. 'change':function(){
  42. //if($.isUp || !$.trim($(this).val())) return !1;
  43. if(!$.trim($(this).val())) return !1;
  44. upload();
  45. }
  46. });
  47. };
  48. })(jQuery);*/
  49. (function($){
  50. $.upload = function(form,option,fun,before,going){
  51. var settings = {
  52. type:'image'
  53. };
  54. if(option) $.extend(settings,option);
  55. new AjaxUpload(form,{
  56. action:"/upload",
  57. name:$(form).attr('name'),
  58. data:settings,
  59. responseType:'json',
  60. /*onChange:function(file,ext){
  61. alert('vdvdvd');
  62. if(!$.trim($(file).val())) return !1;
  63. },*/
  64. onSubmit:function(file,ext){
  65. if(ext && /^(jpg|jpeg|png|gif)$/.test(ext)){
  66. var af = this._input.files;
  67. var byteSize = af[0].size;
  68. if ((byteSize / 1024) > (2 * 1024)) {
  69. alert('图片大小超出范围!');
  70. return false;
  71. } else {
  72. if(before && !1 == before()) return !1;
  73. //ext是后缀名
  74. form.disabled = "disabled";
  75. }
  76. if(before && !1 == before()) return !1;
  77. form.disabled = "disabled";
  78. } else {
  79. alert('不支持非图片格式!');
  80. return false;
  81. }
  82. if(before && !1 == before()) return !1;
  83. form.disabled = "disabled";
  84. },
  85. onComplete:function(file,result){
  86. form.disabled = "";
  87. if(result.status==1){
  88. fun && fun(result);
  89. }else{
  90. alert(result.msg);
  91. if(result.dialog) location.reload();
  92. }
  93. }
  94. });
  95. };
  96. })(jQuery);