From c919c4bfef4ad9e2dc25d040c0727dd29ad541ae Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 20 Oct 2014 13:25:32 +0300 Subject: introduce require.js and rewrite tests Yes, I'm being lazy. The purpose of require.js is to allow writing modules, i.e. individual smaller then the whole files with clear dependencies. This is achieved by using a new api provided by require.js: define, require, requirejs Read more at [requirejs] (http://requirejs.org) Tests have been rewritten to work correctly with require.js; they still use jsdom. Test output is now stored in the repository, all tests are run via run_tests.js; This is a hack - once a good harness (with assertions, suites - unittest like) presents itself it will be used. Hidden here is also using FileSaver for history saving, so history is saved to history.json instead to a random name. Plus dropping some dead code. --- scripts/buttons.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'scripts/buttons.js') diff --git a/scripts/buttons.js b/scripts/buttons.js index 1543b4cc..bbde2d45 100644 --- a/scripts/buttons.js +++ b/scripts/buttons.js @@ -1,18 +1,19 @@ "use strict" +define('buttons', ['jquery', 'FileSaver', 'rhizicore'], function ($, saveAs, RZ) { $('.tutorial').click(function(){}); var key="#47989379"; $('.save').click(function(){ - var json = graph.save_to_json(); + var json = RZ.graph.save_to_json(); console.log(json); localStorage.setItem(key, json); }); $('.saveToFile').click(function() { - var json = graph.save_to_json(); + var json = RZ.graph.save_to_json(); var filename = 'graph.json'; var blob = new Blob([json], {type: 'application/json'}); console.log('saving ' + json.length + ' bytes to ' + filename); @@ -20,7 +21,7 @@ $('.saveToFile').click(function() { }); var really_load = function() { - if (nodes.length > 0){ + if (!RZ.graph.empty()) { return confirm('All unsaved changes will be deleted, are you sure?'); } return true; @@ -44,7 +45,7 @@ $('.file-load').on('change', function(event) { if (e.target.readyState === FileReader.DONE) { console.log('done reading ' + theFile.name); console.log('got #' + result.length + ' bytes in ' + typeof(result)); - graph.load_from_json(result); + RZ.graph.load_from_json(result); } } })(file); @@ -55,10 +56,8 @@ $('.local-storage-load').click(function(){ if (!really_load()) { return; } - links=[]; // TODO - not global - nodes=[]; // TODO - not global var json_blob = localStorage.getItem(key) - graph.load_from_json(json_blob); + RZ.graph.load_from_json(json_blob); }); $('.set-user').click(function() { @@ -66,7 +65,7 @@ $('.set-user').click(function() { $('.set-user-form').show(); $('.set-user-form').submit(function() { var user = $('.set-user-input').val(); - graph.set_user(user); + RZ.graph.set_user(user); $('.set-user').html('user: ' + user); $('.set-user').show(); $('.set-user-form').hide(); @@ -76,8 +75,10 @@ $('.set-user').click(function() { }); $('.save-history').click(function() { - if (graph.history === undefined) { + if (RZ.graph.history === undefined) { throw "History is undefined"; } - graph.history.save_to_file(); + RZ.graph.history.save_to_file(); }); +return {'buttons': 'nothing here'}; +}); // define -- cgit v1.3.1