[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 /** 2 * bbCode control by subBlue design [ www.subBlue.com ] 3 * Includes unixsafe colour palette selector by SHS` 4 */ 5 6 // Startup variables 7 var imageTag = false; 8 var theSelection = false; 9 var bbcodeEnabled = true; 10 11 // Check for Browser & Platform for PC & IE specific bits 12 // More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html 13 var clientPC = navigator.userAgent.toLowerCase(); // Get client info 14 var clientVer = parseInt(navigator.appVersion, 10); // Get browser version 15 16 var is_ie = ((clientPC.indexOf('msie') !== -1) && (clientPC.indexOf('opera') === -1)); 17 var is_win = ((clientPC.indexOf('win') !== -1) || (clientPC.indexOf('16bit') !== -1)); 18 var baseHeight; 19 20 /** 21 * Shows the help messages in the helpline window 22 */ 23 function helpline(help) { 24 document.forms[form_name].helpbox.value = help_line[help]; 25 } 26 27 /** 28 * Fix a bug involving the TextRange object. From 29 * http://www.frostjedi.com/terra/scripts/demo/caretBug.html 30 */ 31 function initInsertions() { 32 var doc; 33 34 if (document.forms[form_name]) { 35 doc = document; 36 } else { 37 doc = opener.document; 38 } 39 40 var textarea = doc.forms[form_name].elements[text_name]; 41 42 if (is_ie && typeof(baseHeight) !== 'number') { 43 textarea.focus(); 44 baseHeight = doc.selection.createRange().duplicate().boundingHeight; 45 46 if (!document.forms[form_name]) { 47 document.body.focus(); 48 } 49 } 50 } 51 52 /** 53 * bbstyle 54 */ 55 function bbstyle(bbnumber) { 56 if (bbnumber !== -1) { 57 bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]); 58 } else { 59 insert_text('[*]'); 60 document.forms[form_name].elements[text_name].focus(); 61 } 62 } 63 64 /** 65 * Apply bbcodes 66 */ 67 function bbfontstyle(bbopen, bbclose) { 68 theSelection = false; 69 70 var textarea = document.forms[form_name].elements[text_name]; 71 72 textarea.focus(); 73 74 if ((clientVer >= 4) && is_ie && is_win) { 75 // Get text selection 76 theSelection = document.selection.createRange().text; 77 78 if (theSelection) { 79 // Add tags around selection 80 document.selection.createRange().text = bbopen + theSelection + bbclose; 81 textarea.focus(); 82 theSelection = ''; 83 return; 84 } 85 } else if (textarea.selectionEnd && (textarea.selectionEnd - textarea.selectionStart > 0)) { 86 mozWrap(textarea, bbopen, bbclose); 87 textarea.focus(); 88 theSelection = ''; 89 return; 90 } 91 92 //The new position for the cursor after adding the bbcode 93 var caret_pos = getCaretPosition(textarea).start; 94 var new_pos = caret_pos + bbopen.length; 95 96 // Open tag 97 insert_text(bbopen + bbclose); 98 99 // Center the cursor when we don't have a selection 100 // Gecko and proper browsers 101 if (!isNaN(textarea.selectionStart)) { 102 textarea.selectionStart = new_pos; 103 textarea.selectionEnd = new_pos; 104 } 105 // IE 106 else if (document.selection) { 107 var range = textarea.createTextRange(); 108 range.move("character", new_pos); 109 range.select(); 110 storeCaret(textarea); 111 } 112 113 textarea.focus(); 114 return; 115 } 116 117 /** 118 * Insert text at position 119 */ 120 function insert_text(text, spaces, popup) { 121 var textarea; 122 123 if (!popup) { 124 textarea = document.forms[form_name].elements[text_name]; 125 } else { 126 textarea = opener.document.forms[form_name].elements[text_name]; 127 } 128 129 if (spaces) { 130 text = ' ' + text + ' '; 131 } 132 133 // Since IE9, IE also has textarea.selectionStart, but it still needs to be treated the old way. 134 // Therefore we simply add a !is_ie here until IE fixes the text-selection completely. 135 if (!isNaN(textarea.selectionStart) && !is_ie) { 136 var sel_start = textarea.selectionStart; 137 var sel_end = textarea.selectionEnd; 138 139 mozWrap(textarea, text, ''); 140 textarea.selectionStart = sel_start + text.length; 141 textarea.selectionEnd = sel_end + text.length; 142 } else if (textarea.createTextRange && textarea.caretPos) { 143 if (baseHeight !== textarea.caretPos.boundingHeight) { 144 textarea.focus(); 145 storeCaret(textarea); 146 } 147 148 var caret_pos = textarea.caretPos; 149 caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) === ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text; 150 } else { 151 textarea.value = textarea.value + text; 152 } 153 154 if (!popup) { 155 textarea.focus(); 156 } 157 } 158 159 /** 160 * Add inline attachment at position 161 */ 162 function attachInline(index, filename) { 163 insert_text('[attachment=' + index + ']' + filename + '[/attachment]'); 164 document.forms[form_name].elements[text_name].focus(); 165 } 166 167 /** 168 * Add quote text to message 169 */ 170 function addquote(post_id, username, l_wrote) { 171 var message_name = 'message_' + post_id; 172 var theSelection = ''; 173 var divarea = false; 174 var i; 175 176 if (l_wrote === undefined) { 177 // Backwards compatibility 178 l_wrote = 'wrote'; 179 } 180 181 if (document.all) { 182 divarea = document.all[message_name]; 183 } else { 184 divarea = document.getElementById(message_name); 185 } 186 187 // Get text selection - not only the post content :( 188 // IE9 must use the document.selection method but has the *.getSelection so we just force no IE 189 if (window.getSelection && !is_ie && !window.opera) { 190 theSelection = window.getSelection().toString(); 191 } else if (document.getSelection && !is_ie) { 192 theSelection = document.getSelection(); 193 } else if (document.selection) { 194 theSelection = document.selection.createRange().text; 195 } 196 197 if (theSelection === '' || typeof theSelection === 'undefined' || theSelection === null) { 198 if (divarea.innerHTML) { 199 theSelection = divarea.innerHTML.replace(/<br>/ig, '\n'); 200 theSelection = theSelection.replace(/<br\/>/ig, '\n'); 201 theSelection = theSelection.replace(/<\;/ig, '<'); 202 theSelection = theSelection.replace(/>\;/ig, '>'); 203 theSelection = theSelection.replace(/&\;/ig, '&'); 204 theSelection = theSelection.replace(/ \;/ig, ' '); 205 } else if (document.all) { 206 theSelection = divarea.innerText; 207 } else if (divarea.textContent) { 208 theSelection = divarea.textContent; 209 } else if (divarea.firstChild.nodeValue) { 210 theSelection = divarea.firstChild.nodeValue; 211 } 212 } 213 214 if (theSelection) { 215 if (bbcodeEnabled) { 216 insert_text('[quote="' + username + '"]' + theSelection + '[/quote]'); 217 } else { 218 insert_text(username + ' ' + l_wrote + ':' + '\n'); 219 var lines = split_lines(theSelection); 220 for (i = 0; i < lines.length; i++) { 221 insert_text('> ' + lines[i] + '\n'); 222 } 223 } 224 } 225 226 return; 227 } 228 229 function split_lines(text) { 230 var lines = text.split('\n'); 231 var splitLines = new Array(); 232 var j = 0; 233 var i; 234 235 for(i = 0; i < lines.length; i++) { 236 if (lines[i].length <= 80) { 237 splitLines[j] = lines[i]; 238 j++; 239 } else { 240 var line = lines[i]; 241 var splitAt; 242 do { 243 splitAt = line.indexOf(' ', 80); 244 245 if (splitAt === -1) { 246 splitLines[j] = line; 247 j++; 248 } else { 249 splitLines[j] = line.substring(0, splitAt); 250 line = line.substring(splitAt); 251 j++; 252 } 253 } 254 while(splitAt !== -1); 255 } 256 } 257 return splitLines; 258 } 259 260 /** 261 * From http://www.massless.org/mozedit/ 262 */ 263 function mozWrap(txtarea, open, close) { 264 var selLength = (typeof(txtarea.textLength) === 'undefined') ? txtarea.value.length : txtarea.textLength; 265 var selStart = txtarea.selectionStart; 266 var selEnd = txtarea.selectionEnd; 267 var scrollTop = txtarea.scrollTop; 268 269 var s1 = (txtarea.value).substring(0,selStart); 270 var s2 = (txtarea.value).substring(selStart, selEnd); 271 var s3 = (txtarea.value).substring(selEnd, selLength); 272 273 txtarea.value = s1 + open + s2 + close + s3; 274 txtarea.selectionStart = selStart + open.length; 275 txtarea.selectionEnd = selEnd + open.length; 276 txtarea.focus(); 277 txtarea.scrollTop = scrollTop; 278 279 return; 280 } 281 282 /** 283 * Insert at Caret position. Code from 284 * http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130 285 */ 286 function storeCaret(textEl) { 287 if (textEl.createTextRange && document.selection) { 288 textEl.caretPos = document.selection.createRange().duplicate(); 289 } 290 } 291 292 /** 293 * Caret Position object 294 */ 295 function caretPosition() { 296 var start = null; 297 var end = null; 298 } 299 300 /** 301 * Get the caret position in an textarea 302 */ 303 function getCaretPosition(txtarea) { 304 var caretPos = new caretPosition(); 305 306 // simple Gecko/Opera way 307 if (txtarea.selectionStart || txtarea.selectionStart === 0) { 308 caretPos.start = txtarea.selectionStart; 309 caretPos.end = txtarea.selectionEnd; 310 } 311 // dirty and slow IE way 312 else if (document.selection) { 313 // get current selection 314 var range = document.selection.createRange(); 315 316 // a new selection of the whole textarea 317 var range_all = document.body.createTextRange(); 318 range_all.moveToElementText(txtarea); 319 320 // calculate selection start point by moving beginning of range_all to beginning of range 321 var sel_start; 322 for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) { 323 range_all.moveStart('character', 1); 324 } 325 326 txtarea.sel_start = sel_start; 327 328 // we ignore the end value for IE, this is already dirty enough and we don't need it 329 caretPos.start = txtarea.sel_start; 330 caretPos.end = txtarea.sel_start; 331 } 332 333 return caretPos; 334 } 335 336 /** 337 * Allow to use tab character when typing code 338 * Keep indentation of last line of code when typing code 339 */ 340 (function($) { 341 $(document).ready(function() { 342 var doc, textarea; 343 344 // find textarea, make sure browser supports necessary functions 345 if (document.forms[form_name]) { 346 doc = document; 347 } else { 348 doc = opener.document; 349 } 350 351 if (!doc.forms[form_name]) { 352 return; 353 } 354 355 textarea = doc.forms[form_name].elements[text_name]; 356 357 phpbb.applyCodeEditor(textarea); 358 if ($('#attach-panel').length) { 359 phpbb.showDragNDrop(textarea); 360 } 361 362 $('textarea').on('keydown', function (e) { 363 if (e.which === 13 && (e.metaKey || e.ctrlKey)) { 364 $(this).closest('form').submit(); 365 } 366 }); 367 }); 368 })(jQuery); 369
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |