Skip to content

Commit

Permalink
HTML4/HTML5/BrowserPlus: avoid adding mime type twice to dialog trigg…
Browse files Browse the repository at this point in the history
…er (as minimum - no need).
  • Loading branch information
jayarjo committed Jan 6, 2012
1 parent 75323c4 commit 5693935
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 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.',
Expand Down
12 changes: 8 additions & 4 deletions src/javascript/plupload.browserplus.js
Expand Up @@ -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();

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/javascript/plupload.html4.js
Expand Up @@ -68,7 +68,7 @@

type = plupload.mimeTypes[ext[y]];

if (type) {
if (type && plupload.inArray(type, mimes) === -1) {
mimes.push(type);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/javascript/plupload.html5.js
Expand Up @@ -289,7 +289,7 @@

type = plupload.mimeTypes[ext[y]];

if (type) {
if (type && plupload.inArray(type, mimes) === -1) {
mimes.push(type);
}
}
Expand Down
28 changes: 27 additions & 1 deletion src/javascript/plupload.js
Expand Up @@ -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," +
Expand All @@ -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," +
Expand All @@ -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"
);

/**
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5693935

Please sign in to comment.