author | Dan Fuhry <dan@enanocms.org> |
Sun, 01 Aug 2010 12:41:45 -0400 | |
changeset 1284 | 35380c89b5bf |
parent 1231 | 4797a4a88533 |
permissions | -rw-r--r-- |
1231
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
1 |
// |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
2 |
// Add the wrappers for preformatted tags within content. |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
3 |
// |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
4 |
|
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
5 |
addOnloadHook(function() |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
6 |
{ |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
7 |
preformat_process_all(); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
8 |
}); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
9 |
|
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
10 |
function preformat_process_all() |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
11 |
{ |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
12 |
var aec = document.getElementById('ajaxEditContainer'); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
13 |
if ( !aec ) |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
14 |
return false; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
15 |
var pres = aec.getElementsByTagName('pre'); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
16 |
for ( var i = 0; i < pres.length; i++ ) |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
17 |
{ |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
18 |
if ( pres[i].hasButtonPanel ) |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
19 |
continue; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
20 |
pres[i].hasButtonPanel = true; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
21 |
|
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
22 |
var btnp = document.createElement('div'); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
23 |
btnp.mypre = pres[i]; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
24 |
btnp.className = 'preformat-panel'; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
25 |
btnp.appendChild(document.createTextNode($lang.get('onpage_pre_lbl_code'))); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
26 |
btnp.appendChild(document.createTextNode(' <')); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
27 |
var a_sel = document.createElement('a'); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
28 |
a_sel.href = '#'; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
29 |
a_sel.onclick = function() |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
30 |
{ |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
31 |
preformat_handle_select_click(this.parentNode); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
32 |
return false; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
33 |
}; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
34 |
a_sel.appendChild(document.createTextNode($lang.get('onpage_pre_btn_select'))); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
35 |
btnp.appendChild(a_sel); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
36 |
btnp.appendChild(document.createTextNode('> <')); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
37 |
var a_pop = document.createElement('a'); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
38 |
a_pop.href = '#'; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
39 |
a_pop.onclick = function() |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
40 |
{ |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
41 |
preformat_handle_popup_click(this.parentNode); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
42 |
return false; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
43 |
}; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
44 |
a_pop.appendChild(document.createTextNode($lang.get('onpage_pre_btn_popup'))); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
45 |
btnp.appendChild(a_pop); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
46 |
btnp.appendChild(document.createTextNode('>')); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
47 |
pres[i].parentNode.insertBefore(btnp, pres[i]); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
48 |
} |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
49 |
} |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
50 |
|
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
51 |
function preformat_handle_select_click(btnp) |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
52 |
{ |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
53 |
var pre = btnp.mypre; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
54 |
select_element(pre); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
55 |
} |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
56 |
|
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
57 |
function preformat_handle_popup_click(btnp) |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
58 |
{ |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
59 |
var pre = btnp.mypre; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
60 |
var text = pre.innerHTML; |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
61 |
var newwin = window.open('about:blank', 'codepopwin', 'width=800,height=600,status=no,toolbars=no,toolbar=no,address=no,scroll=yes'); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
62 |
newwin.document.open(); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
63 |
newwin.document.write('<html><head><title>' + $lang.get('onpage_pre_popup_title') + '</title></head><body>'); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
64 |
newwin.document.write('<pre>' + text + '</pre>'); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
65 |
newwin.document.write('</body></html>'); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
66 |
newwin.document.close(); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
67 |
} |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
68 |
|
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
69 |
function select_element(element) |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
70 |
{ |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
71 |
if (IE) |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
72 |
{ |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
73 |
// IE |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
74 |
var range = document.body.createTextRange(); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
75 |
range.moveToElementText(element); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
76 |
range.select(); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
77 |
} |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
78 |
else if (is_Gecko || is_Opera) |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
79 |
{ |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
80 |
// Mozilla/Opera |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
81 |
var selection = window.getSelection(); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
82 |
var range = document.createRange(); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
83 |
range.selectNodeContents(element); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
84 |
selection.removeAllRanges(); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
85 |
selection.addRange(range); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
86 |
} |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
87 |
else if (is_Webkit) |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
88 |
{ |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
89 |
// Safari (Chrome?) |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
90 |
var selection = window.getSelection(); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
91 |
selection.setBaseAndExtent(element, 0, element, 1); |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
92 |
} |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
93 |
} |
4797a4a88533
Added selection and popup for <pre> tags within wikitext. Also fixed more bugs found in the HTML paragraph parser (mostly self-closing tags e.g. <hr />).
Dan
parents:
diff
changeset
|
94 |