diff --git a/phpBB/assets/javascript/installer.js b/phpBB/assets/javascript/installer.js index da30f136bd..4e44e2755c 100644 --- a/phpBB/assets/javascript/installer.js +++ b/phpBB/assets/javascript/installer.js @@ -3,398 +3,398 @@ */ (function($) { // Avoid conflicts with other libraries - 'use strict'; + 'use strict'; - // Installer variables - var pollTimer = null; - var nextReadPosition = 0; - var progressBarTriggered = false; - var progressTimer = null; - var currentProgress = 0; + // Installer variables + var pollTimer = null; + var nextReadPosition = 0; + var progressBarTriggered = false; + var progressTimer = null; + var currentProgress = 0; - // Template related variables - var $contentWrapper = $('.install-body').find('.main'); + // Template related variables + var $contentWrapper = $('.install-body').find('.main'); - // Intercept form submits - interceptFormSubmit($('#install_install')); + // Intercept form submits + interceptFormSubmit($('#install_install')); - /** - * Creates an XHR object - * - * jQuery cannot be used as the response is streamed, and - * as of now, jQuery does not provide access to the response until - * the connection is not closed. - * - * @return XMLHttpRequest - */ - function createXhrObject() { - return new XMLHttpRequest(); - } + /** + * Creates an XHR object + * + * jQuery cannot be used as the response is streamed, and + * as of now, jQuery does not provide access to the response until + * the connection is not closed. + * + * @return XMLHttpRequest + */ + function createXhrObject() { + return new XMLHttpRequest(); + } - /** - * Displays error, warning and log messages - * - * @param type - * @param messages - */ - function addMessage(type, messages) { - // Get message containers - var $errorContainer = $('#error-container'); - var $warningContainer = $('#warning-container'); - var $logContainer = $('#log-container'); + /** + * Displays error, warning and log messages + * + * @param type + * @param messages + */ + function addMessage(type, messages) { + // Get message containers + var $errorContainer = $('#error-container'); + var $warningContainer = $('#warning-container'); + var $logContainer = $('#log-container'); - var $title, $description, $msgElement, arraySize = messages.length; - for (var i = 0; i < arraySize; i++) { - $msgElement = $('
'); - $title = $(document.createElement('strong')); - $title.text(messages[i].title); - $msgElement.append($title); + var $title, $description, $msgElement, arraySize = messages.length; + for (var i = 0; i < arraySize; i++) { + $msgElement = $(''); + $title = $(document.createElement('strong')); + $title.text(messages[i].title); + $msgElement.append($title); - if (messages[i].hasOwnProperty('description')) { - $description = $(document.createElement('p')); - $description.html(messages[i].description); - $msgElement.append($description); - } + if (messages[i].hasOwnProperty('description')) { + $description = $(document.createElement('p')); + $description.html(messages[i].description); + $msgElement.append($description); + } - switch (type) { - case 'error': - $msgElement.addClass('errorbox'); - $errorContainer.append($msgElement); - break; - case 'warning': - $msgElement.addClass('warningbox'); - $warningContainer.append($msgElement); - break; - case 'log': - $msgElement.addClass('log'); - $logContainer.append($msgElement); - break; - case 'success': - $msgElement.addClass('successbox'); - $errorContainer.prepend($msgElement); - break; - } - } - } + switch (type) { + case 'error': + $msgElement.addClass('errorbox'); + $errorContainer.append($msgElement); + break; + case 'warning': + $msgElement.addClass('warningbox'); + $warningContainer.append($msgElement); + break; + case 'log': + $msgElement.addClass('log'); + $logContainer.append($msgElement); + break; + case 'success': + $msgElement.addClass('successbox'); + $errorContainer.prepend($msgElement); + break; + } + } + } - /** - * Displays a form from the response - * - * @param formHtml - */ - function addForm(formHtml) { - var $formContainer = $('#content-container'); - $formContainer.html(formHtml); - var $form = $('#install_install'); - interceptFormSubmit($form); - } + /** + * Displays a form from the response + * + * @param formHtml + */ + function addForm(formHtml) { + var $formContainer = $('#content-container'); + $formContainer.html(formHtml); + var $form = $('#install_install'); + interceptFormSubmit($form); + } - /** - * Handles navigation status updates - * - * @param navObj - */ - function updateNavbarStatus(navObj) { - var navID, $stage, $stageListItem, $active; - $active = $('#activemenu'); + /** + * Handles navigation status updates + * + * @param navObj + */ + function updateNavbarStatus(navObj) { + var navID, $stage, $stageListItem, $active; + $active = $('#activemenu'); - if (navObj.hasOwnProperty('finished')) { - // This should be an Array - var navItems = navObj.finished; + if (navObj.hasOwnProperty('finished')) { + // This should be an Array + var navItems = navObj.finished; - for (var i = 0; i < navItems.length; i++) { - navID = 'installer-stage-' + navItems[i]; - $stage = $('#' + navID); - $stageListItem = $stage.parent(); + for (var i = 0; i < navItems.length; i++) { + navID = 'installer-stage-' + navItems[i]; + $stage = $('#' + navID); + $stageListItem = $stage.parent(); - if ($active.length && $active.is($stageListItem)) { - $active.removeAttr('id'); - } + if ($active.length && $active.is($stageListItem)) { + $active.removeAttr('id'); + } - $stage.addClass('completed'); - } - } + $stage.addClass('completed'); + } + } - if (navObj.hasOwnProperty('active')) { - navID = 'installer-stage-' + navObj.active; - $stage = $('#' + navID); - $stageListItem = $stage.parent(); + if (navObj.hasOwnProperty('active')) { + navID = 'installer-stage-' + navObj.active; + $stage = $('#' + navID); + $stageListItem = $stage.parent(); - if ($active.length && !$active.is($stageListItem)) { - $active.removeAttr('id'); - } + if ($active.length && !$active.is($stageListItem)) { + $active.removeAttr('id'); + } - $stageListItem.attr('id', 'activemenu'); - } - } + $stageListItem.attr('id', 'activemenu'); + } + } - /** - * Renders progress bar - * - * @param progressObject - */ - function setProgress(progressObject) { - var $statusText, $progressBar, $progressText, $progressFiller; + /** + * Renders progress bar + * + * @param progressObject + */ + function setProgress(progressObject) { + var $statusText, $progressBar, $progressText, $progressFiller; - if (progressObject.task_name.length) { - if (!progressBarTriggered) { - // Create progress bar - var $contentContainer = $('#content-container'); + if (progressObject.task_name.length) { + if (!progressBarTriggered) { + // Create progress bar + var $contentContainer = $('#content-container'); - // Create progress bar elements - $progressBar = $(''); - $progressBar.attr('id', 'progress-bar'); - $progressText = $(''); - $progressText.attr('id', 'progress-bar-text'); - $progressFiller = $(''); - $progressFiller.attr('id', 'progress-bar-filler'); + // Create progress bar elements + $progressBar = $(''); + $progressBar.attr('id', 'progress-bar'); + $progressText = $(''); + $progressText.attr('id', 'progress-bar-text'); + $progressFiller = $(''); + $progressFiller.attr('id', 'progress-bar-filler'); - $statusText = $(''); - $statusText.attr('id', 'progress-status-text'); + $statusText = $(''); + $statusText.attr('id', 'progress-status-text'); - $progressBar.append($progressFiller); - $progressBar.append($progressText); + $progressBar.append($progressFiller); + $progressBar.append($progressText); - $contentContainer.append($statusText); - $contentContainer.append($progressBar); + $contentContainer.append($statusText); + $contentContainer.append($progressBar); - progressBarTriggered = true; - } else { - $statusText = $('#progress-status-text'); - } + progressBarTriggered = true; + } else { + $statusText = $('#progress-status-text'); + } - // Update progress bar - $statusText.text(progressObject.task_name + '…'); - incrementProgressBar(Math.round(progressObject.task_num / progressObject.task_count * 100)); - } - } + // Update progress bar + $statusText.text(progressObject.task_name + '…'); + incrementProgressBar(Math.round(progressObject.task_num / progressObject.task_count * 100)); + } + } - // Set cookies - function setCookies(cookies) { - var cookie; + // Set cookies + function setCookies(cookies) { + var cookie; - for (var i = 0; i < cookies.length; i++) { - // Set cookie name and value - cookie = encodeURIComponent(cookies[i].name) + '=' + encodeURIComponent(cookies[i].value); - // Set path - cookie += '; path=/'; - document.cookie = cookie; - } - } + for (var i = 0; i < cookies.length; i++) { + // Set cookie name and value + cookie = encodeURIComponent(cookies[i].name) + '=' + encodeURIComponent(cookies[i].value); + // Set path + cookie += '; path=/'; + document.cookie = cookie; + } + } - /** - * Parse messages from the response object - * - * @param messageJSON - */ - function parseMessage(messageJSON) { - $('#loading_indicator').css('display', 'none'); + /** + * Parse messages from the response object + * + * @param messageJSON + */ + function parseMessage(messageJSON) { + $('#loading_indicator').css('display', 'none'); - var responseObject = JSON.parse(messageJSON); + var responseObject = JSON.parse(messageJSON); - // Parse object - if (responseObject.hasOwnProperty('errors')) { - addMessage('error', responseObject.errors); - } + // Parse object + if (responseObject.hasOwnProperty('errors')) { + addMessage('error', responseObject.errors); + } - if (responseObject.hasOwnProperty('warnings')) { - addMessage('warning', responseObject.warnings); - } + if (responseObject.hasOwnProperty('warnings')) { + addMessage('warning', responseObject.warnings); + } - if (responseObject.hasOwnProperty('logs')) { - addMessage('log', responseObject.logs); - } + if (responseObject.hasOwnProperty('logs')) { + addMessage('log', responseObject.logs); + } - if (responseObject.hasOwnProperty('success')) { - addMessage('success', responseObject.success); - } + if (responseObject.hasOwnProperty('success')) { + addMessage('success', responseObject.success); + } - if (responseObject.hasOwnProperty('form')) { - addForm(responseObject.form); - } + if (responseObject.hasOwnProperty('form')) { + addForm(responseObject.form); + } - if (responseObject.hasOwnProperty('progress')) { - setProgress(responseObject.progress); - } + if (responseObject.hasOwnProperty('progress')) { + setProgress(responseObject.progress); + } - if (responseObject.hasOwnProperty('nav')) { - updateNavbarStatus(responseObject.nav); - } + if (responseObject.hasOwnProperty('nav')) { + updateNavbarStatus(responseObject.nav); + } - if (responseObject.hasOwnProperty('cookies')) { - setCookies(responseObject.cookies); - } - } + if (responseObject.hasOwnProperty('cookies')) { + setCookies(responseObject.cookies); + } + } - /** - * Process updates in streamed response - * - * @param xhReq XHR object - */ - function pollContent(xhReq) { - var messages = xhReq.responseText; - var msgSeparator = '}\n\n'; - var unprocessed, messageEndIndex, endOfMessageIndex, message; + /** + * Process updates in streamed response + * + * @param xhReq XHR object + */ + function pollContent(xhReq) { + var messages = xhReq.responseText; + var msgSeparator = '}\n\n'; + var unprocessed, messageEndIndex, endOfMessageIndex, message; - do { - unprocessed = messages.substring(nextReadPosition); - messageEndIndex = unprocessed.indexOf(msgSeparator); + do { + unprocessed = messages.substring(nextReadPosition); + messageEndIndex = unprocessed.indexOf(msgSeparator); - if (messageEndIndex !== -1) { - endOfMessageIndex = messageEndIndex + msgSeparator.length; - message = unprocessed.substring(0, endOfMessageIndex); - parseMessage(message); - nextReadPosition += endOfMessageIndex; - } - } while (messageEndIndex !== -1); + if (messageEndIndex !== -1) { + endOfMessageIndex = messageEndIndex + msgSeparator.length; + message = unprocessed.substring(0, endOfMessageIndex); + parseMessage(message); + nextReadPosition += endOfMessageIndex; + } + } while (messageEndIndex !== -1); - if (xhReq.readyState === 4) { - $('#loading_indicator').css('display', 'none'); - resetPolling(); - } - } + if (xhReq.readyState === 4) { + $('#loading_indicator').css('display', 'none'); + resetPolling(); + } + } - /** - * Animates the progress bar - * - * @param $progressText - * @param $progressFiller - * @param progressLimit - */ - function incrementFiller($progressText, $progressFiller, progressLimit) { - if (currentProgress >= progressLimit || currentProgress >= 100) { - clearInterval(progressTimer); - return; - } + /** + * Animates the progress bar + * + * @param $progressText + * @param $progressFiller + * @param progressLimit + */ + function incrementFiller($progressText, $progressFiller, progressLimit) { + if (currentProgress >= progressLimit || currentProgress >= 100) { + clearInterval(progressTimer); + return; + } - currentProgress++; - $progressText.text(currentProgress + '%'); - $progressFiller.css('width', currentProgress + '%'); - } + currentProgress++; + $progressText.text(currentProgress + '%'); + $progressFiller.css('width', currentProgress + '%'); + } - /** - * Wrapper function for progress bar rendering and animating - * - * @param progressLimit - */ - function incrementProgressBar(progressLimit) { - var $progressFiller = $('#progress-bar-filler'); - var $progressText = $('#progress-bar-text'); - var progressStart = $progressFiller.width() / $progressFiller.offsetParent().width() * 100; - currentProgress = Math.floor(progressStart); + /** + * Wrapper function for progress bar rendering and animating + * + * @param progressLimit + */ + function incrementProgressBar(progressLimit) { + var $progressFiller = $('#progress-bar-filler'); + var $progressText = $('#progress-bar-text'); + var progressStart = $progressFiller.width() / $progressFiller.offsetParent().width() * 100; + currentProgress = Math.floor(progressStart); - clearInterval(progressTimer); - progressTimer = setInterval(function() { - incrementFiller($progressText, $progressFiller, progressLimit); - }, 10); - } + clearInterval(progressTimer); + progressTimer = setInterval(function() { + incrementFiller($progressText, $progressFiller, progressLimit); + }, 10); + } - /** - * Resets the polling timer - */ - function resetPolling() { - clearInterval(pollTimer); - nextReadPosition = 0; - } + /** + * Resets the polling timer + */ + function resetPolling() { + clearInterval(pollTimer); + nextReadPosition = 0; + } - /** - * Sets up timer for processing the streamed HTTP response - * - * @param xhReq - */ - function startPolling(xhReq) { - resetPolling(); - pollTimer = setInterval(function () { - pollContent(xhReq); - }, 250); - } + /** + * Sets up timer for processing the streamed HTTP response + * + * @param xhReq + */ + function startPolling(xhReq) { + resetPolling(); + pollTimer = setInterval(function () { + pollContent(xhReq); + }, 250); + } - /** - * Renders the AJAX UI layout - */ - function setupAjaxLayout() { - // Clear content - $contentWrapper.html(''); + /** + * Renders the AJAX UI layout + */ + function setupAjaxLayout() { + // Clear content + $contentWrapper.html(''); - var $header = $(''); - $header.attr('id', 'header-container'); - $contentWrapper.append($header); + var $header = $(''); + $header.attr('id', 'header-container'); + $contentWrapper.append($header); - var $description = $(''); - $description.attr('id', 'description-container'); - $contentWrapper.append($description); + var $description = $(''); + $description.attr('id', 'description-container'); + $contentWrapper.append($description); - var $errorContainer = $(''); - $errorContainer.attr('id', 'error-container'); - $contentWrapper.append($errorContainer); + var $errorContainer = $(''); + $errorContainer.attr('id', 'error-container'); + $contentWrapper.append($errorContainer); - var $warningContainer = $(''); - $warningContainer.attr('id', 'warning-container'); - $contentWrapper.append($warningContainer); + var $warningContainer = $(''); + $warningContainer.attr('id', 'warning-container'); + $contentWrapper.append($warningContainer); - var $installerContentWrapper = $(''); - $installerContentWrapper.attr('id', 'content-container'); - $contentWrapper.append($installerContentWrapper); + var $installerContentWrapper = $(''); + $installerContentWrapper.attr('id', 'content-container'); + $contentWrapper.append($installerContentWrapper); - var $logContainer = $(''); - $logContainer.attr('id', 'log-container'); - $contentWrapper.append($logContainer); + var $logContainer = $(''); + $logContainer.attr('id', 'log-container'); + $contentWrapper.append($logContainer); - var $spinner = $(''); - $spinner.attr('id', 'loading_indicator'); - $spinner.html(' '); - $contentWrapper.append($spinner); - } + var $spinner = $(''); + $spinner.attr('id', 'loading_indicator'); + $spinner.html(' '); + $contentWrapper.append($spinner); + } - // Submits a form - function submitForm($form, $submitBtn) { - $form.css('display', 'none'); + // Submits a form + function submitForm($form, $submitBtn) { + $form.css('display', 'none'); - var xhReq = createXhrObject(); - xhReq.open('POST', $form.attr('action'), true); - xhReq.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); - xhReq.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); - xhReq.send(getFormFields($form, $submitBtn)); + var xhReq = createXhrObject(); + xhReq.open('POST', $form.attr('action'), true); + xhReq.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + xhReq.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + xhReq.send(getFormFields($form, $submitBtn)); - // Disable language selector - $('#language_selector :input, label').css('display', 'none'); + // Disable language selector + $('#language_selector :input, label').css('display', 'none'); - // Clear content - setupAjaxLayout(); - $('#loading_indicator').css('display', 'block'); + // Clear content + setupAjaxLayout(); + $('#loading_indicator').css('display', 'block'); - startPolling(xhReq); - } + startPolling(xhReq); + } - /** - * Add submit button to the POST information - * - * @param $form - * @param $submitBtn - * - * @returns {*} - */ - function getFormFields($form, $submitBtn) { - var formData = $form.serialize(); - formData += ((formData.length) ? '&' : '') + encodeURIComponent($submitBtn.attr('name')) + '='; - formData += encodeURIComponent($submitBtn.attr('value')); + /** + * Add submit button to the POST information + * + * @param $form + * @param $submitBtn + * + * @returns {*} + */ + function getFormFields($form, $submitBtn) { + var formData = $form.serialize(); + formData += ((formData.length) ? '&' : '') + encodeURIComponent($submitBtn.attr('name')) + '='; + formData += encodeURIComponent($submitBtn.attr('value')); - return formData; - } + return formData; + } - /** - * Intercept form submit events and determine the submit button used - * - * @param $form - */ - function interceptFormSubmit($form) { - if (!$form.length) { - return; - } + /** + * Intercept form submit events and determine the submit button used + * + * @param $form + */ + function interceptFormSubmit($form) { + if (!$form.length) { + return; + } - $form.find(':submit').bind('click', function (event) { - event.preventDefault(); - submitForm($form, $(this)); - }); - } + $form.find(':submit').bind('click', function (event) { + event.preventDefault(); + submitForm($form, $(this)); + }); + } })(jQuery); // Avoid conflicts with other libraries