📄 editorshared.js
字号:
wp_getTable(obj)
var numrows = wp_thisTable.getElementsByTagName('TR').length
var topRowIndex = wp_thisRow.rowIndex
if (numrows - (topRowIndex + wp_thisCell.rowSpan) <= 0) {
alert(obj.lng['different_column_spans'])
return
}
if (!wp_thisRow.nextSibling) {
alert(obj.lng['no_cell_below'])
return
}
var bottomCell = wp_thisRow.parentNode.childNodes[ topRowIndex + wp_thisCell.rowSpan ].childNodes[ wp_thisCell.cellIndex ]
var bottomRow = wp_thisRow.parentNode.childNodes[topRowIndex + wp_thisCell.rowSpan ]
// don't allow merging rows with different colspans
if (wp_thisCell.colSpan != bottomCell.colSpan) {
alert(obj.lng['different_column_spans'])
return
}
// do the merge
if (bottomCell.innerHTML.toLowerCase() != obj.tdInners) {
if (wp_thisCell.innerHTML.toLowerCase() == obj.tdInners) {
wp_thisCell.innerHTML = bottomCell.innerHTML
} else {
wp_thisCell.innerHTML += bottomCell.innerHTML
}
}
wp_thisCell.setAttribute("HEIGHT", '', 0)
wp_thisCell.rowSpan += bottomCell.rowSpan
bottomRow.removeChild(bottomCell)
wp_thisCell=null
wp_thisRow=null
wp_thisTable=null
}
obj.edit_object.focus()
}
// unMergeDown
function wp_unMergeDown(obj) {
if (wp_isInside(obj, 'TD')) {
wp_getTable(obj)
if (wp_thisCell.rowSpan < 2) {
alert(obj.lng['only_split_merged_cells'])
return
}
var topRowIndex = wp_thisCell.parentNode.rowIndex
// add a cell to the beginning of the next row
var newCell = wp_thisRow.parentNode.childNodes[ topRowIndex + wp_thisCell.rowSpan - 1 ].appendChild( obj.edit_object.document.createElement("TD") )
newCell.innerHTML = obj.tdInners
newCell.vAlign = wp_thisCell.vAlign
newCell.colSpan = wp_thisCell.colSpan
wp_thisCell.rowSpan -= 1
if (obj.border_visible == 1) {
wp_show_borders(obj)
}
wp_thisCell=null
wp_thisRow=null
wp_thisTable=null
}
obj.edit_object.focus()
}
// fixes column widths, alignment and inserts spacers.
// should be called after doing any column manipulation
function wp_reprocess_columns(obj) {
var nocolumns = 0
var tableRows = wp_thisTable.getElementsByTagName('TR')
var tableColumns = tableRows[0].getElementsByTagName('TD')
// get the number of columns taking into account colspans
var n=tableColumns.length
for (var i=0; i < n; i++) {
if (tableColumns[i].getAttribute('colSpan') >= 2) {
nocolumns += tableColumns[i].getAttribute('colSpan')
} else {
nocolumns +=1
}
}
// calculate the column widths
var tdwidth = 100/nocolumns
var tableCells = wp_thisTable.getElementsByTagName('TD')
// now resize the columns, also insert spacers into cells with no inner html and fix text alignment
var n=tableCells.length
for (var i=0; i < n; i++) {
if (tableCells[i].getAttribute('colSpan') < 2) {
tableCells[i].width = tdwidth + '%'
}
if (tableCells[i].innerHTML == '') {
tableCells[i].innerHTML = obj.tdInners
}
if ((tableCells[i].getAttribute('vAlign') == '') || (tableCells[i].getAttribute('vAlign') == null)) {
tableCells[i].vAlign = 'top'
}
}
if (obj.border_visible == 1) {
wp_show_borders(obj)
}
}
///////////////////////////
// Save functions //
///////////////////////////
// function to ensure updates are sent to the textarea before saving, should be called from the save button or the form in an onsubmit statement
function wp_submit_editors() {
if (!this.wp_has_submitted) {
submit_form()
}
this.wp_has_submitted = true;
}
function submit_form() {
var editors = document.getElementsByTagName("TEXTAREA")
for (var i=0; i<editors.length; i++) {
if (editors[i].className == "wpHtmlEditArea") {
wp_prepare_submission(editors[i])
}
}
return true
}
function wp_prepare_submission(obj) {
if (obj.html_mode==false) {
wp_send_to_html(obj)
var str = obj.html_edit_area.value
if (str == '<p> </p>'
|| str == '<div> </div>'
|| str == '<div>\n<br></div>'
|| str == '<div>\n<br /></div>'
|| str == '<p>\n<br></p>'
|| str == '<p>\n<br /></p>'
|| str == '<br>'
|| str == '<br />'
|| str == ' '
|| str == ' \n<br>'
|| str == ' \n<br />'
) {
obj.html_edit_area.value = ''
}
return true
} else {
return true
}
}
// context menu mouse overs //
function wp_menuover(srcElement) {
tds=srcElement.getElementsByTagName('TD')
tds[0].className = "wpContextCellOneOver"
tds[1].className = "wpContextCellTwoOver"
}
function wp_menuout(srcElement) {
tds=srcElement.getElementsByTagName('TD')
tds[0].className = "wpContextCellOne"
tds[1].className = "wpContextCellTwo"
}
/////////////////////
// Tab view script //
/////////////////////
function wp_showDesign() {
if (this.html_mode==true) {
if (document.getElementById(this.name+'_designTab')) {
document.getElementById(this.name+"_load_message").style.display ='block'
setTimeout("wp_on_enter_tab_one("+this.name+")",1);
}
}
}
function wp_on_enter_tab_one(obj) {
if (obj.html_mode==true) {
var tab_one = document.getElementById(obj.name+'_tab_one')
if (wp_is_ie) {
tab_one.style.display = 'block'
} else {
document.getElementById(obj.name+'_editFrame').style.width = '100%'
tab_one.style.visibility = "visible"
tab_one.style.height = ''
}
document.getElementById(obj.name+'_tab_two').style.display = "none"
document.getElementById(obj.name+'_tab_three').style.display = "none"
if (document.getElementById(obj.name+'_designTab'))
document.getElementById(obj.name+'_designTab').className = "wpTButtonUp"
if (document.getElementById(obj.name+'_sourceTab'))
document.getElementById(obj.name+'_sourceTab').className = "wpTButtonDown"
if (document.getElementById(obj.name+'_previewTab'))
document.getElementById(obj.name+'_previewTab').className = "wpTButtonDown"
wp_send_to_edit_object(obj)
obj.html_mode=false
obj.preview_mode=false
}
document.getElementById(obj.name+"_load_message").style.display ='none'
if (wp_is_ie)
obj.edit_object.focus()
}
function wp_showCode() {
if (this.html_mode==false || this.preview_mode==true) {
if (document.getElementById(this.name+'_sourceTab')) {
document.getElementById(this.name+"_load_message").style.display ='block'
setTimeout("wp_on_enter_tab_two("+this.name+")",1);
}
}
}
function wp_on_enter_tab_two(obj) {
if (obj.html_mode==false || obj.preview_mode==true) {
wp_hide_menu(obj)
var tab_one = document.getElementById(obj.name+'_tab_one')
if (wp_is_ie) {
tab_one.style.display = 'none'
} else {
document.getElementById(obj.name+'_editFrame').style.width = '0px'
tab_one.style.visibility = "hidden"
tab_one.style.height = '0px'
}
document.getElementById(obj.name+'_tab_two').style.display = "block"
document.getElementById(obj.name+'_tab_three').style.display = "none"
obj.html_edit_area.style.visibility = "visible"
if (document.getElementById(obj.name+'_designTab'))
document.getElementById(obj.name+'_designTab').className = "wpTButtonDown"
if (document.getElementById(obj.name+'_sourceTab'))
document.getElementById(obj.name+'_sourceTab').className = "wpTButtonUp"
if (document.getElementById(obj.name+'_previewTab'))
document.getElementById(obj.name+'_previewTab').className = "wpTButtonDown"
obj.html_mode=true
if (obj.preview_mode==false) {
wp_send_to_html(obj)
}
obj.preview_mode=false
}
document.getElementById(obj.name+"_load_message").style.display ='none'
obj.html_edit_area.focus()
}
function wp_showPreview() {
if (this.preview_mode==false) {
if (document.getElementById(this.name+'_previewTab')) {
document.getElementById(this.name+"_load_message").style.display ='block'
setTimeout("wp_on_enter_tab_three("+this.name+")",1);
}
}
}
function wp_on_enter_tab_three(obj) {
if (obj.preview_mode==false) {
wp_hide_menu(obj)
var tab_one = document.getElementById(obj.name+'_tab_one')
if (wp_is_ie) {
tab_one.style.display = 'none'
} else {
document.getElementById(obj.name+'_editFrame').style.width = '0px'
tab_one.style.visibility = "hidden"
tab_one.style.height = '0px'
}
document.getElementById(obj.name+'_tab_two').style.display = "none"
document.getElementById(obj.name+'_tab_three').style.display = "block"
if (document.getElementById(obj.name+'_designTab'))
document.getElementById(obj.name+'_designTab').className = "wpTButtonDown"
if (document.getElementById(obj.name+'_sourceTab'))
document.getElementById(obj.name+'_sourceTab').className = "wpTButtonDown"
if (document.getElementById(obj.name+'_previewTab'))
document.getElementById(obj.name+'_previewTab').className = "wpTButtonUp"
if (obj.html_mode==false) {
wp_send_to_html(obj)
}
obj.html_mode=true
obj.preview_mode=true
wp_send_to_preview(obj)
}
document.getElementById(obj.name+"_load_message").style.display ='none'
obj.previewFrame.focus()
}
function wp_on_mouse_down_tab(srcElement, obj) {
//document.getElementById(obj.name+"_load_message").style.display ='block'
if (srcElement.className != 'tbuttonUp')
srcElement.className='wpTButtonMouseDown'
}
function wp_send_to_preview(obj, dontFocus) {
obj.previewFrame.document.open()
obj.previewFrame.document.write(obj.getPreviewCode())
obj.previewFrame.document.close()
if (!dontFocus) {
obj.previewFrame.focus()
}
}
function updateAllWysiwyg() {
submit_form()
}
function updateAllHTML() {
var editors = document.getElementsByTagName("TEXTAREA")
for (var i=0; i<editors.length; i++) {
if (editors[i].className == "wpHtmlEditArea") {
wp_send_to_edit_object(editors[i])
}
}
}
function wp_InsertAtSelection(code) {
wp_insert_code(this, code)
}
function wp_SetCode(code) {
this.html_edit_area.value = code
wp_send_to_edit_object(this)
}
function wp_GetSelectedText() {
var selectedText
if (wp_is_ie) {
selectedText = this.edit_object.document.selection.createRange().text
} else {
selectedText = this.edit_object.getSelection().getRangeAt(0)
}
return selectedText
}
function wp_GetCode() {
if (this.html_mode==false) {
wp_send_to_html(this)
}
return this.html_edit_area.value
}
function wp_GetPreviewCode() {
if (this.html_mode==false) {
wp_send_to_html(this)
}
var str = this.baseURL;
if (this.stylesheet != '') {
var num = this.stylesheet.length;
for (var i=0; i < num; i++) {
str += '<link rel="stylesheet" href="' + this.stylesheet[i] + '" type="text/css">'
}
}
return str + this.html_edit_area.value
}
function wp_Focus() {
if (wp_is_ie) {
var previewFrame = document.frames(this.name+'_previewFrame')
} else {
var previewFrame = document.getElementById(this.name+'_previewFrame').contentWindow
}
if (this.html_mode==true) {
this.html_edit_area.focus()
} else if (this.preview_mode == true) {
previewFrame.focus()
} else {
this.edit_object.focus()
}
return true;
}
function wp_initAll() {
var editors = document.getElementsByTagName("TEXTAREA")
for (var i=0; i<editors.length; i++) {
if (editors[i].className == "wpHtmlEditArea") {
wp_editor(editors[i],eval("config_"+editors[i].id))
}
}
}
function wp_updateHTML() {
if (this.html_mode==false) {
wp_send_to_html(this)
}
}
function wp_updateWysiwyg() {
wp_send_to_edit_object(this)
}
// wp 222
if (window.addEventListener) {
window.addEventListener('load', wp_initAll, false)
} else if (window.attachEvent) {
window.attachEvent('onload', wp_initAll)
} else {
window.onload = wp_initAll
}
// end wp 222
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -