PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.3.0
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.3.0
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.0, at assets/wpuf/js/upload.js

240 lines 8.0 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
115
116 this.count = uploader.files.length - this.removed_files.length ;
117 this.showHide();
118
119
120 },
121
122 progress: function (up, file) {
123 var item = $('#' + file.id);
124
125 $('.bar', item).css({ width: file.percent + '%' });
126 $('.percent', item).html( file.percent + '%' );
127 },
128
129 error: function (up, error) {
130 $('#' + this.container).find('#' + error.file.id).remove();
131
132 var msg = '';
133 switch (error.code) {
134 case -600:
135 msg = wpuf_frontend_upload.plupload.size_error;
136 break;
137
138 case -601:
139 msg = wpuf_frontend_upload.plupload.type_error;
140 break;
141
142 default:
143 msg = 'Error #' + error.code + ': ' + error.message;
144 break;
145 }
146
147 alert(msg);
148
149 this.count -= 1;
150 this.showHide();
151 this.uploader.refresh();
152 },
153
154 uploaded: function (up, file, response) {
155 // var res = $.parseJSON(response.response);
156 var self = this;
157
158 $('#' + file.id + " b").html("100%");
159 $('#' + file.id).remove();
160
161 if(response.response !== 'error') {
162
163 this.perFileCount++;
164 this.UploadedFiles++;
165 var $container = $('#' + this.container).find('.wpuf-attachment-list');
166 $container.append(response.response);
167
168 if ( this.perFileCount > this.max ) {
169 var attach_id = $('.wpuf-image-wrap:last a.attachment-delete',$container).data('attach_id');
170 self.removeExtraAttachment(attach_id);
171 $('.wpuf-image-wrap',$container).last().remove();
172 this.perFileCount--;
173 }
174
175 } else {
176 alert(response.error);
177
178 this.count -= 1;
179 this.showHide();
180 }
181
182 var uploaded = this.UploadedFiles,
183 FileProgress = up.files.length,
184 imageCount = $('ul.wpuf-attachment-list > li').length;
185
186 if ( imageCount >= this.max ) {
187 $('#' + this.container).find('.file-selector').hide();
188 }
189
190 if ( FileProgress === uploaded ) {
191 $(".wpuf-submit-button").removeAttr("disabled");
192 }
193 },
194
195 removeAttachment: function(e) {
196 e.preventDefault();
197
198 var self = this,
199 el = $(e.currentTarget);
200
201 if ( confirm(wpuf_frontend_upload.confirmMsg) ) {
202 var data = {
203 'attach_id' : el.data('attach_id'),
204 'nonce' : wpuf_frontend_upload.nonce,
205 'action' : 'wpuf_file_del'
206 };
207 this.removed_files.push(data);
208 jQuery('#del_attach').val(el.data('attach_id'));
209 jQuery.post(wpuf_frontend_upload.ajaxurl, data, function() {
210 self.perFileCount--;
211 el.parent().parent().remove();
212
213 self.count -= 1;
214 self.showHide();
215 self.uploader.refresh();
216 });
217 }
218 },
219
220 removeExtraAttachment : function( attach_id ) {
221
222
223 var self = this;
224
225 var data = {
226 'attach_id' : attach_id,
227 'nonce' : wpuf_frontend_upload.nonce,
228 'action' : 'wpuf_file_del'
229 };
230 this.removed_files.push(data);
231 jQuery.post(wpuf_frontend_upload.ajaxurl, data, function() {
232 self.count -= 1;
233 self.showHide();
234 self.uploader.refresh();
235 });
236 }
237
238 };
239 })(jQuery);
240