diff options
| author | LV-426 <lv-426@taproot.org.il> | 2014-11-19 03:20:36 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-11-25 15:08:59 +0200 |
| commit | 356b1785c8e257ec7d161d44495c1e1e724e7291 (patch) | |
| tree | 1f5c08b267c8b2931c7e260a284af7d1587f9fe6 /src | |
| parent | 5f4c3dbd58d99ddfad18ac22dcbece9ef7698042 (diff) | |
add rz_config, provide id generation scheme control: hash/seq, defaulting to seq
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.js | 9 | ||||
| -rw-r--r-- | src/model/core.js | 28 | ||||
| -rw-r--r-- | src/rz_config.js | 6 |
3 files changed, 37 insertions, 6 deletions
diff --git a/src/main.js b/src/main.js index b55a3a3d..bfe81eb0 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,5 @@ -define(['jquery', 'textanalysis.ui', 'buttons', 'history', 'drag_n_drop', 'robot', 'rz_core'], -function($, textanalysis_ui, buttons, history, drag_n_drop, robot, rz_core) { +define(['textanalysis.ui', 'buttons', 'history', 'drag_n_drop', 'robot', 'model/core', 'rz_config', 'rz_core'], +function(textanalysis_ui, buttons, history, drag_n_drop, robot, model_core, rz_config, rz_core) { function getParameterByName(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); @@ -25,13 +25,16 @@ function($, textanalysis_ui, buttons, history, drag_n_drop, robot $('#textanalyser').onkeyup = function() { expand(this); }; textanalysis_ui.main(); + // TODO: jquery BBQ: $.deparam.querystring().json; json = getParameterByName('json'); if (json) { rz_core.load_from_json(json); } + // TODO: interaction between the hack above and this + model_core.init(rz_config); } - + return { main: main }; } diff --git a/src/model/core.js b/src/model/core.js index 6111954b..aff222f6 100644 --- a/src/model/core.js +++ b/src/model/core.js @@ -8,12 +8,33 @@ define([], function() { /** * return a random id */ - var random_id = function() { - return Math.random().toString(36).substring(2); + var random_id; + + var random_id__hash = function() { + return Math.random().toString(36).substring(2, 10); + } + + var random_id__seq = function () { + var id = 0; + function get_next() { + var next = id; + id += 1; + return next; + } + return get_next; } function random_node_name() { - return Math.random().toString(36).substring(2, 10); + return random_id__hash(); + } + + function init(config){ + if (config['rand_id_generator'] == 'hash') { + random_id = random_id__hash; + } + if (config['rand_id_generator'] == 'seq') { + random_id = random_id__seq(); + } } function Node() { @@ -144,6 +165,7 @@ define([], function() { } return { + init : init, random_node_name : random_node_name, crete_node_from_spec : crete_node_from_spec, crete_link_from_spec : crete_link_from_spec, diff --git a/src/rz_config.js b/src/rz_config.js new file mode 100644 index 00000000..6093573a --- /dev/null +++ b/src/rz_config.js @@ -0,0 +1,6 @@ +define(function() { + + return { + 'rand_id_generator' : 'hash', + }; +}); |
