~azzar1/unity/add-show-desktop-key

443 by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0
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
10
// Check for Browser & Platform for PC & IE specific bits
11
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
12
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
13
var clientVer = parseInt(navigator.appVersion); // Get browser version
14
15
var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
16
var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));
17
18
var baseHeight;
19
window.onload = initInsertions;
20
21
/**
22
* Shows the help messages in the helpline window
23
*/
24
function helpline(help)
25
{
26
	document.forms[form_name].helpbox.value = help_line[help];
27
}
28
29
/**
30
* Fix a bug involving the TextRange object. From
31
* http://www.frostjedi.com/terra/scripts/demo/caretBug.html
32
*/ 
33
function initInsertions() 
34
{
35
	var doc;
36
	if(document.forms[form_name])
37
	{
38
		doc = document;
39
	}
40
	else
41
	{
42
		doc = opener.document;
43
	}
44
45
	var textarea = doc.forms[form_name].elements[text_name];
46
	if (is_ie && typeof(baseHeight) != 'number')
47
	{
48
		textarea.focus();
49
		baseHeight = doc.selection.createRange().duplicate().boundingHeight;
50
		// document.body.focus();
51
	}
52
}
53
54
/**
55
* bbstyle
56
*/
57
function bbstyle(bbnumber)
58
{
59
	if (bbnumber != -1)
60
	{
61
		bbfontstyle(bbtags[bbnumber], bbtags[bbnumber+1]);
62
	}
63
	else
64
	{
65
		insert_text('[*]');
66
		document.forms[form_name].elements[text_name].focus();		
67
	}
68
}
69
70
/**
71
* Apply bbcodes
72
*/
73
function bbfontstyle(bbopen, bbclose)
74
{
75
	theSelection = false;
76
		
77
	var textarea = document.forms[form_name].elements[text_name];
78
79
	textarea.focus();
80
81
	if ((clientVer >= 4) && is_ie && is_win)
82
	{
83
		// Get text selection
84
		theSelection = document.selection.createRange().text;
85
86
		if (theSelection)
87
		{
88
			// Add tags around selection
89
			document.selection.createRange().text = bbopen + theSelection + bbclose;
90
			document.forms[form_name].elements[text_name].focus();
91
			theSelection = '';
92
			return;
93
		}
94
	}
95
	else if (document.forms[form_name].elements[text_name].selectionEnd && (document.forms[form_name].elements[text_name].selectionEnd - document.forms[form_name].elements[text_name].selectionStart > 0))
96
	{
97
		mozWrap(document.forms[form_name].elements[text_name], bbopen, bbclose);
98
		document.forms[form_name].elements[text_name].focus();
99
		theSelection = '';
100
		return;
101
	}
102
	
103
	//The new position for the cursor after adding the bbcode
104
	var caret_pos = getCaretPosition(textarea).start;
105
	var new_pos = caret_pos + bbopen.length;		
106
107
	// Open tag
108
	insert_text(bbopen + bbclose);
109
110
	// Center the cursor when we don't have a selection
111
	// Gecko and proper browsers
112
	if (!isNaN(textarea.selectionStart))
113
	{
114
		textarea.selectionStart = new_pos;
115
		textarea.selectionEnd = new_pos;
116
	}	
117
	// IE
118
	else if (document.selection)
119
	{
120
		var range = textarea.createTextRange(); 
121
		range.move("character", new_pos); 
122
		range.select();
123
		storeCaret(textarea);
124
	}
125
126
	textarea.focus();
127
	return;
128
}
129
130
/**
131
* Insert text at position
132
*/
133
function insert_text(text, spaces, popup)
134
{
135
	var textarea;
136
	
137
	if (!popup)
138
	{
139
		textarea = document.forms[form_name].elements[text_name];
140
	}
141
	else
142
	{
143
		textarea = opener.document.forms[form_name].elements[text_name];
144
	}
145
146
	if (spaces)
147
	{
148
		text = ' ' + text + ' ';
149
	}
150
151
	if (!isNaN(textarea.selectionStart))
152
	{
153
		var sel_start = textarea.selectionStart;
154
		var sel_end = textarea.selectionEnd;
155
156
		mozWrap(textarea, text, '')
157
		textarea.selectionStart = sel_start + text.length;
158
		textarea.selectionEnd = sel_end + text.length;
159
	}	
160
	
161
	else if (textarea.createTextRange && textarea.caretPos)
162
	{
163
		if (baseHeight != textarea.caretPos.boundingHeight) 
164
		{
165
			textarea.focus();
166
			storeCaret(textarea);
167
		}
168
		var caret_pos = textarea.caretPos;
169
		caret_pos.text = caret_pos.text.charAt(caret_pos.text.length - 1) == ' ' ? caret_pos.text + text + ' ' : caret_pos.text + text;
170
		
171
	}
172
	else
173
	{
174
		textarea.value = textarea.value + text;
175
	}
176
177
	if (!popup)
178
	{
179
		textarea.focus();
180
	}
181
182
}
183
184
/**
185
* Add inline attachment at position
186
*/
187
function attach_inline(index, filename)
188
{
189
	insert_text('[attachment=' + index + ']' + filename + '[/attachment]');
190
	document.forms[form_name].elements[text_name].focus();
191
}
192
193
/**
194
* Add quote text to message
195
*/
196
function addquote(post_id, username)
197
{
198
	var message_name = 'message_' + post_id;
199
	var theSelection = '';
200
	var divarea = false;
201
202
	if (document.all)
203
	{
204
		divarea = document.all[message_name];
205
	}
206
	else
207
	{
208
		divarea = document.getElementById(message_name);
209
	}
210
211
	// Get text selection - not only the post content :(
212
	if (window.getSelection)
213
	{
214
		theSelection = window.getSelection().toString();
215
	}
216
	else if (document.getSelection)
217
	{
218
		theSelection = document.getSelection();
219
	}
220
	else if (document.selection)
221
	{
222
		theSelection = document.selection.createRange().text;
223
	}
224
225
	if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null)
226
	{
227
		if (divarea.innerHTML)
228
		{
229
			theSelection = divarea.innerHTML.replace(/<br>/ig, '\n');
230
			theSelection = theSelection.replace(/<br\/>/ig, '\n');
231
			theSelection = theSelection.replace(/&lt\;/ig, '<');
232
			theSelection = theSelection.replace(/&gt\;/ig, '>');
233
			theSelection = theSelection.replace(/&amp\;/ig, '&');			
234
		}
235
		else if (document.all)
236
		{
237
			theSelection = divarea.innerText;
238
		}
239
		else if (divarea.textContent)
240
		{
241
			theSelection = divarea.textContent;
242
		}
243
		else if (divarea.firstChild.nodeValue)
244
		{
245
			theSelection = divarea.firstChild.nodeValue;
246
		}
247
	}
248
249
	if (theSelection)
250
	{
251
		insert_text('[quote="' + username + '"]' + theSelection + '[/quote]');
252
	}
253
254
	return;
255
}
256
257
/**
258
* From http://www.massless.org/mozedit/
259
*/
260
function mozWrap(txtarea, open, close)
261
{
262
	var selLength = txtarea.textLength;
263
	var selStart = txtarea.selectionStart;
264
	var selEnd = txtarea.selectionEnd;
265
	var scrollTop = txtarea.scrollTop;
266
267
	if (selEnd == 1 || selEnd == 2) 
268
	{
269
		selEnd = selLength;
270
	}
271
272
	var s1 = (txtarea.value).substring(0,selStart);
273
	var s2 = (txtarea.value).substring(selStart, selEnd)
274
	var s3 = (txtarea.value).substring(selEnd, selLength);
275
276
	txtarea.value = s1 + open + s2 + close + s3;
277
	txtarea.selectionStart = selEnd + open.length + close.length;
278
	txtarea.selectionEnd = txtarea.selectionStart;
279
	txtarea.focus();
280
	txtarea.scrollTop = scrollTop;
281
282
	return;
283
}
284
285
/**
286
* Insert at Caret position. Code from
287
* http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
288
*/
289
function storeCaret(textEl)
290
{
291
	if (textEl.createTextRange)
292
	{
293
		textEl.caretPos = document.selection.createRange().duplicate();
294
	}
295
}
296
297
/**
298
* Color pallette
299
*/
300
function colorPalette(dir, width, height)
301
{
302
	var r = 0, g = 0, b = 0;
303
	var numberList = new Array(6);
304
	var color = '';
305
306
	numberList[0] = '00';
307
	numberList[1] = '40';
308
	numberList[2] = '80';
309
	numberList[3] = 'BF';
310
	numberList[4] = 'FF';
311
312
	document.writeln('<table class="type2">');
313
314
	for (r = 0; r < 5; r++)
315
	{
316
		if (dir == 'h')
317
		{
318
			document.writeln('<tr>');
319
		}
320
321
		for (g = 0; g < 5; g++)
322
		{
323
			if (dir == 'v')
324
			{
325
				document.writeln('<tr>');
326
			}
327
			
328
			for (b = 0; b < 5; b++)
329
			{
330
				color = String(numberList[r]) + String(numberList[g]) + String(numberList[b]);
331
				document.write('<td bgcolor="#' + color + '">');
332
				document.write('<a href="#" onclick="bbfontstyle(\'[color=#' + color + ']\', \'[/color]\'); return false;" onmouseover="helpline(\'s\');"  onmouseout="helpline(\'tip\');"><img src="images/spacer.gif" width="' + width + '" height="' + height + '" alt="#' + color + '" title="#' + color + '" /></a>');
333
				document.writeln('</td>');
334
			}
335
336
			if (dir == 'v')
337
			{
338
				document.writeln('</tr>');
339
			}
340
		}
341
342
		if (dir == 'h')
343
		{
344
			document.writeln('</tr>');
345
		}
346
	}
347
	document.writeln('</table>');
348
}
349
350
351
/**
352
* Caret Position object
353
*/
354
function caretPosition()
355
{
356
	var start = null;
357
	var end = null;
358
}
359
360
361
/**
362
* Get the caret position in an textarea
363
*/
364
function getCaretPosition(txtarea)
365
{
366
	var caretPos = new caretPosition();
367
	
368
	// simple Gecko/Opera way
369
	if (txtarea.selectionStart || txtarea.selectionStart == 0)
370
	{
371
		caretPos.start = txtarea.selectionStart;
372
		caretPos.end = txtarea.selectionEnd;
373
	}
374
	// dirty and slow IE way
375
	else if (document.selection)
376
	{
377
		// get current selection
378
		var range = document.selection.createRange();
379
380
		// a new selection of the whole textarea
381
		var range_all = document.body.createTextRange();
382
		range_all.moveToElementText(txtarea);
383
		
384
		// calculate selection start point by moving beginning of range_all to beginning of range
385
		var sel_start;
386
		for (sel_start = 0; range_all.compareEndPoints('StartToStart', range) < 0; sel_start++)
387
		{
388
			range_all.moveStart('character', 1);
389
		}
390
	
391
		txtarea.sel_start = sel_start;
392
	
393
		// we ignore the end value for IE, this is already dirty enough and we don't need it
394
		caretPos.start = txtarea.sel_start;
395
		caretPos.end = txtarea.sel_start;			
396
	}
397
398
	return caretPos;
399
}