From d5a788ae5b615c1b6b642c631884a4d936be2a4c Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Thu, 21 Jun 2012 19:16:05 +0100 Subject: [ticket/10949] Converted AJAX coding standards to new guidelines. Basically, moved parentheses to same line and changed variable names to camel case. PHPBB3-10949 --- phpBB/assets/javascript/core.js | 195 ++++++++++++++++------------------------ 1 file changed, 78 insertions(+), 117 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 958b6c9ff6..53b85e677a 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -1,5 +1,5 @@ var phpbb = {}; -phpbb.alert_time = 100; +phpbb.alertTime = 100; (function($) { // Avoid conflicts with other libraries @@ -12,35 +12,31 @@ var keymap = { }; var dark = $('#darkenwrapper'); -var loading_alert = $('#loadingalert'); +var loadingAlert = $('#loadingalert'); /** - * Display a loading screen. + * Display a loading screen * - * @returns object Returns loading_alert. + * @returns object Returns loadingAlert. */ -phpbb.loading_alert = function() { - if (dark.is(':visible')) - { - loading_alert.fadeIn(phpbb.alert_time); - } - else - { - loading_alert.show(); - dark.fadeIn(phpbb.alert_time, function() { +phpbb.loadingAlert = function() { + if (dark.is(':visible')) { + loadingAlert.fadeIn(phpbb.alertTime); + } else { + loadingAlert.show(); + dark.fadeIn(phpbb.alertTime, function() { // Wait five seconds and display an error if nothing has been returned by then. setTimeout(function() { - if (loading_alert.is(':visible')) - { + if (loadingAlert.is(':visible')) { phpbb.alert($('#phpbb_alert').attr('data-l-err'), $('#phpbb_alert').attr('data-l-timeout-processing-req')); } }, 5000); }); } - return loading_alert; -} + return loadingAlert; +}; /** * Display a simple alert similar to JSs native alert(). @@ -67,7 +63,7 @@ phpbb.alert = function(title, msg, fadedark) { div.find('.alert_close').unbind('click'); fade = (typeof fadedark !== 'undefined' && !fadedark) ? div : dark; - fade.fadeOut(phpbb.alert_time, function() { + fade.fadeOut(phpbb.alertTime, function() { div.hide(); }); @@ -90,27 +86,22 @@ phpbb.alert = function(title, msg, fadedark) { e.preventDefault(); }); - if (loading_alert.is(':visible')) - { - loading_alert.fadeOut(phpbb.alert_time, function() { + if (loadingAlert.is(':visible')) { + loadingAlert.fadeOut(phpbb.alertTime, function() { dark.append(div); - div.fadeIn(phpbb.alert_time); + div.fadeIn(phpbb.alertTime); }); - } - else if (dark.is(':visible')) - { + } else if (dark.is(':visible')) { dark.append(div); - div.fadeIn(phpbb.alert_time); - } - else - { + div.fadeIn(phpbb.alertTime); + } else { dark.append(div); div.show(); - dark.fadeIn(phpbb.alert_time); + dark.fadeIn(phpbb.alertTime); } return div; -} +}; /** * Display a simple yes / no box to the user. @@ -136,7 +127,7 @@ phpbb.confirm = function(msg, callback, fadedark) { var click_handler = function(e) { var res = this.className === 'button1'; var fade = (typeof fadedark !== 'undefined' && !fadedark && res) ? div : dark; - fade.fadeOut(phpbb.alert_time, function() { + fade.fadeOut(phpbb.alertTime, function() { div.hide(); }); div.find('input[type="button"]').unbind('click', click_handler); @@ -151,7 +142,7 @@ phpbb.confirm = function(msg, callback, fadedark) { dark.one('click', function(e) { div.find('.alert_close').unbind('click'); - dark.fadeOut(phpbb.alert_time, function() { + dark.fadeOut(phpbb.alertTime, function() { div.hide(); }); callback(false); @@ -174,7 +165,7 @@ phpbb.confirm = function(msg, callback, fadedark) { div.find('.alert_close').one('click', function(e) { var fade = (typeof fadedark !== 'undefined' && fadedark) ? div : dark; - fade.fadeOut(phpbb.alert_time, function() { + fade.fadeOut(phpbb.alertTime, function() { div.hide(); }); callback(false); @@ -182,27 +173,22 @@ phpbb.confirm = function(msg, callback, fadedark) { e.preventDefault(); }); - if (loading_alert.is(':visible')) - { - loading_alert.fadeOut(phpbb.alert_time, function() { + if (loadingAlert.is(':visible')) { + loadingAlert.fadeOut(phpbb.alertTime, function() { dark.append(div); - div.fadeIn(phpbb.alert_time); + div.fadeIn(phpbb.alertTime); }); - } - else if (dark.is(':visible')) - { + } else if (dark.is(':visible')) { dark.append(div); - div.fadeIn(phpbb.alert_time); - } - else - { + div.fadeIn(phpbb.alertTime); + } else { dark.append(div); div.show(); - dark.fadeIn(phpbb.alert_time); + dark.fadeIn(phpbb.alertTime); } return div; -} +}; /** * Turn a querystring into an array. @@ -214,13 +200,12 @@ phpbb.parse_querystring = function(string) { var params = {}, i, split; string = string.split('&'); - for (i = 0; i < string.length; i++) - { + for (i = 0; i < string.length; i++) { split = string[i].split('='); params[split[0]] = decodeURIComponent(split[1]); } return params; -} +}; /** @@ -246,14 +231,13 @@ phpbb.ajaxify = function(options) { 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'; + isForm = elements.is('form'), + eventName = isForm ? 'submit' : 'click'; - elements.bind(event_name, function(event) { + elements.bind(eventName, function(event) { var action, method, data, submit, that = this, $this = $(this); - if ($this.find('input[type="submit"][data-clicked]').attr('data-ajax') === 'false') - { + if ($this.find('input[type="submit"][data-clicked]').attr('data-ajax') === 'false') { return; } @@ -267,84 +251,69 @@ phpbb.ajaxify = function(options) { * * @param object res The object sent back by the server. */ - function return_handler(res) - { + function returnHandler(res) { var alert; // Is a confirmation required? - if (typeof res.S_CONFIRM_ACTION === 'undefined') - { + if (typeof res.S_CONFIRM_ACTION === 'undefined') { // If a confirmation is not required, display an alert and call the // callbacks. - if (typeof res.MESSAGE_TITLE !== 'undefined') - { + if (typeof res.MESSAGE_TITLE !== 'undefined') { alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - } - else - { - dark.fadeOut(phpbb.alert_time); + } else { + dark.fadeOut(phpbb.alertTime); } - if (typeof phpbb.ajax_callbacks[callback] === 'function') - { - phpbb.ajax_callbacks[callback].call(that, res); + if (typeof phpbb.ajaxCallbacks[callback] === 'function') { + phpbb.ajaxCallbacks[callback].call(that, res); } // If the server says to refresh the page, check whether the page should // be refreshed and refresh page after specified time if required. - if (res.REFRESH_DATA) - { - if (typeof refresh === 'function') - { + if (res.REFRESH_DATA) { + if (typeof refresh === 'function') { refresh = refresh(res.REFRESH_DATA.url); - } - else if (typeof refresh !== 'boolean') - { + } else if (typeof refresh !== 'boolean') { refresh = false; } setTimeout(function() { - if (refresh) - { + if (refresh) { window.location = res.REFRESH_DATA.url; } // Hide the alert even if we refresh the page, in case the user // presses the back button. - dark.fadeOut(phpbb.alert_time, function() { + dark.fadeOut(phpbb.alertTime, function() { alert.hide(); }); }, res.REFRESH_DATA.time * 1000); // Server specifies time in seconds } - } - else - { + } else { // If confirmation is required, display a diologue to the user. phpbb.confirm(res.MESSAGE_TEXT, function(del) { - if (del) - { - phpbb.loading_alert(); + if (del) { + phpbb.loadingAlert(); data = $('
' + res.S_HIDDEN_FIELDS + '
').serialize(); $.ajax({ url: res.S_CONFIRM_ACTION, type: 'POST', data: data + '&confirm=' + res.YES_VALUE, - success: return_handler, - error: error_handler + success: returnHandler, + error: errorHandler }); } }, false); } } - function error_handler() - { + function errorHandler() { var alert; alert = phpbb.alert(dark.attr('data-ajax-error-title'), dark.attr('data-ajax-error-text')); setTimeout(function () { - dark.fadeOut(phpbb.alert_time, function() { + dark.fadeOut(phpbb.alertTime, function() { alert.hide(); }); }, 5000); @@ -352,25 +321,21 @@ phpbb.ajaxify = function(options) { // If the element is a form, POST must be used and some extra data must // be taken from the form. - var run_filter = (typeof options.filter === 'function'); + var runFilter = (typeof options.filter === 'function'); - if (is_form) - { + if (isForm) { action = $this.attr('action').replace('&', '&'); data = $this.serializeArray(); method = $this.attr('method') || 'GET'; - if ($this.find('input[type="submit"][data-clicked]')) - { + if ($this.find('input[type="submit"][data-clicked]')) { submit = $this.find('input[type="submit"][data-clicked]'); data.push({ name: submit.attr('name'), value: submit.val() }); } - } - else - { + } else { action = this.href; data = null; method = 'GET'; @@ -378,28 +343,26 @@ phpbb.ajaxify = function(options) { // If filter function returns false, cancel the AJAX functionality, // and return true (meaning that the HTTP request will be sent normally). - if (run_filter && !options.filter.call(this, data)) - { + if (runFilter && !options.filter.call(this, data)) { return; } - if (overlay) - { - phpbb.loading_alert(); + if (overlay) { + phpbb.loadingAlert(); } $.ajax({ url: action, type: method, data: data, - success: return_handler, - error: error_handler + success: returnHandler, + error: errorHandler }); event.preventDefault(); }); - if (is_form) { + if (isForm) { elements.find('input:submit').click(function () { var $this = $(this); @@ -409,9 +372,9 @@ phpbb.ajaxify = function(options) { } return this; -} +}; -phpbb.ajax_callbacks = {}; +phpbb.ajaxCallbacks = {}; /** * Adds an AJAX callback to be used by phpbb.ajaxify. @@ -421,14 +384,12 @@ phpbb.ajax_callbacks = {}; * @param string id The name of the callback. * @param function callback The callback to be called. */ -phpbb.add_ajax_callback = function(id, callback) -{ - if (typeof callback === 'function') - { - phpbb.ajax_callbacks[id] = callback; +phpbb.add_ajax_callback = function(id, callback) { + if (typeof callback === 'function') { + phpbb.ajaxCallbacks[id] = callback; } return this; -} +}; /** @@ -438,11 +399,11 @@ phpbb.add_ajax_callback = function(id, callback) */ phpbb.add_ajax_callback('alt_text', function(data) { var el = $(this), - alt_text; + altText; - alt_text = el.attr('data-alt-text'); - el.attr('title', alt_text); - el.text(alt_text); + altText = el.attr('data-alt-text'); + el.attr('title', altText); + el.text(altText); }); -- cgit v1.2.1 From 0d7f61dc7ab8b875b288b2d41ef27aa360973e57 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 18 Dec 2012 13:31:38 +0100 Subject: [ticket/11166] Use provided custom templates on AJAX confirm box PHPBB3-11166 --- phpBB/assets/javascript/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index f7d6688f68..aab9153003 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -320,7 +320,7 @@ phpbb.ajaxify = function(options) { else { // If confirmation is required, display a diologue to the user. - phpbb.confirm(res.MESSAGE_TEXT, function(del) { + phpbb.confirm(res.MESSAGE_BODY, function(del) { if (del) { phpbb.loading_alert(); -- cgit v1.2.1 From 693778fa0737229d294ee03945ac23d063ad0ba4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 18 Dec 2012 23:37:00 +0100 Subject: [ticket/10803] Show failure message until user dismisses it PHPBB3-10803 --- phpBB/assets/javascript/core.js | 6 ------ 1 file changed, 6 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index f7d6688f68..c18bec7035 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -342,12 +342,6 @@ phpbb.ajaxify = function(options) { var alert; alert = phpbb.alert(dark.attr('data-ajax-error-title'), dark.attr('data-ajax-error-text')); - - setTimeout(function () { - dark.fadeOut(phpbb.alert_time, function() { - alert.hide(); - }); - }, 5000); } // If the element is a form, POST must be used and some extra data must -- cgit v1.2.1 From 5d07ddffaf1f5a173ce3b4fede45e80ff8f7d1af Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 19 Dec 2012 16:41:25 +0100 Subject: [ticket/10805] Clear loading alert timeout after ajax request finished The timeout for the "request timed out" popup should be cleared if it finished. Since it is currently not cleared, the timeout alert appears as an extra overlay if another ajaxified function is ran within 5 seconds of the initial function call. This patch will take care of clearing the timeout if either the success (function return_handler()) or error (function error_handler()) functions are called. PHPBB3-10805 --- phpBB/assets/javascript/core.js | 16 +++++++++++++++- 1 file changed, 15 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 c18bec7035..36e547b056 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -13,6 +13,7 @@ var keymap = { var dark = $('#darkenwrapper'); var loading_alert = $('#loadingalert'); +var phpbbAlertTimer = 0; /** @@ -30,7 +31,7 @@ phpbb.loading_alert = function() { loading_alert.show(); dark.fadeIn(phpbb.alert_time, function() { // Wait five seconds and display an error if nothing has been returned by then. - setTimeout(function() { + phpbbAlertTimer = setTimeout(function() { if (loading_alert.is(':visible')) { phpbb.alert($('#phpbb_alert').attr('data-l-err'), $('#phpbb_alert').attr('data-l-timeout-processing-req')); @@ -42,6 +43,16 @@ phpbb.loading_alert = function() { return loading_alert; } +/** + * Clear loading alert timeout +*/ +phpbb.clearLoadingTimeout = function() { + if (phpbbAlertTimer != 0) { + clearTimeout(phpbbAlertTimer); + phpbbAlertTimer = 0; + } +} + /** * Display a simple alert similar to JSs native alert(). * @@ -271,6 +282,8 @@ phpbb.ajaxify = function(options) { { var alert; + phpbb.clearLoadingTimeout(); + // Is a confirmation required? if (typeof res.S_CONFIRM_ACTION === 'undefined') { @@ -341,6 +354,7 @@ phpbb.ajaxify = function(options) { { var alert; + phpbb.clearLoadingTimeout(); alert = phpbb.alert(dark.attr('data-ajax-error-title'), dark.attr('data-ajax-error-text')); } -- cgit v1.2.1 From 48b6e45f7cee93dcbcc3b9b3ca857a4ed8f07437 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 2 Jan 2013 16:44:05 +0100 Subject: [ticket/10805] Compare phpbbAlertTimer against null PHPBB3-10805 --- phpBB/assets/javascript/core.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 36e547b056..29b1ec7872 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -13,7 +13,7 @@ var keymap = { var dark = $('#darkenwrapper'); var loading_alert = $('#loadingalert'); -var phpbbAlertTimer = 0; +var phpbbAlertTimer = null; /** @@ -47,9 +47,9 @@ phpbb.loading_alert = function() { * Clear loading alert timeout */ phpbb.clearLoadingTimeout = function() { - if (phpbbAlertTimer != 0) { + if (phpbbAlertTimer != null) { clearTimeout(phpbbAlertTimer); - phpbbAlertTimer = 0; + phpbbAlertTimer = null; } } -- cgit v1.2.1 From e211009eb7f2c595fcc0b64a4f60e2bd08f13303 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 2 Jan 2013 22:05:14 +0100 Subject: [ticket/11302] Correctly select first timezone or selected timezone While registering, we should default to a given timezone. By selecting the first timezone by default, this is fulfilled. This doesn't happen currently, as only the "Select a timezone" selection appears. If a user selects a timezone during the registration process we should also make sure that the selected element is still selected; even if we have to return to the registration page, i.e. if there was an error while submitting the form. This is currently not the case. With this patch the javascript code will behave correctly. Additionally, a duplicate inclusion of timezone.js has been removed as it was not needed. PHPBB3-11302 --- phpBB/assets/javascript/core.js | 5 ++++- 1 file changed, 4 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 c18bec7035..a4f7455b01 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -438,7 +438,10 @@ phpbb.timezone_switch_date = function(keep_selection) { } if (typeof keep_selection !== 'undefined' && !keep_selection) { - $('#timezone > option:first').attr('selected', true); + var timezoneOptions = $('#timezone > optgroup option'); + if (timezoneOptions.filter(':selected').length <= 0) { + timezoneOptions.filter(':first').attr('selected', true); + } } } -- cgit v1.2.1 From b5cc1ed683c1e8ca2e189e75e0e3302cc37c5fbf Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 4 Jan 2013 22:46:12 +0100 Subject: [ticket/10949] Converted missing code to new JS coding guidelines A few missing semi-colons were also added where needed. PHPBB3-10949 --- phpBB/assets/javascript/core.js | 74 ++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 421d6a12dc..d4b98d3ee0 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -43,11 +43,11 @@ phpbb.loadingAlert = function() { * Clear loading alert timeout */ phpbb.clearLoadingTimeout = function() { - if (phpbbAlertTimer != null) { + if (phpbbAlertTimer !== null) { clearTimeout(phpbbAlertTimer); phpbbAlertTimer = null; } -} +}; /** * Display a simple alert similar to JSs native alert(). @@ -135,13 +135,13 @@ phpbb.confirm = function(msg, callback, fadedark) { e.stopPropagation(); }); - var click_handler = function(e) { + var clickHandler = function(e) { var res = this.className === 'button1'; var fade = (typeof fadedark !== 'undefined' && !fadedark && res) ? div : dark; fade.fadeOut(phpbb.alertTime, function() { div.hide(); }); - div.find('input[type="button"]').unbind('click', click_handler); + div.find('input[type="button"]').unbind('click', clickHandler); callback(res); if (e) { @@ -149,7 +149,7 @@ phpbb.confirm = function(msg, callback, fadedark) { e.stopPropagation(); } }; - div.find('input[type="button"]').one('click', click_handler); + div.find('input[type="button"]').one('click', clickHandler); dark.one('click', function(e) { div.find('.alert_close').unbind('click'); @@ -207,7 +207,7 @@ phpbb.confirm = function(msg, callback, fadedark) { * @argument string string The querystring to parse. * @returns object The object created. */ -phpbb.parse_querystring = function(string) { +phpbb.parseQuerystring = function(string) { var params = {}, i, split; string = string.split('&'); @@ -386,9 +386,9 @@ phpbb.ajaxify = function(options) { /** * 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. +* @param bool keepSelection Shall we keep the value selected, or shall the user be forced to repick one. */ -phpbb.timezone_switch_date = function(keep_selection) { +phpbb.timezoneSwitchDate = function(keepSelection) { if ($('#timezone_copy').length == 0) { // We make a backup of the original dropdown, so we can remove optgroups // instead of setting display to none, because IE and chrome will not @@ -412,30 +412,30 @@ phpbb.timezone_switch_date = function(keep_selection) { 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; + keepSelection = true; } - if (typeof keep_selection !== 'undefined' && !keep_selection) { + if (typeof keepSelection !== 'undefined' && !keepSelection) { var timezoneOptions = $('#timezone > optgroup option'); if (timezoneOptions.filter(':selected').length <= 0) { timezoneOptions.filter(':first').attr('selected', true); } } -} +}; /** * Display the date/time select */ -phpbb.timezone_enable_date_selection = function() { +phpbb.timezoneEnableDateSelection = 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? +* @param bool forceSelector Shall we select the suggestion? */ -phpbb.timezone_preselect_select = function(force_selector) { +phpbb.timezonePreselectSelect = function(forceSelector) { // The offset returned here is in minutes and negated. // http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp @@ -464,21 +464,21 @@ phpbb.timezone_preselect_select = function(force_selector) { } var prefix = 'GMT' + sign + hours + ':' + minutes; - var prefix_length = prefix.length; - var selector_options = $('#tz_date > option'); + var prefixLength = prefix.length; + var selectorOptions = $('#tz_date > option'); - for (var i = 0; i < selector_options.length; ++i) { - var option = selector_options[i]; + for (var i = 0; i < selectorOptions.length; ++i) { + var option = selectorOptions[i]; - if (option.value.substring(0, prefix_length) == prefix) { - if ($('#tz_date').val() != option.value && !force_selector) { + if (option.value.substring(0, prefixLength) == prefix) { + if ($('#tz_date').val() != option.value && !forceSelector) { // We do not select the option for the user, but notify him, // that we would suggest a different setting. - phpbb.timezone_switch_date(true); + phpbb.timezoneSwitchDate(true); $('#tz_select_date_suggest').css('display', 'inline'); } else { option.selected = true; - phpbb.timezone_switch_date(!force_selector); + phpbb.timezoneSwitchDate(!forceSelector); $('#tz_select_date_suggest').css('display', 'none'); } @@ -490,7 +490,7 @@ phpbb.timezone_preselect_select = function(force_selector) { return; } } -} +}; phpbb.ajaxCallbacks = {}; @@ -502,7 +502,7 @@ phpbb.ajaxCallbacks = {}; * @param string id The name of the callback. * @param function callback The callback to be called. */ -phpbb.add_ajax_callback = function(id, callback) { +phpbb.addAjaxCallback = function(id, callback) { if (typeof callback === 'function') { phpbb.ajaxCallbacks[id] = callback; } @@ -515,7 +515,7 @@ 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() { +phpbb.addAjaxCallback('alt_text', function() { var el = $(this), altText; @@ -534,28 +534,28 @@ phpbb.add_ajax_callback('alt_text', function() { * Additionally it replaces the class of the link's parent * and changes the link itself. */ -phpbb.add_ajax_callback('toggle_link', function() { +phpbb.addAjaxCallback('toggle_link', function() { var el = $(this), - toggle_text, - toggle_url, - toggle_class; + toggleText, + toggleUrl, + toggleClass; // Toggle link text - toggle_text = el.attr('data-toggle-text'); + toggleText = el.attr('data-toggle-text'); el.attr('data-toggle-text', el.text()); - el.attr('title', toggle_text); - el.text(toggle_text); + el.attr('title', toggleText); + el.text(toggleText); // Toggle link url - toggle_url = el.attr('data-toggle-url'); + toggleUrl = el.attr('data-toggle-url'); el.attr('data-toggle-url', el.attr('href')); - el.attr('href', toggle_url); + el.attr('href', toggleUrl); // Toggle class of link parent - toggle_class = el.attr('data-toggle-class'); + toggleClass = el.attr('data-toggle-class'); el.attr('data-toggle-class', el.parent().attr('class')); - el.parent().attr('class', toggle_class); + el.parent().attr('class', toggleClass); }); })(jQuery); // Avoid conflicts with other libraries -- cgit v1.2.1 From fbdd3170c9a74d1352f242cc184d576765c95f88 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 8 Jan 2013 23:35:39 +0100 Subject: [ticket/11313] Use correct object el instead of eel in alt_text callback This typo was added by the PRs #860 and #1178. Only the object el exists and is correct. Due to this the text of links using the alt_text callback were not modified while executing the callback. PHPBB3-11313 --- phpBB/assets/javascript/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index d4b98d3ee0..16ed04746d 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -522,7 +522,7 @@ phpbb.addAjaxCallback('alt_text', function() { altText = el.attr('data-alt-text'); el.attr('data-alt-text', el.text()); el.attr('title', altText); - eel.text(altText); + el.text(altText); }); /** -- cgit v1.2.1 From 9c4f0d51df4424f410534686f00bf629d98d53e0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 10 Jan 2013 10:59:20 +0100 Subject: [ticket/11314] Cleanup core.js coding function errorHandler() was used in returnHandler() before it was defined. The unused variable alert has been removed from errorHandler(). Overuse of the var keyword for the variable sign has been removed and the if statement has been simplified. The definition of the variable i has been moved outside of the for loop definition. The var keyword shouldn't be used inside the definition of the for loop. PHPBB3-11314 --- phpBB/assets/javascript/core.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 16ed04746d..9323f4a447 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -252,6 +252,11 @@ phpbb.ajaxify = function(options) { return; } + function errorHandler() { + phpbb.clearLoadingTimeout(); + phpbb.alert(dark.attr('data-ajax-error-title'), dark.attr('data-ajax-error-text')); + } + /** * This is a private function used to handle the callbacks, refreshes * and alert. It calls the callback, refreshes the page if necessary, and @@ -320,13 +325,6 @@ phpbb.ajaxify = function(options) { } } - function errorHandler() { - var alert; - - phpbb.clearLoadingTimeout(); - alert = phpbb.alert(dark.attr('data-ajax-error-title'), dark.attr('data-ajax-error-text')); - } - // If the element is a form, POST must be used and some extra data must // be taken from the form. var runFilter = (typeof options.filter === 'function'); @@ -440,12 +438,11 @@ phpbb.timezonePreselectSelect = function(forceSelector) { // The offset returned here is in minutes and negated. // http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp var offset = (new Date()).getTimezoneOffset(); + var sign = '-'; if (offset < 0) { - var sign = '+'; + sign = '+'; offset = -offset; - } else { - var sign = '-'; } var minutes = offset % 60; @@ -466,8 +463,9 @@ phpbb.timezonePreselectSelect = function(forceSelector) { var prefix = 'GMT' + sign + hours + ':' + minutes; var prefixLength = prefix.length; var selectorOptions = $('#tz_date > option'); + var i; - for (var i = 0; i < selectorOptions.length; ++i) { + for (i = 0; i < selectorOptions.length; ++i) { var option = selectorOptions[i]; if (option.value.substring(0, prefixLength) == prefix) { -- cgit v1.2.1 From 49edfa49ab9b475e02997f8a89050acc73bf30c8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 12 Jan 2013 19:08:34 +0100 Subject: [ticket/11314] Fix whitespace issues PHPBB3-11314 --- phpBB/assets/javascript/core.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 9323f4a447..f38b35d613 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -57,7 +57,7 @@ phpbb.clearLoadingTimeout = function() { * @param string title Title of the message, eg "Information" (HTML). * @param string msg Message to display (HTML). * @param bool fadedark Remove the dark background when done? Defaults - * to yes. + * to yes. * * @returns object Returns the div created. */ @@ -121,9 +121,9 @@ phpbb.alert = function(title, msg, fadedark) { * * @param string msg Message to display (HTML). * @param function callback Callback. Bool param, whether the user pressed - * yes or no (or whatever their language is). + * yes or no (or whatever their language is). * @param bool fadedark Remove the dark background when done? Defaults - * to yes. + * to yes. * * @returns object Returns the div created. */ @@ -232,10 +232,10 @@ phpbb.parseQuerystring = function(string) { * * @param object options Options. * @param bool/function refresh If we are sent back a refresh, should it be - * acted upon? This can either be true / false / a function. + * acted upon? This can either be true / false / a function. * @param function callback Callback to call on completion of event. Has - * three parameters: the element that the event was evoked from, the JSON - * that was returned and (if it is a form) the form action. + * three parameters: the element that the event was evoked from, the JSON + * that was returned and (if it is a form) the form action. */ phpbb.ajaxify = function(options) { var elements = $(options.selector), -- cgit v1.2.1 From 5028fb981d422111f02fac31fdd48aa8f3da5617 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 15 Jan 2013 13:10:25 +0100 Subject: [ticket/11166] Fix typo in comment PHPBB3-11166 --- phpBB/assets/javascript/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index aab9153003..0862c553d9 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -319,7 +319,7 @@ phpbb.ajaxify = function(options) { } else { - // If confirmation is required, display a diologue to the user. + // If confirmation is required, display a dialog to the user. phpbb.confirm(res.MESSAGE_BODY, function(del) { if (del) { -- cgit v1.2.1 From 623b9af38bd56e1bfc234675f7d2e2404298fbf7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 15 Jan 2013 12:30:26 -0600 Subject: [ticket/11103] Only lookup $(target) once PHPBB3-11103 --- phpBB/assets/javascript/core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index a5a10e7377..9909359c2c 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -498,9 +498,9 @@ $('#notification_list_button').click(function(e) { e.preventDefault(); }); $('#phpbb').click(function(e) { - var target = e.target; + var target = $(e.target); - if (!$(target).is('#notification_list') && !$(target).is('#notification_list_button') && !$(target).parents().is('#notification_list')) { + if (!target.is('#notification_list') && !target.is('#notification_list_button') && !target.parents().is('#notification_list')) { $('#notification_list').hide(); } }); -- cgit v1.2.1 From 36168b311e5f12937977ffd1040ca4a39f70a0e8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 27 Feb 2013 23:12:34 +0100 Subject: [ticket/11314] Fix issues mentioned in jshint report Additionally, the editor.js files are now the same file in both subsilver2, prosilver, and the acp. PHPBB3-11314 --- phpBB/assets/javascript/core.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index f38b35d613..b718dabe6c 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -353,7 +353,7 @@ phpbb.ajaxify = function(options) { return; } - if (overlay && (typeof $this.attr('data-overlay') === 'undefined' || $this.attr('data-overlay') == 'true')) + if (overlay && (typeof $this.attr('data-overlay') === 'undefined' || $this.attr('data-overlay') === 'true')) { phpbb.loadingAlert(); } @@ -387,7 +387,7 @@ phpbb.ajaxify = function(options) { * @param bool keepSelection Shall we keep the value selected, or shall the user be forced to repick one. */ phpbb.timezoneSwitchDate = function(keepSelection) { - if ($('#timezone_copy').length == 0) { + if ($('#timezone_copy').length === 0) { // We make a backup of the original dropdown, so we can remove optgroups // instead of setting display to none, because IE and chrome will not // hide options inside of optgroups and selects via css @@ -397,17 +397,17 @@ phpbb.timezoneSwitchDate = function(keepSelection) { $('#timezone').replaceWith($('#timezone_copy').clone().attr('id', 'timezone').css('display', 'block').attr('name', 'tz')); } - if ($('#tz_date').val() != '') { + if ($('#tz_date').val() !== '') { $('#timezone > optgroup').remove(":not([label='" + $('#tz_date').val() + "'])"); } - if ($('#tz_date').val() == $('#tz_select_date_suggest').attr('data-suggested-tz')) { + 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 ($("#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); keepSelection = true; @@ -468,8 +468,8 @@ phpbb.timezonePreselectSelect = function(forceSelector) { for (i = 0; i < selectorOptions.length; ++i) { var option = selectorOptions[i]; - if (option.value.substring(0, prefixLength) == prefix) { - if ($('#tz_date').val() != option.value && !forceSelector) { + if (option.value.substring(0, prefixLength) === prefix) { + if ($('#tz_date').val() !== option.value && !forceSelector) { // We do not select the option for the user, but notify him, // that we would suggest a different setting. phpbb.timezoneSwitchDate(true); -- cgit v1.2.1 From f0b0978538a1b1e25b688cce1794c764f2d363f0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 26 Mar 2013 13:13:33 +0100 Subject: [ticket/11314] Modify files to comply with coding standards PHPBB3-11314 --- phpBB/assets/javascript/core.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index b718dabe6c..424989a9f3 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -57,7 +57,7 @@ phpbb.clearLoadingTimeout = function() { * @param string title Title of the message, eg "Information" (HTML). * @param string msg Message to display (HTML). * @param bool fadedark Remove the dark background when done? Defaults - * to yes. + * to yes. * * @returns object Returns the div created. */ @@ -353,8 +353,7 @@ phpbb.ajaxify = function(options) { return; } - if (overlay && (typeof $this.attr('data-overlay') === 'undefined' || $this.attr('data-overlay') === 'true')) - { + if (overlay && (typeof $this.attr('data-overlay') === 'undefined' || $this.attr('data-overlay') === 'true')) { phpbb.loadingAlert(); } -- cgit v1.2.1 From 88072fd6c2c3ec6cc6d2a880bd76a9c601fd0767 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 9 Apr 2013 18:38:59 +0300 Subject: [ticket/10741] Function to resize textarea elements New function to automatically resize textarea elements as user types text PHPBB3-10741 --- 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 8bbea8b8c9..6fe71d141a 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -568,4 +568,89 @@ phpbb.addAjaxCallback('toggle_link', function() { el.parent().attr('class', toggleClass); }); +/** +* Automatically resize textarea +* +* This function automatically resizes textarea elements when user +* types text. +* +* @param jQuery item jQuery object to resize +* @param object options Optional parameter that adjusts default +* configuration. See configuration variable +*/ +phpbb.resizeTextArea = function(items) { + // Configuration + var configuration = { + minWindowHeight: 500, // Minimum browser window height when textareas are resized + minHeight: 200, // Minimum height of textarea + maxHeight: 500, // Maximum height of textarea + heightDiff: 200, // Minimum difference between window and textarea height + // In following callbacks parameter "item" is jQuery object. "this" points to DOM object + resizeCallback: function(item) { }, // Function to call after resizing textarea. + resetCallback: function(item) { } // Function to call when resize has been canceled + } + + if (arguments.length > 1) + { + configuration = $.extend(configuration, arguments[1]); + } + + function resetAutoResize(item) + { + var $item = $(item); + if ($item.hasClass('auto-resized')) + { + $(item).css('height', '').removeClass('auto-resized'); + configuration.resetCallback.call(item, $item); + } + }; + + function autoResize(item) + { + function setHeight(height) + { + $item.css('height', height + 'px').addClass('auto-resized'); + configuration.resizeCallback.call(item, $item); + } + + var windowHeight = $(window).height(); + + if (windowHeight < configuration.minWindowHeight) + { + resetAutoResize(item); + return; + } + + var maxHeight = Math.min(Math.max(windowHeight - configuration.heightDiff, configuration.minHeight), configuration.maxHeight), + $item = $(item), + height = parseInt($item.height()), + scrollHeight = (item.scrollHeight) ? item.scrollHeight : 0; + + if (height > maxHeight) + { + setHeight(maxHeight); + } + else if (scrollHeight > (height + 5)) + { + setHeight(Math.min(maxHeight, scrollHeight)); + } + }; + + items.bind('focus change keyup', function() { + $(this).each(function() { + autoResize(this); + }); + }).css('resize', 'none').change(); + + $(window).resize(function() { + items.each(function() { + if ($(this).hasClass('auto-resized')) + { + autoResize(this); + } + }); + }); +}; + + })(jQuery); // Avoid conflicts with other libraries -- cgit v1.2.1 From cbb9f084fce0fd42ed1481233f417c79e8a0abfa Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 10 Apr 2013 09:08:25 +0300 Subject: [ticket/10741] Fix for browser-specific resizing of textarea Disable browser-specific resizing only after textarea has been resized Enable browser-specific resizing after script resizing has been reset PHPBB3-10741 --- phpBB/assets/javascript/core.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 6fe71d141a..827ed2e34a 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -600,7 +600,7 @@ phpbb.resizeTextArea = function(items) { var $item = $(item); if ($item.hasClass('auto-resized')) { - $(item).css('height', '').removeClass('auto-resized'); + $(item).css({height: '', resize: ''}).removeClass('auto-resized'); configuration.resetCallback.call(item, $item); } }; @@ -609,7 +609,7 @@ phpbb.resizeTextArea = function(items) { { function setHeight(height) { - $item.css('height', height + 'px').addClass('auto-resized'); + $item.css({height: height + 'px', resize: 'none'}).addClass('auto-resized'); configuration.resizeCallback.call(item, $item); } @@ -640,7 +640,7 @@ phpbb.resizeTextArea = function(items) { $(this).each(function() { autoResize(this); }); - }).css('resize', 'none').change(); + }).change(); $(window).resize(function() { items.each(function() { -- cgit v1.2.1 From 947550df8f5e2ba624adc26ddd22c7fe74e4f602 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 30 Apr 2013 11:27:43 +0300 Subject: [ticket/10741] Docblock for phpbb.resizeTextArea Better description of phpBB.resizeTextArea with detailed explanation of all optional parameters. Removed unnecessary semicolons PHPBB3-10741 --- phpBB/assets/javascript/core.js | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 827ed2e34a..bb1fef253e 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -571,28 +571,39 @@ phpbb.addAjaxCallback('toggle_link', function() { /** * Automatically resize textarea * -* This function automatically resizes textarea elements when user +* This function automatically resizes textarea elements when user * types text. * -* @param jQuery item jQuery object to resize -* @param object options Optional parameter that adjusts default +* @param {jQuery} items jQuery object(s) to resize +* @param {object} options Optional parameter that adjusts default * configuration. See configuration variable +* +* Optional parameters: +* minWindowHeight {number} Minimum browser window height when textareas are resized. Default = 500 +* minHeight {number} Minimum height of textarea. Default = 200 +* maxHeight {number} Maximum height of textarea. Default = 500 +* heightDiff {number} Minimum difference between window and textarea height. Default = 200 +* resizeCallback {function} Function to call after resizing textarea +* resetCallback {function} Function to call when resize has been canceled + +* Callback function format: function(item) {} +* this points to DOM object +* item is a jQuery object, same as this */ -phpbb.resizeTextArea = function(items) { +phpbb.resizeTextArea = function(items, options) { // Configuration var configuration = { - minWindowHeight: 500, // Minimum browser window height when textareas are resized - minHeight: 200, // Minimum height of textarea - maxHeight: 500, // Maximum height of textarea - heightDiff: 200, // Minimum difference between window and textarea height - // In following callbacks parameter "item" is jQuery object. "this" points to DOM object - resizeCallback: function(item) { }, // Function to call after resizing textarea. - resetCallback: function(item) { } // Function to call when resize has been canceled - } + minWindowHeight: 500, + minHeight: 200, + maxHeight: 500, + heightDiff: 200, + resizeCallback: function(item) { }, + resetCallback: function(item) { } + }; if (arguments.length > 1) { - configuration = $.extend(configuration, arguments[1]); + configuration = $.extend(configuration, options); } function resetAutoResize(item) @@ -603,7 +614,7 @@ phpbb.resizeTextArea = function(items) { $(item).css({height: '', resize: ''}).removeClass('auto-resized'); configuration.resetCallback.call(item, $item); } - }; + } function autoResize(item) { @@ -634,7 +645,7 @@ phpbb.resizeTextArea = function(items) { { setHeight(Math.min(maxHeight, scrollHeight)); } - }; + } items.bind('focus change keyup', function() { $(this).each(function() { -- cgit v1.2.1 From 1834ceb614a1bf82aa0369a2b731475a82abfade Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 8 May 2013 00:08:35 +0200 Subject: [ticket/11442] Use button name as indicator instead of css classes This leaves it up to the style authors how to style any buttons, without messing up any functionality. PHPBB3-11442 --- phpBB/assets/javascript/core.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 8bbea8b8c9..642d513cb6 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -136,7 +136,7 @@ phpbb.confirm = function(msg, callback, fadedark) { }); var clickHandler = function(e) { - var res = this.className === 'button1'; + var res = this.name === 'confirm'; var fade = (typeof fadedark !== 'undefined' && !fadedark && res) ? div : dark; fade.fadeOut(phpbb.alertTime, function() { div.hide(); @@ -164,11 +164,11 @@ phpbb.confirm = function(msg, callback, fadedark) { $(document).bind('keydown', function(e) { if (e.keyCode === keymap.ENTER) { - $('input[type="button"].button1').trigger('click'); + $('input[name="confirm"]').trigger('click'); e.preventDefault(); e.stopPropagation(); } else if (e.keyCode === keymap.ESC) { - $('input[type="button"].button2').trigger('click'); + $('input[name="cancel"]').trigger('click'); e.preventDefault(); e.stopPropagation(); } -- cgit v1.2.1 From b2e5cc89344d641394e5c15575379de3c86c0806 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Mon, 20 May 2013 20:29:37 +0300 Subject: [feature/editor-code-tabs] Apply code editor to everything Move code editor from prosilver to assets Apply code editor to subsilver2 Apply code editor to ACP elements where bbcode is allowed PHPBB3-11557 --- phpBB/assets/javascript/core.js | 140 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index e3f1f9f55b..ba76ba8c10 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -663,5 +663,145 @@ phpbb.resizeTextArea = function(items, options) { }); }; +/** +* Adjust textarea to manage code bbcode +* +* This function allows to use tab characters when typing code +* and keeps indentation of previous line of code when adding new +* line while typing code. +* +* Editor's functionality is changed only when cursor is between +* [code] and [/code] bbcode tags. +* +* @param {object} textarea Textarea DOM object to apply editor to +*/ +phpbb.applyCodeEditor = function(textarea) { + // list of allowed start and end bbcode code tags, in lower case + var startTags = ['[code]', '[code='], + startTagsEnd = ']', + endTags = ['[/code]']; + + if ($(textarea).data('code-editor') === true) { + return; + } + + /** + * Check if cursor is currently inside code tag + * + * @return {boolean} True if cursor is in code tag + */ + function inTag() { + var start = textarea.selectionStart, + lastEnd = -1, + lastStart = -1, + i, index, value; + + value = textarea.value.toLowerCase(); + + for (i = 0; i < startTags.length; i++) { + var tagLength = startTags[i].length; + if (start >= tagLength) { + index = value.lastIndexOf(startTags[i], start - tagLength); + lastStart = Math.max(lastStart, index); + } + } + if (lastStart == -1) return false; + + if (start > 0) { + for (i = 0; i < endTags.length; i++) { + index = value.lastIndexOf(endTags[i], start - 1); + lastEnd = Math.max(lastEnd, index); + } + } + + return (lastEnd < lastStart); + } + + /** + * Get line of text before cursor + * + * @param {boolean} stripCodeStart If true, only part of line + * after [code] tag will be returned. + * + * @return {string} Line of text + */ + function getLastLine(stripCodeStart) { + var start = textarea.selectionStart, + value = textarea.value, + index = value.lastIndexOf("\n", start - 1); + + value = value.substring(index + 1, start); + + if (stripCodeStart) { + for (var i = 0; i < startTags.length; i++) { + index = value.lastIndexOf(startTags[i]); + if (index >= 0) { + var tagLength = startTags[i].length; + + value = value.substring(index + tagLength); + if (startTags[i].lastIndexOf(startTagsEnd) != tagLength) { + index = value.indexOf(startTagsEnd); + + if (index >= 0) { + value = value.substr(index + 1); + } + } + } + } + } + + return value; + } + + /** + * Append text at cursor position + * + * @param {string} Text Text to append + */ + function appendText(text) { + var start = textarea.selectionStart, + end = textarea.selectionEnd, + value = textarea.value; + + textarea.value = value.substr(0, start) + text + value.substr(end); + textarea.selectionStart = textarea.selectionEnd = start + text.length; + } + + $(textarea).data('code-editor', true).on('keydown', function(event) { + var key = event.keyCode || event.which; + + // intercept tabs + if (key == 9) { + if (inTag()) { + appendText("\t"); + event.preventDefault(); + return; + } + } + + // intercept new line characters + if (key == 13) { + if (inTag()) { + var lastLine = getLastLine(true), + code = '' + /^\s*/g.exec(lastLine); + + if (code.length > 0) { + appendText("\n" + code); + event.preventDefault(); + return; + } + } + } + }); +}; + +/** +* Apply code editor to all textarea elements with data-bbcode attribute +*/ +$(document).ready(function() { + $('textarea[data-bbcode]').each(function() { + phpbb.applyCodeEditor(this); + }); +}); })(jQuery); // Avoid conflicts with other libraries -- cgit v1.2.1 From 809c51f30d28e5dc1449f817b7563d12e4050f7e Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Mon, 20 May 2013 20:33:51 +0300 Subject: [feature/editor-code-tabs] Check for browser support in function Check for browser support and valid textarea in function instead of before applying function. PHPBB3-11557 --- phpBB/assets/javascript/core.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index ba76ba8c10..1a8beb8224 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -681,6 +681,10 @@ phpbb.applyCodeEditor = function(textarea) { startTagsEnd = ']', endTags = ['[/code]']; + if (!textarea || typeof textarea.selectionStart !== 'number') { + return; + } + if ($(textarea).data('code-editor') === true) { return; } -- cgit v1.2.1 From a9c9448ebbaaeef9c120bdf2eaf7360380eabe03 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Mon, 20 May 2013 21:35:51 +0300 Subject: [ticket/11279] Clearer AJAX errors Display clearer AJAX errors rather than generic error PHPBB3-11279 --- phpBB/assets/javascript/core.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index e3f1f9f55b..4b5b5258bc 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -252,9 +252,21 @@ phpbb.ajaxify = function(options) { return; } - function errorHandler() { + /** + * Handler for AJAX errors + */ + function errorHandler(jqXHR, textStatus, errorThrown) { phpbb.clearLoadingTimeout(); - phpbb.alert(dark.attr('data-ajax-error-title'), dark.attr('data-ajax-error-text')); + var errorText = false; + if (typeof errorThrown === 'string' && errorThrown.length > 0) { + errorText = errorThrown; + } + else { + errorText = dark.attr('data-ajax-error-text-' + textStatus); + if (typeof errorText !== 'string' || !errorText.length) + errorText = dark.attr('data-ajax-error-text'); + } + phpbb.alert(dark.attr('data-ajax-error-title'), errorText); } /** -- cgit v1.2.1 From 67053d0b4efdffa12ba6dce40a0f556a9f88f46c Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Mon, 20 May 2013 22:12:20 +0300 Subject: [ticket/11279] Log error in console PHPBB-11279 --- phpBB/assets/javascript/core.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 4b5b5258bc..e0f1dc1eef 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -256,6 +256,9 @@ phpbb.ajaxify = function(options) { * Handler for AJAX errors */ function errorHandler(jqXHR, textStatus, errorThrown) { + if (console && console.log) { + console.log('AJAX error. status: ' + textStatus + ', message: ' + errorThrown); + } phpbb.clearLoadingTimeout(); var errorText = false; if (typeof errorThrown === 'string' && errorThrown.length > 0) { -- cgit v1.2.1 From 9db0fa88569da1922ac21d9a003b7e577a96c810 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 22 May 2013 20:52:15 +0300 Subject: [feature/editor-code-tabs] Make inTag function reusable Change inTag function to reusable JS function that can check for any BBCode PHPBB3-11557 --- phpBB/assets/javascript/core.js | 73 +++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 29 deletions(-) (limited to 'phpBB/assets/javascript/core.js') diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 1a8beb8224..be4b21abf0 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -663,6 +663,49 @@ phpbb.resizeTextArea = function(items, options) { }); }; +/** +* Check if cursor in textarea is currently inside a bbcode tag +* +* @param {object} textarea Textarea DOM object +* @param {Array} startTags List of start tags to look for +* For example, Array('[code]', '[code=') +* @param {Array} endTags List of end tags to look for +* For example, Array('[/code]') +* +* @return {boolean} True if cursor is in bbcode tag +*/ +phpbb.inBBCodeTag = function(textarea, startTags, endTags) { + var start = textarea.selectionStart, + lastEnd = -1, + lastStart = -1, + i, index, value; + + if (typeof start !== 'number') { + return false; + } + + value = textarea.value.toLowerCase(); + + for (i = 0; i < startTags.length; i++) { + var tagLength = startTags[i].length; + if (start >= tagLength) { + index = value.lastIndexOf(startTags[i], start - tagLength); + lastStart = Math.max(lastStart, index); + } + } + if (lastStart == -1) return false; + + if (start > 0) { + for (i = 0; i < endTags.length; i++) { + index = value.lastIndexOf(endTags[i], start - 1); + lastEnd = Math.max(lastEnd, index); + } + } + + return (lastEnd < lastStart); +} + + /** * Adjust textarea to manage code bbcode * @@ -689,36 +732,8 @@ phpbb.applyCodeEditor = function(textarea) { return; } - /** - * Check if cursor is currently inside code tag - * - * @return {boolean} True if cursor is in code tag - */ function inTag() { - var start = textarea.selectionStart, - lastEnd = -1, - lastStart = -1, - i, index, value; - - value = textarea.value.toLowerCase(); - - for (i = 0; i < startTags.length; i++) { - var tagLength = startTags[i].length; - if (start >= tagLength) { - index = value.lastIndexOf(startTags[i], start - tagLength); - lastStart = Math.max(lastStart, index); - } - } - if (lastStart == -1) return false; - - if (start > 0) { - for (i = 0; i < endTags.length; i++) { - index = value.lastIndexOf(endTags[i], start - 1); - lastEnd = Math.max(lastEnd, index); - } - } - - return (lastEnd < lastStart); + return phpbb.inBBCodeTag(textarea, startTags, endTags); } /** -- cgit v1.2.1