1 var topWin=window.dialogArguments||opener||parent||top;function fileDialogStart(){jQuery("#media-upload-error").empty()}function fileQueued(a){jQuery(".media-blank").remove();if(jQuery("form.type-form #media-items").children().length==1&&jQuery(".hidden","#media-items").length>0){jQuery(".describe-toggle-on").show();jQuery(".describe-toggle-off").hide();jQuery(".slidetoggle").slideUp(200).siblings().removeClass("hidden")}jQuery("#media-items").append('<div id="media-item-'+a.id+'" class="media-item child-of-'+post_id+'"><div class="progress"><div class="bar"></div></div><div class="filename original"><span class="percent"></span> '+a.name+"</div></div>");jQuery(".progress","#media-item-"+a.id).show();jQuery("#insert-gallery").prop("disabled",true);jQuery("#cancel-upload").prop("disabled",false)}function uploadStart(a){try{if(typeof topWin.tb_remove!="undefined"){topWin.jQuery("#TB_overlay").unbind("click",topWin.tb_remove)}}catch(b){}return true}function uploadProgress(e,b,d){var a=jQuery("#media-items").width()-2,c=jQuery("#media-item-"+e.id);jQuery(".bar",c).width(a*b/d);jQuery(".percent",c).html(Math.ceil(b/d*100)+"%");if(b==d){jQuery(".bar",c).html('<strong class="crunching">'+swfuploadL10n.crunching+"</strong>")}}function prepareMediaItem(c,a){var d=(typeof shortform=="undefined")?1:2,b=jQuery("#media-item-"+c.id);jQuery(".bar",b).remove();jQuery(".progress",b).hide();try{if(typeof topWin.tb_remove!="undefined"){topWin.jQuery("#TB_overlay").click(topWin.tb_remove)}}catch(g){}if(isNaN(a)||!a){b.append(a);prepareMediaItemInit(c)}else{b.load("async-upload.php",{attachment_id:a,fetch:d},function(){prepareMediaItemInit(c);updateMediaForm()})}}function prepareMediaItemInit(b){var a=jQuery("#media-item-"+b.id);jQuery(".thumbnail",a).clone().attr("class","pinkynail toggle").prependTo(a);jQuery(".filename.original",a).replaceWith(jQuery(".filename.new",a));jQuery("a.toggle",a).click(function(){jQuery(this).siblings(".slidetoggle").slideToggle(350,function(){var d=jQuery(window).height(),e=jQuery(this).offset().top,f=jQuery(this).height(),c;if(d&&e&&f){c=e+f;if(c>d&&(f+48)<d){window.scrollBy(0,c-d+13)}else{if(c>d){window.scrollTo(0,e-36)}}}});jQuery(this).siblings(".toggle").andSelf().toggle();jQuery(this).siblings("a.toggle").focus();return false});jQuery("a.delete",a).click(function(){jQuery.ajax({url:ajaxurl,type:"post",success:deleteSuccess,error:deleteError,id:b.id,data:{id:this.id.replace(/[^0-9]/g,""),action:"trash-post",_ajax_nonce:this.href.replace(/^.*wpnonce=/,"")}});return false});jQuery("a.undo",a).click(function(){jQuery.ajax({url:ajaxurl,type:"post",id:b.id,data:{id:this.id.replace(/[^0-9]/g,""),action:"untrash-post",_ajax_nonce:this.href.replace(/^.*wpnonce=/,"")},success:function(d,e){var c=jQuery("#media-item-"+b.id);if(type=jQuery("#type-of-"+b.id).val()){jQuery("#"+type+"-counter").text(jQuery("#"+type+"-counter").text()-0+1)}if(c.hasClass("child-of-"+post_id)){jQuery("#attachments-count").text(jQuery("#attachments-count").text()-0+1)}jQuery(".filename .trashnotice",c).remove();jQuery(".filename .title",c).css("font-weight","normal");jQuery("a.undo",c).addClass("hidden");jQuery("a.describe-toggle-on, .menu_order_input",c).show();c.css({backgroundColor:"#ceb"}).animate({backgroundColor:"#fff"},{queue:false,duration:500,complete:function(){jQuery(this).css({backgroundColor:""})}}).removeClass("undo")}});return false});jQuery("#media-item-"+b.id+".startopen").removeClass("startopen").slideToggle(500).siblings(".toggle").toggle()}function itemAjaxError(d,b){var c=jQuery("#media-item-"+d);var a=jQuery(".filename",c).text();c.html('<div class="error-div"><a class="dismiss" href="#">'+swfuploadL10n.dismiss+"</a><strong>"+swfuploadL10n.error_uploading.replace("%s",a)+"</strong><br />"+b+"</div>");c.find("a.dismiss").click(function(){jQuery(this).parents(".media-item").slideUp(200,function(){jQuery(this).remove()})})}function deleteSuccess(b,d){if(b=="-1"){return itemAjaxError(this.id,"You do not have permission. Has your session expired?")}if(b=="0"){return itemAjaxError(this.id,"Could not be deleted. Has it been deleted already?")}var c=this.id,a=jQuery("#media-item-"+c);if(type=jQuery("#type-of-"+c).val()){jQuery("#"+type+"-counter").text(jQuery("#"+type+"-counter").text()-1)}if(a.hasClass("child-of-"+post_id)){jQuery("#attachments-count").text(jQuery("#attachments-count").text()-1)}if(jQuery("form.type-form #media-items").children().length==1&&jQuery(".hidden","#media-items").length>0){jQuery(".toggle").toggle();jQuery(".slidetoggle").slideUp(200).siblings().removeClass("hidden")}jQuery(".toggle",a).toggle();jQuery(".slidetoggle",a).slideUp(200).siblings().removeClass("hidden");a.css({backgroundColor:"#faa"}).animate({backgroundColor:"#f4f4f4"},{queue:false,duration:500}).addClass("undo");jQuery(".filename:empty",a).remove();jQuery(".filename .title",a).css("font-weight","bold");jQuery(".filename",a).append('<span class="trashnotice"> '+swfuploadL10n.deleted+" </span>").siblings("a.toggle").hide();jQuery(".filename",a).append(jQuery("a.undo",a).removeClass("hidden"));jQuery(".menu_order_input",a).hide();return}function deleteError(c,b,a){}function updateMediaForm(){var b=jQuery("form.type-form #media-items").children(),a=jQuery("#media-items").children();if(b.length==1){jQuery(".slidetoggle",b).slideDown(500).siblings().addClass("hidden").filter(".toggle").toggle()}if(a.not(".media-blank").length>0){jQuery(".savebutton").show()}else{jQuery(".savebutton").hide()}if(a.length>1){jQuery(".insert-gallery").show()}else{jQuery(".insert-gallery").hide()}}function uploadSuccess(b,a){if(a.match("media-upload-error")){jQuery("#media-item-"+b.id).html(a);return}prepareMediaItem(b,a);updateMediaForm();if(jQuery("#media-item-"+b.id).hasClass("child-of-"+post_id)){jQuery("#attachments-count").text(1*jQuery("#attachments-count").text()+1)}}function uploadComplete(a){if(swfu.getStats().files_queued==0){jQuery("#cancel-upload").prop("disabled",true);jQuery("#insert-gallery").prop("disabled",false)}}function wpQueueError(a){jQuery("#media-upload-error").show().text(a)}function wpFileError(d,c){var b=jQuery("#media-item-"+d.id);var a=jQuery(".filename",b).text();b.html('<div class="error-div"><a class="dismiss" href="#">'+swfuploadL10n.dismiss+"</a><strong>"+swfuploadL10n.error_uploading.replace("%s",a)+"</strong><br />"+c+"</div>");b.find("a.dismiss").click(function(){jQuery(this).parents(".media-item").slideUp(200,function(){jQuery(this).remove()})})}function fileQueueError(c,a,b){if(a==SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED){wpQueueError(swfuploadL10n.queue_limit_exceeded)}else{if(a==SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT){fileQueued(c);wpFileError(c,swfuploadL10n.file_exceeds_size_limit)}else{if(a==SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE){fileQueued(c);wpFileError(c,swfuploadL10n.zero_byte_file)}else{if(a==SWFUpload.QUEUE_ERROR.INVALID_FILETYPE){fileQueued(c);wpFileError(c,swfuploadL10n.invalid_filetype)}else{wpQueueError(swfuploadL10n.default_error)}}}}}function fileDialogComplete(b){try{if(b>0){this.startUpload()}}catch(a){this.debug(a)}}function switchUploader(b){var c=document.getElementById(swfu.customSettings.swfupload_element_id),a=document.getElementById(swfu.customSettings.degraded_element_id);if(b){c.style.display="block";a.style.display="none"}else{c.style.display="none";a.style.display="block"}}function swfuploadPreLoad(){if(!uploaderMode){switchUploader(1)}else{switchUploader(0)}}function swfuploadLoadFailed(){switchUploader(0);jQuery(".upload-html-bypass").hide()}function uploadError(b,c,a){switch(c){case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:wpFileError(b,swfuploadL10n.missing_upload_url);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:wpFileError(b,swfuploadL10n.upload_limit_exceeded);break;case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:wpQueueError(swfuploadL10n.http_error);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:wpQueueError(swfuploadL10n.upload_failed);break;case SWFUpload.UPLOAD_ERROR.IO_ERROR:wpQueueError(swfuploadL10n.io_error);break;case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:wpQueueError(swfuploadL10n.security_error);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:jQuery("#media-item-"+b.id).remove();break;default:wpFileError(b,swfuploadL10n.default_error)}}function cancelUpload(){swfu.cancelQueue()}jQuery(document).ready(function(a){a('input[type="radio"]',"#media-items").live("click",function(){var b=a(this).closest("tr");if(a(b).hasClass("align")){setUserSetting("align",a(this).val())}else{if(a(b).hasClass("image-size")){setUserSetting("imgsize",a(this).val())}}});a("button.button","#media-items").live("click",function(){var b=this.className||"";b=b.match(/url([^ '"]+)/);if(b&&b[1]){setUserSetting("urlbutton",b[1]);a(this).siblings(".urlfield").val(a(this).attr("title"))}})}); |
1 var topWin = window.dialogArguments || opener || parent || top; |
|
2 |
|
3 function fileDialogStart() { |
|
4 jQuery("#media-upload-error").empty(); |
|
5 } |
|
6 |
|
7 // progress and success handlers for media multi uploads |
|
8 function fileQueued(fileObj) { |
|
9 // Get rid of unused form |
|
10 jQuery('.media-blank').remove(); |
|
11 // Collapse a single item |
|
12 if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) { |
|
13 jQuery('.describe-toggle-on').show(); |
|
14 jQuery('.describe-toggle-off').hide(); |
|
15 jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden'); |
|
16 } |
|
17 // Create a progress bar containing the filename |
|
18 jQuery('#media-items').append('<div id="media-item-' + fileObj.id + '" class="media-item child-of-' + post_id + '"><div class="progress"><div class="bar"></div></div><div class="filename original"><span class="percent"></span> ' + fileObj.name + '</div></div>'); |
|
19 // Display the progress div |
|
20 jQuery('.progress', '#media-item-' + fileObj.id).show(); |
|
21 |
|
22 // Disable submit and enable cancel |
|
23 jQuery('#insert-gallery').prop('disabled', true); |
|
24 jQuery('#cancel-upload').prop('disabled', false); |
|
25 } |
|
26 |
|
27 function uploadStart(fileObj) { |
|
28 try { |
|
29 if ( typeof topWin.tb_remove != 'undefined' ) |
|
30 topWin.jQuery('#TB_overlay').unbind('click', topWin.tb_remove); |
|
31 } catch(e){} |
|
32 |
|
33 return true; |
|
34 } |
|
35 |
|
36 function uploadProgress(fileObj, bytesDone, bytesTotal) { |
|
37 // Lengthen the progress bar |
|
38 var w = jQuery('#media-items').width() - 2, item = jQuery('#media-item-' + fileObj.id); |
|
39 jQuery('.bar', item).width( w * bytesDone / bytesTotal ); |
|
40 jQuery('.percent', item).html( Math.ceil(bytesDone / bytesTotal * 100) + '%' ); |
|
41 |
|
42 if ( bytesDone == bytesTotal ) |
|
43 jQuery('.bar', item).html('<strong class="crunching">' + swfuploadL10n.crunching + '</strong>'); |
|
44 } |
|
45 |
|
46 function prepareMediaItem(fileObj, serverData) { |
|
47 var f = ( typeof shortform == 'undefined' ) ? 1 : 2, item = jQuery('#media-item-' + fileObj.id); |
|
48 // Move the progress bar to 100% |
|
49 jQuery('.bar', item).remove(); |
|
50 jQuery('.progress', item).hide(); |
|
51 |
|
52 try { |
|
53 if ( typeof topWin.tb_remove != 'undefined' ) |
|
54 topWin.jQuery('#TB_overlay').click(topWin.tb_remove); |
|
55 } catch(e){} |
|
56 |
|
57 // Old style: Append the HTML returned by the server -- thumbnail and form inputs |
|
58 if ( isNaN(serverData) || !serverData ) { |
|
59 item.append(serverData); |
|
60 prepareMediaItemInit(fileObj); |
|
61 } |
|
62 // New style: server data is just the attachment ID, fetch the thumbnail and form html from the server |
|
63 else { |
|
64 item.load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()}); |
|
65 } |
|
66 } |
|
67 |
|
68 function prepareMediaItemInit(fileObj) { |
|
69 var item = jQuery('#media-item-' + fileObj.id); |
|
70 // Clone the thumbnail as a "pinkynail" -- a tiny image to the left of the filename |
|
71 jQuery('.thumbnail', item).clone().attr('class', 'pinkynail toggle').prependTo(item); |
|
72 |
|
73 // Replace the original filename with the new (unique) one assigned during upload |
|
74 jQuery('.filename.original', item).replaceWith( jQuery('.filename.new', item) ); |
|
75 |
|
76 // Also bind toggle to the links |
|
77 jQuery('a.toggle', item).click(function(){ |
|
78 jQuery(this).siblings('.slidetoggle').slideToggle(350, function(){ |
|
79 var w = jQuery(window).height(), t = jQuery(this).offset().top, h = jQuery(this).height(), b; |
|
80 |
|
81 if ( w && t && h ) { |
|
82 b = t + h; |
|
83 |
|
84 if ( b > w && (h + 48) < w ) |
|
85 window.scrollBy(0, b - w + 13); |
|
86 else if ( b > w ) |
|
87 window.scrollTo(0, t - 36); |
|
88 } |
|
89 }); |
|
90 jQuery(this).siblings('.toggle').andSelf().toggle(); |
|
91 jQuery(this).siblings('a.toggle').focus(); |
|
92 return false; |
|
93 }); |
|
94 |
|
95 // Bind AJAX to the new Delete button |
|
96 jQuery('a.delete', item).click(function(){ |
|
97 // Tell the server to delete it. TODO: handle exceptions |
|
98 jQuery.ajax({ |
|
99 url: ajaxurl, |
|
100 type: 'post', |
|
101 success: deleteSuccess, |
|
102 error: deleteError, |
|
103 id: fileObj.id, |
|
104 data: { |
|
105 id : this.id.replace(/[^0-9]/g, ''), |
|
106 action : 'trash-post', |
|
107 _ajax_nonce : this.href.replace(/^.*wpnonce=/,'') |
|
108 } |
|
109 }); |
|
110 return false; |
|
111 }); |
|
112 |
|
113 // Bind AJAX to the new Undo button |
|
114 jQuery('a.undo', item).click(function(){ |
|
115 // Tell the server to untrash it. TODO: handle exceptions |
|
116 jQuery.ajax({ |
|
117 url: ajaxurl, |
|
118 type: 'post', |
|
119 id: fileObj.id, |
|
120 data: { |
|
121 id : this.id.replace(/[^0-9]/g,''), |
|
122 action: 'untrash-post', |
|
123 _ajax_nonce: this.href.replace(/^.*wpnonce=/,'') |
|
124 }, |
|
125 success: function(data, textStatus){ |
|
126 var item = jQuery('#media-item-' + fileObj.id); |
|
127 |
|
128 if ( type = jQuery('#type-of-' + fileObj.id).val() ) |
|
129 jQuery('#' + type + '-counter').text(jQuery('#' + type + '-counter').text()-0+1); |
|
130 if ( item.hasClass('child-of-'+post_id) ) |
|
131 jQuery('#attachments-count').text(jQuery('#attachments-count').text()-0+1); |
|
132 |
|
133 jQuery('.filename .trashnotice', item).remove(); |
|
134 jQuery('.filename .title', item).css('font-weight','normal'); |
|
135 jQuery('a.undo', item).addClass('hidden'); |
|
136 jQuery('a.describe-toggle-on, .menu_order_input', item).show(); |
|
137 item.css( {backgroundColor:'#ceb'} ).animate( {backgroundColor: '#fff'}, { queue: false, duration: 500, complete: function(){ jQuery(this).css({backgroundColor:''}); } }).removeClass('undo'); |
|
138 } |
|
139 }); |
|
140 return false; |
|
141 }); |
|
142 |
|
143 // Open this item if it says to start open (e.g. to display an error) |
|
144 jQuery('#media-item-' + fileObj.id + '.startopen').removeClass('startopen').slideToggle(500).siblings('.toggle').toggle(); |
|
145 } |
|
146 |
|
147 function itemAjaxError(id, html) { |
|
148 var item = jQuery('#media-item-' + id); |
|
149 var filename = jQuery('.filename', item).text(); |
|
150 |
|
151 item.html('<div class="error-div">' |
|
152 + '<a class="dismiss" href="#">' + swfuploadL10n.dismiss + '</a>' |
|
153 + '<strong>' + swfuploadL10n.error_uploading.replace('%s', filename) + '</strong><br />' |
|
154 + html |
|
155 + '</div>'); |
|
156 item.find('a.dismiss').click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})}); |
|
157 } |
|
158 |
|
159 function deleteSuccess(data, textStatus) { |
|
160 if ( data == '-1' ) |
|
161 return itemAjaxError(this.id, 'You do not have permission. Has your session expired?'); |
|
162 if ( data == '0' ) |
|
163 return itemAjaxError(this.id, 'Could not be deleted. Has it been deleted already?'); |
|
164 |
|
165 var id = this.id, item = jQuery('#media-item-' + id); |
|
166 |
|
167 // Decrement the counters. |
|
168 if ( type = jQuery('#type-of-' + id).val() ) |
|
169 jQuery('#' + type + '-counter').text( jQuery('#' + type + '-counter').text() - 1 ); |
|
170 if ( item.hasClass('child-of-'+post_id) ) |
|
171 jQuery('#attachments-count').text( jQuery('#attachments-count').text() - 1 ); |
|
172 |
|
173 if ( jQuery('form.type-form #media-items').children().length == 1 && jQuery('.hidden', '#media-items').length > 0 ) { |
|
174 jQuery('.toggle').toggle(); |
|
175 jQuery('.slidetoggle').slideUp(200).siblings().removeClass('hidden'); |
|
176 } |
|
177 |
|
178 // Vanish it. |
|
179 jQuery('.toggle', item).toggle(); |
|
180 jQuery('.slidetoggle', item).slideUp(200).siblings().removeClass('hidden'); |
|
181 item.css( {backgroundColor:'#faa'} ).animate( {backgroundColor:'#f4f4f4'}, {queue:false, duration:500} ).addClass('undo'); |
|
182 |
|
183 jQuery('.filename:empty', item).remove(); |
|
184 jQuery('.filename .title', item).css('font-weight','bold'); |
|
185 jQuery('.filename', item).append('<span class="trashnotice"> ' + swfuploadL10n.deleted + ' </span>').siblings('a.toggle').hide(); |
|
186 jQuery('.filename', item).append( jQuery('a.undo', item).removeClass('hidden') ); |
|
187 jQuery('.menu_order_input', item).hide(); |
|
188 |
|
189 return; |
|
190 } |
|
191 |
|
192 function deleteError(X, textStatus, errorThrown) { |
|
193 // TODO |
|
194 } |
|
195 |
|
196 function updateMediaForm() { |
|
197 var one = jQuery('form.type-form #media-items').children(), items = jQuery('#media-items').children(); |
|
198 |
|
199 // Just one file, no need for collapsible part |
|
200 if ( one.length == 1 ) { |
|
201 jQuery('.slidetoggle', one).slideDown(500).siblings().addClass('hidden').filter('.toggle').toggle(); |
|
202 } |
|
203 |
|
204 // Only show Save buttons when there is at least one file. |
|
205 if ( items.not('.media-blank').length > 0 ) |
|
206 jQuery('.savebutton').show(); |
|
207 else |
|
208 jQuery('.savebutton').hide(); |
|
209 |
|
210 // Only show Gallery button when there are at least two files. |
|
211 if ( items.length > 1 ) |
|
212 jQuery('.insert-gallery').show(); |
|
213 else |
|
214 jQuery('.insert-gallery').hide(); |
|
215 } |
|
216 |
|
217 function uploadSuccess(fileObj, serverData) { |
|
218 // if async-upload returned an error message, place it in the media item div and return |
|
219 if ( serverData.match('media-upload-error') ) { |
|
220 jQuery('#media-item-' + fileObj.id).html(serverData); |
|
221 return; |
|
222 } |
|
223 |
|
224 prepareMediaItem(fileObj, serverData); |
|
225 updateMediaForm(); |
|
226 |
|
227 // Increment the counter. |
|
228 if ( jQuery('#media-item-' + fileObj.id).hasClass('child-of-' + post_id) ) |
|
229 jQuery('#attachments-count').text(1 * jQuery('#attachments-count').text() + 1); |
|
230 } |
|
231 |
|
232 function uploadComplete(fileObj) { |
|
233 // If no more uploads queued, enable the submit button |
|
234 if ( swfu.getStats().files_queued == 0 ) { |
|
235 jQuery('#cancel-upload').prop('disabled', true); |
|
236 jQuery('#insert-gallery').prop('disabled', false); |
|
237 } |
|
238 } |
|
239 |
|
240 |
|
241 // wp-specific error handlers |
|
242 |
|
243 // generic message |
|
244 function wpQueueError(message) { |
|
245 jQuery('#media-upload-error').show().text(message); |
|
246 } |
|
247 |
|
248 // file-specific message |
|
249 function wpFileError(fileObj, message) { |
|
250 var item = jQuery('#media-item-' + fileObj.id); |
|
251 var filename = jQuery('.filename', item).text(); |
|
252 |
|
253 item.html('<div class="error-div">' |
|
254 + '<a class="dismiss" href="#">' + swfuploadL10n.dismiss + '</a>' |
|
255 + '<strong>' + swfuploadL10n.error_uploading.replace('%s', filename) + '</strong><br />' |
|
256 + message |
|
257 + '</div>'); |
|
258 item.find('a.dismiss').click(function(){jQuery(this).parents('.media-item').slideUp(200, function(){jQuery(this).remove();})}); |
|
259 } |
|
260 |
|
261 function fileQueueError(fileObj, error_code, message) { |
|
262 // Handle this error separately because we don't want to create a FileProgress element for it. |
|
263 if ( error_code == SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED ) { |
|
264 wpQueueError(swfuploadL10n.queue_limit_exceeded); |
|
265 } |
|
266 else if ( error_code == SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT ) { |
|
267 fileQueued(fileObj); |
|
268 wpFileError(fileObj, swfuploadL10n.file_exceeds_size_limit); |
|
269 } |
|
270 else if ( error_code == SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE ) { |
|
271 fileQueued(fileObj); |
|
272 wpFileError(fileObj, swfuploadL10n.zero_byte_file); |
|
273 } |
|
274 else if ( error_code == SWFUpload.QUEUE_ERROR.INVALID_FILETYPE ) { |
|
275 fileQueued(fileObj); |
|
276 wpFileError(fileObj, swfuploadL10n.invalid_filetype); |
|
277 } |
|
278 else { |
|
279 wpQueueError(swfuploadL10n.default_error); |
|
280 } |
|
281 } |
|
282 |
|
283 function fileDialogComplete(num_files_queued) { |
|
284 try { |
|
285 if (num_files_queued > 0) { |
|
286 this.startUpload(); |
|
287 } |
|
288 } catch (ex) { |
|
289 this.debug(ex); |
|
290 } |
|
291 } |
|
292 |
|
293 function switchUploader(s) { |
|
294 var f = document.getElementById(swfu.customSettings.swfupload_element_id), h = document.getElementById(swfu.customSettings.degraded_element_id); |
|
295 if ( s ) { |
|
296 f.style.display = 'block'; |
|
297 h.style.display = 'none'; |
|
298 } else { |
|
299 f.style.display = 'none'; |
|
300 h.style.display = 'block'; |
|
301 } |
|
302 } |
|
303 |
|
304 function swfuploadPreLoad() { |
|
305 if ( !uploaderMode ) { |
|
306 switchUploader(1); |
|
307 } else { |
|
308 switchUploader(0); |
|
309 } |
|
310 } |
|
311 |
|
312 function swfuploadLoadFailed() { |
|
313 switchUploader(0); |
|
314 jQuery('.upload-html-bypass').hide(); |
|
315 } |
|
316 |
|
317 function uploadError(fileObj, errorCode, message) { |
|
318 |
|
319 switch (errorCode) { |
|
320 case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL: |
|
321 wpFileError(fileObj, swfuploadL10n.missing_upload_url); |
|
322 break; |
|
323 case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED: |
|
324 wpFileError(fileObj, swfuploadL10n.upload_limit_exceeded); |
|
325 break; |
|
326 case SWFUpload.UPLOAD_ERROR.HTTP_ERROR: |
|
327 wpQueueError(swfuploadL10n.http_error); |
|
328 break; |
|
329 case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED: |
|
330 wpQueueError(swfuploadL10n.upload_failed); |
|
331 break; |
|
332 case SWFUpload.UPLOAD_ERROR.IO_ERROR: |
|
333 wpQueueError(swfuploadL10n.io_error); |
|
334 break; |
|
335 case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR: |
|
336 wpQueueError(swfuploadL10n.security_error); |
|
337 break; |
|
338 case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED: |
|
339 case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED: |
|
340 jQuery('#media-item-' + fileObj.id).remove(); |
|
341 break; |
|
342 default: |
|
343 wpFileError(fileObj, swfuploadL10n.default_error); |
|
344 } |
|
345 } |
|
346 |
|
347 function cancelUpload() { |
|
348 swfu.cancelQueue(); |
|
349 } |
|
350 |
|
351 // remember the last used image size, alignment and url |
|
352 jQuery(document).ready(function($){ |
|
353 $('input[type="radio"]', '#media-items').live('click', function(){ |
|
354 var tr = $(this).closest('tr'); |
|
355 |
|
356 if ( $(tr).hasClass('align') ) |
|
357 setUserSetting('align', $(this).val()); |
|
358 else if ( $(tr).hasClass('image-size') ) |
|
359 setUserSetting('imgsize', $(this).val()); |
|
360 }); |
|
361 |
|
362 $('button.button', '#media-items').live('click', function(){ |
|
363 var c = this.className || ''; |
|
364 c = c.match(/url([^ '"]+)/); |
|
365 if ( c && c[1] ) { |
|
366 setUserSetting('urlbutton', c[1]); |
|
367 $(this).siblings('.urlfield').val( $(this).attr('title') ); |
|
368 } |
|
369 }); |
|
370 }); |