diff options
author | Marc Alexander <admin@m-a-styles.de> | 2013-02-27 23:12:34 +0100 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2013-03-26 10:31:28 +0100 |
commit | 36168b311e5f12937977ffd1040ca4a39f70a0e8 (patch) | |
tree | 306f368af5841e93dfd59a78bf6dc0a9368c83e9 /phpBB/styles | |
parent | 96b1cabcf2fbc4955bab65a4931f1815548d4df4 (diff) | |
download | forums-36168b311e5f12937977ffd1040ca4a39f70a0e8.tar forums-36168b311e5f12937977ffd1040ca4a39f70a0e8.tar.gz forums-36168b311e5f12937977ffd1040ca4a39f70a0e8.tar.bz2 forums-36168b311e5f12937977ffd1040ca4a39f70a0e8.tar.xz forums-36168b311e5f12937977ffd1040ca4a39f70a0e8.zip |
[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
Diffstat (limited to 'phpBB/styles')
-rw-r--r-- | phpBB/styles/prosilver/template/ajax.js | 6 | ||||
-rw-r--r-- | phpBB/styles/prosilver/template/editor.js | 92 | ||||
-rw-r--r-- | phpBB/styles/prosilver/template/forum_fn.js | 114 | ||||
-rw-r--r-- | phpBB/styles/prosilver/template/timezone.js | 2 | ||||
-rw-r--r-- | phpBB/styles/subsilver2/template/editor.js | 98 |
5 files changed, 169 insertions, 143 deletions
diff --git a/phpBB/styles/prosilver/template/ajax.js b/phpBB/styles/prosilver/template/ajax.js index e38e3d4cb2..8c61be5942 100644 --- a/phpBB/styles/prosilver/template/ajax.js +++ b/phpBB/styles/prosilver/template/ajax.js @@ -39,7 +39,7 @@ phpbb.addAjaxCallback('mark_forums_read', function(res) { // Mark topics read if we are watching a category and showing active topics if ($('#active_topics').length) { - phpbb.ajaxCallbacks['mark_topics_read'].call(this, res, false); + phpbb.ajaxCallbacks.mark_topics_read.call(this, res, false); } // Update mark forums read links @@ -75,7 +75,7 @@ phpbb.addAjaxCallback('mark_topics_read', function(res, update_topic_links) { $.each(iconsArray, function(unreadClass, readClass) { $.each(iconsState, function(key, value) { // Only topics can be hot - if ((value == '_hot' || value == '_hot_mine') && unreadClass != 'topic_unread') { + if ((value === '_hot' || value === '_hot_mine') && unreadClass !== 'topic_unread') { return true; } classMap[unreadClass + value] = readClass + value; @@ -218,7 +218,7 @@ $('#quick-mod-select').change(function () { */ $('#member_search').click(function () { $('#memberlist_search').slideToggle('fast'); - phpbb.ajax_callbacks['alt_text'].call(this); + phpbb.ajax_callbacks.alt_text.call(this); // Focus on the username textbox if it's available and displayed if ($('#memberlist_search').is(':visible')) { $('#username').focus(); diff --git a/phpBB/styles/prosilver/template/editor.js b/phpBB/styles/prosilver/template/editor.js index c099466005..13e9ca3c66 100644 --- a/phpBB/styles/prosilver/template/editor.js +++ b/phpBB/styles/prosilver/template/editor.js @@ -6,15 +6,15 @@ // Startup variables var imageTag = false; var theSelection = false; - var bbcodeEnabled = true; + // Check for Browser & Platform for PC & IE specific bits // More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html var clientPC = navigator.userAgent.toLowerCase(); // Get client info var clientVer = parseInt(navigator.appVersion, 10); // Get browser version -var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1)); -var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1)); +var is_ie = ((clientPC.indexOf('msie') !== -1) && (clientPC.indexOf('opera') === -1)); +var is_win = ((clientPC.indexOf('win') !== -1) || (clientPC.indexOf('16bit') !== -1)); var baseHeight; /** @@ -29,7 +29,7 @@ function helpline(help) * Fix a bug involving the TextRange object. From * http://www.frostjedi.com/terra/scripts/demo/caretBug.html */ -function initInsertions() +function initInsertions() { var doc; @@ -37,14 +37,14 @@ function initInsertions() { doc = document; } - else + else { doc = opener.document; } var textarea = doc.forms[form_name].elements[text_name]; - if (is_ie && typeof(baseHeight) != 'number') + if (is_ie && typeof(baseHeight) !== 'number') { textarea.focus(); baseHeight = doc.selection.createRange().duplicate().boundingHeight; @@ -60,12 +60,12 @@ function initInsertions() * bbstyle */ function bbstyle(bbnumber) -{ - if (bbnumber != -1) +{ + if (bbnumber !== -1) { bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]); - } - else + } + else { insert_text('[*]'); document.forms[form_name].elements[text_name].focus(); @@ -104,10 +104,10 @@ function bbfontstyle(bbopen, bbclose) theSelection = ''; return; } - + //The new position for the cursor after adding the bbcode var caret_pos = getCaretPosition(textarea).start; - var new_pos = caret_pos + bbopen.length; + var new_pos = caret_pos + bbopen.length; // Open tag insert_text(bbopen + bbclose); @@ -118,7 +118,7 @@ function bbfontstyle(bbopen, bbclose) { textarea.selectionStart = new_pos; textarea.selectionEnd = new_pos; - } + } // IE else if (document.selection) { @@ -138,16 +138,17 @@ function bbfontstyle(bbopen, bbclose) function insert_text(text, spaces, popup) { var textarea; - - if (!popup) + + if (!popup) { textarea = document.forms[form_name].elements[text_name]; - } - else + } + else { textarea = opener.document.forms[form_name].elements[text_name]; } - if (spaces) + + if (spaces) { text = ' ' + text + ' '; } @@ -165,20 +166,21 @@ function insert_text(text, spaces, popup) } else if (textarea.createTextRange && textarea.caretPos) { - if (baseHeight != textarea.caretPos.boundingHeight) + if (baseHeight !== textarea.caretPos.boundingHeight) { textarea.focus(); storeCaret(textarea); } var caret_pos = textarea.caretPos; - caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text; + caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) === ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text; } else { textarea.value = textarea.value + text; } - if (!popup) + + if (!popup) { textarea.focus(); } @@ -201,6 +203,7 @@ function addquote(post_id, username, l_wrote) var message_name = 'message_' + post_id; var theSelection = ''; var divarea = false; + var i; if (l_wrote === undefined) { @@ -232,7 +235,7 @@ function addquote(post_id, username, l_wrote) theSelection = document.selection.createRange().text; } - if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null) + if (theSelection === '' || typeof theSelection === 'undefined' || theSelection === null) { if (divarea.innerHTML) { @@ -282,6 +285,8 @@ function split_lines(text) var lines = text.split('\n'); var splitLines = new Array(); var j = 0; + var i; + for(i = 0; i < lines.length; i++) { if (lines[i].length <= 80) @@ -292,11 +297,12 @@ function split_lines(text) else { var line = lines[i]; + var splitAt; do { - var splitAt = line.indexOf(' ', 80); - - if (splitAt == -1) + splitAt = line.indexOf(' ', 80); + + if (splitAt === -1) { splitLines[j] = line; j++; @@ -308,22 +314,23 @@ function split_lines(text) j++; } } - while(splitAt != -1); + while(splitAt !== -1); } } return splitLines; } + /** * From http://www.massless.org/mozedit/ */ function mozWrap(txtarea, open, close) { - var selLength = (typeof(txtarea.textLength) == 'undefined') ? txtarea.value.length : txtarea.textLength; + var selLength = (typeof(txtarea.textLength) === 'undefined') ? txtarea.value.length : txtarea.textLength; var selStart = txtarea.selectionStart; var selEnd = txtarea.selectionEnd; var scrollTop = txtarea.scrollTop; - if (selEnd == 1 || selEnd == 2) + if (selEnd === 1 || selEnd === 2) { selEnd = selLength; } @@ -372,18 +379,18 @@ function colorPalette(dir, width, height) for (r = 0; r < 5; r++) { - if (dir == 'h') + if (dir === 'h') { document.writeln('<tr>'); } for (g = 0; g < 5; g++) { - if (dir == 'v') + if (dir === 'v') { document.writeln('<tr>'); } - + for (b = 0; b < 5; b++) { color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]); @@ -392,13 +399,13 @@ function colorPalette(dir, width, height) document.writeln('</td>'); } - if (dir == 'v') + if (dir === 'v') { document.writeln('</tr>'); } } - if (dir == 'h') + if (dir === 'h') { document.writeln('</tr>'); } @@ -406,7 +413,6 @@ function colorPalette(dir, width, height) document.writeln('</table>'); } - /** * Caret Position object */ @@ -416,43 +422,41 @@ function caretPosition() var end = null; } - /** * Get the caret position in an textarea */ function getCaretPosition(txtarea) { var caretPos = new caretPosition(); - + // simple Gecko/Opera way - if(txtarea.selectionStart || txtarea.selectionStart == 0) + if (txtarea.selectionStart || txtarea.selectionStart === 0) { caretPos.start = txtarea.selectionStart; caretPos.end = txtarea.selectionEnd; } // dirty and slow IE way - else if(document.selection) + else if (document.selection) { - // get current selection var range = document.selection.createRange(); // a new selection of the whole textarea var range_all = document.body.createTextRange(); range_all.moveToElementText(txtarea); - + // calculate selection start point by moving beginning of range_all to beginning of range var sel_start; for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) - { + { range_all.moveStart('character', 1); } - + txtarea.sel_start = sel_start; - + // we ignore the end value for IE, this is already dirty enough and we don't need it caretPos.start = txtarea.sel_start; - caretPos.end = txtarea.sel_start; + caretPos.end = txtarea.sel_start; } return caretPos; diff --git a/phpBB/styles/prosilver/template/forum_fn.js b/phpBB/styles/prosilver/template/forum_fn.js index 995b4b0ab7..677e9274c4 100644 --- a/phpBB/styles/prosilver/template/forum_fn.js +++ b/phpBB/styles/prosilver/template/forum_fn.js @@ -23,9 +23,9 @@ function jumpto() { var page = prompt(jump_page, on_page); - if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0) + if (page !== null && !isNaN(page) && page === Math.floor(page) && page > 0) { - if (base_url.indexOf('?') == -1) + if (base_url.indexOf('?') === -1) { document.location.href = base_url + '?start=' + ((page - 1) * per_page); } @@ -53,7 +53,7 @@ function marklist(id, name, state) for (var r = 0; r < rb.length; r++) { - if (rb[r].name.substr(0, name.length) == name) + if (rb[r].name.substr(0, name.length) === name) { rb[r].checked = state; } @@ -66,7 +66,10 @@ function marklist(id, name, state) */ function viewableArea(e, itself) { - if (!e) return; + if (!e) { + return; + } + if (!itself) { e = e.parentNode; @@ -106,9 +109,9 @@ function dE(n, s, type) var e = document.getElementById(n); if (!s) { - s = (e.style.display == '' || e.style.display == type) ? -1 : 1; + s = (e.style.display === '' || e.style.display === type) ? -1 : 1; } - e.style.display = (s == 1) ? type : 'none'; + e.style.display = (s === 1) ? type : 'none'; } /** @@ -118,7 +121,7 @@ function subPanels(p) { var i, e, t; - if (typeof(p) == 'string') + if (typeof(p) === 'string') { show_panel = p; } @@ -130,7 +133,7 @@ function subPanels(p) if (e) { - if (panels[i] == show_panel) + if (panels[i] === show_panel) { e.style.display = 'block'; if (t) @@ -173,7 +176,7 @@ function printPage() */ function displayBlocks(c, e, t) { - var s = (e.checked == true) ? 1 : -1; + var s = (e.checked === true) ? 1 : -1; if (t) { @@ -184,9 +187,9 @@ function displayBlocks(c, e, t) for (var d = 0; d < divs.length; d++) { - if (divs[d].className.indexOf(c) == 0) + if (divs[d].className.indexOf(c) === 0) { - divs[d].style.display = (s == 1) ? 'none' : 'block'; + divs[d].style.display = (s === 1) ? 'none' : 'block'; } } } @@ -195,11 +198,12 @@ function selectCode(a) { // Get ID of code block var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0]; + var s, r; // Not IE and IE9+ if (window.getSelection) { - var s = window.getSelection(); + s = window.getSelection(); // Safari if (s.setBaseAndExtent) { @@ -209,12 +213,12 @@ function selectCode(a) else { // workaround for bug # 42885 - if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>') + if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) === '<BR>') { e.innerHTML = e.innerHTML + ' '; } - var r = document.createRange(); + r = document.createRange(); r.selectNodeContents(e); s.removeAllRanges(); s.addRange(r); @@ -223,8 +227,8 @@ function selectCode(a) // Some older browsers else if (document.getSelection) { - var s = document.getSelection(); - var r = document.createRange(); + s = document.getSelection(); + r = document.createRange(); r.selectNodeContents(e); s.removeAllRanges(); s.addRange(r); @@ -232,7 +236,7 @@ function selectCode(a) // IE else if (document.selection) { - var r = document.body.createTextRange(); + r = document.body.createTextRange(); r.moveToElementText(e); r.select(); } @@ -245,22 +249,23 @@ function selectCode(a) function play_qt_file(obj) { var rectangle = obj.GetRectangle(); + var width, height; if (rectangle) { rectangle = rectangle.split(','); - var x1 = parseInt(rectangle[0]); - var x2 = parseInt(rectangle[2]); - var y1 = parseInt(rectangle[1]); - var y2 = parseInt(rectangle[3]); + var x1 = parseInt(rectangle[0], 10); + var x2 = parseInt(rectangle[2], 10); + var y1 = parseInt(rectangle[1], 10); + var y2 = parseInt(rectangle[3], 10); - var width = (x1 < 0) ? (x1 * -1) + x2 : x2 - x1; - var height = (y1 < 0) ? (y1 * -1) + y2 : y2 - y1; + width = (x1 < 0) ? (x1 * -1) + x2 : x2 - x1; + height = (y1 < 0) ? (y1 * -1) + y2 : y2 - y1; } else { - var width = 200; - var height = 0; + width = 200; + height = 0; } obj.width = width; @@ -276,7 +281,7 @@ function play_qt_file(obj) */ function is_node_name(elem, name) { - return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase(); + return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase(); } /** @@ -285,10 +290,12 @@ function is_node_name(elem, name) */ function is_in_array(elem, array) { - for (var i = 0, length = array.length; i < length; i++) + for (var i = 0, length = array.length; i < length; i++) { // === is correct (IE) - if (array[i] === elem) + if (array[i] === elem) { return i; + } + } return -1; } @@ -304,17 +311,22 @@ function find_in_tree(node, tag, type, class_name) for (element = node.childNodes[0]; i < length; element = node.childNodes[++i]) { - if (!element || element.nodeType != 1) continue; + if (!element || element.nodeType !== 1) { + continue; + } - if ((!tag || is_node_name(element, tag)) && (!type || element.type == type) && (!class_name || is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1)) + if ((!tag || is_node_name(element, tag)) && (!type || element.type === type) && (!class_name || is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1)) { return element; } - if (element.childNodes.length) + if (element.childNodes.length) { result = find_in_tree(element, tag, type, class_name); + } - if (result) return result; + if (result) { + return result; + } } } @@ -327,14 +339,15 @@ var last_key_entered = ''; function phpbb_check_key(event) { // Keycode is array down or up? - if (event.keyCode && (event.keyCode == 40 || event.keyCode == 38)) + if (event.keyCode && (event.keyCode === 40 || event.keyCode === 38)) { in_autocomplete = true; + } // Make sure we are not within an "autocompletion" field if (in_autocomplete) { // If return pressed and key changed we reset the autocompletion - if (!last_key_entered || last_key_entered == event.which) + if (!last_key_entered || last_key_entered === event.which) { in_autocompletion = false; return true; @@ -342,7 +355,7 @@ function phpbb_check_key(event) } // Keycode is not return, then return. ;) - if (event.which != 13) + if (event.which !== 13) { last_key_entered = event.which; return true; @@ -357,17 +370,20 @@ function phpbb_check_key(event) function submit_default_button(event, selector, class_name) { // Add which for key events - if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode)) + if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode)) { event.which = event.charCode || event.keyCode; + } - if (phpbb_check_key(event)) + if (phpbb_check_key(event)) { return true; + } - var current = selector['parentNode']; + var current = selector.parentNode; // Search parent form element - while (current && (!current.nodeName || current.nodeType != 1 || !is_node_name(current, 'form')) && current != document) - current = current['parentNode']; + while (current && (!current.nodeName || current.nodeType !== 1 || !is_node_name(current, 'form')) && current !== document) { + current = current.parentNode; + } // Find the input submit button with the class name //current = find_in_tree(current, 'input', 'submit', class_name); @@ -376,12 +392,14 @@ function submit_default_button(event, selector, class_name) for (var i = 0, element = input_tags[0]; i < input_tags.length; element = input_tags[++i]) { - if (element.type == 'submit' && is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1) + if (element.type === 'submit' && is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1) { current = element; + } } - if (!current) + if (!current) { return true; + } // Submit form current.focus(); @@ -403,13 +421,15 @@ function apply_onkeypress_event() { var default_button = jQuery(this).parents('form').find('input[type=submit].default-submit-action'); - if (!default_button || default_button.length <= 0) + if (!default_button || default_button.length <= 0) { return true; + } - if (phpbb_check_key(e)) + if (phpbb_check_key(e)) { return true; + } - if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) + if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) { default_button.click(); return false; @@ -425,7 +445,7 @@ function apply_onkeypress_event() for (var i = 0, element = input_tags[0]; i < input_tags.length ; element = input_tags[++i]) { - if (element.type == 'text' || element.type == 'password') + if (element.type === 'text' || element.type === 'password') { // onkeydown is possible too element.onkeypress = function (evt) { submit_default_button((evt || window.event), this, 'default-submit-action'); }; @@ -436,4 +456,4 @@ function apply_onkeypress_event() /** * Detect JQuery existance. We currently do not deliver it, but some styles do, so why not benefit from it. ;) */ -var jquery_present = typeof jQuery == 'function'; +var jquery_present = typeof jQuery === 'function'; diff --git a/phpBB/styles/prosilver/template/timezone.js b/phpBB/styles/prosilver/template/timezone.js index b0e8a38366..ed7cf0e051 100644 --- a/phpBB/styles/prosilver/template/timezone.js +++ b/phpBB/styles/prosilver/template/timezone.js @@ -15,7 +15,7 @@ $(document).ready( ); $(document).ready( - phpbb.timezonePreselectSelect($('#tz_select_date_suggest').attr('data-is-registration') == 'true') + phpbb.timezonePreselectSelect($('#tz_select_date_suggest').attr('data-is-registration') === 'true') ); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/subsilver2/template/editor.js b/phpBB/styles/subsilver2/template/editor.js index 0b5b15643a..13e9ca3c66 100644 --- a/phpBB/styles/subsilver2/template/editor.js +++ b/phpBB/styles/subsilver2/template/editor.js @@ -11,11 +11,10 @@ var bbcodeEnabled = true; // Check for Browser & Platform for PC & IE specific bits // More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html var clientPC = navigator.userAgent.toLowerCase(); // Get client info -var clientVer = parseInt(navigator.appVersion); // Get browser version - -var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1)); -var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1)); +var clientVer = parseInt(navigator.appVersion, 10); // Get browser version +var is_ie = ((clientPC.indexOf('msie') !== -1) && (clientPC.indexOf('opera') === -1)); +var is_win = ((clientPC.indexOf('win') !== -1) || (clientPC.indexOf('16bit') !== -1)); var baseHeight; /** @@ -30,7 +29,7 @@ function helpline(help) * Fix a bug involving the TextRange object. From * http://www.frostjedi.com/terra/scripts/demo/caretBug.html */ -function initInsertions() +function initInsertions() { var doc; @@ -38,14 +37,15 @@ function initInsertions() { doc = document; } - else + else { doc = opener.document; } var textarea = doc.forms[form_name].elements[text_name]; - if (is_ie && typeof(baseHeight) != 'number') - { + + if (is_ie && typeof(baseHeight) !== 'number') + { textarea.focus(); baseHeight = doc.selection.createRange().duplicate().boundingHeight; @@ -60,12 +60,12 @@ function initInsertions() * bbstyle */ function bbstyle(bbnumber) -{ - if (bbnumber != -1) +{ + if (bbnumber !== -1) { bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]); - } - else + } + else { insert_text('[*]'); document.forms[form_name].elements[text_name].focus(); @@ -78,7 +78,7 @@ function bbstyle(bbnumber) function bbfontstyle(bbopen, bbclose) { theSelection = false; - + var textarea = document.forms[form_name].elements[text_name]; textarea.focus(); @@ -104,7 +104,7 @@ function bbfontstyle(bbopen, bbclose) theSelection = ''; return; } - + //The new position for the cursor after adding the bbcode var caret_pos = getCaretPosition(textarea).start; var new_pos = caret_pos + bbopen.length; @@ -118,7 +118,7 @@ function bbfontstyle(bbopen, bbclose) { textarea.selectionStart = new_pos; textarea.selectionEnd = new_pos; - } + } // IE else if (document.selection) { @@ -138,16 +138,17 @@ function bbfontstyle(bbopen, bbclose) function insert_text(text, spaces, popup) { var textarea; - - if (!popup) + + if (!popup) { textarea = document.forms[form_name].elements[text_name]; - } - else + } + else { textarea = opener.document.forms[form_name].elements[text_name]; } - if (spaces) + + if (spaces) { text = ' ' + text + ' '; } @@ -162,23 +163,23 @@ function insert_text(text, spaces, popup) mozWrap(textarea, text, ''); textarea.selectionStart = sel_start + text.length; textarea.selectionEnd = sel_end + text.length; - } - + } else if (textarea.createTextRange && textarea.caretPos) { - if (baseHeight != textarea.caretPos.boundingHeight) + if (baseHeight !== textarea.caretPos.boundingHeight) { textarea.focus(); storeCaret(textarea); - } + } + var caret_pos = textarea.caretPos; - caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text; - + caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) === ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text; } else { textarea.value = textarea.value + text; } + if (!popup) { textarea.focus(); @@ -202,6 +203,7 @@ function addquote(post_id, username, l_wrote) var message_name = 'message_' + post_id; var theSelection = ''; var divarea = false; + var i; if (l_wrote === undefined) { @@ -233,7 +235,7 @@ function addquote(post_id, username, l_wrote) theSelection = document.selection.createRange().text; } - if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null) + if (theSelection === '' || typeof theSelection === 'undefined' || theSelection === null) { if (divarea.innerHTML) { @@ -278,12 +280,13 @@ function addquote(post_id, username, l_wrote) return; } - function split_lines(text) { var lines = text.split('\n'); var splitLines = new Array(); var j = 0; + var i; + for(i = 0; i < lines.length; i++) { if (lines[i].length <= 80) @@ -294,11 +297,12 @@ function split_lines(text) else { var line = lines[i]; + var splitAt; do { - var splitAt = line.indexOf(' ', 80); - - if (splitAt == -1) + splitAt = line.indexOf(' ', 80); + + if (splitAt === -1) { splitLines[j] = line; j++; @@ -310,7 +314,7 @@ function split_lines(text) j++; } } - while(splitAt != -1); + while(splitAt !== -1); } } return splitLines; @@ -321,12 +325,12 @@ function split_lines(text) */ function mozWrap(txtarea, open, close) { - var selLength = (typeof(txtarea.textLength) == 'undefined') ? txtarea.value.length : txtarea.textLength; + var selLength = (typeof(txtarea.textLength) === 'undefined') ? txtarea.value.length : txtarea.textLength; var selStart = txtarea.selectionStart; var selEnd = txtarea.selectionEnd; var scrollTop = txtarea.scrollTop; - if (selEnd == 1 || selEnd == 2) + if (selEnd === 1 || selEnd === 2) { selEnd = selLength; } @@ -375,18 +379,18 @@ function colorPalette(dir, width, height) for (r = 0; r < 5; r++) { - if (dir == 'h') + if (dir === 'h') { document.writeln('<tr>'); } for (g = 0; g < 5; g++) { - if (dir == 'v') + if (dir === 'v') { document.writeln('<tr>'); } - + for (b = 0; b < 5; b++) { color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]); @@ -395,13 +399,13 @@ function colorPalette(dir, width, height) document.writeln('</td>'); } - if (dir == 'v') + if (dir === 'v') { document.writeln('</tr>'); } } - if (dir == 'h') + if (dir === 'h') { document.writeln('</tr>'); } @@ -409,7 +413,6 @@ function colorPalette(dir, width, height) document.writeln('</table>'); } - /** * Caret Position object */ @@ -419,22 +422,21 @@ function caretPosition() var end = null; } - /** * Get the caret position in an textarea */ function getCaretPosition(txtarea) { var caretPos = new caretPosition(); - + // simple Gecko/Opera way - if(txtarea.selectionStart || txtarea.selectionStart == 0) + if (txtarea.selectionStart || txtarea.selectionStart === 0) { caretPos.start = txtarea.selectionStart; caretPos.end = txtarea.selectionEnd; } // dirty and slow IE way - else if(document.selection) + else if (document.selection) { // get current selection var range = document.selection.createRange(); @@ -442,16 +444,16 @@ function getCaretPosition(txtarea) // a new selection of the whole textarea var range_all = document.body.createTextRange(); range_all.moveToElementText(txtarea); - + // calculate selection start point by moving beginning of range_all to beginning of range var sel_start; for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) - { + { range_all.moveStart('character', 1); } - + txtarea.sel_start = sel_start; - + // we ignore the end value for IE, this is already dirty enough and we don't need it caretPos.start = txtarea.sel_start; caretPos.end = txtarea.sel_start; |