Révision 6eb8d15f
Ajouté par Assos Assos il y a presque 10 ans
drupal7/sites/all/modules/imce/js/imce.js | ||
---|---|---|
7 | 7 |
//initiate imce. |
8 | 8 |
initiate: function() { |
9 | 9 |
imce.conf = Drupal.settings.imce || {}; |
10 |
imce.ie = (navigator.userAgent.match(/msie (\d+)/i) || ['', 0])[1] * 1; |
|
11 | 10 |
if (imce.conf.error != false) return; |
11 |
imce.ie = (navigator.userAgent.match(/msie (\d+)/i) || ['', 0])[1] * 1; |
|
12 | 12 |
imce.FLW = imce.el('file-list-wrapper'), imce.SBW = imce.el('sub-browse-wrapper'); |
13 | 13 |
imce.NW = imce.el('navigation-wrapper'), imce.BW = imce.el('browse-wrapper'); |
14 | 14 |
imce.PW = imce.el('preview-wrapper'), imce.FW = imce.el('forms-wrapper'); |
... | ... | |
19 | 19 |
imce.initiateList();//process file list |
20 | 20 |
imce.initiateOps();//prepare operation tabs |
21 | 21 |
imce.refreshOps(); |
22 |
// Bind global error handler |
|
23 |
$(document).ajaxError(imce.ajaxError); |
|
22 | 24 |
imce.invoke('load', window);//run functions set by external applications. |
23 | 25 |
}, |
24 | 26 |
|
... | ... | |
241 | 243 |
|
242 | 244 |
//convert upload form to an op. |
243 | 245 |
setUploadOp: function () { |
244 |
var form = imce.el('imce-upload-form'); |
|
246 |
var el, form = imce.el('imce-upload-form');
|
|
245 | 247 |
if (!form) return; |
246 | 248 |
$(form).ajaxForm(imce.uploadSettings()).find('fieldset').each(function() {//clean up fieldsets |
247 | 249 |
this.removeChild(this.firstChild); |
248 | 250 |
$(this).after(this.childNodes); |
249 | 251 |
}).remove(); |
252 |
// Set html response flag |
|
253 |
el = form.elements['files[imce]']; |
|
254 |
if (el && el.files && window.FormData) { |
|
255 |
if (el = form.elements.html_response) { |
|
256 |
el.value = 0; |
|
257 |
} |
|
258 |
} |
|
250 | 259 |
imce.opAdd({name: 'upload', title: Drupal.t('Upload'), content: form});//add op |
251 | 260 |
}, |
252 | 261 |
|
... | ... | |
257 | 266 |
$(form.elements.filenames).parent().remove(); |
258 | 267 |
$(form).find('fieldset').each(function() {//remove fieldsets |
259 | 268 |
var $sbmt = $('input:submit', this); |
260 |
if (!$sbmt.size()) return;
|
|
269 |
if (!$sbmt.length) return;
|
|
261 | 270 |
var Op = {name: $sbmt.attr('id').substr(5)}; |
262 | 271 |
var func = function() {imce.fopSubmit(Op.name); return false;}; |
263 | 272 |
$sbmt.click(func); |
... | ... | |
279 | 288 |
//add a new file operation |
280 | 289 |
opAdd: function (op) { |
281 | 290 |
var oplist = imce.el('ops-list'), opcons = imce.el('op-contents'); |
282 |
var name = op.name || ('op-'+ $(oplist).children('li').size());
|
|
291 |
var name = op.name || ('op-'+ $(oplist).children('li').length);
|
|
283 | 292 |
var title = op.title || 'Untitled'; |
284 | 293 |
var Op = imce.ops[name] = {title: title}; |
285 | 294 |
if (op.content) { |
... | ... | |
323 | 332 |
var $inputs = $('input', imce.ops[imce.vars.op].div); |
324 | 333 |
$inputs.eq(0).focus(); |
325 | 334 |
//form inputs become invisible in IE. Solution is as stupid as the behavior. |
326 |
$('html').is('.ie') && $inputs.addClass('dummyie').removeClass('dummyie');
|
|
335 |
$('html').hasClass('ie') && $inputs.addClass('dummyie').removeClass('dummyie');
|
|
327 | 336 |
} |
328 | 337 |
}); |
329 | 338 |
}); |
... | ... | |
439 | 448 |
|
440 | 449 |
//settings for upload |
441 | 450 |
uploadSettings: function () { |
442 |
return {beforeSubmit: imce.uploadValidate, success: function (response) {imce.processResponse($.parseJSON(response));}, complete: function () {imce.fopLoading('upload', false);}, resetForm: true}; |
|
451 |
return { |
|
452 |
beforeSubmit: imce.uploadValidate, |
|
453 |
success: function (response) { |
|
454 |
try{ |
|
455 |
imce.processResponse($.parseJSON(response)); |
|
456 |
} catch(e) {} |
|
457 |
}, |
|
458 |
complete: function () { |
|
459 |
imce.fopLoading('upload', false); |
|
460 |
}, |
|
461 |
resetForm: true, |
|
462 |
dataType: 'text' |
|
463 |
}; |
|
443 | 464 |
}, |
444 | 465 |
|
445 | 466 |
//validate default ops(delete, thumb, resize) |
... | ... | |
449 | 470 |
case 'delete': |
450 | 471 |
return confirm(Drupal.t('Delete selected files?')); |
451 | 472 |
case 'thumb': |
452 |
if (!$('input:checked', imce.ops['thumb'].div).size()) {
|
|
473 |
if (!$('input:checked', imce.ops['thumb'].div).length) {
|
|
453 | 474 |
return imce.setMessage(Drupal.t('Please select a thumbnail.'), 'error'); |
454 | 475 |
} |
455 | 476 |
return imce.validateImage(); |
... | ... | |
486 | 507 |
|
487 | 508 |
//settings for default file operations |
488 | 509 |
fopSettings: function (fop) { |
489 |
return {url: imce.ajaxURL(fop), type: 'POST', dataType: 'json', success: imce.processResponse, complete: function (response) {imce.fopLoading(fop, false);}, data: imce.vars.opform +'&filenames='+ escape(imce.serialNames()) +'&jsop='+ fop + (imce.ops[fop].div ? '&'+ $('input, select, textarea', imce.ops[fop].div).serialize() : '')};
|
|
510 |
return {url: imce.ajaxURL(fop), type: 'POST', dataType: 'json', success: imce.processResponse, complete: function (response) {imce.fopLoading(fop, false);}, data: imce.vars.opform +'&filenames='+ encodeURIComponent(imce.serialNames()) +'&jsop='+ fop + (imce.ops[fop].div ? '&'+ $('input, select, textarea', imce.ops[fop].div).serialize() : '')};
|
|
490 | 511 |
}, |
491 | 512 |
|
492 | 513 |
//toggle loading state |
... | ... | |
536 | 557 |
$('>div', msgs).each(function (){ |
537 | 558 |
var type = this.className.split(' ')[1]; |
538 | 559 |
var li = $('>ul li', this); |
539 |
if (li.size()) li.each(function () {imce.setMessage(this.innerHTML, type);});
|
|
560 |
if (li.length) li.each(function () {imce.setMessage(this.innerHTML, type);});
|
|
540 | 561 |
else imce.setMessage(this.innerHTML, type); |
541 | 562 |
}); |
542 | 563 |
$(msgs).remove(); |
... | ... | |
703 | 724 |
|
704 | 725 |
//decode urls. uses unescape. can be overridden to use decodeURIComponent |
705 | 726 |
decode: function (str) { |
706 |
return unescape(str); |
|
727 |
try { |
|
728 |
return decodeURIComponent(str); |
|
729 |
} catch(e) {} |
|
730 |
return str; |
|
707 | 731 |
}, |
708 | 732 |
|
709 | 733 |
//decode and convert to plain text |
... | ... | |
771 | 795 |
return false; |
772 | 796 |
}).appendTo('#op-contents')[0]; |
773 | 797 |
//navigation-header |
774 |
if (!$('#navigation-header').size()) {
|
|
798 |
if (!$('#navigation-header').length) {
|
|
775 | 799 |
$(imce.NW).children('.navigation-text').attr('id', 'navigation-header').wrapInner('<span></span>'); |
776 | 800 |
} |
777 | 801 |
//log |
... | ... | |
801 | 825 |
}; |
802 | 826 |
|
803 | 827 |
//initiate |
804 |
$(document).ready(imce.initiate).ajaxError(imce.ajaxError);
|
|
828 |
$(document).ready(imce.initiate); |
|
805 | 829 |
|
806 | 830 |
})(jQuery); |
Formats disponibles : Unified diff
Weekly update of contrib modules