From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastian Rose Subject: Re: Re: Highlight current page in TOC Date: Tue, 30 Nov 2010 21:27:42 +0100 Message-ID: <87ipzeo8u9.fsf@gmx.de> References: <87vd3mpruj.fsf@gmx.de> <87ipzmpmx8.fsf@gmx.de> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=46111 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNdgp-0007lC-SR for emacs-orgmode@gnu.org; Tue, 30 Nov 2010 22:49:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PNWoU-0004Js-9Y for emacs-orgmode@gnu.org; Tue, 30 Nov 2010 15:28:35 -0500 Received: from mailout-de.gmx.net ([213.165.64.23]:44690 helo=mail.gmx.net) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PNWoT-0004BJ-Rr for emacs-orgmode@gnu.org; Tue, 30 Nov 2010 15:28:34 -0500 In-Reply-To: <87ipzmpmx8.fsf@gmx.de> (Sebastian Rose's message of "Wed, 24 Nov 2010 20:00:03 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Benny Simonsen Cc: emacs-orgmode@gnu.org 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: #+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
... // 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