aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/assets/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/assets/javascript')
-rw-r--r--phpBB/assets/javascript/core.js105
-rw-r--r--phpBB/assets/javascript/jquery.min.js (renamed from phpBB/assets/javascript/jquery.js)0
2 files changed, 102 insertions, 3 deletions
diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js
index f461d5a175..9eba80542c 100644
--- a/phpBB/assets/javascript/core.js
+++ b/phpBB/assets/javascript/core.js
@@ -84,8 +84,8 @@ phpbb.alert = function(title, msg, fadedark) {
e.stopPropagation();
});
- $(document).bind('keydown', function(e) {
- if (e.keyCode === keymap.ENTER || e.keyCode === keymap.ESC) {
+ $(document).keydown(function(e) {
+ if ((e.keyCode === keymap.ENTER || e.keyCode === keymap.ESC) && dark.is(':visible')) {
dark.trigger('click');
e.preventDefault();
@@ -333,7 +333,9 @@ phpbb.ajaxify = function(options) {
// Hide the alert even if we refresh the page, in case the user
// presses the back button.
dark.fadeOut(phpbb.alertTime, function() {
- alert.hide();
+ if (typeof alert !== 'undefined') {
+ alert.hide();
+ }
});
}, res.REFRESH_DATA.time * 1000); // Server specifies time in seconds
}
@@ -694,6 +696,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
*
@@ -1408,6 +1478,21 @@ phpbb.toggleDisplay = function(id, action, type) {
}
/**
+* Toggle additional settings based on the selected
+* option of select element.
+*
+* @param jQuery el jQuery select element object.
+* @return undefined
+*/
+phpbb.toggleSelectSettings = function(el) {
+ el.children().each(function() {
+ var option = $(this),
+ setting = $(option.data('toggle-setting'));
+ setting.toggle(option.is(':selected'));
+ });
+};
+
+/**
* Get function from name.
* Based on http://stackoverflow.com/a/359910
*
@@ -1444,6 +1529,20 @@ $(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'));
+
+ // Hide settings that are not selected via select element.
+ $('select[data-togglable-settings]').each(function() {
+ var select = $(this);
+
+ select.change(function() {
+ phpbb.toggleSelectSettings(select);
+ });
+ phpbb.toggleSelectSettings(select);
+ });
});
})(jQuery); // Avoid conflicts with other libraries
diff --git a/phpBB/assets/javascript/jquery.js b/phpBB/assets/javascript/jquery.min.js
index 73f33fb3aa..73f33fb3aa 100644
--- a/phpBB/assets/javascript/jquery.js
+++ b/phpBB/assets/javascript/jquery.min.js