/** * @file * org-info.js, v.0.0.7.3 * * @author Sebastian Rose, Hannover, Germany - sebastian_rose at gmx dot de * * * This software is subject to the GNU General Public Licens version 2: * see: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Usage: * * Include this scipt into the Header of your HTML-exported org files by * customizing the variable org-export-html-style (TODO: add file local export * Options here). * You will also need this here somewhere in the HTML-page: * * * * * * The script is now roughly devided in sections by form-feeds. Editors can * move section wise using the common emacs commands for this purpos ('M-x ]' * and 'M-x ]'). * * The sections are: * 1. This comment block. * 2. Everything around =OrgNodes=. * 3. =org_html_manager= constructor and setup. * 4. =org_html_manager= folding and view related stuff. * 5. =org_html_manager= history related methods. * 6. =org_html_manager= minibuffer handling. * 7. =org_html_manager= user input. * 8. =org_html_manager= search functonality. * 9. =org_html_manager= misc. * 10. Global functions. */ /** * Creates a new OrgNode. * An OrgOutline stores some refs to its assoziated node in the document tree * along with some additional properties. */ function OrgNode ( _div, _heading, _link, _depth, _parent, _base_id) { this.div = _div; this.base_id = _base_id; this.idx = -1; // The index in OrgHtmlManager::SECS[] this.heading = _heading; this.link = _link; this.hasHighlight = false; // Node highlighted (search) this.parent = _parent; this.durty = false; // Node is durty, when children get // folded seperatly. this.state = OrgNode.STATE_FOLDED; this.depth = _depth; // The Rootelement will have // the depth 0. All other // Nodes get the depth from // their h-level (h1, h2...) this.folder = null; this.children = new Array(); this.info_navigation = ""; this.buttons = null; if(null != this.parent) { this.parent.addChild(this); this.hide(); } var folder = document.getElementById("text-"+this.base_id); if(null != folder) { folder.isOrgNodeFolder = true; this.folder = folder; } } // static variables OrgNode.STATE_FOLDED = 0; OrgNode.STATE_HEADLINES = 1; OrgNode.STATE_UNFOLDED = 2; // // static functions // OrgNode.hideElement = function (e) { if(e) { e.style.display = 'none'; e.style.visibility = 'hidden'; } }; OrgNode.showElement = function (e) { if(e) { e.style.display = 'block'; e.style.visibility = 'visible'; } }; OrgNode.toggleElement = function (e) { if(e.style.display == 'none') { e.style.display = 'block'; e.style.visibility = 'visible'; } else { e.style.display = 'none'; e.style.visibility = 'hidden'; } }; /** * Find the OrgNode containing a DOM-text-node. * @param dom The text node. * @param org The OrgNode containing the OrgNode in question. */ OrgNode.textNodeToIdx = function (dom, org) { while(dom.nodeType != 1 /* IE has no Node.ELEMENT_NODE... */ || -1 == dom.attributes["id"].value.indexOf("outline-container-")) { dom = dom.parentNode; } var base_id = dom.attributes["id"].value.substr(18); return OrgNode.idxForBaseId(base_id, org); }; /** * Find an OrgNode with base_id inside an OrgNode and return it's idx. * @param base The base_id. * @param org The OrgNode. */ OrgNode.idxForBaseId = function(base, org) { if(org.base_id == base) return org; for(var i = 0; i < org.children.length; ++i) { var o = OrgNode.idxForBaseId(idx, org.children[i]); if(null != o) return o; } return null; }; // // member functions // OrgNode.prototype.addChild = function (child) { this.children.push(child); return this.parent; }; OrgNode.prototype.getParent = function () { return this.parent; }; // // OrgNode methods for paging (info mode) // OrgNode.prototype.hide = function () { OrgNode.hideElement(this.div); if(this.parent) this.parent.hide(); }; OrgNode.prototype.show = function () { OrgNode.showElement(this.div); if(this.depth > 2) this.parent.show(); }; OrgNode.prototype.showAllChildren = function () { for(var i=0;i