aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/assets/javascript/core.js
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-05-08 13:23:12 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-05-08 13:23:12 +0200
commite976f7908a85623a7f7ce30f1366d0b52957f8b5 (patch)
tree4c00bd36ffb10cf7b9831fcd45ed9ea0249b9f3b /phpBB/assets/javascript/core.js
parent416c58a4183c6cef877b4c91a7b7469a88696314 (diff)
parented14d12d148b1aa7e726121afa9ad79718745e1c (diff)
downloadforums-e976f7908a85623a7f7ce30f1366d0b52957f8b5.tar
forums-e976f7908a85623a7f7ce30f1366d0b52957f8b5.tar.gz
forums-e976f7908a85623a7f7ce30f1366d0b52957f8b5.tar.bz2
forums-e976f7908a85623a7f7ce30f1366d0b52957f8b5.tar.xz
forums-e976f7908a85623a7f7ce30f1366d0b52957f8b5.zip
Merge pull request #2414 from prototech/ticket/12440
[ticket/12440] Set browser URL to point to specific post when using view=unread * prototech/ticket/12440: [ticket/12440] Use a more generic approach for replacing the URL. [ticket/12440] Set browser URL to point to specific post when using view=unread Conflicts: phpBB/styles/prosilver/template/viewtopic_body.html
Diffstat (limited to 'phpBB/assets/javascript/core.js')
-rw-r--r--phpBB/assets/javascript/core.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js
index f461d5a175..ae8583ddbf 100644
--- a/phpBB/assets/javascript/core.js
+++ b/phpBB/assets/javascript/core.js
@@ -694,6 +694,74 @@ $('#phpbb').click(function(e) {
}
});
+phpbb.history = {};
+
+/**
+* Check whether a method in the native history object is supported.
+*
+* @param string fn Method name.
+* @return bool Returns true if the method is supported.
+*/
+phpbb.history.isSupported = function(fn) {
+ if (typeof history === 'undefined' || typeof history[fn] === 'undefined') {
+ return false;
+ }
+ return true;
+};
+
+/**
+* Wrapper for the pushState and replaceState methods of the
+* native history object.
+*
+* @param string mode Mode. Either push or replace.
+* @param string url New URL.
+* @param string title Optional page title.
+* @patam object obj Optional state object.
+*
+* @return undefined
+*/
+phpbb.history.alterUrl = function(mode, url, title, obj) {
+ var fn = mode + 'State';
+
+ if (!url || !phpbb.history.isSupported(fn)) {
+ return;
+ }
+ if (!title) {
+ title = document.title;
+ }
+ if (!obj) {
+ obj = null;
+ }
+
+ history[fn](obj, title, url);
+};
+
+/**
+* Wrapper for the native history.replaceState method.
+*
+* @param string url New URL.
+* @param string title Optional page title.
+* @patam object obj Optional state object.
+*
+* @return undefined
+*/
+phpbb.history.replaceUrl = function(url, title, obj) {
+ phpbb.history.alterUrl('replace', url, title, obj);
+};
+
+/**
+* Wrapper for the native history.pushState method.
+*
+* @param string url New URL.
+* @param string title Optional page title.
+* @patam object obj Optional state object.
+*
+* @return undefined
+*/
+phpbb.history.pushUrl = function(url, title, obj) {
+ phpbb.history.alterUrl('push', url, title, obj);
+};
+
/**
* Hide the optgroups that are not the selected timezone
*
@@ -1444,6 +1512,10 @@ $(document).ready(function() {
$('#color_palette_placeholder').each(function() {
phpbb.registerPalette($(this));
});
+
+ // Update browser history URL to point to specific post in viewtopic.php
+ // when using view=unread#unread link.
+ phpbb.history.replaceUrl($('#unread[data-url]').data('url'));
});
})(jQuery); // Avoid conflicts with other libraries