[ticket/13898] js coding standaaards

PHPBB3-13898
This commit is contained in:
Callum Macrae 2015-05-30 14:44:48 +02:00
parent 049f584111
commit e3090e04c3
5 changed files with 181 additions and 70 deletions

79
phpBB/.jscsrc Normal file
View file

@ -0,0 +1,79 @@
{
"excludeFiles": ["node_modules/**", "**/build/**"],
"requireCurlyBraces": [
"if", "else", "for", "while", "do", "try", "catch"
],
"requireSpaceBeforeKeywords": [
"else", "while", "catch"
],
"requireSpaceAfterKeywords": [
"do", "for", "if", "else", "switch", "case", "try", "catch", "while", "return", "typeof"
],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireSpacesInFunction": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInCallExpression": true,
"requireBlocksOnNewline": true,
"requirePaddingNewlinesBeforeKeywords": ["case"],
"disallowEmptyBlocks": true,
"disallowSpacesInsideArrayBrackets": "nested",
"disallowSpacesInsideParentheses": true,
"requireSpacesInsideObjectBrackets": "all",
"disallowQuotedKeysInObjects": "allButReserved",
"disallowSpaceAfterObjectKeys": true,
"requireSpaceBeforeObjectValues": true,
"requireCommaBeforeLineBreak": true,
"requireOperatorBeforeLineBreak": [
"?", "=", "+", "-", "/", "*", "===", "!==", ">", ">=", "<", "<="
],
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
"requireSpaceBeforeBinaryOperators": [
"=", "+", "+=", "-", "-=", "/", "/=", "*", "*=", "===", "!==", "<", "<=", ">", ">="
],
"requireSpaceAfterBinaryOperators": [
"=", "+", "+=", "-", "-=", "/", "/=", "*", "*=", "===", "!==", "<", "<=", ">", ">="
],
"requireCamelCaseOrUpperCaseIdentifiers": true,
"disallowKeywords": ["with"],
"disallowMultipleLineStrings": true,
"disallowMixedSpacesAndTabs": "smart",
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"disallowKeywordsOnNewLine": ["else"],
"requireLineFeedAtFileEnd": true,
"maximumLineLength": {
"value": 120,
"tabSize": 2,
"allowUrlComments": true,
"allowRegex": true
},
"requireCapitalizedConstructors": true,
"requireDotNotation": true,
"disallowYodaConditions": true,
"requireSpaceAfterLineComment": {
"allExcept": ["#", "="]
},
"disallowNewlineBeforeBlockStatements": true,
"validateQuoteMarks": {
"mark": "'",
"escape": true
},
"validateParameterSeparator": ", ",
"safeContextKeyword": ["that"]
}

24
phpBB/.jshintrc Normal file
View file

@ -0,0 +1,24 @@
{
"bitwise": true,
"curly": true,
"eqeqeq": true,
"es3": true,
"forin": false,
"freeze": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonbsp": true,
"undef": true,
"unused": true,
"strict": true,
"browser": true,
"devel": true,
"jquery": true,
"globals": {
"JSON": true
}
}

View file

@ -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');
@ -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;
}
@ -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());
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>';
}
}

View 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);
@ -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.
@ -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 });
});
/**

View file

@ -9,9 +9,9 @@ phpbb.addAjaxCallback('mark_forums_read', function(res) {
var readTitle = res.NO_UNREAD_POSTS;
var unreadTitle = res.UNREAD_POSTS;
var iconsArray = {
'forum_unread': 'forum_read',
'forum_unread_subforum': 'forum_read_subforum',
'forum_unread_locked': 'forum_read_locked'
forum_unread: 'forum_read',
forum_unread_subforum: 'forum_read_subforum',
forum_unread_locked: 'forum_read_locked'
};
$('li.row').find('dl[class*="forum_unread"]').each(function() {
@ -49,10 +49,10 @@ phpbb.addAjaxCallback('mark_topics_read', function(res, updateTopicLinks) {
var readTitle = res.NO_UNREAD_POSTS;
var unreadTitle = res.UNREAD_POSTS;
var iconsArray = {
'global_unread': 'global_read',
'announce_unread': 'announce_read',
'sticky_unread': 'sticky_read',
'topic_unread': 'topic_read'
global_unread: 'global_read',
announce_unread: 'announce_read',
sticky_unread: 'sticky_read',
topic_unread: 'topic_read'
};
var iconsState = ['', '_hot', '_hot_mine', '_locked', '_locked_mine', '_mine'];
var unreadClassSelectors;
@ -287,10 +287,10 @@ phpbb.addAjaxCallback('vote_poll', function(res) {
var panelHeight = panel.height();
var innerHeight = panel.find('.inner').outerHeight();
if (panelHeight != innerHeight) {
panel.css({'min-height': '', 'height': panelHeight})
if (panelHeight !== innerHeight) {
panel.css({ minHeight: '', height: panelHeight })
.animate({ height: innerHeight }, time, function () {
panel.css({'min-height': innerHeight, 'height': ''});
panel.css({ minHeight: innerHeight, height: '' });
});
}
};
@ -377,7 +377,8 @@ $('#member_search').click(function () {
* Automatically resize textarea
*/
$(function() {
phpbb.resizeTextArea($('textarea:not(#message-box textarea, .no-auto-resize)'), {minHeight: 75, maxHeight: 250});
var $textarea = $('textarea:not(#message-box textarea, .no-auto-resize)');
phpbb.resizeTextArea($textarea, { minHeight: 75, maxHeight: 250 });
phpbb.resizeTextArea($('textarea', '#message-box'));
});