// Copyright (C) 2000, Microsoft, Corp. All rights reserved.
// File: rte.js
// Author: Scott Isaacs
// Contents: RTE Management Code
// EDITOR PUBLIC (API)
var isIE4 = (navigator.appVersion.indexOf("MSIE 4")>0)
function setHTML(szHTML)
{
if (szHTML=="") szHTML = L_DEFAULTHTML_TEXT
if (g_state.bMode)
idEditbox.document.body.innerHTML = szHTML
else
idEditbox.document.body.innerText = szHTML
if (g_state.bLoaded)
setSelection(true)
}
function set(szHTML)
{
idEditbox.document.body.innerHTML = szHTML
}
function getHTML()
{
var szRet = (g_state.bMode ? _CUtil_TrimCR(_CUtil_CleanHTML()) : _CUtil_TrimCR(idEditbox.document.body.innerText))
return szRet
}
function getText() {
var szRet = ""
if (g_state.bMode)
szRet = idEditbox.document.body.innerText
else {
setMode(true)
szRet = idEditbox.document.body.innerText
setMode(false)
}
return szRet
}
function getBody()
{
var oRet = idEditbox.document.body
return oRet
}
function getWidth()
{
var nRet = document.body.offsetWidth
return nRet
}
function getHeight()
{
var nRet = document.body.offsetHeight
return nRet
}
function insertHTML(szHTML)
{
var sType
var sel = g_state.GetSelection()
sType = sel.type
if (g_state.bMode) {
if (sType=="Control")
sel.item(0).outerHTML = szHTML
else
sel.pasteHTML(szHTML)
}
else
sel.text = szHTML
g_state.selection = null
}
function setFocus() {
idEditbox.focus()
}
function appendHTML(szHTML) {
if (g_state.bMode)
idEditbox.document.body.insertAdjacentHTML("beforeEnd",szHTML)
else
idEditbox.document.body.insertAdjacentText("beforeEnd",szHTML)
}
function setBGColor(szValue)
{
g_state.bgColor = szValue
if (g_state.bMode)
idEditbox.document.body.bgColor = g_state.bgColor
}
function setSelection(bDir) {
var tr = idEditbox.document.body.createTextRange()
tr.collapse(bDir)
tr.select()
g_state.SaveSelection()
}
function getBGColor()
{
var szRet = g_state.bgColor
return szRet
}
function setDefaultStyle(szValue)
{
g_state.css = szValue
if (g_state.bMode)
idEditbox.document.body.style.cssText = g_state.css
}
function getDefaultStyle()
{
var oRet = g_state.css
return oRet
}
function setSkin(szSkin)
{
if (szSkin == null)
document.styleSheets.skin.cssText = g_state.defaultSkin
else
document.styleSheets.skin.cssText = szSkin
document.styleSheets.skin.disabled = false
}
function appendSkin(szSkin)
{
document.styleSheets.appendSkin.cssText = szSkin
}
function setPopupSkin(szSkin)
{
if (szSkin == null)
document.styleSheets.popupSkin.cssText = g_state.popupSkin
else
document.styleSheets.popupSkin.cssText = szSkin
_CPopup_Init()
}
function setToolbar(id,g_state)
{
var el = document.all[id]
if (el)
el.style.display = (g_state) ? "" : "none"
if (id=="tbmode") {
_setSize()
}
}
function setLinks(arLinks)
{
g_state.aLinks = arLinks
}
function setBindings(aBindings)
{
if ((aBindings) && (aBindings.length>0))
{
g_state.aBindings = aBindings
for (var iField = DBSelect.length-1; iField > 0; iField--)
DBSelect[iField] = null
for (var iField = 0; iField < g_state.aBindings.length; iField++)
DBSelect.add(new Option(g_state.aBindings[iField]))
tbDBSelect.style.display = "inline"
}
else
tbDBSelect.style.display = ""
}
function setMode(bMode)
{
if (bMode!=g_state.bMode) {
g_state.bMode = bMode
var objBody = idEditbox.document.body
if (!bMode&& !g_state.bMode)
{
_CPopup_Hide()
objBody.bgColor = objBody.style.cssText = ""
if (g_state.customButtons)
idStandardBar.style.display = "none"
else
idToolbar.style.display = "none"
objBody.innerText = idEditbox.document.body.innerHTML
objBody.className = "textMode"
}
if ((bMode) && (g_state.bMode))
{
setDefaultStyle(g_state.css)
setBGColor(g_state.bgColor)
objBody.className = idStandardBar.style.display = idToolbar.style.display = ""
objBody.innerHTML = idEditbox.document.body.innerText
}
_setSize()
cbMode.checked = !bMode
setSelection(true)
setFocus()
}
return bMode
}
function addButton(sID,sButton)
{
if (!sID)
tbButtons.insertAdjacentHTML("beforeEnd","<BR>")
else
tbButtons.insertAdjacentHTML("beforeEnd","<BUTTON TYPE=\"button\" ONCLICK=\"_userButtonClick(this)\" CLASS=\"userButton\" ID=\"" + sID + "\">" + sButton + "\</BUTTON> ")
g_state.customButtons = true
return tbButtons.all[sID]
}
// EDITOR PRIVATE
function _Format(szHow, szValue) {
var oSel = g_state.GetSelection()
var sType = oSel.type
var oTarget = (sType == "None" ? idEditbox.document : oSel)
var oBlock = (oSel.parentElement != null ? _CUtil_GetBlock(oSel.parentElement()) : oSel.item(0))
setFocus()
switch(szHow)
{
case "BackColor":
var el = null
if (oSel.parentElement != null) {
el = _CUtil_GetElement(oSel.parentElement(),"TD")
if (!el) el = _CUtil_GetElement(oSel.parentElement(),"TH")
if (!el) el = _CUtil_GetElement(oSel.parentElement(),"TR")
if (!el) el = _CUtil_GetElement(oSel.parentElement(),"TABLE")
}
else
el = _CUtil_GetElement(oSel.item(0),"TABLE")
if (el)
el.bgColor = szValue
else
setBGColor(szValue)
break;
case "Justify":
if (oBlock)
{
oBlock.style.textAlign = ""
if (((oBlock.tagName=="TABLE") || (oBlock.tagName=="IMG")) && (("left"==oBlock.align) && ("Left"==szValue))) {
oBlock.align = ""
break;
}
oBlock.align = szValue
if ((oBlock.tagName=="HR") || ((oBlock.tagName=="IMG") && szValue!="Center")) break;
}
szHow=szHow+szValue
szValue=""
// Fall through
default:
oTarget.execCommand(szHow, false, szValue)
break
}
g_state.RestoreSelection()
setFocus()
return true
}
function _fireFocus() {
if (self.parent.RTEFocus)
self.parent.RTEFocus(self)
}
function _initEditor() {
g_state = new _CState()
window.onresize = _setSize
var sz = ""
sz += ""
+ "<STYLE>"
+ ".DataBound{border:1 solid #999999;margin:1;font-family:Courier;background:#F1F1F1}\n"
+ ".textMode {border-top: 1px black solid;font: 10pt courier}\n.NOBORDER TD {border:1px gray solid}"
+ "BODY {border: 1px black solid;border-top: none;}"
+ "</STYLE>"
+ "<BODY bgcolor=#FFFFFF ONCONTEXTMENU=\"return false\">"
+ L_DEFAULTHTML_TEXT
+ "</BODY>"
_CPopup_Init()
idEditbox.document.designMode = "on"
idEditbox.document.open("text/html","replace")
idEditbox.document.write(sz)
idEditbox.document.close()
idEditbox.document.body.onblur = idEditbox.onblur = g_state.SaveSelection
idEditbox.document.onkeydown = _Editor_KeyDownHandler
idEditbox.document.onmousedown = _Editor_ClickHandler
idEditbox.document.ondblclick = _Editor_DblClickHandler
setTimeout("_pageReady()",0)
}
function _Editor_ClickHandler() {
g_state.selection = null
}
function _Editor_KeyDownHandler() {
var ev = this.parentWindow.event
if ((ev.keyCode==78 || ev.keyCode==72) && ev.ctrlKey) {
if (ev.keyCode==78)
window.open(parent.location)
ev.keyCode=0;ev.returnValue=false
}
if (ev.keyCode==9)
g_state.SaveSelection()
else
g_state.selection=null
}
function _Editor_DblClickHandler() {
// Shortcuts
var el = this.parentWindow.event.srcElement
if (el.tagName=="IMG") {
el.removeAttribute("width")
el.removeAttribute("height")
el.style.removeAttribute("width")
el.style.removeAttribute("height")
el.width = el.width
el.height = el.height
}
if (el.tagName=="TABLE")
_CPopup_Show('Table')
}
function _setSize() {
document.all.idEditbox.style.pixelHeight = document.body.clientHeight - idToolbar.offsetHeight - document.all.idMode.offsetHeight
document.all.idPopup.style.pixelLeft = (document.body.clientWidth - i