/* * Released under BSD License * Copyright (c) 2014-2015 hizzgdev@163.com * * Project Home: * https://github.com/hizzgdev/jsmind/ */ (function($w){ 'use strict'; var $d = $w.document; var __name__ = 'jsMind'; var jsMind = $w[__name__]; if(!jsMind){return;} if(typeof(jsMind.shell)!='undefined'){return;} var options = { play_delay : 1000 }; jsMind.shell = function(jm){ this.jm = jm; this.step = 0; this.commands = []; //version this.delay_handle = 0; this.playing = false; this.jm_editable = this.jm.get_editable(); }; jsMind.shell.prototype = { init:function(){ this.playing = false; }, record:function(action,obj){ if(!this.playing){ var command = {action:action,data:obj.data,node:obj.node}; var prev_command = this.commands[this.step-1]; if(command.action === 'update_node' && prev_command.action === 'add_node' && prev_command.data[2]==='New Node'){ prev_command.data[2] = command.data[1]; this.commands[this.step-1] = prev_command; }else{ this.step = this.commands.push(command); } } }, execute:function(command){ var func = this.jm[command.action]; var node = command.node; this.jm.enable_edit(); func.apply(this.jm,command.data); this.jm.disable_edit(); if(!!node){ this.jm.select_node(node); } }, add_command:function(command){ this.commands.push(command); play(); }, replay:function(){ this.step = 0; this.play(); }, play:function(){ this.jm.disable_edit(); this.playing = true; this._play_stepbystep(); }, _play_stepbystep:function(){ if(this.delay_handle != 0){ $w.clearTimeout(this.delay_handle); this.delay_handle = 0; } if(this.step