From 63bd7089b3485055643a800c836a3bda3d2dfe42 Mon Sep 17 00:00:00 2001 From: andress19 Date: Tue, 19 Dec 2017 13:08:07 -0500 Subject: [PATCH] Add performance improvement Close unselected nodes when uthe user open a new node --- src/json-formatter.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/json-formatter.js b/src/json-formatter.js index cb92b5c..3ab4f9b 100644 --- a/src/json-formatter.js +++ b/src/json-formatter.js @@ -153,6 +153,13 @@ angular.module('jsonFormatter', ['RecursionHelper']) // If 'open' attribute is present scope.isOpen = !!scope.open; scope.toggleOpen = function () { + if (!scope.$parent.$parent.$parent.selected) { + scope.$parent.$parent.$parent.selected = scope; + } + if (scope.$parent.$parent.$parent.selected.$id != scope.$id) { + scope.$parent.$parent.$parent.selected.isOpen = false; + scope.$parent.$parent.$parent.selected = scope; + } scope.isOpen = !scope.isOpen; }; scope.childrenOpen = function () { @@ -226,4 +233,4 @@ angular.module('jsonFormatter', ['RecursionHelper']) // angular.module('myApp', [require('jsonformatter')]); if (typeof module === 'object') { module.exports = 'jsonFormatter'; -} \ No newline at end of file +}