Do not clear URL hash when no external mount params given

Whenever external share parameters were passed through the URL hash, the
URL hash will now be cleared.

In other cases, the hash needs to be left alone because it is used as
workaround for the lack of history API in IE8 / IE9

Removed getParamterByName() and use OC.Util.History.parseUrlQuery() that
does the same, including replacing the "+" with spaces.
This commit is contained in:
Vincent Petry 2014-06-25 12:24:46 +02:00
parent c6bcb07f83
commit 363f8f3205
1 changed files with 23 additions and 23 deletions

View File

@ -8,13 +8,6 @@
* *
*/ */
(function () { (function () {
var getParameterByName = function (query, name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\#&]" + name + "=([^&#]*)"),
results = regex.exec(query);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
};
var addExternalShare = function (remote, token, owner, name, password) { var addExternalShare = function (remote, token, owner, name, password) {
return $.post(OC.generateUrl('apps/files_sharing/external'), { return $.post(OC.generateUrl('apps/files_sharing/external'), {
remote: remote, remote: remote,
@ -25,7 +18,16 @@
}); });
}; };
var showAddExternalDialog = function (remote, token, owner, name, passwordProtected) { /**
* Shows "add external share" dialog.
*
* @param {String} remote remote server URL
* @param {String} owner owner name
* @param {String} name name of the shared folder
* @param {String} token authentication token
* @param {bool} passwordProtected true if the share is password protected
*/
OCA.Sharing.showAddExternalDialog = function (remote, token, owner, name, passwordProtected) {
var remoteClean = (remote.substr(0, 8) === 'https://') ? remote.substr(8) : remote.substr(7); var remoteClean = (remote.substr(0, 8) === 'https://') ? remote.substr(8) : remote.substr(7);
var callback = function (add, password) { var callback = function (add, password) {
password = password || ''; password = password || '';
@ -47,25 +49,23 @@
, 'Add Share', callback, true, 'Password', true); , 'Add Share', callback, true, 'Password', true);
} }
}; };
OCA.Sharing.showAddExternalDialog = function (hash) {
var remote = getParameterByName(hash, 'remote');
var owner = getParameterByName(hash, 'owner');
var name = getParameterByName(hash, 'name');
var token = getParameterByName(hash, 'token');
var passwordProtected = parseInt(getParameterByName(hash, 'protected'), 10);
if (remote && token && owner && name) {
showAddExternalDialog(remote, token, owner, name, passwordProtected);
}
};
})(); })();
$(document).ready(function () { $(document).ready(function () {
// FIXME: HACK: do not init when running unit tests, need a better way // FIXME: HACK: do not init when running unit tests, need a better way
if (!window.TESTING && OCA.Files) {// only run in the files app if (!window.TESTING && OCA.Files) {// only run in the files app
var hash = location.hash; var params = OC.Util.History.parseUrlQuery();
location.hash = ''; if (params.remote && params.token && params.owner && params.name) {
OCA.Sharing.showAddExternalDialog(hash); // clear hash, it is unlikely that it contain any extra parameters
location.hash = '';
params.passwordProtected = parseInt(params.passwordProtected, 10) === 1;
OCA.Sharing.showAddExternalDialog(
params.remote,
params.token,
params.owner,
params.name,
params.passwordProtected
);
}
} }
}); });