diff options
author | Callum Macrae <callum@macr.ae> | 2015-05-30 14:44:48 +0200 |
---|---|---|
committer | Callum Macrae <callum@macr.ae> | 2015-05-30 14:44:48 +0200 |
commit | e3090e04c3fc2505155118abfd7e354bd858056b (patch) | |
tree | 6a3fb3db15daea1458f2fb0e686c87af1efcf950 /phpBB/assets/javascript | |
parent | 049f584111b5d7ce307d57d36b3be8a34d06194b (diff) | |
download | forums-e3090e04c3fc2505155118abfd7e354bd858056b.tar forums-e3090e04c3fc2505155118abfd7e354bd858056b.tar.gz forums-e3090e04c3fc2505155118abfd7e354bd858056b.tar.bz2 forums-e3090e04c3fc2505155118abfd7e354bd858056b.tar.xz forums-e3090e04c3fc2505155118abfd7e354bd858056b.zip |
[ticket/13898] js coding standaaards
PHPBB3-13898
Diffstat (limited to 'phpBB/assets/javascript')
-rw-r--r-- | phpBB/assets/javascript/core.js | 77 | ||||
-rw-r--r-- | phpBB/assets/javascript/plupload.js | 40 |
2 files changed, 62 insertions, 55 deletions
diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 88ef5733fe..efa6ecbc74 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -264,11 +264,9 @@ phpbb.ajaxify = function(options) { } catch (e) {} if (typeof responseText === 'string' && responseText.length > 0) { errorText = responseText; - } - else if (typeof errorThrown === 'string' && errorThrown.length > 0) { + } else if (typeof errorThrown === 'string' && errorThrown.length > 0) { errorText = errorThrown; - } - else { + } else { errorText = $dark.attr('data-ajax-error-text-' + textStatus); if (typeof errorText !== 'string' || !errorText.length) { errorText = $dark.attr('data-ajax-error-text'); @@ -429,7 +427,7 @@ phpbb.search = { }; /** - * Get cached search data. + * Get cached search data. * * @param {string} id Search ID. * @returns {bool|object} Cached data object. Returns false if no data exists. @@ -442,7 +440,7 @@ phpbb.search.cache.get = function(id) { }; /** - * Set search cache data value. + * Set search cache data value. * * @param {string} id Search ID. * @param {string} key Data key. @@ -450,13 +448,13 @@ phpbb.search.cache.get = function(id) { */ phpbb.search.cache.set = function(id, key, value) { if (!this.data[id]) { - this.data[id] = {results: []}; + this.data[id] = { results: [] }; } this.data[id][key] = value; }; /** - * Cache search result. + * Cache search result. * * @param {string} id Search ID. * @param {string} keyword Keyword. @@ -496,7 +494,7 @@ phpbb.search.getKeyword = function($input, keyword, multiline) { /** * Get the textarea line number on which the keyword resides - for textareas - * that support multiple keywords (one per line). + * that support multiple keywords (one per line). * * @param {jQuery} $textarea Search textarea. * @returns {int} The line number. @@ -525,7 +523,8 @@ phpbb.search.setValue = function($input, value, multiline) { }; /** - * Sets the onclick event to set the value on the input|textarea to the selected search result. + * Sets the onclick event to set the value on the input|textarea to the + * selected search result. * * @param {jQuery} $input Search input|textarea. * @param {object} value Result object. @@ -554,7 +553,7 @@ phpbb.search.setValueOnClick = function($input, value, $row, $container) { phpbb.search.filter = function(data, event, sendRequest) { var $this = $(this), dataName = ($this.attr('data-name') !== undefined) ? $this.attr('data-name') : $this.attr('name'), - minLength = parseInt($this.attr('data-min-length')), + minLength = parseInt($this.attr('data-min-length'), 10), searchID = $this.attr('data-results'), keyword = phpbb.search.getKeyword($this, data[dataName], $this.attr('data-multiline')), cache = phpbb.search.cache.get(searchID), @@ -576,7 +575,10 @@ phpbb.search.filter = function(data, event, sendRequest) { } else { // Do we already have results for this? if (cache.results[keyword]) { - var response = {keyword: keyword, results: cache.results[keyword]}; + var response = { + keyword: keyword, + results: cache.results[keyword] + }; phpbb.search.handleResponse(response, $this, true); proceed = false; } @@ -587,8 +589,8 @@ phpbb.search.filter = function(data, event, sendRequest) { phpbb.search.cache.set(searchID, 'lastSearch', keyword); phpbb.search.cache.setResults(searchID, keyword, []); proceed = false; - } - } + } + } } if (proceed) { @@ -601,7 +603,7 @@ phpbb.search.filter = function(data, event, sendRequest) { }; /** - * Handle search result response. + * Handle search result response. * * @param {object} res Data received from server. * @param {jQuery} $input Search input|textarea. @@ -781,7 +783,7 @@ phpbb.timezoneSwitchDate = function(keepSelection) { } else { $tzSelectDateSuggest.css('display', 'inline'); } - + var $tzOptions = $timezone.children('optgroup[data-tz-value="' + $tzDate.val() + '"]').children('option'); if ($tzOptions.length === 1) { @@ -1006,7 +1008,9 @@ phpbb.resizeTextArea = function($items, options) { function resetAutoResize(item) { var $item = $(item); if ($item.hasClass('auto-resized')) { - $(item).css({height: '', resize: ''}).removeClass('auto-resized'); + $(item) + .css({ height: '', resize: '' }) + .removeClass('auto-resized'); configuration.resetCallback.call(item, $item); } } @@ -1014,7 +1018,9 @@ phpbb.resizeTextArea = function($items, options) { function autoResize(item) { function setHeight(height) { height += parseInt($item.css('height'), 10) - $item.height(); - $item.css({height: height + 'px', resize: 'none'}).addClass('auto-resized'); + $item + .css({ height: height + 'px', resize: 'none' }) + .addClass('auto-resized'); configuration.resizeCallback.call(item, $item); } @@ -1039,8 +1045,7 @@ phpbb.resizeTextArea = function($items, options) { if (height > maxHeight) { setHeight(maxHeight); - } - else if (scrollHeight > (height + 5)) { + } else if (scrollHeight > (height + 5)) { setHeight(Math.min(maxHeight, scrollHeight)); } } @@ -1157,7 +1162,7 @@ phpbb.applyCodeEditor = function(textarea) { var tagLength = startTags[i].length; value = value.substring(index + tagLength); - if (startTags[i].lastIndexOf(startTagsEnd) != tagLength) { + if (startTags[i].lastIndexOf(startTagsEnd) !== tagLength) { index = value.indexOf(startTagsEnd); if (index >= 0) { @@ -1333,12 +1338,15 @@ phpbb.toggleDropdown = function() { fullFreeSpace = freeSpace + parent.outerWidth(); options.dropdown.find('.dropdown-contents').each(function() { - contentWidth = parseInt($(this).outerWidth()); - $(this).css({marginLeft: 0, left: 0}); + contentWidth = parseInt($(this).outerWidth(), 10); + $(this).css({ marginLeft: 0, left: 0 }); }); var maxOffset = Math.min(contentWidth, fullFreeSpace) + 'px'; - options.dropdown.css({'width': maxOffset, 'margin-left': '-' + maxOffset}); + options.dropdown.css({ + width: maxOffset, + marginLeft: -maxOffset + }); } } else { options.dropdown.css('margin-right', '-' + (windowWidth + freeSpace) + 'px'); @@ -1405,9 +1413,7 @@ phpbb.registerDropdown = function(toggle, dropdown, options) { * @param {int} height Palette cell height. */ phpbb.colorPalette = function(dir, width, height) { - var r = 0, - g = 0, - b = 0, + var r, g, b, numberList = new Array(6), color = '', html = ''; @@ -1418,32 +1424,33 @@ phpbb.colorPalette = function(dir, width, height) { numberList[3] = 'BF'; numberList[4] = 'FF'; - var tableClass = (dir == 'h') ? 'horizontal-palette' : 'vertical-palette'; + var tableClass = (dir === 'h') ? 'horizontal-palette' : 'vertical-palette'; html += '<table class="not-responsive colour-palette ' + tableClass + '" style="width: auto;">'; for (r = 0; r < 5; r++) { - if (dir == 'h') { + if (dir === 'h') { html += '<tr>'; } for (g = 0; g < 5; g++) { - if (dir == 'v') { + if (dir === 'v') { html += '<tr>'; } for (b = 0; b < 5; b++) { - color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]); + color = '' + numberList[r] + numberList[g] + numberList[b]; html += '<td style="background-color: #' + color + '; width: ' + width + 'px; height: ' + height + 'px;">'; - html += '<a href="#" data-color="' + color + '" style="display: block; width: ' + width + 'px; height: ' + height + 'px; " alt="#' + color + '" title="#' + color + '"></a>'; + html += '<a href="#" data-color="' + color + '" style="display: block; width: ' + width + 'px; height: ' + + height + 'px; " alt="#' + color + '" title="#' + color + '"></a>'; html += '</td>'; } - if (dir == 'v') { + if (dir === 'v') { html += '</tr>'; } } - if (dir == 'h') { + if (dir === 'h') { html += '</tr>'; } } @@ -1530,7 +1537,7 @@ phpbb.toggleSelectSettings = function(el) { * @returns function */ phpbb.getFunctionByName = function (functionName) { - var namespaces = functionName.split('.'), + var namespaces = functionName.split('.'), func = namespaces.pop(), context = window; diff --git a/phpBB/assets/javascript/plupload.js b/phpBB/assets/javascript/plupload.js index 3845de6c56..96e5ca96e6 100644 --- a/phpBB/assets/javascript/plupload.js +++ b/phpBB/assets/javascript/plupload.js @@ -105,7 +105,7 @@ phpbb.plupload.getIndex = function(attachId) { /** * Set the data in phpbb.plupload.data and phpbb.plupload.ids arrays. - * + * * @param {Array} data Array containing the new data to use. In the form of * array(index => object(property: value). Requires attach_id to be one of the object properties. */ @@ -121,7 +121,7 @@ phpbb.plupload.setData = function(data) { /** * Update the attachment data in the HTML and the phpbb & phpbb.plupload objects. - * + * * @param {Array} data Array containing the new data to use. * @param {string} action The action that required the update. Used to update the inline attachment bbcodes. * @param {int} index The index from phpbb.plupload_ids that was affected by the action. @@ -138,7 +138,7 @@ phpbb.plupload.update = function(data, action, index, downloadUrl) { /** * Update the relevant elements and hidden data for all attachments. - * + * * @param {Array} downloadUrl Optional array of download urls to update. */ phpbb.plupload.updateRows = function(downloadUrl) { @@ -152,7 +152,7 @@ phpbb.plupload.updateRows = function(downloadUrl) { * using the id "attach-row-tpl" to be present. This snippet is cloned and the * data for the file inserted into it. The row is then appended or prepended to * #file-list based on the attach_order setting. - * + * * @param {object} file Plupload file object for the new attachment. */ phpbb.plupload.insertRow = function(file) { @@ -162,7 +162,7 @@ phpbb.plupload.insertRow = function(file) { row.find('.file-name').html(plupload.xmlEncode(file.name)); row.find('.file-size').html(plupload.formatSize(file.size)); - if (phpbb.plupload.order == 'desc') { + if (phpbb.plupload.order === 'desc') { $('#file-list').prepend(row); } else { $('#file-list').append(row); @@ -171,7 +171,7 @@ phpbb.plupload.insertRow = function(file) { /** * Update the relevant elements and hidden data for an attachment. - * + * * @param {int} index The index from phpbb.plupload.ids of the attachment to edit. * @param {Array} downloadUrl Optional array of download urls to update. */ @@ -209,7 +209,7 @@ phpbb.plupload.updateHiddenData = function(row, attach, index) { var input = $('<input />') .attr('type', 'hidden') - .attr('name', 'attachment_data[' + index + '][' + key +']') + .attr('name', 'attachment_data[' + index + '][' + key + ']') .attr('value', attach[key]); $('textarea', row).after(input); } @@ -256,7 +256,7 @@ phpbb.plupload.deleteFile = function(row, attachId) { // trigger_error() was called which likely means a permission error was encountered. if (typeof response.title !== 'undefined') { - phpbb.plupload.uploader.trigger('Error', {message: response.message}); + phpbb.plupload.uploader.trigger('Error', { message: response.message }); // We will have to assume that the deletion failed. So leave the file status as uploaded. row.find('.file-status').toggleClass('file-uploaded'); @@ -281,7 +281,7 @@ phpbb.plupload.deleteFile = function(row, attachId) { $.ajax(phpbb.plupload.config.url, { type: 'POST', data: $.extend(fields, phpbb.plupload.getSerializedData()), - headers: {'X-PHPBB-USING-PLUPLOAD': '1', 'X-Requested-With': 'XMLHttpRequest'} + headers: { 'X-PHPBB-USING-PLUPLOAD': '1', 'X-Requested-With': 'XMLHttpRequest' } }) .always(always) .done(done); @@ -297,10 +297,10 @@ phpbb.plupload.hideEmptyList = function() { }; /** - * Update the indices used in inline attachment bbcodes. This ensures that the bbcodes - * correspond to the correct file after a file is added or removed. This should be called - * before the phpbb.plupload,data and phpbb.plupload.ids arrays are updated, otherwise it will - * not work correctly. + * Update the indices used in inline attachment bbcodes. This ensures that the + * bbcodes correspond to the correct file after a file is added or removed. + * This should be called before the phpbb.plupload,data and phpbb.plupload.ids + * arrays are updated, otherwise it will not work correctly. * * @param {string} action The action that occurred -- either "addition" or "removal" * @param {int} index The index of the attachment from phpbb.plupload.ids that was affected. @@ -323,7 +323,7 @@ phpbb.plupload.updateBbcode = function(action, index) { return ''; } var newIndex = i + ((removal) ? -1 : 1); - return '[attachment=' + newIndex +']' + fileName + '[/attachment]'; + return '[attachment=' + newIndex + ']' + fileName + '[/attachment]'; }); } @@ -380,10 +380,10 @@ phpbb.plupload.handleMaxFilesReached = function() { phpbb.plupload.markQueuedFailed(phpbb.plupload.lang.TOO_MANY_ATTACHMENTS); // Disable the uploader. phpbb.plupload.disableUploader(); - phpbb.plupload.uploader.trigger('Error', {message: phpbb.plupload.lang.TOO_MANY_ATTACHMENTS}); + phpbb.plupload.uploader.trigger('Error', { message: phpbb.plupload.lang.TOO_MANY_ATTACHMENTS }); return true; - } else if(phpbb.plupload.maxFiles > phpbb.plupload.ids.length) { + } else if (phpbb.plupload.maxFiles > phpbb.plupload.ids.length) { // Enable the uploader if the user is under the limit phpbb.plupload.enableUploader(); } @@ -504,7 +504,7 @@ phpbb.plupload.uploader.bind('BeforeUpload', function(up, file) { return; } - phpbb.plupload.updateMultipartParams({'real_filename': file.name}); + phpbb.plupload.updateMultipartParams({ real_filename: file.name }); }); /** @@ -538,7 +538,7 @@ phpbb.plupload.uploader.bind('ChunkUploaded', function(up, file, response) { // If trigger_error() was called, then a permission error likely occurred. if (typeof json.title !== 'undefined') { - json.error = {message: json.message}; + json.error = { message: json.message }; } if (json.error) { @@ -619,7 +619,7 @@ phpbb.plupload.uploader.bind('FileUploaded', function(up, file, response) { // If trigger_error() was called, then a permission error likely occurred. if (typeof json.title !== 'undefined') { error = json.message; - up.trigger('Error', {message: error}); + up.trigger('Error', { message: error }); // The rest of the queue will fail. phpbb.plupload.markQueuedFailed(error); @@ -640,7 +640,7 @@ phpbb.plupload.uploader.bind('FileUploaded', function(up, file, response) { }); /** - * Fires when the entire queue of files have been uploaded. + * Fires when the entire queue of files have been uploaded. */ phpbb.plupload.uploader.bind('UploadComplete', function() { // Hide the progress bar |