From dd2c16e22b76ca299c4edfcd8f62d22e6bf39baa Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 9 Mar 2015 20:09:48 +0200 Subject: client: search in nodes and attributes Fixes #358 Implementation limitations: - uses hasOwnProperty for search, and further filters on strings. So technically could be oversearching - i.e. string properties that are not attributes. We should keep an attribute key on Node and Link - there is no selected link, just selected nodes. So we select both source and destination. Opening issue #367 for this. --- src/client/view/search.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/client/view/search.js') diff --git a/src/client/view/search.js b/src/client/view/search.js index 29e702d1..09950687 100644 --- a/src/client/view/search.js +++ b/src/client/view/search.js @@ -28,9 +28,24 @@ function init() { return true; }); + function attribute_match(obj, regexp) { + var v, k; + + for (k in obj) { + if (obj.hasOwnProperty(k)) { + v = obj[k]; + if ("string" === typeof(v) && v.match(regexp)) { + return true; + } + } + } + return false; + } + function search_on_submit() { var text = search[0].value.trim(), - r; + r, + selector = function (obj) { return attribute_match(obj, r); }; try { r = new RegExp(text.replace(/ /, '|'), 'i'); @@ -38,7 +53,7 @@ function init() { return; // don't clear selection either } if (text.length > 0) { - selection.byVisitors(function (n) { return n.name.match(r); }); + selection.byVisitors(selector, selector); } else { selection.clear(); } -- cgit v1.3.1