From 286aebd93bd49eac2ff80c3a6930f7f692a4c3ef Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 18 Apr 2012 17:01:40 +0200 Subject: [ticket/10811] Fix AJAX callback alt_text so it can be repeated. PHPBB3-10811 --- phpBB/assets/javascript/core.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 958b6c9ff6..74c71fca79 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -436,11 +436,12 @@ 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); }); -- cgit v1.2.1 From 53a47fdcc323a5d7dc3696215cc47285a0c99042 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 18 Apr 2012 17:03:24 +0200 Subject: [ticket/10811] Make subscribe/unsubscribe repeatable with AJAX PHPBB3-10811 --- phpBB/assets/javascript/core.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 74c71fca79..3c1e39fca6 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -446,5 +446,30 @@ phpbb.add_ajax_callback('alt_text', function() { 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 icon of the link and changes the link itself. + */ +phpbb.add_ajax_callback('toggle_subscribe', function() { + var el = $(this), + alt_text; + + phpbb.ajax_callbacks['alt_text'].call(this); + + if (el.attr('href').indexOf('unwatch') !== -1) + { + el.attr('href', el.attr('href').replace('unwatch', 'watch')); + el.parent().attr('class', 'icon-subscribe'); + } + else + { + el.attr('href', el.attr('href').replace('watch', 'unwatch')); + el.parent().attr('class', 'icon-unsubscribe'); + } +}); })(jQuery); // Avoid conflicts with other libraries -- cgit v1.2.1 From 7b4f9765f8ab515c19d360818d7e57e5d6e47bd3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 19 Jun 2012 18:57:20 +0200 Subject: [feature/new-tz-handling] Move js functions into assets core.js PHPBB3-9558 --- phpBB/assets/javascript/core.js | 85 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 958b6c9ff6..ab1aaa8505 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -411,6 +411,91 @@ 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 ($("#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))); + phpbb.timezone_switch_date(true); + } else { + option.selected = true; + phpbb.timezone_switch_date(!force_selector); + $('#tz_select_date_suggest').css('display', 'none'); + } + break; + } + } +} + phpbb.ajax_callbacks = {}; /** -- cgit v1.2.1 From f1056a9b2fd6e4ff7bc107372e9210bae9e077f0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 5 Jul 2012 00:30:02 +0200 Subject: [ticket/10811] Make toogle_subscribe more generic so it can toogle all links PHPBB3-10811 --- phpBB/assets/javascript/core.js | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 3c1e39fca6..76615eb051 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -452,24 +452,31 @@ phpbb.add_ajax_callback('alt_text', function() { * 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 icon of the link and changes the link itself. + * Additionally it replaces the class of the link's parent + * and changes the link itself. */ -phpbb.add_ajax_callback('toggle_subscribe', function() { +phpbb.add_ajax_callback('toggle_link', function() { var el = $(this), - alt_text; - - phpbb.ajax_callbacks['alt_text'].call(this); - - if (el.attr('href').indexOf('unwatch') !== -1) - { - el.attr('href', el.attr('href').replace('unwatch', 'watch')); - el.parent().attr('class', 'icon-subscribe'); - } - else - { - el.attr('href', el.attr('href').replace('watch', 'unwatch')); - el.parent().attr('class', 'icon-unsubscribe'); - } + 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 -- cgit v1.2.1 From d099ef8cade0194fa8056439d489b159d5890f29 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 19 Jul 2012 10:34:21 +0200 Subject: [feature/new-tz-handling] Display suggestion when a different value is selected PHPBB3-9558 --- phpBB/assets/javascript/core.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index f07a245307..c40852388e 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -420,6 +420,12 @@ 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); @@ -485,10 +491,12 @@ phpbb.timezone_preselect_select = function(force_selector) { $('#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; -- cgit v1.2.1