User:Cheng chai fung/Editor/function.js

维基百科,自由的百科全书

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。

/** Window Creator ****************************************************
 *
 *  Description: Using the create_window() function to open a window.
 *
 */
function create_window(id, width, height, title, plink)
{
	var pop_window = window.open('', 'pop_window', 'width=' + width + ', height=' + height + ', toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
	pop_window.document.write('<HTML>');
	pop_window.document.write('<HEAD>');
	pop_window.document.write('<META HTTP-EQUIV=\'Content-Type\' CONTENT=\'text/html; charset=utf-8\'>');
	pop_window.document.write('<META HTTP-EQUIV=\'Pragma\' CONTENT=\'no-cache\'>');
	pop_window.document.write('<TITLE>' + title + '<\/TITLE>');
	pop_window.document.write('<SCRIPT TYPE=\'text\/javascript\'>');
	pop_window.document.write('var wgCanonicalNamespace = \'' + wgCanonicalNamespace + '\';');
	pop_window.document.write('var wgCanonicalSpecialPageName = \'' + wgCanonicalSpecialPageName + '\';');
	pop_window.document.write('var wgNamespaceNumber = ' + wgNamespaceNumber + ';');
	pop_window.document.write('var wgPageName = \'' + wgPageName + '\';');
	pop_window.document.write('var wgTitle = \'' + wgTitle + '\';');
	pop_window.document.write('var wgAction = \'' + wgAction + '\';');
	pop_window.document.write('var wgIsArticle = ' + wgIsArticle + ';');
	pop_window.document.write('var showText = new Array();');
	for(i = 0; i < showText[id].length; i++)
	{
		pop_window.document.write('showText[' + i + '] = \'' + showText[id][i] + '\';');
	}
	pop_window.document.write('window.onload = onloadHook;');
	pop_window.document.write('<\/SCRIPT>');
	pop_window.document.write('<SCRIPT CHARSET=\'UTF-8\' SRC=\'http:\/\/zh.100ke.info\/w\/index.php?title=User:Cheng_chai_fung\/Editor\/function.js&action=raw&ctype=text/javascript\' TYPE=\'text\/javascript\'><\/SCRIPT>');
	pop_window.document.write('<SCRIPT CHARSET=\'UTF-8\' SRC=\'http:\/\/zh.100ke.info\/w\/index.php?title=' + plink + '&action=raw&ctype=text/javascript\' TYPE=\'text\/javascript\'><\/SCRIPT>');
	pop_window.document.write('<\/HEAD>');
	pop_window.document.write('<BODY ONLOAD=\'onloadHook();\' \/>');
	pop_window.document.write('<\/HTML>');
	pop_window.document.close();
}

/** Editor Button ****************************************************
 *
 *  Description: This function used to create the button list.
 *
 */
function create_EditorButton(id, toolbutton, tooltip, title, plink, width, height)
{
	mw.util.addPortletLink('p-cactions', 'javascript:create_window(\'' + id + '\', ' + width + ', ' + height + ', \'' + title + '\', \'' + plink + '\');', toolbutton, id, tooltip);
}

/** Request ****************************************************
 *
 *  Description: These function use for connection.
 *
 */
function statue_check()
{
	if (request.readyState == 4)
	{
		if (request.status == 200 || request.status == 0)
		{
			editor_request_response();
		} else
		{
			var error = document.createElement('pre');
			error.setAttribute('id', 'Editor_Error');
			error.appendChild(document.createTextNode('There was a problem with the request. ' + request.status + request.responseText));
			error.style.color = 'green';
			document.body.insertBefore(error, document.body.firstChild);
		}
	}
}

/** Others ****************************************************
 *
 *  Description: These function used to avoid the some errors.
 *
 */
function getPositionX(obj) {
	var position = obj.offsetLeft;
	while (obj = obj.offsetParent) {
		position += obj.offsetLeft;
	};
	return position;
}
function getPositionY(obj) {
	var position = obj.offsetTop;
	while (obj = obj.offsetParent) {
		position += obj.offsetTop;
	};
	return position;
}