/*\ title: $:/core/modules/widget/navigator.js type: application/javascript module-type: widget Implements the navigator widget. \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; var NavigatorWidget = function(renderer) { // Save state this.renderer = renderer; // Generate child nodes this.generateChildNodes(); }; NavigatorWidget.prototype.generateChildNodes = function() { // We'll manage our own dependencies this.renderer.dependencies = undefined; // Get our parameters this.storyTitle = this.renderer.getAttribute("story"); this.historyTitle = this.renderer.getAttribute("history"); // Render our children this.children = this.renderer.renderTree.createRenderers(this.renderer.renderContext,this.renderer.parseTreeNode.children); }; NavigatorWidget.prototype.render = function(type) { var output = []; $tw.utils.each(this.children,function(node) { if(node.render) { output.push(node.render(type)); } }); return output.join(""); }; NavigatorWidget.prototype.renderInDom = function(parentElement) { this.parentElement = parentElement; // Render any child nodes $tw.utils.each(this.children,function(node) { if(node.renderInDom) { parentElement.appendChild(node.renderInDom()); } }); // Attach our event handlers $tw.utils.addEventListeners(this.renderer.domNode,[ {name: "tw-navigate", handlerObject: this, handlerMethod: "handleNavigateEvent"}, {name: "tw-EditTiddler", handlerObject: this, handlerMethod: "handleEditTiddlerEvent"}, {name: "tw-SaveTiddler", handlerObject: this, handlerMethod: "handleSaveTiddlerEvent"}, {name: "tw-close", handlerObject: this, handlerMethod: "handleCloseTiddlerEvent"}, {name: "tw-NewTiddler", handlerObject: this, handlerMethod: "handleNewTiddlerEvent"} ]); }; NavigatorWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) { // We don't need to refresh ourselves, so just refresh any child nodes $tw.utils.each(this.children,function(node) { if(node.refreshInDom) { node.refreshInDom(changedTiddlers); } }); }; NavigatorWidget.prototype.getStoryList = function() { var text = this.renderer.renderTree.wiki.getTextReference(this.storyTitle,""); if(text && text.length > 0) { this.storyList = text.split("\n"); } else { this.storyList = []; } }; NavigatorWidget.prototype.saveStoryList = function() { var storyTiddler = this.renderer.renderTree.wiki.getTiddler(this.storyTitle); this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler({ title: this.storyTitle },storyTiddler,{text: this.storyList.join("\n")})); }; NavigatorWidget.prototype.findTitleInStory = function(title,defaultIndex) { for(var t=0; t