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

📄 mozscript.js

📁 类似youtube的视频分享网站源码。有后台管理系统及模板
💻 JS
📖 第 1 页 / 共 4 页
字号:
// Purpose: functions specific to Gecko based browsers that support Midas
var wp_is_ie50 = false;
function wp_keyHandler (obj, evt) {
	var keyCode = (evt.which || evt.charCode || evt.keyCode)
	if (obj.edit_object.getSelection) {
		if (!evt.shiftKey) {
			if (keyCode == 13) {
				wp_divReturn(obj, evt)
			} else if (keyCode == 8) {
				wp_remove_first_br(obj)
			}
		} else if (keyCode == 39 || keyCode == 37) {
			wp_set_button_states(obj)
		}
	}
}
function wp_mouseUpHandler(obj, evt) {
	wp_hide_menu(obj); 
	wp_set_button_states(obj); 
	wp_current_obj = obj; 
	wp_select_fix(obj, evt); 
}
function wp_context(obj, evnt) {
	var sel1 = window.getSelection()
	sel1.removeAllRanges()
	wp_closePopup()
	wp_current_obj = obj;
	var range = obj.edit_object.getSelection().getRangeAt(0)
	var container = range.startContainer
	var pos = range.startOffset
	var imageNode = null
	var tableNode = null
	var canLink = true
	var inside_link = wp_isInside(obj, 'A')
	if (range == '' && container.nodeType != 1 && !inside_link) {
		canLink = false
	}
	if (container.tagName) {
		var images = container.getElementsByTagName('IMG');
		var cn = container.childNodes
		if (cn[pos]) {
			if (cn[pos].tagName == 'IMG') {
				imageNode = cn[pos]
			}
		}
	}	
	if (imageNode) {
		if ((imageNode.getAttribute('name')) && (imageNode.src.search(wp_directory+"/images/bookmark_symbol.gif") != -1)) {
			var menu = document.getElementById(obj.name+"_bookmarkMenu")
			oWidth=230
			oHeight = obj.bmenu_height + 2
		} else {
			var menu = document.getElementById(obj.name+"_imageMenu")
			oWidth=230
			oHeight = obj.imenu_height + 2
		}
	} else if (wp_isInside(obj, 'TD')) {
		var menu = document.getElementById(obj.name+"_tableMenu")
		oWidth=270
		oHeight = obj.tmenu_height + 2
		wp_getTable(obj)
	} else {
		var menu = document.getElementById(obj.name+"_standardMenu")
		oWidth=230
		oHeight = obj.smenu_height + 2
	}
	// make inactive menu items disabled
	var menuRows = menu.getElementsByTagName('TR')
	var n=menuRows.length
	if (n >= 1) {
		for (var i=0; i < n; i++) {
			var cmd = menuRows[i].getAttribute('cid')
			tds=menuRows[i].getElementsByTagName('TD')
			tds[0].className = "wpContextCellOne"
			tds[1].className = "wpContextCellTwo"
			if (cmd=="createlink") {
				if (!canLink) {
					menuRows[i].disabled = true
					tds[1].style.color = 'threedshadow'
				} else {
					menuRows[i].disabled = false
					tds[1].style.color = ''
				}
			} else if (cmd == 'unmergeright') {
				if (wp_thisCell.colSpan < 2) {
					menuRows[i].disabled = true
					tds[1].style.color = 'threedshadow'
				} else {
					menuRows[i].disabled = false
					tds[1].style.color = ''
				}
			} else if (cmd == 'mergeright') {
				if ((!wp_thisCell.nextSibling) || (wp_thisCell.rowSpan != wp_thisCell.nextSibling.rowSpan)) {
					menuRows[i].disabled = true
					tds[1].style.color = 'threedshadow'
				} else {
					menuRows[i].disabled = false
					tds[1].style.color = ''
				}
			} else if (cmd == 'mergebelow') {
				var numrows = wp_thisTable.getElementsByTagName('TR').length
				var topRowIndex = wp_thisRow.rowIndex
				if ((!wp_thisRow.nextSibling) || (numrows - (topRowIndex + wp_thisCell.rowSpan) <= 0)) {
					menuRows[i].disabled = true
					tds[1].style.color = 'threedshadow'
				} else {
					menuRows[i].disabled = false
					tds[1].style.color = ''
				}
			} else if (cmd == 'unmergebelow') {
				if (wp_thisCell.rowSpan < 2) {
					menuRows[i].disabled = true
					tds[1].style.color = 'threedshadow'
				} else {
					menuRows[i].disabled = false
					tds[1].style.color = ''
				}
			} else {
				try {				
					if (!obj.edit_object.document.queryCommandEnabled(cmd)) {
						menuRows[i].disabled = true
						tds[1].style.color = 'threedshadow'
					} else {
						menuRows[i].disabled = false
						tds[1].style.color = ''
					}
				} catch (e) {
					menuRows[i].disabled = false
					tds[1].style.color = ''
				}
			}
		}
		// now actually make the menus	
		var frame = document.getElementById(obj.name+'_editFrame')
		position = wp_getElementPosition(frame)
		var topPos
		var leftPos
		var scrollLeft = document.body.scrollLeft + document.documentElement.scrollLeft
		var scrollTop = document.body.scrollTop + document.documentElement.scrollTop
		availHeight = window.innerHeight + scrollTop
		availWidth = window.innerWidth + scrollLeft
		var clientX = evnt.clientX + position['left']
		var clientY = evnt.clientY + position['top']
		if (clientX + oWidth > availWidth) {
			leftPos = availWidth - oWidth - 2
		} else {
			leftPos = clientX
		}
		if (clientY + oHeight > availHeight) {
			topPos = availHeight - oHeight
		} else {
			topPos = clientY
		}
		menu.style.position = 'absolute'
		menu.style.left = leftPos+'px'
		menu.style.top = topPos+'px'
		menu.style.width = oWidth+'px'
		menu.style.display='block'
		document.addEventListener('mouseup', wp_closePopupTimer, true)
	}
	evnt.stopPropagation()
	evnt.preventDefault()
}
function wp_closePopup(objname) {
	var editors = document.getElementsByTagName("TEXTAREA")
	for (var i=0; i<editors.length; i++) {
		if (editors[i].className == "wpHtmlEditArea") {
			document.getElementById(editors[i].id+"_bookmarkMenu").style.display = 'none'
			document.getElementById(editors[i].id+"_imageMenu").style.display = 'none'
			document.getElementById(editors[i].id+"_standardMenu").style.display = 'none'
			document.getElementById(editors[i].id+"_tableMenu").style.display = 'none'
			document.getElementById(editors[i].id+"_standardMenu").style.display = 'none'
		}
	}
}
// removes those br tags that mozilla adds when you backspace through a node
function wp_remove_first_br (obj, evt) {
	var sel = obj.edit_object.getSelection()
	var range = sel.getRangeAt(0)
	var startContainer = range.startContainer
	var container = startContainer.parentNode
	// find the parent node	
	var node = wp_skipInline(container)
	// traverse the node backwards to find the last br
	if (node.firstChild) {
		if (node.firstChild.nodeType == 3) {
			if (node.firstChild.nextSibling) {
					node = node.firstChild.nextSibling
			}
		}
		while (node.firstChild && node.firstChild.nodeType == 1) {
			node = node.firstChild;
		}
		// if more than one br assume it's meant to be there otherwise remove it
		var previousTag = ''
		if (node.nextSibling) {
			nextTag = node.nextSibling.nodeName
			if (node.nodeName == 'BR' && nextTag != 'BR') {
				node.parentNode.removeChild(node)
			}
		}
	}
}
// non-br returns
function wp_divReturn(obj, evt) {
	if (wp_isInside(obj, 'LI')) {
		return;
	}
	var sel = obj.edit_object.getSelection()
	var range = sel.getRangeAt(0)
	var startContainer = range.startContainer
	var container = startContainer.parentNode
	// find the parent node	
	var parentTag = wp_skipInline(container)
	var endContainer = range.endContainer
	var endNode1 = endContainer.parentNode
	// determine the tag that the parent node replacement (before node) should be
	var beforeTag; var afterTag; var addAttributes = false; var attributes; var className; var cssText;
	if (parentTag.tagName) {
		// if a supported block get attributes
		if (wp_supported_blocks.test(parentTag.tagName)) {
			addAttributes = true
			attributes = parentTag.attributes
		}
		if (parentTag.tagName != 'P' && wp_supported_blocks.test(parentTag.tagName)) {
			beforeTag = parentTag.tagName
		} else if (obj.usep) {
			beforeTag = 'P'
		} else if (!wp_supported_blocks.test(parentTag.tagName)) {
			beforeTag = 'DIV'
		} else {
			beforeTag = 'DIV'
			// replace with div tag then continue
			obj.edit_object.document.execCommand("FormatBlock", false, "div")
		}
	} else if (obj.usep) {
		beforeTag = 'P'
	} else {
		beforeTag = 'DIV'
	}
	// determine the tag that the new after node should be (adjust this later)
	var afterTag = beforeTag
	// make sure we overwrite the selection
	if (container != endNode1) {
		obj.edit_object.document.execCommand('Delete', false, null)
	}
	// create and find ranges to cut
	var rngbefore = obj.edit_object.document.createRange()		
	var rngafter = obj.edit_object.document.createRange()
	rngbefore.setStart(sel.anchorNode, sel.anchorOffset);	
	rngafter.setStart(sel.focusNode, sel.focusOffset);
	rngbefore.collapse(true);					
	rngafter.collapse(true);
	var direct = rngbefore.compareBoundaryPoints(rngbefore.START_TO_END, rngafter) < 0;
	var startNode = direct ? sel.anchorNode : sel.focusNode;
	var startOffset = direct ? sel.anchorOffset : sel.focusOffset;
	var endNode = direct ? sel.focusNode : sel.anchorNode;
	var endOffset = direct ? sel.focusOffset : sel.anchorOffset;
	// find parent blocks
	var startBlock = wp_skipInline(startNode);
	var endBlock = wp_skipInline(endNode);
	// find start and end points
	var startCut = startNode;
	var endCut = endNode;
	while ((startCut.previousSibling && startCut.previousSibling.nodeName != beforeTag) || (startCut.parentNode && startCut.parentNode != startBlock && startCut.parentNode.nodeType != 9)) {
		startCut = startCut.previousSibling ? startCut.previousSibling : startCut.parentNode;
	}
	while ((endCut.nextSibling && endCut.nextSibling.nodeName != afterTag) || (endCut.parentNode && endCut.parentNode != endBlock && endCut.parentNode.nodeType != 9)) {
		endCut = endCut.nextSibling ? endCut.nextSibling : endCut.parentNode;
	}
	// get the contents for each new tag
	rngbefore.setStartBefore(startCut);
	rngbefore.setEnd(startNode,startOffset);
	var beforeContents = rngbefore.cloneContents()
	rngafter.setEndAfter(endCut);
	rngafter.setStart(endNode,endOffset);
	var afterContents = rngafter.cloneContents()
	// test to see if after tag will be empty and if so change to p or div
	if (!wp_has_content(afterContents )) {
		if (obj.usep) {
			afterTag = 'p'
		} else {
			afterTag = 'div'
		}
	}
	// create the new elements
	var newbefore = obj.edit_object.document.createElement(beforeTag);
	var newafter = obj.edit_object.document.createElement(afterTag);
	// place content into the new tags
	newbefore.appendChild(beforeContents)
	newafter.appendChild(afterContents)
	// fill tags if empty
	wp_fill_content(newbefore)
	wp_fill_content(newafter)
	// add attributes
	if (addAttributes) {
		wp_add_attributes(newbefore, attributes)
		wp_add_attributes(newafter, attributes, false, true)
	}
	// make a range around everything
	var rngSurround = obj.edit_object.document.createRange();
	if (!startCut.previousSibling && startCut.parentNode.nodeName == beforeTag) {
		rngSurround.setStartBefore(startCut.parentNode);
	} else {
		rngSurround.setStart(rngbefore.startContainer, rngbefore.startOffset)
	}
	if (!endCut.nextSibling && endCut.parentNode.nodeName == beforeTag) {
		rngSurround.setEndAfter(endCut.parentNode);
	} else {
		rngSurround.setEnd(rngafter.endContainer, rngafter.endOffset)
	}
	// delete old tag
	rngSurround.deleteContents();
	// insert the two new tags
	rngSurround.insertNode(newafter)
	rngSurround.insertNode(newbefore)
	// scroll to the new cursor position
	var scrollTop = obj.edit_object.document.body.scrollTop + obj.edit_object.document.documentElement.scrollTop
	var scrollLeft = obj.edit_object.document.body.scrollLeft + obj.edit_object.document.documentElement.scrollLeft
	var scrollBottom = document.getElementById(obj.name+'_editFrame').style.height
	scrollBottom = scrollBottom.replace(/px/i, '')
	var frameHeight = scrollBottom
	scrollBottom = scrollTop + parseInt(scrollBottom)
	var afterposition = wp_getElementPosition(newafter)
	if (afterposition['top'] > scrollBottom - 25) {
		obj.edit_object.scrollTo(afterposition['left'], afterposition['top'] - parseInt(frameHeight) + 25)
	} else {
		obj.edit_object.scrollBy(afterposition['left'] - scrollLeft, 0)
	}
	// move the cursor
	while (newafter.firstChild && wp_inline_tags.test(newafter.firstChild.nodeName)) {
		newafter = newafter.firstChild;
	}
	if (newafter.firstChild && newafter.firstChild.nodeType == 3) {
		newafter = newafter.firstChild
	}
	var rngCaret = obj.edit_object.document.createRange()
	rngCaret.setStart(newafter, 0);
	rngCaret.collapse(true)
	sel = obj.edit_object.getSelection()
	sel.removeAllRanges()
	sel.addRange(rngCaret)
	// stop browser default action
	evt.stopPropagation()
	evt.preventDefault()
}
// determins the absolute position of an element
function wp_getElementPosition(elem) {
    var offsetTrail = elem;
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    return {left:offsetLeft, top:offsetTop};
}
// finds first block level tag surrounding a given node
function wp_skipInline(foo) {
	while (foo.parentNode && (foo.nodeType != 1 || wp_inline_tags.test(foo.tagName))) {
		foo = foo.parentNode;
	}
	return foo
}
// returns true if a node contains text content, if node contains only empty tags return false.
function wp_has_content(node) {
	if (node.firstChild) {
		var istChild = node.firstChild;
		var val;

⌨️ 快捷键说明

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