PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.3.3
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.3.3
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / assets / wpuf / js / upload.js

upload.js in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.3.3, at assets/wpuf/js/upload.js

245 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ;(function($) {
2
3 /**
4 * Upload handler helper
5 *
6 * @param string {browse_button} browse_button ID of the pickfile
7 * @param string {container} container ID of the wrapper
8 * @param int {max} maximum number of file uplaods
9 * @param string {type}
10 */
11 window.WPUF_Uploader = function (browse_button, container, max, type, allowed_type, max_file_size) {
12 this.removed_files = [];
13 this.container = container;
14 this.browse_button = browse_button;
15 this.max = max || 1;
16 this.count = $('#' + container).find('.wpuf-attachment-list > li').length; //count how many items are there
17 this.perFileCount = 0; //file count on each upload
18 this.UploadedFiles = 0; //file count on each upload
19
20 //if no element found on the page, bail out
21 if( !$('#'+browse_button).length ) {
22 return;
23 }
24
25 // enable drag option for ordering
26 $( "ul.wpuf-attachment-list" ).sortable({
27 placeholder: "highlight"
28 });
29 $( "ul.wpuf-attachment-list" ).disableSelection();
30
31 //instantiate the uploader
32 this.uploader = new plupload.Uploader({
33 runtimes: 'html5,html4',
34 browse_button: browse_button,
35 container: container,
36 multipart: true,
37 multipart_params: {
38 action: 'wpuf_upload_file',
39 form_id: $( '#' + browse_button ).data('form_id')
40 },
41 max_file_count : 2,
42 multiple_queues: false,
43 multi_selection: ( ( browse_button == 'wpuf-avatar-pickfiles' || browse_button == 'wpuf-featured_image-pickfiles' ) ? false : true ),
44 urlstream_upload: true,
45 file_data_name: 'wpuf_file',
46 max_file_size: max_file_size + 'kb',
47 url: wpuf_frontend_upload.plupload.url + '&type=' + type,
48 flash_swf_url: wpuf_frontend_upload.flash_swf_url,
49 filters: [{
50 title: 'Allowed Files',
51 extensions: allowed_type
52 }]
53 });
54
55 //attach event handlers
56 this.uploader.bind('Init', $.proxy(this, 'init'));
57 this.uploader.bind('FilesAdded', $.proxy(this, 'added'));
58 this.uploader.bind('QueueChanged', $.proxy(this, 'upload'));
59 this.uploader.bind('UploadProgress', $.proxy(this, 'progress'));
60 this.uploader.bind('Error', $.proxy(this, 'error'));
61 this.uploader.bind('FileUploaded', $.proxy(this, 'uploaded'));
62
63 this.uploader.init();
64
65 $('#' + container).on('click', 'a.attachment-delete', $.proxy(this.removeAttachment, this));
66
67 return this.uploader;
68 };
69
70 WPUF_Uploader.prototype = {
71
72 init: function (up, params) {
73 this.showHide();
74 $('#' + this.container).prepend('<div class="wpuf-file-warning"></div>');
75 },
76
77 showHide: function () {
78
79 if ( this.count >= this.max) {
80
81 if ( this.count > this.max ) {
82 $('#' + this.container + ' .wpuf-file-warning').html( wpuf_frontend_upload.warning );
83 } else {
84 $('#' + this.container + ' .wpuf-file-warning').html( wpuf_frontend_upload.warning );
85 }
86
87 $('#' + this.container).find('.file-selector').hide();
88
89 return;
90 };
91 $('#' + this.container + ' .wpuf-file-warning').html( '' );
92 $('#' + this.container).find('.file-selector').show();
93 },
94
95 added: function (up, files) {
96 var $container = $('#' + this.container).find('.wpuf-attachment-upload-filelist');
97
98 this.showHide();
99
100 $.each(files, function(i, file) {
101 $(".wpuf-submit-button").attr("disabled", "disabled");
102
103 $container.append(
104 '<div class="upload-item" id="' + file.id + '"><div class="progress progress-striped active"><div class="bar"></div></div><div class="filename original">' +
105 file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' +
106 '</div></div>');
107 });
108
109 up.refresh(); // Reposition Flash/Silverlight
110 up.start();
111 },
112
113 upload: function (uploader) {
114 this.count = uploader.files.length - this.removed_files.length ;
115 this.showHide();
116 },
117
118 progress: function (up, file) {
119 var item = $('#' + file.id);
120
121 $('.bar', item).css({ width: file.percent + '%' });
122 $('.percent', item).html( file.percent + '%' );
123 },
124
125 error: function (up, error) {
126 $('#' + this.container).find('#' + error.file.id).remove();
127
128 var msg = '';
129 switch (error.code) {
130 case -600:
131 msg = wpuf_frontend_upload.plupload.size_error;
132 break;
133
134 case -601:
135 msg = wpuf_frontend_upload.plupload.type_error;
136 break;
137
138 default:
139 msg = 'Error #' + error.code + ': ' + error.message;
140 break;
141 }
142
143 alert(msg);
144
145 this.count -= 1;
146 this.showHide();
147 this.uploader.refresh();
148 },
149
150 uploaded: function (up, file, response) {
151 // var res = $.parseJSON(response.response);
152 var self = this;
153
154 $('#' + file.id + " b").html("100%");
155 $('#' + file.id).remove();
156
157 if(response.response !== 'error') {
158
159 this.perFileCount++;
160 this.UploadedFiles++;
161 var $container = $('#' + this.container).find('.wpuf-attachment-list');
162 $container.append(response.response);
163
164 if ( this.perFileCount > this.max ) {
165 var attach_id = $('.wpuf-image-wrap:last a.attachment-delete',$container).data('attach_id');
166 self.removeExtraAttachment(attach_id);
167 $('.wpuf-image-wrap',$container).last().remove();
168 this.perFileCount--;
169 }
170
171 } else {
172 alert(response.error);
173
174 this.count -= 1;
175 this.showHide();
176 }
177
178 var uploaded = this.UploadedFiles,
179 FileProgress = up.files.length,
180 imageCount = $('ul.wpuf-attachment-list > li').length;
181
182 if ( imageCount >= this.max ) {
183 $('#' + this.container).find('.file-selector').hide();
184 }
185
186 if ( FileProgress === uploaded ) {
187 $(".wpuf-submit-button").removeAttr("disabled");
188 }
189 },
190
191 removeAttachment: function(e) {
192 e.preventDefault();
193
194 var self = this,
195 el = $(e.currentTarget);
196
197 swal({
198 text: wpuf_frontend_upload.confirmMsg,
199 type: 'warning',
200 showCancelButton: true,
201 confirmButtonColor: '#d54e21',
202 confirmButtonText: wpuf_frontend_upload.delete_it,
203 cancelButtonText: wpuf_frontend_upload.cancel_it,
204 confirmButtonClass: 'btn btn-success',
205 cancelButtonClass: 'btn btn-danger',
206 }).then(function () {
207 var data = {
208 'attach_id' : el.data('attach_id'),
209 'nonce' : wpuf_frontend_upload.nonce,
210 'action' : 'wpuf_file_del'
211 };
212 self.removed_files.push(data);
213 jQuery('#del_attach').val(el.data('attach_id'));
214 jQuery.post(wpuf_frontend_upload.ajaxurl, data, function() {
215 self.perFileCount--;
216 el.parent().parent().remove();
217
218 self.count -= 1;
219 self.showHide();
220 self.uploader.refresh();
221 });
222 });
223 },
224
225 removeExtraAttachment : function( attach_id ) {
226
227
228 var self = this;
229
230 var data = {
231 'attach_id' : attach_id,
232 'nonce' : wpuf_frontend_upload.nonce,
233 'action' : 'wpuf_file_del'
234 };
235 this.removed_files.push(data);
236 jQuery.post(wpuf_frontend_upload.ajaxurl, data, function() {
237 self.count -= 1;
238 self.showHide();
239 self.uploader.refresh();
240 });
241 }
242
243 };
244 })(jQuery);
245