emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Sebastian Rose <sebastian_rose@gmx.de>
To: Benny Simonsen <benny@slbs.dk>
Cc: emacs-orgmode@gnu.org
Subject: Re: Re: Highlight current page in TOC
Date: Tue, 30 Nov 2010 21:27:42 +0100	[thread overview]
Message-ID: <87ipzeo8u9.fsf@gmx.de> (raw)
In-Reply-To: <87ipzmpmx8.fsf@gmx.de> (Sebastian Rose's message of "Wed, 24 Nov 2010 20:00:03 +0100")

Hi Benny,


I found the code did not work for org-export, since user-defined
#+STYLE: stuff is inserted _before_ all the automatically created
javascript stuff.

So I had to fall back on a global value, to make the hooks work.


This is in the docs on http://orgmode.org/worg/code/org-info-js/#hooks
once the page is republished:



   Currently two hooks are provided.  Each hook function is called with
   one or more parameters the first of which is the OrgHtmlManager
   object.

   - '~onReady~' :: This hook is run once the document is loaded, the
                    view is setup and the startup section is shown.  The
                    second parameter is the first section shown, i.e. an
                    OrgNode object.

   - '~onShowSection~' :: This one runs after showing a new section.
                          This hook is not called for the first section
                          shown.  Use the '~onReady~' hook for the first
                          section.  The second parameter is an object
                          with to OrgNodes: the previously shown section
                          and the current section.


   To add functions to the hooks, fill a global object ~orgInfoHooks~
   with the function objects you need.  This is necessary, because code
   added via the ~#+STYLE:~ option lines is executed before org-info.js
   is loaded.

#+begin_src org
  ,#+STYLE: <script type="text/javascript">
  ,#+STYLE: /* <![CDATA[ */
  ,#+STYLE:
  ,#+STYLE: var f = function(){ alert("I'll be removed :("); };
  ,#+STYLE:
  ,#+STYLE: orgInfoHooks = {
  ,#+STYLE:  'onReady': [
  ,#+STYLE:     function(ohm, sec){alert("I'm the only 'onReady' hook here.");}
  ,#+STYLE:   ],
  ,#+STYLE: 'onShowSection': [
  ,#+STYLE:     f,
  ,#+STYLE:     function (ohm, secs) {
  ,#+STYLE:       alert("You're looking at section "+secs['current']['I']+":\n"+
  ,#+STYLE:             "\n            <<< "+ohm.rT(secs['current']['H']['innerHTML'])+" >>>");},
  ,#+STYLE:     function(){
  ,#+STYLE:          alert("I'll now remove my f and myself, too.");
  ,#+STYLE:          org_html_manager.removeHook('onShowSection', f);
  ,#+STYLE:          org_html_manager.removeHook('onShowSection',
  ,#+STYLE:              orgInfoHooks['onShowSection'][ orgInfoHooks['onShowSection'].length - 1 ]);}
  ,#+STYLE:   ]};
  ,#+STYLE: /* ]]> */
  ,#+STYLE: </script>
#+end_src

   *Make sure to remove hook functions at the end of the hook*.  Strange
   things could happen otherwise (the hook loop will overlook a
   member. While the hook loop runs in first hook first, the remove loop
   removes the last hook first).



Your lightbox code would go in one of these hooks (you don't have to
supply all possible hooks):



orgInfoHooks = {

  // Actions on startup, after org_html_manager is done:

 'onReady': [
     function (ohm) {
       var root = ohm.R;    // R is the root of the OrgNode tree.
       var content = ohm.B; // B is the <div id="content">
         ...
       // Run for the first section:
       ohm.runHooks('onShowSection', { last: null, current: ohm.N });
       }],

  // Always, when the user navigates to a section:

 'onShowSection': [
     function (ohm, secs) {

       // You could test for (secs.last == null) to know your
       // called from the onReady hook.
       // A better alternative would be, to define a separate
       // function and call it from here and from onReady.

       var previous = secs['last'];
       var current  = secs['current'];
       if(current['F']) {
         // sec.F is the div that holds the contents of the section
         var imgs = sec.F.getElementsByTagName('img');
         ...
     }}
  ]};




Let me know if you run into problems.  Ideas welcome.


Sebastian

      reply	other threads:[~2010-12-01  3:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-14 16:51 Highlight current page in TOC Benny Simonsen
2010-11-22 20:06 ` Benny Simonsen
2010-11-24 17:13   ` Sebastian Rose
2010-11-24 19:00     ` Sebastian Rose
2010-11-30 20:27       ` Sebastian Rose [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ipzeo8u9.fsf@gmx.de \
    --to=sebastian_rose@gmx.de \
    --cc=benny@slbs.dk \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).