addPhoto.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <style>
  2. .plusForm div.btn {padding: 0px;}
  3. .plusForm .content div{margin-bottom: 0px;}
  4. #filePicker>.webuploader-pick{background: none; color: #000000; padding: 0px; height: 29px; line-height: 29px; width: 98px; border: none;}
  5. </style>
  6. <div class="plusForm photo">
  7. <div>
  8. <div class="title">Upload photo</div>
  9. <div class="close"><a href="javascript:;"><img src="<%=public_path%>/img/close-btn.png" alt=""/></a></div>
  10. </div>
  11. <div class="content">
  12. <div>Photo <label>(JPG & PNG only, size less than 3M. Image short-edit must be longer than 380px.)</label></div>
  13. <input class="uploadFile" id="uploadFile" disabled="disabled" style="background: none;" placeholder=""/>
  14. <div class="fileUpload btn btn-primary">
  15. <div id="filePicker">Browse photo</div>
  16. <input type="hidden" name="img" value="">
  17. </div>
  18. <!--<div>Photo description <label> (28 character limited)</label></div>-->
  19. <!--<input type="text" name="title" class="dec" maxlength="28">-->
  20. <button class="Submit cursor">Upload</button>
  21. <img id="text" src="">
  22. </div>
  23. </div>
  24. <script>
  25. $(function(){
  26. //创建文件上传
  27. var uploader = WebUploader.create({
  28. auto: true,
  29. fileSingleSizeLimit: 1024*1024*3,//最大只能上传10M
  30. swf: '<%=public_path%>' + '/js/webuploader/Uploader.swf',
  31. server: '<%=server_host%>/api/?act=uploadAlbum',
  32. pick: '#filePicker',
  33. accept: {
  34. title: 'Images',
  35. extensions: 'jpg,jpeg,png',
  36. mimeTypes: 'image/jpg,image/jpeg,image/png'
  37. },
  38. compress: null
  39. });
  40. // 图片上传中
  41. var uploadProgress = 0;//防止重复提示
  42. var load = '';
  43. uploader.on( 'uploadProgress', function( file, percentage ) {
  44. if (!uploadProgress) {
  45. load = layer.load(2);
  46. }
  47. uploadProgress = 1//等于1表示不上传动作已经开启
  48. });
  49. //文件上传成功
  50. uploader.on( 'uploadSuccess', function( file, response) {
  51. if(response.errno == 13){
  52. myParentAlert("The image size must be larger than 380px(width) * 380px(height).");
  53. }
  54. if(response.errno == 14){
  55. myParentAlert("The photo resolution can not be larger than 3600 * 3600.");
  56. }
  57. uploader.removeFile(file);//从队列中移除上传的文件,以便可以重复上传
  58. if(response.errno == 0){
  59. $('#uploadFile').val(file.name);
  60. $('input[name="img"]').val(response.data.url);
  61. }
  62. uploadProgress =0;//重置开关
  63. layer.close(load);
  64. });
  65. //文件上传失败
  66. uploader.on( 'uploadError', function( file ) {
  67. myParentAlert("Failed to upload. Please try again.");
  68. uploadProgress = 0;//重置开关
  69. layer.close(load);
  70. });
  71. //错误提示
  72. uploader.on("error", function (type) {
  73. if(type == "Q_TYPE_DENIED"){
  74. myParentAlert("Incorrect format. Only JPG and PNG format allowed. File size must be 3M or less.");
  75. }
  76. if(type == "F_EXCEED_SIZE"){
  77. myParentAlert("Incorrect format. Only JPG and PNG format allowed. File size must be 3M or less.");
  78. }
  79. });
  80. var index = parent.layer.getFrameIndex(window.name);
  81. parent.layer.iframeAuto(index);
  82. $('.close').click(function(){
  83. parent.layer.close(index);
  84. })
  85. var change_status = 0;//防止多次点击
  86. $('.Submit').click(function(){
  87. if(change_status){
  88. return false;
  89. }
  90. change_status = 1;
  91. // var title = $('input[name="title"]').val();
  92. var img = $('input[name="img"]').val();
  93. if(!img){
  94. myParentAlert('Please select an valid photo.');
  95. change_status = 0;
  96. return false;
  97. }
  98. // if(!title){
  99. // myParentAlert('Please enter photo description.');
  100. // change_status = 0;
  101. // return false;
  102. // }
  103. // if(title.length > 28){
  104. // myParentAlert('The photo description can not exceed 28 characters.');
  105. // change_status = 0;
  106. // return false;
  107. // }
  108. $.post('/broadcast/albumLayer/addPhoto', {img:img}, function(data){
  109. if(data.errno == 0){
  110. Cookies.set('add_success_photo', {status:1});
  111. parent.layer.close(index);
  112. parent.layer.msg('Submit successfully. Auditing soon.');
  113. }else{
  114. myParentAlert('Failed to submit. Please try again.');
  115. change_status = 0;
  116. }
  117. })
  118. })
  119. })
  120. </script>