/*\ title: js/macros/story.js \*/ (function(){ /*jslint node: true, jquery: true */ "use strict"; var Tiddler = require("../Tiddler.js").Tiddler, Renderer = require("../Renderer.js").Renderer, Dependencies = require("../Dependencies.js").Dependencies, utils = require("../Utils.js"); function scrollToTop(duration) { if (duration < 0) { return; } var delta = (-document.body.scrollTop/duration) * 10; window.setTimeout(function() { document.body.scrollTop = document.body.scrollTop + delta; scrollToTop(duration-10); }, 10); } exports.macro = { name: "story", params: { story: {byName: "default", type: "tiddler"}, defaultViewTemplate: {byName: true, type: "tiddler"}, defaultEditTemplate: {byName: true, type: "tiddler"} }, events: { "tw-navigate": function(event) { var template = this.hasParameter("defaultViewTemplate") ? this.params.defaultViewTemplate : "ViewTemplate", storyTiddler = this.store.getTiddler(this.params.story), story = {tiddlers: []}; if(storyTiddler && storyTiddler.hasOwnProperty("text")) { story = JSON.parse(storyTiddler.text); } story.tiddlers.unshift({title: event.navigateTo, template: template}); this.store.addTiddler(new Tiddler(storyTiddler,{text: JSON.stringify(story)})); scrollToTop(400); event.stopPropagation(); return false; }, "tw-EditTiddler": function(event) { var template = this.hasParameter("defaultEditTemplate") ? this.params.defaultEditTemplate : "EditTemplate", storyTiddler = this.store.getTiddler(this.params.story), story = {tiddlers: []}; if(storyTiddler && storyTiddler.hasOwnProperty("text")) { story = JSON.parse(storyTiddler.text); } for(var t=0; t t) { // First delete the DOM nodes for(n=t; n story.tiddlers.length) { for(t=story.tiddlers.length; t