Improves URL hashs.
This commit is contained in:
parent
7c1feaebc0
commit
997f1cd80f
4 changed files with 58 additions and 11 deletions
|
@ -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 path problems on servers running on Windows in PHP version
|
||||||
* fixes broken links in custom headers/footers while zipped download enabled
|
* fixes broken links in custom headers/footers while zipped download enabled
|
||||||
* fixes problems with thumbnails for files with single or double quotes in filename
|
* fixes problems with thumbnails for files with single or double quotes in filename
|
||||||
|
* improves url hashes
|
||||||
* updates year in `LICENSE.TXT`
|
* updates year in `LICENSE.TXT`
|
||||||
* updates es translation
|
* updates es translation
|
||||||
* adds zh-tw translation by [Yao Wei](http://github.com/medicalwei)
|
* adds zh-tw translation by [Yao Wei](http://github.com/medicalwei)
|
||||||
|
|
|
@ -44,6 +44,35 @@
|
||||||
});
|
});
|
||||||
return map;
|
return map;
|
||||||
}(config.types)),
|
}(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 () {
|
api = function () {
|
||||||
|
|
||||||
return settings.h5aiAbsHref + "php/api.php";
|
return settings.h5aiAbsHref + "php/api.php";
|
||||||
|
@ -68,6 +97,7 @@
|
||||||
viewmode = amplify.store(settings.store.viewmode);
|
viewmode = amplify.store(settings.store.viewmode);
|
||||||
}
|
}
|
||||||
viewmode = $.inArray(viewmode, settings.viewmodes) >= 0 ? viewmode : settings.viewmodes[0];
|
viewmode = $.inArray(viewmode, settings.viewmodes) >= 0 ? viewmode : settings.viewmodes[0];
|
||||||
|
H5AI.core.hash({view: viewmode});
|
||||||
|
|
||||||
$viewDetails.add($viewIcons).removeClass("current");
|
$viewDetails.add($viewIcons).removeClass("current");
|
||||||
if (viewmode === "details") {
|
if (viewmode === "details") {
|
||||||
|
@ -123,13 +153,19 @@
|
||||||
if ($.inArray("icons", settings.viewmodes) >= 0) {
|
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>")
|
$("<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()
|
.find("img").attr("src", image("view-icons")).end()
|
||||||
.click(function () { viewmode("icons"); })
|
.find("a").click(function (event) {
|
||||||
|
viewmode("icons");
|
||||||
|
event.preventDefault();
|
||||||
|
}).end()
|
||||||
.appendTo($navbar);
|
.appendTo($navbar);
|
||||||
}
|
}
|
||||||
if ($.inArray("details", settings.viewmodes) >= 0) {
|
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>")
|
$("<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()
|
.find("img").attr("src", image("view-details")).end()
|
||||||
.click(function () { viewmode("details"); })
|
.find("a").click(function (event) {
|
||||||
|
viewmode("details");
|
||||||
|
event.preventDefault();
|
||||||
|
}).end()
|
||||||
.appendTo($navbar);
|
.appendTo($navbar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,6 +293,7 @@
|
||||||
$(".lang").text(lang);
|
$(".lang").text(lang);
|
||||||
$(".langOption").removeClass("current");
|
$(".langOption").removeClass("current");
|
||||||
$(".langOption." + lang).addClass("current");
|
$(".langOption." + lang).addClass("current");
|
||||||
|
H5AI.core.hash({lang: lang});
|
||||||
}
|
}
|
||||||
|
|
||||||
formatDates(selected.dateFormat || settings.dateFormat);
|
formatDates(selected.dateFormat || settings.dateFormat);
|
||||||
|
@ -386,6 +423,7 @@
|
||||||
|
|
||||||
return {
|
return {
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
hash: hash,
|
||||||
api: api,
|
api: api,
|
||||||
image: image,
|
image: image,
|
||||||
icon: icon,
|
icon: icon,
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
} else {
|
} else {
|
||||||
$filter.removeClass('current');
|
$filter.removeClass('current');
|
||||||
}
|
}
|
||||||
|
H5AI.core.hash({filter: val});
|
||||||
},
|
},
|
||||||
parseFilterSequence = function (sequence) {
|
parseFilterSequence = function (sequence) {
|
||||||
|
|
||||||
|
@ -91,6 +92,12 @@
|
||||||
})
|
})
|
||||||
.end()
|
.end()
|
||||||
.appendTo($("#navbar"));
|
.appendTo($("#navbar"));
|
||||||
|
|
||||||
|
var initialFilter = H5AI.core.hash('filter');
|
||||||
|
if (initialFilter) {
|
||||||
|
$('#filter input').val(initialFilter);
|
||||||
|
checkState(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -78,14 +78,15 @@
|
||||||
var order = orders[id];
|
var order = orders[id];
|
||||||
|
|
||||||
$all.removeClass("ascending").removeClass("descending");
|
$all.removeClass("ascending").removeClass("descending");
|
||||||
order.head.addClass(order.clas).attr("href", "#!/sort=" + id);
|
order.head.addClass(order.clas);
|
||||||
sort(order.fn);
|
sort(order.fn);
|
||||||
|
H5AI.core.hash({sort: id});
|
||||||
},
|
},
|
||||||
init = function () {
|
init = function () {
|
||||||
|
|
||||||
var $ascending = $("<img src='" + H5AI.core.image("ascending") + "' class='sort ascending' alt='ascending' />"),
|
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' />"),
|
$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"),
|
$header = $("#extended li.header"),
|
||||||
$label = $header.find("a.label"),
|
$label = $header.find("a.label"),
|
||||||
$date = $header.find("a.date"),
|
$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
|
$label
|
||||||
.attr("href", "#!/sort=na")
|
|
||||||
.append($ascending.clone()).append($descending.clone())
|
.append($ascending.clone()).append($descending.clone())
|
||||||
.click(function () {
|
.click(function (event) {
|
||||||
sortBy("n" + ($label.hasClass("ascending") ? "d" : "a"));
|
sortBy("n" + ($label.hasClass("ascending") ? "d" : "a"));
|
||||||
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
$date
|
$date
|
||||||
.attr("href", "#!/sort=da")
|
|
||||||
.prepend($ascending.clone()).prepend($descending.clone())
|
.prepend($ascending.clone()).prepend($descending.clone())
|
||||||
.click(function () {
|
.click(function (event) {
|
||||||
sortBy("d" + ($date.hasClass("ascending") ? "d" : "a"));
|
sortBy("d" + ($date.hasClass("ascending") ? "d" : "a"));
|
||||||
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
$size
|
$size
|
||||||
.attr("href", "#!/sort=sa")
|
|
||||||
.prepend($ascending.clone()).prepend($descending.clone())
|
.prepend($ascending.clone()).prepend($descending.clone())
|
||||||
.click(function () {
|
.click(function (event) {
|
||||||
sortBy("s" + ($size.hasClass("ascending") ? "d" : "a"));
|
sortBy("s" + ($size.hasClass("ascending") ? "d" : "a"));
|
||||||
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue