How to remotely use methods of an instance from another html frame
Hi,
I'm looking for a solution to change the selection of a tree item by clicking into a text content frame.
Just to explain:
I have 3 html files:
- 1 HTML with the FrameSet
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title> This is my title </title>
- </head>
- <frameset cols="20%,*">
- <frame src="src/index_toc.html" name="tocframe" id="tocframe" />
- <frame src="src/index_main.html" name="main_content" id="main_content" />
- </frameset>
- </html>
- them 2 Simple HTML Files
toc has the tree -->
tocframe
index_main is just the content to read, with several chapters -->
main_content
- <script type="text/javascript">
- var mytoc= $(function(){
- // Create the tree inside the <div id="tree"> element.
- $("#toc").fancytree({
- activeVisible: true, // Make sure, active nodes are visible (expanded).
- aria: false, // Enable WAI-ARIA support.
- autoActivate: true, // Automatically activate a node when it is focused (using keys).
- autoCollapse: true, // Automatically collapse all siblings, when a node is expanded.
- autoScroll: false, // Automatically scroll nodes into visible area.
- clickFolderMode: 4, // 1:activate, 2:expand, 3:activate and expand, 4:activate (dblclick expands)
- checkbox: false, // Show checkboxes.
- debugLevel: 2, // 0:quiet, 1:normal, 2:debug
- disabled: false, // Disable control
- focusOnSelect: false, // Set focus when node is checked by a mouse click
- generateIds: false, // Generate id attributes like <span id='fancytree-id-KEY'>
- idPrefix: "ft_", // Used to generate node id´s like <span id='fancytree-id-<key>'>.
- icons: false, // Display node icons.
- keyboard: true, // Support keyboard navigation.
- keyPathSeparator: "/", // Used by node.getKeyPath() and tree.loadKeyPath().
- minExpandLevel: 1, // 1: root node is not collapsible
- quicksearch: false, // Navigate to next node by typing the first letters.
- selectMode: 2, // 1:single, 2:multi, 3:multi-hier
- tabbable: true, // Whole tree behaves as one single control
- titlesTabbable: false, // Node titles can receive keyboard focus
- activate: function(event, data) {
- var node = data.node; // Use <a> href and target attributes to load the content:
- if( node.data.href ){ // Open target
- window.open(node.data.href, node.data.target); // or open target in iframe//
- $("[name=main_target]").attr("src", node.data.href);
- }
- }
- });
- });
- </script>
so now on the content (index_main) I want to change the selected tree items by clicking into the text content.
So when I click somewhere in chapter 2 section 1.1 the tree item 2.1.1 in the toc frame will be selected.
- function add_highlighter() {
- filename = "" + window.location.pathname.substr(window.location.pathname.lastIndexOf("/") + 1);
- element = document.getElementsByTagName("div");
- for (var i = 0; i < element.length; i++) {
- p = element[i].className + "";
- if (p == "chapter" || p == "book" || p == "preface" || p == "section" || p == "appendix" || p == "index") {
- element[i].onmouseup = function () {
- //alert(filename + "#" + this.getElementsByTagName("a")[0].id);
- var frameDocument = $('frame[name="tocframe"]', top.document)[0].contentDocument;
- var myTree = $('mytoc',frameDocument);
- node = myTree.fancytree("getActiveNode");
- node.setTitle("New title");
- };
- }
- }
- }
I was able to change the backgroundcolor by using the
frameDocument but I struggle with the instance of the fancytree.
So is it possible what I'm trying to do?
Best regards
Markus