expander.js

来自「Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是」· JavaScript 代码 · 共 88 行

JS
88
字号


function Expander(editor, extra, delay) {
   // Default to 50 extra pixels in height and 90 milliseconds timeout
   var e = parseInt(extra);
   var d = parseInt(delay);
   this._extra = (((e < 50) || isNaN(e)) ? 50 : e);
   this._delay = (((d < 90) || isNaN(d)) ? 90 : d);
   this._editor = editor;
};

Expander._pluginInfo = {
         name          : "Expander",
         version       : "1.0",
         developer     : "Pier Fumagalli",
         developer_url : "http://www.apache.org/~pier/",
         license       : "Apache 2.0",
         description   : "Forces HTMLArea to expand and contract depending on its contents"
};

Expander.prototype.onGenerate = function () {
   this.arrangeSize();
}

Expander.prototype.onKeyPress = function (event) {

   // We arrange the size after a timeout to give time to
   // the browser to process the keypress event fully.
   var inst = this;
   setTimeout(function () { inst.arrangeSize() }, this._delay);

   //DEBUG
   //setTimeout(function () { notify.value = inst._editor._iframe.contentWindow.document.body.innerHTML; }, 100);
}

Expander.prototype.arrangeSize = function (param) {
   var w = (HTMLArea.is_ie ? h = this._editor._doc.body.scrollWidth: w = this._editor._doc.body.offsetWidth);
   var h = (HTMLArea.is_ie ? h = this._editor._doc.body.scrollHeight: h = this._editor._doc.body.offsetHeight);
   
   var fullScr = this._editor._fullscreen_on;
   
    var x,y;
    if (window.innerHeight) // all except Explorer
    {
      x = window.innerWidth;
      y = window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
      // Explorer 6 Strict Mode
    {
      x = document.documentElement.clientWidth;
      y = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
      x = document.body.clientWidth;
      y = document.body.clientHeight;
    }
   
   
   var configHeight = this._editor.config.height;
   if(configHeight!=null && configHeight!="auto")
   {
     configHeight = configHeight.substr(0,configHeight.length-2);
   }

   var configWidth = this._editor.config.width;
   if(configWidth!=null && configWidth!="auto")
   {
     configWidth = configWidth.substr(0,configWidth.length-2);
   }
   if(configWidth!="auto" && w < configWidth)
   {
     w = configWidth;
   } 
   if(configHeight!="auto" && h < configHeight)
   { 
     h = configHeight;
   } 
   var myHeight = (parseInt(h) + parseInt(this._extra));
   if(!fullScr) {   	
   	this._editor.sizeEditor(w+"px", myHeight+"px" , true, true);
   }
   else {
   	this._editor.sizeEditor((x-10)+"px", (y-10)+"px" , true, true);
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?