⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xcolumns.js

📁 一个免费的php的blog程序,很好用
💻 JS
📖 第 1 页 / 共 2 页
字号:
// **********************************************************//// Copyright 2002-2003 Sebastian Werner// http://sebastian-werner.net// // Licensed under://// Attribution-NonCommercial-ShareAlike License 1.0// by CreativeCommon (http://creativecommons.org)//// Key License Terms:// * Attribution. //   The licensor permits others to copy, distribute, //   display, and perform the work. In return, licensees //   must give the original author credit.// * Noncommercial. //   The licensor permits others to copy, distribute, //   display, and perform the work. In return, licensees //   may not use the work for commercial purposes -- unless //   they get the licensor's permission.// * Share Alike. //   The licensor permits others to distribute derivative //   works only under a license identical to the one that //   governs the licensor's work.//// for details visit:// http://creativecommons.org/licenses/by-nc-sa/1.0///// **********************************************************// **********************************************************//  COLUMNS// **********************************************************function xColumns(config){  this.__initproperties = function()  {    this.splitable = new xHash();      this.splitable.set("span", true)        this.splitable.set("table", true)    this.splitable.set("tbody", true)        this.splitable.set("td", true)    this.splitable.set("ul", true)    this.splitable.set("ol", true)    this.splitable.set("div", true)    this.topelements = new xHash();    this.topelements.set("h1", true);    this.topelements.set("h2", true);    this.topelements.set("h3", true);    this.topelements.set("h4", true);    this.topelements.set("h5", true);    this.topelements.set("h6", true);                                this.splittext = new xHash();    this.splittext.set("p", true);        // This holds all columns created later    this.columns = new Array();      // Hide original content    this.css.display = "none";     this.prozsum = 0;    this.prozcount = 0;        this.pos = 0;  }      // **********************************************  //  INTERNAL - FUNCTIONS  // **********************************************        // Internal ... to get a tagname of a given node  this.tagname = function(node)  {    return node.tagName.toLowerCase();  }    // Internal ... to get the handling for a adv-setting  this.flag = function(name, tag)  {    var value = eval("this." + name + ".get('" + tag + "')");    if (typeof(value) == "undefined") value = false;            return value;  }        // **********************************************  //  MAIN-NODE-SPLITTER - FUNCTION  // **********************************************        this.sub = function(parents)  {    var tag, backup, last, lastobj;    var splitable, topelem, splittext;        var current = parents[parents.length-1];    var childs = current.childNodes;        var last = -1;    var count = 0;    var i = 0;            // rebuild parents in helplayer    lastobj = this.rebuildParents(parents)    // Moving childs to columns         for (i=0; i<childs.length; i++)    {      // only handle node if type is equal to tag      if (childs[i].nodeType != 1) continue;            // increment counter      count++;      // get tagname      tag = this.tagname(childs[i]);            // advanced handling data      splitable = this.flag("splitable", tag);      splittext = this.flag("splittext", tag);      topelem = this.flag("topelements", tag)       topelem = last == -1 ? topelem : topelem && !this.flag("topelements", this.tagname(childs[last]));            // if this is a topelement      if (topelem && childs.length > (i+1))      {        // first try to copy full node with all childs...        lastobj.appendChild(childs[i].cloneNode(true));        // find next child and append        var foundhead=false;        for (var j=i+1; j<childs.length; j++)          if (childs[j].nodeType == 1)          {            foundhead=true;            break;          }        if (foundhead)          lastobj.appendChild(childs[j].cloneNode(true));      }      else      {              // first try to copy full node with all childs        lastobj.appendChild(childs[i].cloneNode(true));        }        // check if the helpframe is ok in size              if (this.recalcHeight() > this.config.get("realheight"))      {        if (splitable)        {          // remove the whole created node-set          this.removeLastChild(1)                    // build new parents array          var data = new Array();          // copy parents from this call                 for (var n=0; n<parents.length; n++)            data[n] = parents[n];                              // and add current child to list          data[data.length] = childs[i]                    // call myself with new params          this.sub(data);                    // goto next child          continue;        }        else if (splittext)        {          // holds nodes for the next column          var remain = new Array();          var allchilds = lastobj.lastChild.childNodes;                    var text, words, cache, rest, tagobj;                    // revert loop through the childs                     for (var k=allchilds.length - 1; k>=0; k--)          {            // if it is a real subtag            if (allchilds[k].nodeType == 1)            {              // copy to remaining list              remain[remain.length] = allchilds[k].cloneNode(true);              lastobj.lastChild.removeChild(allchilds[k]);                                  if (this.recalcHeight() <= this.config.get("realheight")) break;            }            // or if it is normal text            else if(allchilds[k].nodeType == 3)            {              // some cache variables              cache = allchilds[k].nodeValue              words = cache.split(" ");                            // first check if it's small enough if all text will be removed              allchilds[k].nodeValue = "";              if (this.recalcHeight() > this.config.get("realheight"))              {                // copy to remaining list                remain[remain.length] = document.createTextNode(cache);                lastobj.lastChild.removeChild(allchilds[k]);               }              else              {                // restore node data                allchilds[k].nodeValue = cache;                rest = "";                              // revert loop through words                for (var l=words.length-1; l>=0; l--)                {                  // caching string                  rest = words[l] + " " + rest;                                    // build new text string                  text = lastobj.lastChild.lastChild.nodeValue;                  text = text.substr(0, text.length-words[l].length-1)                                   // replacing nodeValue                  lastobj.lastChild.lastChild.nodeValue = text;                                  if (this.recalcHeight() <= this.config.get("realheight"))                    break;                               }                                // put string to remaining list                remain[remain.length] = document.createTextNode(rest);                              if (this.recalcHeight() <= this.config.get("realheight"))                  break;              }             }                        }                              if (remain.length > 0)          {            // before delete content add values to the stat            this.updateStat();            this.publishHelpLayer();            this.clearHelpLayer();                                       // rebuild parents in helplayer            lastobj = this.rebuildParents(parents)                            // creating parent-tag                       tagobj = document.createElement(tag);                        // revert loop through cache to restore childs            for (var m=remain.length-1; m>=0; m--)              tagobj.appendChild(remain[m]);                          // append temporary child to parent            lastobj.appendChild(tagobj);          }        }                else        {          // remove last child                    this.removeLastChild(parents.length);                              // if a topelement we need to remove to elements          if (topelem)            this.removeLastChild(parents.length);                          // before delete content add values to the stat          this.updateStat();          this.publishHelpLayer();          this.clearHelpLayer();                    // rebuild parents in helplayer          lastobj = this.rebuildParents(parents)                              // copy full node with all childs to the fresh helplayer          lastobj.appendChild(childs[i].cloneNode(true));                    // Setze Klasse f黵 erstes Element in Spalte          lastobj.lastChild.className = this.config.get("topclass");                      // is it always to big?          if (this.recalcHeight() > this.config.get("realheight"))          {            _debug.warn("Element ist zu gross!");            // goto next child            continue;                    }          }      }      else if (topelem)      {        // remove last child                  this.removeLastChild(parents.length);      }            // before goto next, store current position      last = i;    }        // If this is the end:     // Clear help layer and publish last part of the document     // and don't create a new column :)    if (parents.length == 1)    {      this.publishHelpLayer(false);      this.clearHelpLayer();    }    }      // **********************************************  //  RENDER - FUNCTIONS  // **********************************************        // put structure of parents to columns  this.rebuildParents = function(parents)  {    var last, lastobj, i;    // Parents rekonstruieren, dabei den Allerersten    // nicht beachten (das ist der source-frame :))    last = "this.help.obj"    for (i=1; i<parents.length; i++)    {      lastobj = eval(last);      lastobj.appendChild(parents[i].cloneNode(false))      last += ".lastChild";     }        lastobj = eval(last);        return lastobj;  }      // remove last child by given length of parents  this.removeLastChild = function(plength)  {    var last, lastobj, i;    last = "this.help.obj";    for (i=0; i<(plength-1); i++)      last += ".lastChild";               lastobj = eval(last);    lastobj.removeChild(lastobj.lastChild);  }    // this updates the internal stats  this.updateStat = function()  {    if (this.config.get("useStats"))    {      var cheight = this.recalcHeight();            this.prozsum += ((cheight / this.config.get("realheight")) * 100);      this.prozcount ++;      this.prozmiddle = Math.round(this.prozsum / this.prozcount);    }    }     // publish to new column  this.publishHelpLayer = function(param)  {    // Inhalt publizieren    this.columns[this.columns.length-1].obj.innerHTML = this.help.obj.innerHTML;    if (typeof(param) == "undefined" || param)       this.createColumn();      }      // remove all content from the helplayer  this.clearHelpLayer = function()  {    var backup;        // reset old data from help layer    this.help.removeChilds();  }

⌨️ 快捷键说明

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