aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/assets/javascript/core.js
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2012-07-21 15:36:25 +0200
committerIgor Wiedler <igor@wiedler.ch>2012-07-21 15:36:25 +0200
commit5d57caee58c58d2a9c283abe8fe88f4eaec9f662 (patch)
treecd36469a74bf6847e5305d1fb8f4ac35266813e2 /phpBB/assets/javascript/core.js
parent3ebe89cb7eff57c3ffdbe0b7dcd9cdc35b48d26b (diff)
parent841ea0e494504400c798faa6cc860dd1179e1004 (diff)
downloadforums-5d57caee58c58d2a9c283abe8fe88f4eaec9f662.tar
forums-5d57caee58c58d2a9c283abe8fe88f4eaec9f662.tar.gz
forums-5d57caee58c58d2a9c283abe8fe88f4eaec9f662.tar.bz2
forums-5d57caee58c58d2a9c283abe8fe88f4eaec9f662.tar.xz
forums-5d57caee58c58d2a9c283abe8fe88f4eaec9f662.zip
Merge branch 'develop' into feature/dic
* develop: (441 commits) [feature/new-tz-handling] Don't use global user but make it a parameter [feature/new-tz-handling] Fix size of suggestion button in chrome [feature/new-tz-handling] Fall back to UTC, if the timezone is invalid [feature/new-tz-handling] Add previous selected value to validation if valid [feature/new-tz-handling] Display suggestion when a different value is selected [ticket/10998] Add border-radius to forum rules block - prosilver [feature/new-tz-handling] Remove additional marking of selected items [feature/new-tz-handling] Move update helper function to new class [feature/new-tz-handling] Fix unit test [feature/new-tz-handling] Delete old variable which is not used anymore [feature/new-tz-handling] Rename $user->tz back to $user->timezone [feature/pagination-as-list] New parameter for name of start var [feature/pagination-as-list] Updates for nils comments [feature/pagination-as-list] Rename and deprecate functions [feature/pagination-as-list] Various fixes and improvements [ticket/10968] Render pagination within the template [feature/new-tz-handling] Remove "timezone might be numeric" [feature/new-tz-handling] Add function to update the timezone [feature/new-tz-handling] Correctly update user and board timezones on update [ticket/10996] Use correct DBMS name in Travis config for PostgreSQL ... Conflicts: phpBB/common.php phpBB/composer.json phpBB/composer.lock tests/cron/task_provider_test.php
Diffstat (limited to 'phpBB/assets/javascript/core.js')
-rw-r--r--phpBB/assets/javascript/core.js134
1 files changed, 132 insertions, 2 deletions
diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js
index c41edfa145..c40852388e 100644
--- a/phpBB/assets/javascript/core.js
+++ b/phpBB/assets/javascript/core.js
@@ -245,6 +245,7 @@ phpbb.ajaxify = function(options) {
var elements = $(options.selector),
refresh = options.refresh,
callback = options.callback,
+ overlay = (typeof options.overlay !== 'undefined') ? options.overlay : true,
is_form = elements.is('form'),
event_name = is_form ? 'submit' : 'click';
@@ -382,7 +383,10 @@ phpbb.ajaxify = function(options) {
return;
}
- phpbb.loading_alert();
+ if (overlay)
+ {
+ phpbb.loading_alert();
+ }
$.ajax({
url: action,
@@ -407,6 +411,99 @@ phpbb.ajaxify = function(options) {
return this;
}
+/**
+* Hide the optgroups that are not the selected timezone
+*
+* @param bool keep_selection Shall we keep the value selected, or shall the user be forced to repick one.
+*/
+phpbb.timezone_switch_date = function(keep_selection) {
+ $('#timezone > optgroup').css('display', 'none');
+ $("#timezone > optgroup[label='" + $('#tz_date').val() + "']").css('display', 'block');
+
+ if ($('#tz_date').val() == $('#tz_select_date_suggest').attr('data-suggested-tz')) {
+ $('#tz_select_date_suggest').css('display', 'none');
+ } else {
+ $('#tz_select_date_suggest').css('display', 'inline');
+ }
+
+ if ($("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option").size() == 1) {
+ // If there is only one timezone for the selected date, we just select that automatically.
+ $("#timezone > optgroup[label='" + $('#tz_date').val() + "'] > option:first").attr('selected', true);
+ keep_selection = true;
+ }
+
+ if (typeof keep_selection !== 'undefined' && !keep_selection) {
+ $('#timezone > option:first').attr('selected', true);
+ }
+}
+
+/**
+* Display the date/time select
+*/
+phpbb.timezone_enable_date_selection = function() {
+ $('#tz_select_date').css('display', 'block');
+}
+
+/**
+* Preselect a date/time or suggest one, if it is not picked.
+*
+* @param bool force_selector Shall we select the suggestion?
+*/
+phpbb.timezone_preselect_select = function(force_selector) {
+
+ // The offset returned here is in minutes and negated.
+ // http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp
+ var offset = (new Date()).getTimezoneOffset();
+
+ if (offset < 0) {
+ var sign = '+';
+ offset = -offset;
+ } else {
+ var sign = '-';
+ }
+
+ var minutes = offset % 60;
+ var hours = (offset - minutes) / 60;
+
+ if (hours < 10) {
+ hours = '0' + hours.toString();
+ } else {
+ hours = hours.toString();
+ }
+
+ if (minutes < 10) {
+ minutes = '0' + minutes.toString();
+ } else {
+ minutes = minutes.toString();
+ }
+
+ var prefix = 'GMT' + sign + hours + ':' + minutes;
+ var prefix_length = prefix.length;
+ var selector_options = $('#tz_date > option');
+
+ for (var i = 0; i < selector_options.length; ++i) {
+ var option = selector_options[i];
+
+ if (option.value.substring(0, prefix_length) == prefix) {
+ if ($('#tz_date').val() != option.value && !force_selector) {
+ // We do not select the option for the user, but notify him,
+ // that we would suggest a different setting.
+ $('#tz_select_date_suggest').css('display', 'inline');
+ $('#tz_select_date_suggest').attr('title', $('#tz_select_date_suggest').attr('data-l-suggestion').replace("%s", option.innerHTML));
+ $('#tz_select_date_suggest').attr('value', $('#tz_select_date_suggest').attr('data-l-suggestion').replace("%s", option.innerHTML.substring(0, 9)));
+ $('#tz_select_date_suggest').attr('data-suggested-tz', option.innerHTML);
+ phpbb.timezone_switch_date(true);
+ } else {
+ option.selected = true;
+ phpbb.timezone_switch_date(!force_selector);
+ $('#tz_select_date_suggest').attr('data-suggested-tz', option.innerHTML);
+ $('#tz_select_date_suggest').css('display', 'none');
+ }
+ break;
+ }
+ }
+}
+
phpbb.ajax_callbacks = {};
/**
@@ -432,14 +529,47 @@ phpbb.add_ajax_callback = function(id, callback)
* the alt-text data attribute, and replaces the text in the attribute with the
* current text so that the process can be repeated.
*/
-phpbb.add_ajax_callback('alt_text', function(data) {
+phpbb.add_ajax_callback('alt_text', function() {
var el = $(this),
alt_text;
alt_text = el.attr('data-alt-text');
+ el.attr('data-alt-text', el.text());
el.attr('title', alt_text);
el.text(alt_text);
});
+/**
+ * This callback is based on the alt_text callback.
+ *
+ * It replaces the current text with the text in the alt-text data attribute,
+ * and replaces the text in the attribute with the current text so that the
+ * process can be repeated.
+ * Additionally it replaces the class of the link's parent
+ * and changes the link itself.
+ */
+phpbb.add_ajax_callback('toggle_link', function() {
+ var el = $(this),
+ toggle_text,
+ toggle_url,
+ toggle_class;
+
+ // Toggle link text
+
+ toggle_text = el.attr('data-toggle-text');
+ el.attr('data-toggle-text', el.text());
+ el.attr('title', toggle_text);
+ el.text(toggle_text);
+
+ // Toggle link url
+ toggle_url = el.attr('data-toggle-url');
+ el.attr('data-toggle-url', el.attr('href'));
+ el.attr('href', toggle_url);
+
+ // Toggle class of link parent
+ toggle_class = el.attr('data-toggle-class');
+ el.attr('data-toggle-class', el.parent().attr('class'));
+ el.parent().attr('class', toggle_class);
+});
})(jQuery); // Avoid conflicts with other libraries