diff -u /home/dto/Downloads/org-info-src.js /home/dto/notebook/org-info-src.js --- /home/dto/Downloads/org-info-src.js 2022-12-10 11:47:20.086746072 -0500 +++ /home/dto/notebook/org-info-src.js 2022-12-24 10:18:38.010260115 -0500 @@ -28,30 +28,87 @@ * * * - * The script is now roughly devided in sections by form-feeds. Editors can - * move section wise using the common emacs commands for this purpos ('C-x ]' - * and 'C-x ]'). + * The script is now roughly divided into sections by + * form-feeds. Editors can move section-wise using the common emacs + * commands for this purpose ('C-x ]' and 'C-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. + * 2. Content hooks + * 3. Everything around =OrgNodes=. + * 4. =org_html_manager= constructor and setup. + * 5. =org_html_manager= folding and view related stuff. + * 6. =org_html_manager= history related methods. + * 7. =org_html_manager= minibuffer handling. + * 8. =org_html_manager= user input. + * 9. =org_html_manager= search functonality. + * 10. =org_html_manager= misc. + * 11. Global functions. */ +/** + * This program has been modified from its original version to add + * hooks for per-page HTML injection and per-click navigation event + * response. A patch is being submitted to upstream. + * - David T. O'Toole + */ +var OrgInfoCurrentSectionNumber = 0; + +/** + * The following variable should hold a function which accepts an + * integer pageNumber and should return HTML to be inserted in the + * OrgInfo header of each page. + */ +var OrgInfoPageInsertFunction = function(pageNumber) {return '';}; + + +/** + * The following variable should hold a function which accepts an + * integer pageNumber and performs a user-defined action after the + * page has flipped. + * + */ +var OrgInfoAfterNavigateFunction = function(pageNumber) {}; + +/** + * The following variable should hold a function which performs a + * user-defined action after Plain View has been activated. + * + */ + +var OrgInfoAfterPlainViewFunction = function() {}; + +/** + * The following variable should hold a function which performs a + * user-defined action after Info View has been activated. + * + */ + +var OrgInfoAfterInfoViewFunction = function() {}; + +/** + * The following variable should hold a function which performs a + * user-defined action after the document is ready. + */ + +var OrgInfoAfterReadyFunction = function() {}; + +/** + * Custom keybindings for Z, K, and Y. + */ +var OrgInfoUserKeyZ = function () {}; +var OrgInfoUserKeyK = function () {}; +var OrgInfoUserKeyY = function () {}; + + + /** * Creates a new OrgNode. - * An OrgOutline stores some refs to its assoziated node in the document tree + * An OrgOutline stores some refs to its associated node in the document tree * along with some additional properties. */ function OrgNode ( _div, _heading, _link, _depth, _parent, _base_id, _toc_anchor) @@ -87,8 +144,17 @@ var fid = _base_id.substring(4); folder = document.getElementById("text-"+fid); // try old schema } - if(null != folder) - t.FOLDER = folder; + + if(null == folder) + { + if (null != t.BASE_ID) { + var did = OrgInfoRecoverSectionID(document.getElementById(t.BASE_ID).textContent); + folder = document.getElementById("text-"+did); + } + } + + if(null != folder) + { t.FOLDER = folder;} t.isTargetFor = new Object(); t.isTargetFor['#' + t.BASE_ID] = 2; @@ -434,7 +500,7 @@ var v = sets[i].substring(pos+1); var k = sets[i].substring(0, pos); switch(k) { - // Explicitely allow overwrites. + // Explicitly allow overwrites. // Fall through: case 'TOC': case 'TOC_DEPTH': @@ -634,6 +700,7 @@ } t.HOOKS.run_hooks = true; // Unblock all hooks. t.runHooks('onReady', this.NODE); + OrgInfoAfterReadyFunction(); }, @@ -734,7 +801,7 @@ t.cutToc(theIndex, 1); } - // Move the title into the first visible section. + // Move the title into the first visible section.urrentpage // TODO: show title above everything if FIXED_TOC !!! t.TITLE = document.getElementsByClassName("title")[0]; if(t.INNER_TITLE && !t.FIXED_TOC && t.VIEW != t.SLIDE_VIEW) { @@ -754,7 +821,7 @@ t.BODY.insertBefore(t.WINDOW, t.NODE.DIV); - return true; + return true; }, /** @@ -904,14 +971,16 @@ for(var i = 0; i < this.SECS.length; ++i) { this.SECS[i].IDX = i; - var html = '' - +'
' - +'' - +'Top: '+index_name+'' - +'' - + this.LINKS - +'toggle view' - +'
'; + var html = + OrgInfoPageInsertFunction(i) + + '' + +'
' + + '' + + 'Top: '+index_name+'' + + '' + + this.LINKS + + 'toggle view' + + '
'; if(i>0) html += '' - +'' + +'' +this.SECS[i].PARENT.HEADING.innerHTML+''; else - html += ''+this.SECS[i].HEADING.innerHTML+''; + html += ''+this.SECS[i].HEADING.innerHTML+''; // Right: html += ''; @@ -1136,7 +1205,9 @@ t.showSection(sec); if(t.POSTAMBLE) OrgNode.showElement(t.POSTAMBLE); if(t.NODE.IDX == 0) window.scrollTo(0, 0); - else t.NODE.DIV.scrollIntoView(true); + else t.NODE.DIV.scrollIntoView(true); + // call hook + OrgInfoAfterPlainViewFunction(); }, infoView: function (sec, skip_show_section) @@ -1157,6 +1228,8 @@ if(!skip_show_section) t.showSection(sec); window.scrollTo(0, 0); + // call hook + OrgInfoAfterInfoViewFunction(); }, slideView: function (sec, skip_show_section) @@ -1259,7 +1332,21 @@ t.NODE = t.SECS[section]; OrgNode.showElement(t.NODE.BUTTONS); }, - + + unfoldAll: function () + { + var t = this; + if(t.ROOT.DIRTY) { + t.ROOT.STATE = OrgNode.STATE_UNFOLDED; + } + for(var i=0;i0) t.navigateTo(i-1); - else t.warn("Already first section."); + else t.warn("This is already the first section."); }, @@ -1345,6 +1432,8 @@ if(t.VIEW == t.SLIDE_VIEW) t.adjustSlide(sec); t.pushHistory(sec, t.NODE.IDX); t.showSection(sec); + OrgInfoCurrentSectionNumber = sec; + OrgInfoAfterNavigateFunction(); }, @@ -1386,7 +1475,7 @@ else if(t.HFO && history.length) history.forward(); else { t.HFO=1; - t.warn("History: No where to foreward go from here. Any key and `B' to move to next file in history."); + t.warn("History: There is nowhere to go forward to from here. Press `B' to move to the next page in your browser history."); } } else { if(t.HISTORY[t.HIST_INDEX - 1]) { @@ -1406,7 +1495,7 @@ else if(t.HBO && history.length) history.back(); else { t.HBO=1; - t.warn("History: No where to back go from here. Any key and `b' to move to previous file in history."); + t.warn("History: Nowhere to go back to from here. Press `b' to move to the previous page in your browser history."); } } }, @@ -1549,18 +1638,23 @@ if (1 == s.length) // one char wide commands { - if ('b' == s) { + if ('z' == s) { + OrgInfoUserKeyZ(); + } + else if ('k' == s) { + OrgInfoUserKeyK(); + } + else if ('y' == s) { + OrgInfoUserKeyY(); + } + else if ('b' == s) { t.popHistory(); } else if ('B' == s) { t.popHistory(true); } else if ('c' == s) { - t.removeSearchHighlight(); - if(t.VIEW == t.INFO_VIEW || t.VIEW == t.SLIDE_VIEW) { - // redisplay in info view mode: - t.showSection(t.NODE.IDX); - } + OrgInfoDoRemoveSearchHighlight(this); } else if ('i' == s) { if(! t.FIXED_TOC) { @@ -1584,7 +1678,7 @@ else if(t.NODE.IDX < t.SECS.length - 1) { t.navigateTo(t.NODE.IDX + 1); } else { - t.warn("Already last section."); + t.warn("This is already the last section."); return; // rely on what happends if messaging } } @@ -1600,14 +1694,14 @@ ++idx; } } - t.warn("No next sibling."); + t.warn("There is no next sibling."); return; // rely on what happends if messaging } else if ('p' == s) { if(t.NODE.IDX > 0) { t.navigateTo(t.NODE.IDX - 1); } else { - t.warn("Already first section."); + t.warn("This is already the first section."); return; // rely on what happends if messaging } } @@ -1623,7 +1717,7 @@ --idx; } } - t.warn("No previous sibling."); + t.warn("There is no previous sibling."); } else if ('q' == s) { if(window.confirm("Really close this file?")) { @@ -1811,56 +1905,15 @@ } else if(command == 's') { // search - if("" == result) return false; - if(t.SEARCH_HIGHLIGHT_ON) t.removeSearchHighlight(); - var restore = t.OCCUR; - var plus = 0; - if(result == t.OCCUR) plus++; - t.OCCUR = result; - t.makeSearchRegexp(); - for(var i = t.NODE.IDX + plus; i < t.SECS.length; ++i) { - if(t.searchTextInOrgNode(i)) { - t.OCCUR = result; - t.hideConsole(); - t.navigateTo(t.SECS[i].IDX); - return; - } - } - t.warn("Search forwards: text not found.", false, t.OCCUR); - t.OCCUR = restore; - return; + OrgInfoDoSearch(this, result); } else if(command == 'S') { // repeat search - for(var i = t.NODE.IDX + 1; i < t.SECS.length; ++i) { - if(t.searchTextInOrgNode(i)) { - t.hideConsole(); - t.navigateTo(t.SECS[i].IDX); - return; - } - } - t.warn("Search forwards: text not found.", false, t.OCCUR); - return; + OrgInfoDoRepeatSearch(this); } else if(command == 'r') { // search backwards - if("" == result) return false; - if(t.SEARCH_HIGHLIGHT_ON) t.removeSearchHighlight(); - var restore = t.OCCUR; - t.OCCUR = result; - var plus = 0; - if(result == t.OCCUR) plus++; - t.makeSearchRegexp(); - for(var i = t.NODE.IDX - plus; i > -1; --i) { - if(t.searchTextInOrgNode(i)) { - t.hideConsole(); - t.navigateTo(t.SECS[i].IDX); - return; - } - } - t.warn("Search backwards: text not found.", false, t.OCCUR); - t.OCCUR = restore; - return; + OrgInfoDoSearchBackward(this, result); } else if(command == 'R') { // repeat search backwards @@ -2004,7 +2057,13 @@ t.SECS[i].HAS_HIGHLIGHT = true; t.SEARCH_HIGHLIGHT_ON = true; } - if(t.SEARCH_REGEX.test(t.SECS[i].FOLDER.innerHTML)) { + + if (t.SECS[i].FOLDER == null) + { + ret = false; + } + + else if (t.SEARCH_REGEX.test(t.SECS[i].FOLDER.innerHTML)) { ret = true; t.setSearchHighlight(t.SECS[i].FOLDER); t.SECS[i].HAS_HIGHLIGHT = true; @@ -2031,10 +2090,11 @@ var tmp = t.SECS[i].HEADING.innerHTML; t.SECS[i].HEADING.innerHTML = tmp.replace(t.SEARCH_HL_REGEX, '$2'); } + if (null != t.SECS[i].FOLDER) { while(t.SEARCH_HL_REGEX.test(t.SECS[i].FOLDER.innerHTML)) { var tmp = t.SECS[i].FOLDER.innerHTML; t.SECS[i].FOLDER.innerHTML = tmp.replace(t.SEARCH_HL_REGEX, '$2'); - } + }} t.SECS[i].HAS_HIGHLIGHT = false; } } @@ -2262,9 +2322,12 @@ +var OrgInfoDisableKeybindings = null; function OrgHtmlManagerKeyEvent (e) { + if (OrgInfoDisableKeybindings == true) return; + var c; if (!e) e = window.event; if (e.which) c = e.which; @@ -2291,3 +2354,81 @@ { org_html_manager.init(); } + + + +function OrgInfoDoSearch (t, result) +{ + if("" == result) return false; + if(t.SEARCH_HIGHLIGHT_ON) t.removeSearchHighlight(); + var restore = t.OCCUR; + var plus = 0; + if(result == t.OCCUR) plus++; + t.OCCUR = result; + t.makeSearchRegexp(); + for(var i = t.NODE.IDX + plus; i < t.SECS.length; ++i) { + if(t.searchTextInOrgNode(i)) { + t.OCCUR = result; + t.hideConsole(); + t.navigateTo(t.SECS[i].IDX); + return; + } + } + t.warn("Search forwards: text not found.", false, t.OCCUR); + t.OCCUR = restore; + return; +} + +function OrgInfoDoRepeatSearch (t) +{ + for(var i = t.NODE.IDX + 1; i < t.SECS.length; ++i) { + if(t.searchTextInOrgNode(i)) { + t.hideConsole(); + t.navigateTo(t.SECS[i].IDX); + return; + } + } + t.warn("Search forwards: text not found.", false, t.OCCUR); + return; +} + +function OrgInfoRecoverSectionID(heading) { + var firstChar = heading[0]; + if (firstChar >= '0' && firstChar <= '9') { + var strings = heading.split(' '); + var id = strings[0].replaceAll('.', '-'); + var len = id.length; + var idf = id.slice(0, len-1); + return idf; + } + return null; +} + +function OrgInfoDoSearchBackward(t, result) { + if("" == result) return false; + if(t.SEARCH_HIGHLIGHT_ON) t.removeSearchHighlight(); + var restore = t.OCCUR; + t.OCCUR = result; + var plus = 0; + if(result == t.OCCUR) plus++; + t.makeSearchRegexp(); + for(var i = t.NODE.IDX - plus; i > -1; --i) { + if(t.searchTextInOrgNode(i)) { + t.hideConsole(); + t.navigateTo(t.SECS[i].IDX); + return; + } + } + t.warn("Search backwards: text not found.", false, t.OCCUR); + t.OCCUR = restore; + return; +} + +function OrgInfoDoRemoveSearchHighlight(t) { + t.removeSearchHighlight(); + if(t.VIEW == t.INFO_VIEW || t.VIEW == t.SLIDE_VIEW) { + // redisplay in info view mode: + t.showSection(t.NODE.IDX); + } +} + Diff finished. Sat Dec 24 10:18:46 2022