/*\ title: $:/core/modules/widgets/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.generate(); }; NavigatorWidget.prototype.generate = function() { // Get our parameters this.storyTitle = this.renderer.getAttribute("story"); this.historyTitle = this.renderer.getAttribute("history"); // Set the element this.tag = "div"; this.attributes = { "class": "tw-navigator" }; this.children = this.renderer.renderTree.createRenderers(this.renderer,this.renderer.parseTreeNode.children); this.events = [ {name: "tw-navigate", handlerObject: this, handlerMethod: "handleNavigateEvent"}, {name: "tw-edit-tiddler", handlerObject: this, handlerMethod: "handleEditTiddlerEvent"}, {name: "tw-delete-tiddler", handlerObject: this, handlerMethod: "handleDeleteTiddlerEvent"}, {name: "tw-save-tiddler", handlerObject: this, handlerMethod: "handleSaveTiddlerEvent"}, {name: "tw-cancel-tiddler", handlerObject: this, handlerMethod: "handleCancelTiddlerEvent"}, {name: "tw-close-tiddler", handlerObject: this, handlerMethod: "handleCloseTiddlerEvent"}, {name: "tw-close-all-tiddlers", handlerObject: this, handlerMethod: "handleCloseAllTiddlersEvent"}, {name: "tw-new-tiddler", 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