Improves URL hashs.

This commit is contained in:
Lars Jung 2012-02-23 22:41:17 +01:00
parent 7c1feaebc0
commit 997f1cd80f
4 changed files with 58 additions and 11 deletions

View file

@ -42,6 +42,7 @@ h5ai is provided under the terms of the [MIT License](http://github.com/lrsjng/h
* fixes path problems on servers running on Windows in PHP version
* fixes broken links in custom headers/footers while zipped download enabled
* fixes problems with thumbnails for files with single or double quotes in filename
* improves url hashes
* updates year in `LICENSE.TXT`
* updates es translation
* adds zh-tw translation by [Yao Wei](http://github.com/medicalwei)

View file

@ -44,6 +44,35 @@
});
return map;
}(config.types)),
hash = function (obj) {
if ($.isPlainObject(obj)) {
var hashStr = '';
$.each($.extend({}, hash(), obj), function (key, value) {
if (value) {
hashStr += '/' + key + '=' + value;
}
});
hashStr = '#!' + hashStr;
window.location.hash = hashStr;
return hashStr;
} else {
var result = {},
parts = document.location.hash.split('/');
if (parts.length >= 2 || parts[0] === '#!') {
parts.shift();
$.each(parts, function (idx, part) {
var match = /^([^=]*)=(.*?)$/.exec(part);
if (match) {
result[match[1]] = match[2];
}
});
}
return typeof obj === 'string' ? result[obj] : result;
}
},
api = function () {
return settings.h5aiAbsHref + "php/api.php";
@ -68,6 +97,7 @@
viewmode = amplify.store(settings.store.viewmode);
}
viewmode = $.inArray(viewmode, settings.viewmodes) >= 0 ? viewmode : settings.viewmodes[0];
H5AI.core.hash({view: viewmode});
$viewDetails.add($viewIcons).removeClass("current");
if (viewmode === "details") {
@ -123,13 +153,19 @@
if ($.inArray("icons", settings.viewmodes) >= 0) {
$("<li id='viewicons' class='view'><a href='#'><img alt='view-icons' /><span class='l10n-icons'>icons</span></a></li>")
.find("img").attr("src", image("view-icons")).end()
.click(function () { viewmode("icons"); })
.find("a").click(function (event) {
viewmode("icons");
event.preventDefault();
}).end()
.appendTo($navbar);
}
if ($.inArray("details", settings.viewmodes) >= 0) {
$("<li id='viewdetails' class='view'><a href='#'><img alt='view-details' /><span class='l10n-details'>details</span></a></li>")
.find("img").attr("src", image("view-details")).end()
.click(function () { viewmode("details"); })
.find("a").click(function (event) {
viewmode("details");
event.preventDefault();
}).end()
.appendTo($navbar);
}
}
@ -257,6 +293,7 @@
$(".lang").text(lang);
$(".langOption").removeClass("current");
$(".langOption." + lang).addClass("current");
H5AI.core.hash({lang: lang});
}
formatDates(selected.dateFormat || settings.dateFormat);
@ -386,6 +423,7 @@
return {
settings: settings,
hash: hash,
api: api,
image: image,
icon: icon,

View file

@ -45,6 +45,7 @@
} else {
$filter.removeClass('current');
}
H5AI.core.hash({filter: val});
},
parseFilterSequence = function (sequence) {
@ -91,6 +92,12 @@
})
.end()
.appendTo($("#navbar"));
var initialFilter = H5AI.core.hash('filter');
if (initialFilter) {
$('#filter input').val(initialFilter);
checkState(false);
}
}
};

View file

@ -78,14 +78,15 @@
var order = orders[id];
$all.removeClass("ascending").removeClass("descending");
order.head.addClass(order.clas).attr("href", "#!/sort=" + id);
order.head.addClass(order.clas);
sort(order.fn);
H5AI.core.hash({sort: id});
},
init = function () {
var $ascending = $("<img src='" + H5AI.core.image("ascending") + "' class='sort ascending' alt='ascending' />"),
$descending = $("<img src='" + H5AI.core.image("descending") + "' class='sort descending' alt='descending' />"),
initialOrder = /^.*#!.*\/sort=(.*?)(?:\/.*)?$/.exec(document.location),
initialOrder = H5AI.core.hash('sort'),
$header = $("#extended li.header"),
$label = $header.find("a.label"),
$date = $header.find("a.date"),
@ -125,27 +126,27 @@
}
};
sortBy(initialOrder ? initialOrder[1] : H5AI.core.settings.sortorder);
sortBy(initialOrder ? initialOrder : H5AI.core.settings.sortorder);
$label
.attr("href", "#!/sort=na")
.append($ascending.clone()).append($descending.clone())
.click(function () {
.click(function (event) {
sortBy("n" + ($label.hasClass("ascending") ? "d" : "a"));
event.preventDefault();
});
$date
.attr("href", "#!/sort=da")
.prepend($ascending.clone()).prepend($descending.clone())
.click(function () {
.click(function (event) {
sortBy("d" + ($date.hasClass("ascending") ? "d" : "a"));
event.preventDefault();
});
$size
.attr("href", "#!/sort=sa")
.prepend($ascending.clone()).prepend($descending.clone())
.click(function () {
.click(function (event) {
sortBy("s" + ($size.hasClass("ascending") ? "d" : "a"));
event.preventDefault();
});
};