?? mozscript.js
字號:
while (istChild) {
if (istChild.nodeType == 1 && !wp_inline_tags.test(istChild.nodeName)) {
return true;
} else if (istChild.nodeType == 3 && istChild.nodeValue.trim() != '') {
return true;
} else if ((val = wp_has_content(istChild)) != false) {
return val;
}
istChild = istChild.nextSibling;
}
}
return false
}
// adds white space to a node with no text nodes
function wp_fill_content(node) {
if (!wp_has_content(node) ) {
//node.innerHTML = node.innerHTML.trim()
while (node.firstChild && node.firstChild.nodeType == 1) {
node = node.firstChild;
}
node.innerHTML = ' '
}
}
// moves cursor to beginning of tags that contain only
function wp_select_fix(obj, evt) {
var sel = obj.edit_object.getSelection()
var range = sel.getRangeAt(0)
var startContainer = range.startContainer
var endContainer = range.endContainer
var startNode = startContainer.parentNode
var endNode = endContainer.parentNode
if (startNode != endNode) {
return
} else {
while (startNode.firstChild && wp_inline_tags.test(startNode.firstChild.nodeName)) {
startNode = startNode.firstChild;
}
if (startNode.innerHTML == ' ' && startNode.firstChild && startNode.firstChild.nodeType == 3) {
startNode = startNode.firstChild
var rngCaret = obj.edit_object.document.createRange();
rngCaret.setStart(startNode, 0);
rngCaret.collapse(true);
sel = obj.edit_object.getSelection();
sel.removeAllRanges();
sel.addRange(rngCaret);
}
}
}
// returns true if inside an li tag
function wp_isInside (obj, tag) {
var sel = obj.edit_object.getSelection()
var range = sel.getRangeAt(0)
var container = range.startContainer
if (container.nodeType != 1) {
var textNode = container
container = textNode.parentNode
}
thisTag = container
while(thisTag.tagName!=tag&&thisTag.tagName!="BODY") {
thisTag = thisTag.parentNode
}
if (thisTag.tagName == tag) {
return true
} else {
return false
}
}
// constructor
function wp_editor(obj,config) {
// strings:
obj.name = config.name
obj.instance_lang = config.instance_lang
obj.encoding = config.encoding
obj.xhtml_lang = config.xhtml_lang
obj.baseURLurl = config.baseURLurl
obj.baseURL = config.baseURL
obj.doctype = config.doctype
obj.charset = config.charset
if (config.domain1) {
obj.domain1 = config.domain1
obj.domain2 = config.domain2
}
obj.instance_img_dir = config.instance_img_dir
obj.instance_doc_dir = config.instance_doc_dir
obj.imagewindow = config.imagewindow
obj.links = config.links
obj.custom_inserts = config.custom_inserts
obj.stylesheet = config.stylesheet
obj.styles = ''
obj.color_swatches = config.color_swatches
// lang
obj.lng = config.lang
// integers
obj.imenu_height = config.imenu_height
obj.bmenu_height = config.bmenu_height
obj.smenu_height = config.smenu_height
obj.tmenu_height = config.tmenu_height
obj.border_visible = config.border_visible
// booleen
obj.usep = config.usep
if (obj.usep) {
obj.tdInners = '<p> </p>';
} else {
obj.tdInners = '<div> </div>';
}
obj.showbookmarkmngr = config.showbookmarkmngr
obj.snippit = true
obj.html_mode=false
obj.preview_mode=false
obj.initfocus = false
obj.subsequent =config.subsequent
obj.useXHTML = config.useXHTML
// methods
obj.getCode = wp_GetCode
obj.getPreviewCode = wp_GetPreviewCode
obj.setCode = wp_SetCode
obj.insertAtSelection = wp_InsertAtSelection
obj.getSelectedText = wp_GetSelectedText
obj.moveFocus = wp_Focus
obj.openDialog = wp_openDialog
obj.showPreview = wp_showPreview
obj.showCode = wp_showCode
obj.showDesign = wp_showDesign
obj.updateHTML = wp_updateHTML
obj.updateWysiwyg = wp_updateWysiwyg
// objects:
obj.html_edit_area = document.getElementById(obj.name)
obj.format_list=document.getElementById(obj.name+'_format_list')
obj.font_face=document.getElementById(obj.name+'_font_face')
obj.font_size=document.getElementById(obj.name+'_font_size')
obj.class_menu=document.getElementById(obj.name+'_class_menu')
obj.foo = obj.html_edit_area.value
// 222 frame position fix
obj.format_frame = document.getElementById(obj.name+"_format_frame").contentWindow
obj.class_frame = document.getElementById(obj.name+"_class_frame").contentWindow
obj.font_frame = document.getElementById(obj.name+"_font_frame").contentWindow
obj.size_frame = document.getElementById(obj.name+"_size_frame").contentWindow
try {
obj.format_frame.written = false
obj.class_frame.written = false
obj.font_frame.written = false
obj.size_frame.written = false
} catch (e) {
}
// ens 222
var tbar=eval("document.getElementById('"+obj.name+"_tab_one')")
var tbarimages = document.getElementById(obj.name+"_tab_one").getElementsByTagName('IMG')
obj.tbarimages = tbarimages
obj.tbarlength = tbarimages.length
obj.safe = true
obj.edit_object = document.getElementById(obj.name+'_editFrame').contentWindow
obj.editFrame = obj.edit_object
obj.previewFrame = document.getElementById(obj.name+"_previewFrame").contentWindow
// submit_form
var container = document.getElementById(obj.name+"_container")
var node = container.parentNode;
while(node.tagName != 'FORM' && node.tagName != "BODY" && node.tagName != "HTML") {
node= node.parentNode;
}
if (node.tagName == 'FORM') {
node.addEventListener('submit', wp_submit_editors, false)
}
// end
var str = ''
if (str.search(/<body/gi) != -1) {
obj.snippit = false
str = obj.doctype
if (obj.baseURL != '') {
str += obj.baseURL
}
if (obj.stylesheet != '') {
var num = obj.stylesheet.length;
for (var i=0; i < num; i++) {
str += '<link rel="stylesheet" href="'+obj.stylesheet[i]+'" type="text/css">'
}
}
} else {
obj.snippit = true
str = obj.doctype+'<html><head><title></title>'+obj.charset
if (obj.baseURL != '') {
str += obj.baseURL
}
if (obj.stylesheet != '') {
var num = obj.stylesheet.length;
for (var i=0; i < num; i++) {
str += '<link rel="stylesheet" href="'+obj.stylesheet[i]+'" type="text/css">'
}
}
str += '</head><body></body></html>'
}
try {
obj.edit_object.document.open()
} catch (e) {
obj.edit_object.document.close()
wp_fail(obj)
return
}
obj.edit_object.document.write(str)
obj.edit_object.document.close()
obj.edit_object.stop()
if (obj.html_edit_area.value.search(/<body/gi) != -1) {
obj.snippit = false
} else {
obj.snippit = true
}
wp_load_data(obj.name)
}
function wp_load_data(name) {
var obj = document.getElementById(name)
if (obj.edit_object.document.body) {
wp_send_to_edit_object(obj, true)
} else {
setTimeout("wp_load_data('"+name+"')",100)
}
}
function wp_enable_designMode(obj) {
try {
obj.edit_object.document.designMode = "on"
} catch (e) {
wp_fail(obj)
return
}
try {
obj.edit_object.document.execCommand("usecss", false, true)
} catch (e) {
wp_fail(obj)
return
}
}
function wp_next(obj) {
wp_send_to_edit_object(obj)
}
function wp_fail(obj) {
document.getElementById(obj.name+'_tab_one').style.display = "none"
document.getElementById(obj.name+'_tab_two').style.display = "block"
document.getElementById(obj.name+'_tab_three').style.display = "none"
document.getElementById(obj.name+'_tab_table').style.display="none"
obj.html_edit_area.style.visibility = "visible"
obj.html_edit_area.value = obj.foo
obj.html_mode=true
document.getElementById(obj.name+'_load_message').style.display ='none'
if (obj.subsequent == false) {
alert(obj.lng['upgrade'])
}
}
function wp_insertNodeAtSelection(win, insertNode) {
var sel = win.getSelection()
var range = sel.getRangeAt(0)
sel.removeAllRanges()
range.deleteContents()
var container = range.startContainer
var pos = range.startOffset
range=document.createRange()
if (container.nodeType==3 && insertNode.nodeType==3) {
container.insertData(pos, insertNode.nodeValue)
range.setEnd(container, pos+insertNode.length)
range.setStart(container, pos+insertNode.length)
} else {
var afterNode
if (container.nodeType==3) {
var textNode = container
container = textNode.parentNode
var text = textNode.nodeValue
var textBefore = text.substr(0,pos)
var textAfter = text.substr(pos)
var beforeNode = document.createTextNode(textBefore)
var afterNode = document.createTextNode(textAfter)
container.insertBefore(afterNode, textNode)
container.insertBefore(insertNode, afterNode)
container.insertBefore(beforeNode, insertNode)
container.removeChild(textNode)
} else {
afterNode = container.childNodes[pos]
container.insertBefore(insertNode, afterNode)
}
if (insertNode.tagName) {
if (insertNode.tagName == 'IMG') {
range.selectNode(insertNode)
} else {
range.setEnd(afterNode, 0)
range.setStart(afterNode, 0)
}
} else {
range.setEnd(afterNode, 0)
range.setStart(afterNode, 0)
}
}
sel = win.getSelection();
sel.removeAllRanges();
sel.addRange(range)
//sel.addRange(rngCaret);
win.focus()
}
// functions for sending html between edit_object and the textarea
function wp_send_to_html(obj) {
var str1 = obj.edit_object.document.body.innerHTML
str1 = str1.replace(/\ /gi, '<!-- WP_SPACEHOLDER -->');
str1 = str1.replace(/<<(.*?)>>/gi, "<$1>")
str1 = str1.replace(/<\/<(.*?)>>/gi, "</$1>")
str1 = str1.replace(/<>/gi, "")
str1 = str1.replace(/<\/>/gi, "")
obj.edit_object.document.body.innerHTML = str1
if (obj.html_edit_area.value.search(/<body/gi) != -1) {
obj.snippit = false
obj.html_edit_area.value = wp_gethtml(obj.edit_object.document,obj)
} else {
obj.snippit = true
obj.html_edit_area.value = wp_gethtml(obj.edit_object.document.body,obj)
}
var str=obj.html_edit_area.value
RegExp.multiline = true
if (obj.domain1 && obj.domain2) {
str = str.replace(obj.domain1, '$1"')
str = str.replace(obj.domain2, '$1"')
}
str = str.replace(/ type=\"_moz\"/gi, '')
str = str.replace(/ style=\"\"/gi, "")
str = str.replace(/<\!-- WP_SPACEHOLDER -->/gi, ' ');
str = str.replace(/<b>/gi, '<strong>');
str = str.replace(/<b /gi, '<strong ');
str = str.replace(/<\/b>/gi, '</strong>');
str = str.replace(/<i>/gi, '<em>');
str = str.replace(/<i /gi, '<em ');
str = str.replace(/<\/i>/gi, '</em>');
str = str.replace(/<p><\/p>/gi, '');
str = str.replace(/<div><\/div>/gi, '');
str = str.replace(/([a-zA-Z0-9\.,:;\!])\n<br[^>]+><\/(p|div|h1|h2|h3|h4|h5|h6)>/gi, '$1</$2>');
str = str.replace(/<(p|div|h1|h2|h3|h4|h5|h6)([^>]+)>\n<br[^>]+><\/(p|div|h1|h2|h3|h4|h5|h6)>/gi, '<$1$2> </$3>');
obj.html_edit_area.value = str
}
function wp_send_to_edit_object(obj, init) {
obj.html_edit_area.value = wp_replace_bookmark (obj.html_edit_area.value)
var str = obj.html_edit_area.value
str = str.replace(/<strong>/gi, '<b>');
str = str.replace(/<strong /gi, '<b ');
str = str.replace(/<\/strong>/gi, '</b>');
str = str.replace(/<em>/gi, '<i>');
str = str.replace(/<em /gi, '<i ');
str = str.replace(/<\/em>/gi, '</i>');
str = str.replace(/<%([^%]+)%>/gi, "<!--asp$1-->");
str = str.replace(/<\?php([^\?]+)\?>/gi, "<!--p$1-->");
obj.html_edit_area.value = str
if (obj.html_edit_area.value.search(/<body/gi) != -1) {
obj.snippit = false
} else {
obj.snippit = true
}
if ((!obj.snippit) && (obj.html_edit_area.value != '')) {
var str = obj.html_edit_area.value
// we cannot write to the document again in Mozilla or we could crash the browser so we need to be creative.
var htmlseparator = new RegExp("<html[^>]*?>","gi")
var bodyseparator = new RegExp("<body[^>]*?>","gi")
var htmlsplit=str.split(htmlseparator)
var bodysplit=str.split(bodyseparator)
var headsplit = str.split(/<head>/gi)
var head = ''
var html = ''
var bodyc = ''
// 222 - body attributes
var arrsplit=str.split(/<body/gi);
var bodytag = obj.edit_object.document.getElementsByTagName('BODY')
// remove all existing body attributes
var attrs = bodytag[0].attributes
var l = attrs.length
for (var i = 0; i < l; i++) {
bodytag[0].setAttribute(attrs[i].nodeName, '')
}
if (arrsplit.length>0) {
var arrsplit2=arrsplit[1].split(">");
var attribute_array = arrsplit2[0].split('" ')
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -