diff options
Diffstat (limited to 'phpBB/styles/subsilver2/template/editor.js')
-rw-r--r-- | phpBB/styles/subsilver2/template/editor.js | 98 |
1 files changed, 50 insertions, 48 deletions
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; |