⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edit.js

📁 java web网络编程示例,原代码资源
💻 JS
📖 第 1 页 / 共 2 页
字号:
}

// scrolls the input form to the position where last element was added or removed
function scrollForm() {
	var posY = 0;
	try {
		posY = top.edit.lastPosY;
	} catch (e) {}
	window.scrollTo(0, posY);
}

// closes the popup window, this method is called by the onunload event
function closeTreeWin() {
	if (treewin != null) {
		// close the file selector window
		window.treewin.close();
		treewin = null;
		treeForm = null;
		treeField = null;
		treeDoc = null;
	}
}

// shows the element operation buttons
function showElementButtons(elementName, elementIndex, showRemove, showUp, showDown, showAdd) {
	var elemId = elementName + "." + elementIndex;
	if (oldEditorButtons != null && oldEditorButtons != elemId) {
		// close eventually open element buttons
		document.getElementById("xmlElementButtons").style.visibility = "hidden";
	}
	// get button element
	var elem = document.getElementById("xmlElementButtons");

	// create the button row HTML
	var buttons = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";

	// remove element button
	if (showRemove) {
		buttons += button("javascript:removeElement('" + elementName + "', " + elementIndex + ")", null, "deletecontent", LANG_BT_DELETE, buttonStyle);
	} else {
		buttons += button(null, null, "deletecontent_in", LANG_BT_DELETE, buttonStyle);
	}

	// move up element button
	if (showUp) {
		buttons += button("javascript:moveElement('" + elementName + "', " + elementIndex + ", 'down')", null, "move_up", LANG_BT_MOVE_UP, buttonStyle);
	} else {
		buttons += button(null, null, "move_up_in", LANG_BT_MOVE_UP, buttonStyle);
	}

	// move down element button
	if (showDown) {
		buttons += button("javascript:moveElement('" + elementName + "', " + elementIndex + ", 'up')", null, "move_down", LANG_BT_MOVE_DOWN, buttonStyle);
	} else {
		buttons += button(null, null, "move_down_in", LANG_BT_MOVE_DOWN, buttonStyle);
	}

	// add element button
	if (showAdd) {
		buttons += button("javascript:addElement('" + elementName + "', " + elementIndex + ")", null, "new", LANG_BT_ADD, buttonStyle);
	} else {
		buttons += button(null, null, "new_in", LANG_BT_ADD, buttonStyle);
	}

	buttons += "</table>";

	// set the created HTML
	elem.innerHTML = buttons;
	// get the icon
	var icon = document.getElementById("btimg." + elemId);
	showEditorElement(elem, icon, 10, 20, true);
	oldEditorButtons = elemId;
}

// hides the element operation buttons
function hideElementButtons() {
	if (oldEditorButtons != null) {
		document.getElementById("xmlElementButtons").style.visibility = "hidden";
		oldEditorButtons = null;
		return false;
	}
	return true;
}

// checks presence of element buttons and hides row after a timeout
function checkElementButtons(resetTimer) {
	if (resetTimer) {
		// reset the timer because cursor is over buttons
		if (buttonTimer != null) {
			clearTimeout(buttonTimer);
		}
	} else {
		// set timeout for button row (mouseout)
		buttonTimer = setTimeout("hideElementButtons()", 1500);
	}
}

// shows the specified element belonging to the given icon (for help & element buttons
function showEditorElement(elem, icon, xOffset, yOffset, alignToLeft) {

    if (elem.style.visibility != "visible" && icon) {
	    var x = findPosX(icon) + xOffset;
	    var y = findPosY(icon) + yOffset;
	    var textHeight = elem.scrollHeight;
	    var textWidth = elem.scrollWidth;
	    var scrollSize = 20;
	    var scrollTop = 0;
	    var scrollLeft = 0;
	    var clientHeight = 0;
	    var clientWidth = 0;
	    if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.clientHeight)) {
	        scrollTop = document.documentElement.scrollTop;
	        scrollLeft = document.documentElement.scrollLeft;
	        clientHeight = document.documentElement.clientHeight;
	        clientWidth = document.documentElement.clientWidth;
	    } else if (document.body) {
	        scrollTop = document.body.scrollTop;
	        scrollLeft = document.body.scrollLeft;
	        clientHeight = document.body.clientHeight;
	        clientWidth = document.body.clientWidth;
	    }
	    if ((y + textHeight) > (clientHeight + scrollTop)) {
	        y = y - textHeight;
	    }
	    if (y < scrollTop) {
	        y = (clientHeight + scrollTop) - (textHeight + scrollSize);
	    }
	    if (y < scrollTop) {
	        y = scrollTop;
	    }
	    if ((x + textWidth) > (clientWidth + scrollLeft) || alignToLeft) {
	        x = x - textWidth;
	    }
	    if (x < scrollLeft) {
	        x = (clientWidth + scrollLeft) - (textWidth + scrollSize);
	    }
	    if (x < scrollLeft) {
	        x = scrollLeft;
	    }

	    if (alignToLeft) {
	    	x += xOffset;
	    }

	    elem.style.left = x + "px";
	    elem.style.top =  y + "px";
	    elem.style.visibility = "visible";
	    return y;
    }
}

// finds the x position of an element
function findPosX(obj) {
    var curleft = 0;
    if (obj && obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft - obj.scrollLeft;
            obj = obj.offsetParent;
        }
    } else if (obj && obj.x) {
        curleft += obj.x;
    }
    return curleft;
}

// finds the y position of an element
function findPosY(obj) {
    var curtop = 0;
    if (obj && obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop - obj.scrollTop;
            obj = obj.offsetParent;
        }
    } else if (obj && obj.y) {
        curtop += obj.y;
    }
    return curtop;
}

// formats a button in one of 3 styles (type 0..2)
function button(href, target, image, label, type) {

	if (image != null && image.indexOf('.') == -1) {
        // append default suffix for images
        image += ".png";
    }

	var result = "<td>";
	switch (type) {
		case 1:
		// image and text
		if (href != null) {
			result += "<a href=\"";
			result += href;
			result += "\" class=\"button\"";
			if (target != null) {
				result += " target=\"";
				result += target;
				result += "\"";
			}
			result += ">";
		}
		result += "<span unselectable=\"on\"";
		if (href != null) {
			result += " class=\"norm\" onmouseover=\"className='over'\" onmouseout=\"className='norm'\" onmousedown=\"className='push'\" onmouseup=\"className='over'\"";
		} else {
			result += " class=\"disabled\"";
		}
		result += "><span unselectable=\"on\" class=\"combobutton\" ";
		result += "style=\"background-image: url('";
		result += skinUri;
		result += "buttons/";
		result += image;
		result += "');\">";
		result += label;
		result += "</span></span>";
		if (href != null) {
			result += "</a>";
		}
		break;

		case 2:
		// text only
		if (href != null) {
			result += "<a href=\"";
			result += href;
			result += "\" class=\"button\"";
			if (target != null) {
				result += " target=\"";
				result += target;
				result += "\"";
			}
			result += ">";
		}
		result += "<span unselectable=\"on\"";
		if (href != null) {
			result += " class=\"norm\" onmouseover=\"className='over'\" onmouseout=\"className='norm'\" onmousedown=\"className='push'\" onmouseup=\"className='over'\"";
		} else {
			result += " class=\"disabled\"";
		}
		result += "><span unselectable=\"on\" class=\"txtbutton\">";
		result += label;
		result += "</span></span>";
		if (href != null) {
			result += "</a>";
		}
		break;

		default:
		// only image
		if (href != null) {
			result += "<a href=\"";
			result += href;
			result += "\" class=\"button\"";
			if (target != null) {
				result += " target=\"";
				result += target;
				result += "\"";
			}
			result += " title=\"";
			result += label;
			result += "\">";
		}
		result += "<span unselectable=\"on\"";
		if (href != null) {
			result += " class=\"norm\" onmouseover=\"className='over'\" onmouseout=\"className='norm'\" onmousedown=\"className='push'\" onmouseup=\"className='over'\"";
		} else {
			result += " class=\"disabled\"";
		}
		result += "><img class=\"button\" src=\"";
		result += skinUri;
		result += "buttons/";
		result += image;
		result += "\">";
		result += "</span>";
		break;
	}
	result += "</td>\n";
	return result;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -