From 5693935fa2d90ec1fdfa097fd7306c1a6c1e8dd5 Mon Sep 17 00:00:00 2001 From: Davit Barbakadze Date: Fri, 6 Jan 2012 20:36:19 +0400 Subject: [PATCH] HTML4/HTML5/BrowserPlus: avoid adding mime type twice to dialog trigger (as minimum - no need). --- src/javascript/i18n/fr.js | 2 +- src/javascript/plupload.browserplus.js | 12 +++++++---- src/javascript/plupload.html4.js | 2 +- src/javascript/plupload.html5.js | 2 +- src/javascript/plupload.js | 28 +++++++++++++++++++++++++- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/javascript/i18n/fr.js b/src/javascript/i18n/fr.js index c534ec4ec..53dbe289f 100644 --- a/src/javascript/i18n/fr.js +++ b/src/javascript/i18n/fr.js @@ -1,4 +1,4 @@ -// .po file like language pack +// French plupload.addI18n({ 'Select files' : 'Sélectionnez les fichiers', 'Add files to the upload queue and click the start button.' : 'Ajoutez des fichiers à la file et appuyez sur le bouton démarrer.', diff --git a/src/javascript/plupload.browserplus.js b/src/javascript/plupload.browserplus.js index 44f99d35d..2cc9e0ed5 100644 --- a/src/javascript/plupload.browserplus.js +++ b/src/javascript/plupload.browserplus.js @@ -143,7 +143,7 @@ } plupload.addEvent(document.getElementById(settings.browse_button), 'click', function(e) { - var mimeTypes = [], i, a, filters = settings.filters, ext; + var mimes = [], i, a, filters = settings.filters, ext, type; e.preventDefault(); @@ -158,15 +158,19 @@ for (a = 0; a < ext.length; a++) { if (ext[a] === '*') { - mimeTypes = []; + mimes = []; break no_type_restriction; } - mimeTypes.push(plupload.mimeTypes[ext[a]]); + type = plupload.mimeTypes[ext[a]]; + + if (type && plupload.inArray(type, mimes) === -1) { + mimes.push(plupload.mimes[ext[a]]); + } } } browserPlus.FileBrowse.OpenBrowseDialog({ - mimeTypes : mimeTypes + mimeTypes : mimes }, function(res) { if (res.success) { addSelectedFiles(res.value); diff --git a/src/javascript/plupload.html4.js b/src/javascript/plupload.html4.js index f49fba769..6ffdec9c7 100644 --- a/src/javascript/plupload.html4.js +++ b/src/javascript/plupload.html4.js @@ -68,7 +68,7 @@ type = plupload.mimeTypes[ext[y]]; - if (type) { + if (type && plupload.inArray(type, mimes) === -1) { mimes.push(type); } } diff --git a/src/javascript/plupload.html5.js b/src/javascript/plupload.html5.js index 2eb295d33..0f9e2a7b4 100644 --- a/src/javascript/plupload.html5.js +++ b/src/javascript/plupload.html5.js @@ -289,7 +289,7 @@ type = plupload.mimeTypes[ext[y]]; - if (type) { + if (type && plupload.inArray(type, mimes) === -1) { mimes.push(type); } } diff --git a/src/javascript/plupload.js b/src/javascript/plupload.js index f666571a8..ef3d2e229 100644 --- a/src/javascript/plupload.js +++ b/src/javascript/plupload.js @@ -57,6 +57,8 @@ "application/vnd.openxmlformats-officedocument.presentationml.presentation,pptx," + "application/vnd.openxmlformats-officedocument.presentationml.template,potx," + "application/vnd.openxmlformats-officedocument.presentationml.slideshow,ppsx," + + "application/x-javascript,js," + + "application/json,json," + "audio/mpeg,mpga mpega mp2 mp3," + "audio/x-wav,wav," + "audio/mp4,m4a," + @@ -69,6 +71,7 @@ "image/tiff,tiff tif," + "text/html,htm html xhtml," + "text/rtf,rtf," + + "text/css,css," + "video/mpeg,mpeg mpg mpe," + "video/quicktime,qt mov," + "video/mp4,mp4," + @@ -80,7 +83,7 @@ "video/vnd.rn-realvideo,rv," + "text/csv,csv," + "text/plain,asc txt text diff log," + - "application/octet-stream,exe" + "application/octet-stream,exe eot otf ttf ttc woff" ); /** @@ -581,6 +584,29 @@ return arr; }, + + /** + * Find an element in array and return it's index if present, otherwise return -1. + * + * @method inArray + * @param {mixed} needle Element to find + * @param {Array} array + * @return {Int} Index of the element, or -1 if not found + */ + inArray : function(needle, array) { + if (array) { + if (Array.prototype.indexOf) { + return Array.prototype.indexOf.call(array, needle); + } + + for (var i = 0, length = array.length; i < length; i++) { + if (array[i] === needle) { + return i; + } + } + } + return -1; + }, /** * Extends the language pack object with new items.