?? easyeditor.js
字號:
?// JScript 文件
/*
EasyEditor1.0
//these code(for a example) was added by EasyEditor's Server Part
*/
/*
Impot Common script
*/
function a$(iterable){
if (!iterable) return [];
if (iterable.toArray) {
return iterable.toArray();
} else {
var results = [];
for (var i = 0; i < iterable.length; i++)
results.push(iterable[i]);
return results;
}
}
Function.prototype.bind = function() {
var __method = this, args = a$(arguments), object = args.shift();
return function() {
return __method.apply(object, args.concat(a$(arguments)));
}
}
function createElement(html,parentEle)
{
if(parentEle == null)
{
parentEle = document.body;
}else{
if(typeof(parentEle) != "object")
return null;
}
var obj = document.createElement(html);
parentEle.appendChild(obj);
return obj;
}
function addJS(jsfile)
{
var head = document.getElementsByTagName('HEAD').item(0);
var script = document.createElement('SCRIPT');
script.src = jsfile;
script.type = "text/javascript";
head.appendChild(script);
}
function addCSS(cssfile){
var head = document.getElementsByTagName('HEAD').item(0);
var style = document.createElement('link');
style.href = cssfile;
style.rel = 'stylesheet'
style.type = 'text/css';
head.appendChild(style);
}
/* Common ends here */
// JScript File
//******************************tools********************************
/*
Easy Editor 1.0
*/
function eeEditor(editorID,ResourcePath,Themes)
{
//addJS(ResourcePath+"Scripts/ToolBar.js");
//addJS(ResourcePath+"Scripts/UI.js");
this._Edit = document.all(editorID);
this._EditID = editorID;
this._ResourcePath = ResourcePath;
this._Themes=Themes;
this._ContentField = null;
this.toolBarDiv = document.all(editorID+"_toolBar");
this.toolBar = new ToolBar(this);
this.footBarDiv = document.all(editorID+"_footBar");
this.footBar = new footBar(this);
this.editor = document.frames[(editorID+"_iframe")];
this.editorIframe = document.all(editorID+"_iframe");
this.editorDiv = document.all(editorID+"_div");
var strHtml = '<html><style>body{font-size:14px;line-height: 20px; margin:2px;}\ntd, a{color:#0000FF; font-size:14px;}</style><body> </body></html>';
this.editor.document.open();
this.editor.document.write(strHtml);
this.editor.document.close();
this.editor.document.designMode="On";
this.editor.focus();
this.SaveText = function(){
this._ContentField.value =this.getContent();
};
this.LoadText= function(){
this._ContentField = document.all(this._EditID+"_content");
this.setContent(this._ContentField.value);
}
this.getContent = function ()
{
return this.correctUrl(this.editor.document.body.innerHTML);
}
this.setContent = function (str)
{
this.editor.document.body.innerHTML=str;
}
this.correctUrl = function (cont)
{
var regExp;
regExp = /<a([^>]*) href\s*=\s*([^\s|>]*)([^>]*)/gi
cont = cont.replace(regExp, "<a href=$2 target=\"_blank\"");
regExp = /<a([^>]*)><\/a>/gi
cont = cont.replace(regExp, "");
return cont;
}
/*
mod = 1:html
mod = 0:text
*/
this.SetMod =function (mod)
{
if(mod==1)
{
var cont=this.editor.document.body.innerHTML;
this.editor.document.body.innerText=cont;
this.toolBarDiv.style.display = "none";
}
else {
var cont=this.editor.document.body.innerText;
this.editor.document.body.innerHTML=cont;
this.toolBarDiv.style.display = "";
}
this.editor.focus();
}
/*
*/
this.insertText = function (text)
{
this.editor.focus();
var caretPos= this.editor.document.selection.createRange().duplicate();
var l = caretPos.text.length; //記錄選種文本長度
caretPos.text = text + caretPos.text;
//向后移動光標 -文本長度
caretPos.moveEnd("character",0-l);
//恢復光標
caretPos.collapse(false);
caretPos.select();
}
/*
*/
this.insertHTML =function (html)
{
this.editor.focus();
var caretPos= this.editor.document.selection.createRange();
caretPos.pasteHTML(html);
}
/*
*/
this.fitSize =function ()
{
var h = this.editorDiv.style.pixelHeight - this.toolBarDiv.offsetHeight - this.footBarDiv.offsetHeight;
this.editorIframe.style.pixelHeight = h;
}
/*
實現TAB功能
*/
this.doKeyDown = function ()
{
var oEvent=this.editor.event;
var code = oEvent.keyCode;
if(code == 9)
{
this.insertText("\t");
oEvent.cancelBubble = false;
oEvent.returnValue = false;
return false;
}
}
this.oEvent = function ()
{
return this.editor.event;
}
this.oElement = function ()
{
if(oEvent())
{
if(oEvent().srcElement)
{
return oEvent().srcElement;
}
}
this.editor.focus();
return this.editor.document.selection.createRange().parentElement();
}
this.execCommand = function(cmd,t,v)
{
var sText = this.editor.document.selection.createRange();
if(sText){
if(v)
this.editor.document.execCommand(cmd, "false", v);
else
this.editor.document.execCommand(cmd);
}
}
this.WordCount = function(){
var iSumWords = 0;
var rng = this.editor.document.body.createTextRange();
rng.collapse(true);
while(rng.move("word",1)) {
iSumWords++;
}
alert("大約 " + iSumWords + " 字");
}
//set event handlers
document.all("form1").attachEvent("onsubmit",this.SaveText.bind(this));
this.editor.attachEvent("onload",this.LoadText.bind(this));
this.editor.document.attachEvent("onkeydown",this.doKeyDown.bind(this));
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -