Users who want to edit the invisible header inside of a Lurch document (which is stored in its metadata) can do so in a second browser window (or tab) containing a full Lurch document editor just for the header of the original document. In such a scheme, we call the first window (containing the whole document) the primary window or primary copy of the app and the second window (containing just the header from the primary window) secondary window or secondary copy of the app.
This module adds features for both the primary and secondary copies of the app. For the primary window, it implements the tools for launching the secondary window and sending it the header data. For the secondary window, it it implements the tools for limiting the UI elements to only what are needed for the secondary copy of the app, and a function for passing the edited header information back to the primary window upon request from the user.
Members
hasEditorOpen
Detect whether the current copy of the app running in this window is the primary window and also currently has a secondary window open for editing this window's header.
Source
Methods
getHeader(editor) → {HTMLElement}
The metadata element for a document is stored in the editor rather than the
DOM, because we do not want TinyMCE to be able to edit it. It is sometimes
useful to be able to extract the header element from that metadata, so that
it can be treated like an entire document (fragment), since it effectively is
one.
Parameters
-
editor
tinymce.Editor
the editor from which to extract the document header
Returns
-
HTMLElement
the HTMLElement that contains the document header for this editor
Source
install(editor)
Install into a TinyMCE editor instance the menu items that can be used in the primary window to pop open the secondary window, or instead to move content between the header and the main document. The menu items in question are intended for the Document menu, but could be placed anywhere.
Parameters
-
editor
tinymce.editor
the TinyMCE editor into which to install the tools
Source
isEditor() → {boolean}
Detect whether the current copy of the app running in this window is the secondary one, created in service to another (primary) window elsewhere. In other words, return true if this is the secondary window and false if it is the primary one.
Returns
-
boolean
whether this app window is for editing the document header from a separate (primary) Lurch app window
Source
listen(editor)
Assuming that we're in the secondary copy of the app, listen for the message from the primary window that sends us the header to edit, and when we receive it, populate our editor with it. While we wait, our editor is read only and says "Loading header..." so that the user knows to wait.
Also, install a new File > Save action that will send our editor's content back to the primary window so that it can store that updated content in its document header.
Parameters
-
editor
tinymce.editor
the TinyMCE editor into which to load the header data, once we receive it from the primary window