?? editor.js
字號:
// JavaScript Document
var sCurrMode = null;
var bEditMode = null;
sCurrMode = "EDIT";
var borderShown = "yes";
var bInitialized = false;
function document.onreadystatechange(){
if (document.readyState!="complete") return;
if (bInitialized) return;
bInitialized = true;
var mBody;
Content.value = parent.document.getElementById(sLinkFieldName).value;
mBody = Content.value;
setHTML(mBody);
}
function setHTML(html) {
switch (sCurrMode){
case "CODE":
html = formatHtml(html);
LinziWebEditor.document.designMode="On";
LinziWebEditor.document.open();
LinziWebEditor.document.write("<head><link href=\"EditorArea.css\" type=\"text/css\" rel=\"stylesheet\"></head><body>");
LinziWebEditor.document.body.innerText=html;
LinziWebEditor.document.body.contentEditable="true";
LinziWebEditor.document.close();
bEditMode=false;
break;
case "EDIT":
html = formatHtml(html);
LinziWebEditor.document.designMode="On";
LinziWebEditor.document.open();
LinziWebEditor.document.write("<head><link href=\"EditorArea.css\" type=\"text/css\" rel=\"stylesheet\"></head><body>"+html);
LinziWebEditor.document.body.contentEditable="true";
LinziWebEditor.document.execCommand("2D-Position",true,true);
LinziWebEditor.document.execCommand("MultipleSelection", true, true);
LinziWebEditor.document.execCommand("LiveResize", true, true);
LinziWebEditor.document.close();
bEditMode=true;
LinziWebEditor.document.onselectionchange = function () { }
break;
case "VIEW":
LinziWebEditor.document.designMode="off";
LinziWebEditor.document.open();
LinziWebEditor.document.write("<head><link href=\"EditorArea.css\" type=\"text/css\" rel=\"stylesheet\"></head><body>"+html);
LinziWebEditor.document.body.contentEditable="false";
LinziWebEditor.document.close();
bEditMode=false;
break;
}
LinziWebEditor.document.body.onpaste = onPaste;
LinziWebEditor.document.onkeydown = new Function("return onKeyDown(LinziWebEditor.event);");
LinziWebEditor.document.oncontextmenu=new Function("return showContextMenu(LinziWebEditor.event);");
LinziWebEditor.document.body.onblur = bodyonBlur;
}
function bodyonBlur()
{
var htmlstr;
htmlstr = getHTML();
parent.document.getElementById(sLinkFieldName).value = htmlstr;
Content.value = htmlstr;
}
function SetMode(newMode){
var sBody = "";
if(newMode==sCurrMode){
return false;
}
if(sCurrMode == "EDIT"){
sBody = LinziWebEditor.document.body.innerHTML;
EDIT_button.className="login_0";
CODE_button.className="login_1";
}else{
sBody = LinziWebEditor.document.body.innerText;
CODE_button.className="login_0";
EDIT_button.className="login_1";
}
LinziWebEditor.focus();
sCurrMode = newMode;
setHTML(sBody);
}
function showContextMenu(event){
showContextMenu(event);
return false;
}
function onPaste(){
if (sCurrMode=="VIEW") return false;
if(sCurrMode == "CODE")
{
LinziWebEditor.document.selection.createRange().pasteHTML(HTMLEncode(clipboardData.getData("Text")));
return false;
}
}
function onKeyDown(event){
var key = String.fromCharCode(event.keyCode).toUpperCase();
switch(sCurrMode){
case "VIEW":
return false;
break;
case "EDIT":
return true;
break;
default:
if (event.keyCode==13){
var sel = LinziWebEditor.document.selection.createRange();
sel.pasteHTML("<BR>");
event.cancelBubble = true;
event.returnValue = false;
sel.select();
sel.moveEnd("character", 1);
sel.moveStart("character", 1);
sel.collapse(false);
return false;
}
// 屏蔽事件
if (event.ctrlKey){
// Ctrl+B,I,U
if ((key == "B")||(key == "I")||(key == "U")){
return false;
}
}
}
}
//開發者:林子 11403891 zoulinxi@163.com
// 取編輯器的內容
function getHTML() {
var html;
if((sCurrMode=="EDIT")||(sCurrMode=="VIEW")){
html = LinziWebEditor.document.body.innerHTML;
}else{
html = LinziWebEditor.document.body.innerText;
}
if (sCurrMode!="TEXT"){
if ((html.toLowerCase()=="<p> </p>")||(html.toLowerCase()=="<p></p>")){
html = "";
}
}
return html;
}
// 替換特殊字符
function HTMLEncode(text){
text = text.replace(/&/g, "&") ;
text = text.replace(/"/g, """) ;
text = text.replace(/</g, "<") ;
text = text.replace(/>/g, ">") ;
text = text.replace(/'/g, "’") ;
text = text.replace(/\ /g," ");
text = text.replace(/\n/g,"<br>");
text = text.replace(/\t/g," ");
return text;
}
// 是否選中指定類型的控件
function isControlSelected(tag){
if (LinziWebEditor.document.selection.type == "Control") {
var oControlRange = LinziWebEditor.document.selection.createRange();
if (oControlRange(0).tagName.toUpperCase() == tag && oControlRange(0).getAttribute("width") != "SITEBOX") {
return true;
}
}
return false;
}
// 格式化編輯器中的內容
function format(what,opt) {
if (sCurrMode!="EDIT") return;
LinziWebEditor.focus();
if (opt=="RemoveFormat"){
what=opt;
opt=null;
}
if (opt==null) LinziWebEditor.document.execCommand(what);
else LinziWebEditor.document.execCommand(what,"",opt);
LinziWebEditor.focus();
}
// 顯示無模式對話框
function ShowDialog(url, width, height, optValidate) {
if (optValidate) {
if (sCurrMode!="EDIT") return;
}
LinziWebEditor.focus();
var arr = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
LinziWebEditor.focus();
}
// 上移(forward)或下移(backward)一層
function zIndex(action){
var objReference = null;
var RangeType = LinziWebEditor.document.selection.type;
if (RangeType != "Control") return;
var selectedRange = LinziWebEditor.document.selection.createRange();
for (var i=0; i<selectedRange.length; i++){
objReference = selectedRange.item(i);
if (action=='forward'){
objReference.style.zIndex +=1;
}else{
objReference.style.zIndex -=1;
}
objReference.style.position='absolute';
}
//LinziWebEditor.content = false;
//LinziWebEditor.setActive();
}
// 改變編輯區高度
function sizeChange(size){
for (var i=0; i<parent.frames.length; i++){
if (parent.frames[i].document==self.document){
var obj=parent.frames[i].frameElement;
var height = parseInt(obj.offsetHeight);
if (height+size>=300){
obj.height=height+size;
}
break;
}
}
}
///插入站點占位符
function SiteBoxInsert()
{
LinziWebEditor.document.selection.createRange().pasteHTML("<table style=\"BORDER: #c9ddf0 1px dashed; float:left;\" width=SITEBOX><tr><TD vAlign=top>{$SiteName}</TD></tr></table>");
}
///插入站點名稱
function SiteNameInsert()
{
LinziWebEditor.document.selection.createRange().pasteHTML("{HL.Config.SiteName}");
}
///插入循環標記
function IndexIDInsert()
{
LinziWebEditor.document.selection.createRange().pasteHTML("{$IndexID}");
}
///插入站點連接
function SiteUrlInsert()
{
if (sCurrMode!="EDIT")
{
LinziWebEditor.document.selection.createRange().pasteHTML("{$SiteUrl}");
return;
}
if (LinziWebEditor.document.selection.type == "Control") {
var oControlRange = LinziWebEditor.document.selection.createRange();
if (oControlRange(0).tagName.toUpperCase() != "IMG") {
alert("鏈接只能是圖片或文本");
return;
}
oControlRange.execCommand("CreateLink",false,"{HL.Config.SiteUrl}");
return;
}else{
var oControlRange = LinziWebEditor.document.selection.createRange();
if(oControlRange.text.length>0)
{
oControlRange.execCommand("CreateLink",false,"{HL.Config.SiteUrl}");
return;
}
}
LinziWebEditor.document.selection.createRange().pasteHTML("{HL.Config.SiteUrl}");
}
///插入站點介紹
function SiteInforInsert()
{
LinziWebEditor.document.selection.createRange().pasteHTML("{HL.Config.Logo}");
}
///格式化轉換
function formatHtml(html)
{
var m_RegExp;
var Matches;
var newhtml;
newhtml = html;
if(sCurrMode == "EDIT")
{
newhtml = html.replace(/<SITEBOX>([\s\S]*?)<\/SITEBOX>/g,"<TABLE style=\"BORDER-RIGHT: #c9ddf0 1px dashed; BORDER-TOP: #c9ddf0 1px dashed; FLOAT: left; BORDER-LEFT: #c9ddf0 1px dashed; BORDER-BOTTOM: #c9ddf0 1px dashed;\" width=SITEBOX><TBODY><TR><TD vAlign=top>$1<\/TD><\/TR><\/TBODY><\/TABLE>");
}
else if(sCurrMode == "CODE")
{
newhtml = html.replace(/<TABLE(.*?)width=SITEBOX>([\s\S]*?)vAlign=top>([\s\S]*?)<\/TD><\/TR><\/TBODY><\/TABLE>/g,"<SITEBOX>$3<\/SITEBOX>");
}
return newhtml;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -