/*
This file is part of rhizi, a collaborative knowledge graph editor.
Copyright (C) 2014-2015 Rhizi
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see
' + JSON.stringify(d) + ''); }; function svg_extract_translate_and_scale(e) { // See: http://stackoverflow.com/questions/10349811/how-to-manipulate-translate-transforms-on-a-svg-element-with-javascript-in-chrom // Using the regexp option right now, did only firefox testing 36 var transform = e.attributes['transform']; if (undefined === transform) { return; } var str = transform.value, parts = /translate\(\s*([^\s,)]+)[ ,]([^\s,)]+)/.exec(str), scale = /scale\(\s*([^\s)]+)\)/.exec(str); if (scale) { var x = parts[1], y = parts[2]; return {scale:+scale[1], translate: [+x, +y]}; } else { return {scale:1.0, translate: [0.0, 0.0]}; } } History.prototype.record_zoom = function(d) { if (this.transform_element === undefined) { // FIXME why is it undefined? set in constructor above return; } var transform = svg_extract_translate_and_scale(this.transform_element); if (transform === undefined) { //console.log('record_zoom: bug: transform_element has no transform attribute'); //FIXME: broken for now, don't spam console return; } this.record(ACTION_ZOOM, {transform: transform}); } History.prototype.save_to_file = function() { var json = JSON.stringify(this.records, function (k, v) { return v; }, 2); saveAs(new Blob([json], {type: 'application/json'}), 'history.json'); }; History.prototype.clear = function() { this.records = []; } History.prototype.record_graph_diff = function(obj) { this.record(ACTION_GRAPH_DIFF, { nodes: {add: obj.nodes && obj.nodes.add, remove: obj.nodes && obj.nodes.remove, change: obj.nodes && obj.nodes.change}, links: {add: obj.links && obj.links.add, remove: obj.links && obj.links.remove, change: obj.links && obj.links.change}, }); } History.prototype.record_keystrokes = function(obj) { var where = obj.where, keys = obj.keys; if (where === undefined || keys === undefined || keys.length === undefined || keys.length <= 0) { console.log("invalid arguments"); return; } keys = keys.filter(function(k) { return k !== undefined; }); if (keys.length == 0) { return; } this.record(ACTION_KEYSTROKES, { keys: keys, where: where }); } History.prototype.record_input = function(obj) { var where = obj.where, input = obj.input; if (where === undefined || input === undefined || input.length === undefined || typeof input !== 'string') { console.log('invalid arguments'); return; } this.record(ACTION_INPUT, {where: where, input: input}); } return { History:History, KEYSTROKE_WHERE_TEXTANALYSIS:KEYSTROKE_WHERE_TEXTANALYSIS, KEYSTROKE_WHERE_DOCUMENT:KEYSTROKE_WHERE_DOCUMENT, KEYSTROKE_WHERE_EDIT_NODE:KEYSTROKE_WHERE_EDIT_NODE }; }); // define