diff options
| author | Alon Levy <alon@pobox.com> | 2015-03-09 20:09:48 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-03-09 20:12:31 +0200 |
| commit | dd2c16e22b76ca299c4edfcd8f62d22e6bf39baa (patch) | |
| tree | 072390f028ac6bf80ff3caec7f27188aa8dd1d5c /src/client/view/search.js | |
| parent | 05e7b8021d17772f3fb0db4667b7901b1c34a474 (diff) | |
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.
Diffstat (limited to 'src/client/view/search.js')
| -rw-r--r-- | src/client/view/search.js | 19 |
1 files changed, 17 insertions, 2 deletions
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(); } |
