Commit 90af4c1f authored by Ryan Herbert's avatar Ryan Herbert

tokeniser.js refactor tokeniser for tests

parent 61ffbdd0
......@@ -45,6 +45,22 @@ Tokeniser.prototype = {
},
tokenise: function(input, target) {
var token = this.createToken($(input));
$(input).val("");
$(input).removeData('set-id');
target.appendChild(token);
},
readTokens: function(target) {
var nodes = $(target).children('.set_token');
return nodes.map(function callback() {
return $(this).data('set-id');
})
.get()
.join();
},
createToken: function($input) {
var class_mapping = {
":p": "patient_token",
":r": "run_token",
......@@ -52,27 +68,25 @@ Tokeniser.prototype = {
};
var token = document.createElement('span');
var text = $(input).val().trim();
var set_id = $(input).data('set-id');
var text = $input.val().trim();
var set_id = $input.data('set-id');
var className = "set_token " + class_mapping[set_id.substr(0, 2)];
token.className = className;
var x = document.createElement('i');
x.className = "icon-cancel";
x.onclick = function() {this.parentNode.parentNode.removeChild(this.parentNode);};
token.appendChild(x);
var close = this.createCloseButton();
token.appendChild(close);
token.appendChild(document.createTextNode(text));
$(token).data('set-id', set_id);
$(input).val("");
$(input).data('set-id');
target.appendChild(token);
return token;
},
readTokens: function(target) {
var nodes = $(target).children('.set_token');
return nodes.map(function callback() {
return $(this).data('set-id');
})
.get()
.join();
createCloseButton: function() {
var x = document.createElement('i');
x.className = "icon-cancel";
x.onclick = function() {this.parentNode.parentNode.removeChild(this.parentNode);};
return x;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment