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