diff options
author | Sergio Abreu García <saggamedeveloper@gmail.com> | 2018-09-23 21:40:37 +0300 |
---|---|---|
committer | Sergio Abreu García <saggamedeveloper@gmail.com> | 2018-09-23 21:40:37 +0300 |
commit | a3dacb57d56246a10bcfaf56455d77b40363e8d3 (patch) | |
tree | 79c6078c932f57544fa4435c623b48ad56dd465c | |
parent | c03e95dd8f57342aff2ea0a6e7347d956d42548a (diff) |
Avoided useless function calls on URL change.
-rw-r--r-- | static/js/router.js | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/static/js/router.js b/static/js/router.js index 028eef6..dbdc9df 100644 --- a/static/js/router.js +++ b/static/js/router.js @@ -2,14 +2,14 @@ var router = function(routes){ this.routes = routes; - this.current_id = id_from_hash(window.location.hash); + this.current_id = ""; this.tab_elements = {}; this.initial_load(); //This initial 'fake' call allows to initialize contents //and link values - this.url_changed_callback(this.current_id); + this.url_changed_callback(id_from_hash(window.location.hash)); //Adds the callback along with the context of the instance var current_context = this; @@ -56,14 +56,16 @@ router.prototype.initial_load = function() { router.prototype.url_changed_callback = function(){ var id = id_from_hash(window.location.hash); - //Update contents each time the URL changes - this.swap_contents(id); - - this.current_id = id; + if (id != this.current_id){ + //Update contents each time the URL changes + this.swap_contents(id); + + this.current_id = id; + } } -router.prototype.swap_contents = function(id){ - this.tab_elements[this.current_id].style = "display: none;"; +router.prototype.swap_contents = function(id){ + if (this.current_id != "") this.tab_elements[this.current_id].style = "display: none;"; this.tab_elements[id].style = "display: block;"; } |