emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* For your consideration: Extending org-info-js with additional hooks
@ 2022-12-12 18:33 David O'Toole
  2022-12-13 10:00 ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: David O'Toole @ 2022-12-12 18:33 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 783 bytes --]

Greetings, Orgmoders.

After some discussion with Yantar on IRC, I humbly submit the attached diff
for your consideration.

It adds new hooks to org-info-js to allow the following: 1. inserting
page-specific HTML into each OrgInfo header, and 2. calling a custom
JavaScript function to run after any page navigation button/link is
clicked. I have used these hooks to implement Org-fleuron, a custom config
with nice navigation buttons, a greeting balloon, and embedded theme/fonts.
You can find out more about org-fleuron here:
https://davidotoole.info/fleuron.html?#org5dc18bc and the page was made
with the setup.

I also corrected some of the English messages displayed by org-info-js.

I hope you will find this useful.

Please let me know if you have any questions or comments!

[-- Attachment #1.2: Type: text/html, Size: 1008 bytes --]

[-- Attachment #2: org-info-src.js.diff --]
[-- Type: text/x-patch, Size: 7951 bytes --]

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-12 11:48:20.471441625 -0500
@@ -28,30 +28,57 @@
  * </script>
  *
  *
- * 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 <deeteeoh1138@gmail.com>
+ */
+
+\f
+
+
+/**
+ * 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) {};
+
 
 \f
 
 
 /**
  * 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)
@@ -904,14 +931,16 @@
     for(var i = 0; i < this.SECS.length; ++i)
     {
       this.SECS[i].IDX = i;
-      var html = '<table class="org-info-js_info-navigation" width="100%" border="0" style="border-bottom:1px solid black;">'
-        +'<tr><td colspan="3" style="text-align:left;border-style:none;vertical-align:bottom;">'
-        +'<span style="float:left;display:inline;text-align:left;">'
-        +'Top: <a accesskey="t" href="javascript:org_html_manager.navigateTo(0);">'+index_name+'</a></span>'
-        +'<span style="float:right;display:inline;text-align:right;font-size:70%;">'
-        + this.LINKS
-        +'<a accesskey="m" href="javascript:org_html_manager.toggleView('+i+');">toggle view</a></span>'
-        +'</td></tr><tr><td style="text-align:left;border-style:none;vertical-align:bottom;width:22%">';
+        var html =
+            OrgInfoPageInsertFunction(i)
+            + '<table class="org-info-js_info-navigation" width="100%" border="0" style="border-bottom:1px solid black;">'
+            +'<tr><td colspan="3" style="text-align:left;border-style:none;vertical-align:bottom;">'
+            + '<span style="float:left;display:inline;text-align:left;">'
+            + 'Top: <a accesskey="t" href="javascript:org_html_manager.navigateTo(0);">'+index_name+'</a></span>'
+            + '<span style="float:right;display:inline;text-align:right;font-size:70%;">'
+            +  this.LINKS
+            + '<a accesskey="m" href="javascript:org_html_manager.toggleView('+i+');">toggle view</a></span>'
+            + '</td></tr><tr><td style="text-align:left;border-style:none;vertical-align:bottom;width:22%">';
 
       if(i>0)
         html += '<a accesskey="p" href="'+this.SECS[i-1].L
@@ -930,10 +959,10 @@
       if(i>0 && this.SECS[i].PARENT.PARENT) // != this.ROOT)
         html += '<a href="'+this.SECS[i].PARENT.L
         +'" title="Go to: '+this.removeTags(this.SECS[i].PARENT.HEADING.innerHTML)+'">'
-        +'<span style="font-variant:small-caps;font-style:italic;">'
+        +'<span class="org-info-js_parent-heading" style="font-variant:small-caps;font-style:italic;">'
         +this.SECS[i].PARENT.HEADING.innerHTML+'</span></a>';
       else
-        html += '<span style="font-variant:small-caps;font-style:italic;">'+this.SECS[i].HEADING.innerHTML+'</span>';
+        html += '<span class="org-info-js_parent-heading" style="font-variant:small-caps;font-style:italic;">'+this.SECS[i].HEADING.innerHTML+'</span>';
 
       // Right:
       html += '</td><td style="text-align:right;vertical-align:bottom;border-style:none;width:22%">';
@@ -1321,7 +1350,7 @@
     var T = this;
     var i = T.NODE.IDX + 1;
     if(i<T.SECS.length) T.navigateTo(i);
-    else T.warn("Already last section.");
+    else T.warn("This is already the last section.");
   },
 
   previousSection: function()
@@ -1329,7 +1358,7 @@
     var t = this;
     var i = t.NODE.IDX;
     if(i>0) t.navigateTo(i-1);
-    else t.warn("Already first section.");
+    else t.warn("This is already the first section.");
   },
 
 
@@ -1345,6 +1374,8 @@
     if(t.VIEW == t.SLIDE_VIEW) t.adjustSlide(sec);
     t.pushHistory(sec, t.NODE.IDX);
     t.showSection(sec);
+
+    OrgInfoAfterNavigateFunction();
   },
 
 
@@ -1386,7 +1417,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 +1437,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.");
       }
     }
   },
@@ -1584,7 +1615,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 +1631,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 +1654,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?")) {
@@ -2291,3 +2322,4 @@
 {
   org_html_manager.init();
 }
+

Diff finished.  Mon Dec 12 11:51:26 2022

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-08-05  9:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-12 18:33 For your consideration: Extending org-info-js with additional hooks David O'Toole
2022-12-13 10:00 ` Ihor Radchenko
2022-12-13 16:32   ` David O'Toole
2022-12-13 17:20     ` David O'Toole
2022-12-14 15:40       ` David O'Toole
2022-12-29 15:38   ` Bastien Guerry
2022-12-29 17:32     ` David O'Toole
2023-08-05  9:25       ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).