Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
editor.js
001 /**
002 * bbCode control by subBlue design [ www.subBlue.com ]
003 * Includes unixsafe colour palette selector by SHS`
004 */
005
006 // Startup variables
007 var imageTag = false;
008 var theSelection = false;
009 var bbcodeEnabled = true;
010
011 // Check for Browser & Platform for PC & IE specific bits
012 // More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
013 var clientPC = navigator.userAgent.toLowerCase(); // Get client info
014 var clientVer = parseInt(navigator.appVersion, 10); // Get browser version
015
016 var is_ie = ((clientPC.indexOf('msie') !== -1) && (clientPC.indexOf('opera') === -1));
017 var is_win = ((clientPC.indexOf('win') !== -1) || (clientPC.indexOf('16bit') !== -1));
018 var baseHeight;
019
020 /**
021 * Fix a bug involving the TextRange object. From
022 * http://www.frostjedi.com/terra/scripts/demo/caretBug.html
023 */
024 function initInsertions() {
025 var doc;
026
027 if (document.forms[form_name]) {
028 doc = document;
029 } else {
030 doc = opener.document;
031 }
032
033 var textarea = doc.forms[form_name].elements[text_name];
034
035 if (is_ie && typeof(baseHeight) !== 'number') {
036 textarea.focus();
037 baseHeight = doc.selection.createRange().duplicate().boundingHeight;
038
039 if (!document.forms[form_name]) {
040 document.body.focus();
041 }
042 }
043 }
044
045 /**
046 * bbstyle
047 */
048 function bbstyle(bbnumber) {
049 if (bbnumber !== -1) {
050 bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]);
051 } else {
052 insert_text('[*]');
053 document.forms[form_name].elements[text_name].focus();
054 }
055 }
056
057 /**
058 * Apply bbcodes
059 */
060 function bbfontstyle(bbopen, bbclose) {
061 theSelection = false;
062
063 var textarea = document.forms[form_name].elements[text_name];
064
065 textarea.focus();
066
067 if ((clientVer >= 4) && is_ie && is_win) {
068 // Get text selection
069 theSelection = document.selection.createRange().text;
070
071 if (theSelection) {
072 // Add tags around selection
073 document.selection.createRange().text = bbopen + theSelection + bbclose;
074 textarea.focus();
075 theSelection = '';
076 return;
077 }
078 } else if (textarea.selectionEnd && (textarea.selectionEnd - textarea.selectionStart > 0)) {
079 mozWrap(textarea, bbopen, bbclose);
080 textarea.focus();
081 theSelection = '';
082 return;
083 }
084
085 //The new position for the cursor after adding the bbcode
086 var caret_pos = getCaretPosition(textarea).start;
087 var new_pos = caret_pos + bbopen.length;
088
089 // Open tag
090 insert_text(bbopen + bbclose);
091
092 // Center the cursor when we don't have a selection
093 // Gecko and proper browsers
094 if (!isNaN(textarea.selectionStart)) {
095 textarea.selectionStart = new_pos;
096 textarea.selectionEnd = new_pos;
097 }
098 // IE
099 else if (document.selection) {
100 var range = textarea.createTextRange();
101 range.move("character", new_pos);
102 range.select();
103 storeCaret(textarea);
104 }
105
106 textarea.focus();
107 }
108
109 /**
110 * Insert text at position
111 */
112 function insert_text(text, spaces, popup) {
113 var textarea;
114
115 if (!popup) {
116 textarea = document.forms[form_name].elements[text_name];
117 } else {
118 textarea = opener.document.forms[form_name].elements[text_name];
119 }
120
121 if (spaces) {
122 text = ' ' + text + ' ';
123 }
124
125 // Since IE9, IE also has textarea.selectionStart, but it still needs to be treated the old way.
126 // Therefore we simply add a !is_ie here until IE fixes the text-selection completely.
127 if (!isNaN(textarea.selectionStart) && !is_ie) {
128 var sel_start = textarea.selectionStart;
129 var sel_end = textarea.selectionEnd;
130
131 mozWrap(textarea, text, '');
132 textarea.selectionStart = sel_start + text.length;
133 textarea.selectionEnd = sel_end + text.length;
134 } else if (textarea.createTextRange && textarea.caretPos) {
135 if (baseHeight !== textarea.caretPos.boundingHeight) {
136 textarea.focus();
137 storeCaret(textarea);
138 }
139
140 var caret_pos = textarea.caretPos;
141 caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) === ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
142 } else {
143 textarea.value = textarea.value + text;
144 }
145
146 if (!popup) {
147 textarea.focus();
148 }
149 }
150
151 /**
152 * Add inline attachment at position
153 */
154 function attachInline(index, filename) {
155 insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
156 document.forms[form_name].elements[text_name].focus();
157 }
158
159 /**
160 * Add quote text to message
161 */
162 function addquote(post_id, username, l_wrote, attributes) {
163 var message_name = 'message_' + post_id;
164 var theSelection = '';
165 var divarea = false;
166 var i;
167
168 if (l_wrote === undefined) {
169 // Backwards compatibility
170 l_wrote = 'wrote';
171 }
172 if (typeof attributes !== 'object') {
173 attributes = {};
174 }
175
176 if (document.all) {
177 divarea = document.all[message_name];
178 } else {
179 divarea = document.getElementById(message_name);
180 }
181
182 // Get text selection - not only the post content :(
183 // IE9 must use the document.selection method but has the *.getSelection so we just force no IE
184 if (window.getSelection && !is_ie && !window.opera) {
185 theSelection = window.getSelection().toString();
186 } else if (document.getSelection && !is_ie) {
187 theSelection = document.getSelection();
188 } else if (document.selection) {
189 theSelection = document.selection.createRange().text;
190 }
191
192 if (theSelection === '' || typeof theSelection === 'undefined' || theSelection === null) {
193 if (divarea.innerHTML) {
194 theSelection = divarea.innerHTML.replace(/<br>/ig, '\n');
195 theSelection = theSelection.replace(/<br\/>/ig, '\n');
196 theSelection = theSelection.replace(/<\;/ig, '<');
197 theSelection = theSelection.replace(/>\;/ig, '>');
198 theSelection = theSelection.replace(/&\;/ig, '&');
199 theSelection = theSelection.replace(/ \;/ig, ' ');
200 } else if (document.all) {
201 theSelection = divarea.innerText;
202 } else if (divarea.textContent) {
203 theSelection = divarea.textContent;
204 } else if (divarea.firstChild.nodeValue) {
205 theSelection = divarea.firstChild.nodeValue;
206 }
207 }
208
209 if (theSelection) {
210 if (bbcodeEnabled) {
211 attributes.author = username;
212 insert_text(generateQuote(theSelection, attributes));
213 } else {
214 insert_text(username + ' ' + l_wrote + ':' + '\n');
215 var lines = split_lines(theSelection);
216 for (i = 0; i < lines.length; i++) {
217 insert_text('> ' + lines[i] + '\n');
218 }
219 }
220 }
221 }
222
223 /**
224 * Create a quote block for given text
225 *
226 * Possible attributes:
227 * - author: author's name (usually a username)
228 * - post_id: post_id of the post being quoted
229 * - user_id: user_id of the user being quoted
230 * - time: timestamp of the original message
231 *
232 * @param {!string} text Quote's text
233 * @param {!Object} attributes Quote's attributes
234 * @return {!string} Quote block to be used in a new post/text
235 */
236 function generateQuote(text, attributes) {
237 text = text.replace(/^\s+/, '').replace(/\s+$/, '');
238 var quote = '[quote';
239 if (attributes.author) {
240 // Add the author as the BBCode's default attribute
241 quote += '=' + formatAttributeValue(attributes.author);
242 delete attributes.author;
243 }
244 for (var name in attributes) {
245 if (attributes.hasOwnProperty(name)) {
246 var value = attributes[name];
247 quote += ' ' + name + '=' + formatAttributeValue(value.toString());
248 }
249 }
250 quote += ']';
251 var newline = ((quote + text + '[/quote]').length > 80 || text.indexOf('\n') > -1) ? '\n' : '';
252 quote += newline + text + newline + '[/quote]';
253
254 return quote;
255 }
256
257 /**
258 * Format given string to be used as an attribute value
259 *
260 * Will return the string as-is if it can be used in a BBCode without quotes. Otherwise,
261 * it will use either single- or double- quotes depending on whichever requires less escaping.
262 * Quotes and backslashes are escaped with backslashes where necessary
263 *
264 * @param {!string} str Original string
265 * @return {!string} Same string if possible, escaped string within quotes otherwise
266 */
267 function formatAttributeValue(str) {
268 if (!/[ "'\\\]]/.test(str)) {
269 // Return as-is if it contains none of: space, ' " \ or ]
270 return str;
271 }
272 var singleQuoted = "'" + str.replace(/[\\']/g, '\\$&') + "'",
273 doubleQuoted = '"' + str.replace(/[\\"]/g, '\\$&') + '"';
274
275 return (singleQuoted.length < doubleQuoted.length) ? singleQuoted : doubleQuoted;
276 }
277
278 function split_lines(text) {
279 var lines = text.split('\n');
280 var splitLines = new Array();
281 var j = 0;
282 var i;
283
284 for(i = 0; i < lines.length; i++) {
285 if (lines[i].length <= 80) {
286 splitLines[j] = lines[i];
287 j++;
288 } else {
289 var line = lines[i];
290 var splitAt;
291 do {
292 splitAt = line.indexOf(' ', 80);
293
294 if (splitAt === -1) {
295 splitLines[j] = line;
296 j++;
297 } else {
298 splitLines[j] = line.substring(0, splitAt);
299 line = line.substring(splitAt);
300 j++;
301 }
302 }
303 while(splitAt !== -1);
304 }
305 }
306 return splitLines;
307 }
308
309 /**
310 * From http://www.massless.org/mozedit/
311 */
312 function mozWrap(txtarea, open, close) {
313 var selLength = (typeof(txtarea.textLength) === 'undefined') ? txtarea.value.length : txtarea.textLength;
314 var selStart = txtarea.selectionStart;
315 var selEnd = txtarea.selectionEnd;
316 var scrollTop = txtarea.scrollTop;
317
318 var s1 = (txtarea.value).substring(0,selStart);
319 var s2 = (txtarea.value).substring(selStart, selEnd);
320 var s3 = (txtarea.value).substring(selEnd, selLength);
321
322 txtarea.value = s1 + open + s2 + close + s3;
323 txtarea.selectionStart = selStart + open.length;
324 txtarea.selectionEnd = selEnd + open.length;
325 txtarea.focus();
326 txtarea.scrollTop = scrollTop;
327
328 return;
329 }
330
331 /**
332 * Insert at Caret position. Code from
333 * http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
334 */
335 function storeCaret(textEl) {
336 if (textEl.createTextRange && document.selection) {
337 textEl.caretPos = document.selection.createRange().duplicate();
338 }
339 }
340
341 /**
342 * Caret Position object
343 */
344 function caretPosition() {
345 var start = null;
346 var end = null;
347 }
348
349 /**
350 * Get the caret position in an textarea
351 */
352 function getCaretPosition(txtarea) {
353 var caretPos = new caretPosition();
354
355 // simple Gecko/Opera way
356 if (txtarea.selectionStart || txtarea.selectionStart === 0) {
357 caretPos.start = txtarea.selectionStart;
358 caretPos.end = txtarea.selectionEnd;
359 }
360 // dirty and slow IE way
361 else if (document.selection) {
362 // get current selection
363 var range = document.selection.createRange();
364
365 // a new selection of the whole textarea
366 var range_all = document.body.createTextRange();
367 range_all.moveToElementText(txtarea);
368
369 // calculate selection start point by moving beginning of range_all to beginning of range
370 var sel_start;
371 for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++) {
372 range_all.moveStart('character', 1);
373 }
374
375 txtarea.sel_start = sel_start;
376
377 // we ignore the end value for IE, this is already dirty enough and we don't need it
378 caretPos.start = txtarea.sel_start;
379 caretPos.end = txtarea.sel_start;
380 }
381
382 return caretPos;
383 }
384
385 /**
386 * Allow to use tab character when typing code
387 * Keep indentation of last line of code when typing code
388 */
389 (function($) {
390 $(document).ready(function() {
391 var doc, textarea;
392
393 // find textarea, make sure browser supports necessary functions
394 if (document.forms[form_name]) {
395 doc = document;
396 } else {
397 doc = opener.document;
398 }
399
400 if (!doc.forms[form_name]) {
401 return;
402 }
403
404 textarea = doc.forms[form_name].elements[text_name];
405
406 phpbb.applyCodeEditor(textarea);
407 if ($('#attach-panel').length) {
408 phpbb.showDragNDrop(textarea);
409 }
410
411 $('textarea').on('keydown', function (e) {
412 if (e.which === 13 && (e.metaKey || e.ctrlKey)) {
413 $(this).closest('form').find(':submit').click();
414 }
415 });
416 });
417 })(jQuery);
418
419