PageSourceSearch

https://static.52pojie.cn/mw_syntaxhighlighter/static/js/mw_syntaxhighlighter.js?KDG

js 52pojie.cn collected 2026-09-24 09:19:39 UTC 8,250 bytes, 224 lines download raw bytes

1function mw_syntaxhighlighter(textareaid) {
2	if(textareaid == 'fastpost') {
3		var code = $('fastpostcode');
4		if(code) {
5			code.onclick = function() {
6				syntaxhighlighter_code_box('fastpost');
7			};
8		}
9	} else if(textareaid == 'newthread') {
10		var code = $(editorid + '_code');
11		if(code) {
12			$(editorid + '_body').onmouseup = function(e) {
13				var code = $(editorid + '_code');
14				code.onclick = function() {
15					return false;
16				};
17				e = e || window.event;
18				if((e.target || e.srcElement) == code) {
19					syntaxhighlighter_code_box('newthread');
20				}
21			}
22		}
23	} else if(textareaid == 'post') {
24		var code = $('postcode');
25		if(code) {
26			code.onclick = function() {
27				syntaxhighlighter_code_box('post');
28			};
29		}
30	}
31}
32
33function syntaxhighlighter_code_box(editortype) {
34	mw_syntaxhighlighter_show_editor_codebox(editortype);
35}
36
37function mw_syntaxhighlighter_show_editor_codebox(editortype) {
38	var tag = 'code';
39	var mw_syntaxhighlighter_tag = 'mw_shl_code';
40	var str = mw_lang_codebox['select_lang'];
41	str += '<select id="brush_lang" name="lang">';
42	for(var lang in mw_brush) {
43		str += '<option value="'+ lang + '">'+ mw_brush[lang][0] + '</option>';
44	}
45	str += '</select><br>';
46	if(mw_gutter == 1) {
47		str += mw_lang_codebox['show_gutter'];
48		str += '<input type="checkbox" id="show_gutter" name="show_gutter" value="1" checked><br>';
49	}
50
51	if(editortype == 'newthread') {
52
53		var sel, selection;
54		var str1 = '', strdialog = 0, stitle = '';
55		var ctrlid = editorid + '_' + tag;
56		var menu = $(ctrlid + '_menu');
57		var pos = [0, 0];
58		var menuwidth = 270;
59		var menupos = '43!';
60		var menutype = 'menu';
61
62		str += '<div id="mw_codearea">'+ mw_lang_codebox['your_code'] +'<br>';
63		str += '<textarea id="' + ctrlid + '_param_1" style="width: 98%" cols="50" rows="5" class="txtarea"></textarea></div>';
64
65		//note 修改了ie下的不兼容问题
66		if(BROWSER.ie) {
67			if(wysiwyg) {
68				editdoc.body.focus();
69				sel = editdoc.selection.createRange();
70			} else {
71				sel = document.selection.createRange();
72			}
73			pos = getCaret();
74		}
75
76		selection = sel ? (wysiwyg ? sel.text : sel.text) : mw_highlighter_getSel();//note 修改sel.HtmlText修改为Text,编辑器中的可视化用插件实现比较困难
77		if(menu) {
78			if($(ctrlid).getAttribute('menupos') !== null) {
79				menupos = $(ctrlid).getAttribute('menupos');
80			}
81			if($(ctrlid).getAttribute('menuwidth') !== null) {
82				menu.style.width = $(ctrlid).getAttribute('menuwidth') + 'px';
83			}
84
85			if(selection) {//note 如果选择了内容的处理
86				$('mw_codearea').style.display = 'none';
87			}
88
89			showMenu({'ctrlid':ctrlid,'evt':'click','pos':menupos,'timeout':250,'duration':in_array(tag, ['fontname', 'fontsize', 'sml']) ? 2 : 3,'drag':1});
90		} else {
91
92			var menu = document.createElement('div');
93			menu.id = ctrlid + '_menu';
94			menu.style.display = 'none';
95			menu.className = 'p_pof upf';
96			menu.style.width = menuwidth + 'px';
97
98			s = '<div class="p_opt cl"><span class="y" style="margin:-10px -10px 0 0">
98<a onclick="hideMenu();return false;" class="flbc" href="javascript:;">'+ mw_lang_codebox['close'] +'</a></span><div>' + str + '</div><div class="pns mtn"><button type="submit" id="' + ctrlid + '_submit" class="pn pnc"><strong>'+ mw_lang_codebox['submit'] +'</strong></button></div></div>';
99			menu.innerHTML = s;
100			$(editorid + '_editortoolbar').appendChild(menu);
101
102			if(selection) {//note 如果选择了内容的处理
103				$('mw_codearea').style.display = 'none';
104			}
105
106			showMenu({'ctrlid':ctrlid,'mtype':menutype,'evt':'click','duration':3,'cache':0,'drag':1,'pos':menupos});
107		}
108
109		try {
110			if($(ctrlid + '_param_1')) {
111				$(ctrlid + '_param_1').focus();
112			}
113		} catch(e) {}
114		var objs = menu.getElementsByTagName('*');
115		for(var i = 0; i < objs.length; i++) {
116			_attachEvent(objs[i], 'keydown', function(e) {
117				e = e ? e : event;
118				obj = BROWSER.ie ? event.srcElement : e.target;
119				if((obj.type == 'text' && e.keyCode == 13) || (obj.type == 'textarea' && e.ctrlKey && e.keyCode == 13)) {
120					if($(ctrlid + '_submit') && tag != 'image') $(ctrlid + '_submit').click();
121					doane(e);
122				} else if(e.keyCode == 27) {
123					hideMenu();
124					doane(e);
125				}
126			});
127		}
128		if($(ctrlid + '_submit')) $(ctrlid + '_submit').onclick = function() {
129			checkFocus();
130			if(BROWSER.ie && wysiwyg) {
131				setCaret(pos[0]);
132			}
133			if(wysiwyg) {
134				if(!BROWSER.ie) {
135					selection = selection ? selection : '';
136				}
137			}
138			str1 = $(ctrlid + '_param_1') && $(ctrlid + '_param_1').value ? $(ctrlid + '_param_1').value : (selection ? selection : '');
139
140			var opentag = '[' + mw_syntaxhighlighter_tag + '=' + $('brush_lang').value + ',' + (($('show_gutter') && $('show_gutter').checked) ? 'true' : 'false') + ']';
141			var closetag = '[/' + mw_syntaxhighlighter_tag + ']';
142
143			if(wysiwyg) {
144				str1 = preg_replace(['<', '>'], ['&lt;', '&gt;'], str1);
145				str1 = str1.replace(/\r?\n/g, '<br />');
146			}
147			str1 = opentag + str1 + closetag;
148			insertText(str1, strlen(opentag), strlen(closetag), false, sel);
149			hideMenu();
150		};
151
152	} else if(editortype == 'fastpost' || editortype == 'post') {
153
154		var sel = false;
155		var seditorkey = editortype;
156		if(!isUndefined($(seditorkey + 'message').selectionStart)) {
157			sel = $(seditorkey + 'message').selectionEnd - $(seditorkey + 'message').selectionStart;
158		} else if(document.selection && document.selection.createRange) {
159			$(seditorkey + 'message').focus();
160			var sel = document.selection.createRange();
161			$(seditorkey + 'message').sel = sel;
162			sel = sel.text ? true : false;
163		}
164
165		var ctrlid = seditorkey + tag;
166		var menuid = ctrlid + '_menu';
167
168		str += '<div id="mw_codearea">'+ mw_lang_codebox['your_code'] +'<br>';
169		str += '<textarea id="' + ctrlid + '_param_1" style="width: 98%" cols="50" rows="5" class="txtarea"></textarea></div>';
170
171		if(!$(menuid)) {
172			var submitstr = "seditor_insertunit('" + seditorkey + "', '[" + mw_syntaxhighlighter_tag + "=' + $('brush_lang').value + ',' + (($('show_gutter') && $('show_gutter').checked) ? 'true' : 'false') + ']'+$('" + ctrlid + "_param_1').value, '[/" + mw_syntaxhighlighter_tag + "]', null, 1);hideMenu();";
173			var menu = document.createElement('div');
174			menu.id = menuid;
175			menu.style.display = 'none';
176			menu.className = 'p_pof upf';
177			menu.style.width = '270px';
178			$('append_parent').appendChild(menu);
179			menu.innerHTML = '<span class="y">
179<a onclick="hideMenu()" class="flbc" href="javascript:;">'+ mw_lang_codebox['close'] +'</a></span><div class="p_opt cl"><form onsubmit="' + submitstr + ';return false;" autocomplete="off"><div>' + str + '</div><div class="pns mtn"><button type="submit" id="' + ctrlid + '_submit" class="pn pnc"><strong>'+ mw_lang_codebox['submit'] +'</strong></button><button type="button" onClick="hideMenu()" class="pn"><em>'+ mw_lang_codebox['cancle'] +'</em></button></div></form></div>';
180		}
181		if(sel) {//note 如果选择了内容的处理
182			$('mw_codearea').style.display = 'none';
183		}
184		showMenu({'ctrlid':ctrlid,'evt':'click','duration':3,'cache':0,'drag':1});
185	}
186}
187
188function mw_highlighter_getSel() {
189	if(wysiwyg) {
190		try {
191			selection = editwin.getSelection();
192			return selection.toString();
193			//checkFocus();
194			//range = selection ? selection.getRangeAt(0) : editdoc.createRange();
195			//return readNodes(range.cloneContents(), false);
196		} catch(e) {
197			try {
198				var range = editdoc.selection.createRange();
199				if(range.htmlText && range.text) {
200					return range.text;
201				} else {
202					var htmltext = '';
203					for(var i = 0; i < range.length; i++) {
204						htmltext += range.item(i).outerHTML;
205					}
206					return htmltext;
207				}
208			} catch(e) {
209				return '';
210			}
211		}
212	} else {
213		if(!isUndefined(editdoc.selectionStart)) {
214			return editdoc.value.substr(editdoc.selectionStart, editdoc.selectionEnd - editdoc.selectionStart);
215		} else if(document.selection && document.selection.createRange) {
216			return document.selection.createRange().text;
217		} else if(window.getSelection) {
218			alert(editdoc);
219			return window.getSelection() + '';
220		} else {
221			return false;
222		}
223	}
224}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.