Merge pull request #722 from falaca/master

parse dropbox URLs for image preview plugin (v4)
This commit is contained in:
Lorenz Hübschle-Schneider 2016-01-03 12:41:02 +01:00
commit a50d72a3b5

View file

@ -280,10 +280,25 @@ plugins.factory('userPlugins', function() {
} else if (url.match(/^http:\/\/(i\.)?imgur\.com\//i)) {
// remove protocol specification to load over https if used by g-b
url = url.replace(/http:/, "");
} else if (url.match(/^https:\/\/www\.dropbox\.com\/s\/[a-z0-9]+\/[^?]+$/i)) {
} else if (url.match(/^https:\/\/www\.dropbox\.com\/s\/[a-z0-9]+\//i)) {
// Dropbox requires a get parameter, dl=1
// TODO strip an existing dl=0 parameter
url = url + "?dl=1";
var dbox_url = document.createElement("a");
dbox_url.href = url;
var base_url = dbox_url.protocol + '//' + dbox_url.host + dbox_url.pathname + '?';
var dbox_params = dbox_url.search.substring(1).split('&');
var dl_added = false;
for (var i = 0; i < dbox_params.length; i++) {
if (dbox_params[i].split('=')[0] === "dl") {
dbox_params[i] = "dl=1";
dl_added = true;
// we continue looking at the other parameters in case
// it's specified twice or something
}
}
if (!dl_added) {
dbox_params.push("dl=1");
}
url = base_url + dbox_params.join('&');
}
return function() {
var element = this.getElement();