diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index cbdba9a9..dbddabfa 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -176,6 +176,11 @@ var ComunicWeb = { */ refresh_current_page: function(){}, + /** + * Inform of page location update + */ + location_updated: function(new_location){}, + /** * Prepare a template load by specifying datas */ diff --git a/assets/js/common/page.js b/assets/js/common/page.js index 066a16e8..783ec675 100644 --- a/assets/js/common/page.js +++ b/assets/js/common/page.js @@ -5,6 +5,12 @@ */ ComunicWeb.common.page = { + + /** + * Save the current page url + */ + _current_url: "", + /** * Empty current page content * @@ -183,6 +189,9 @@ ComunicWeb.common.page = { //Change page URL ComunicWeb.common.url.changeURI(document.title, pageURI); + //Save new url + this._current_url = window.location.href.toString(); + //Get the main contener of the page var mainContenerElem = byId("wrapper"); @@ -263,6 +272,21 @@ ComunicWeb.common.page = { this.openPage(currentPage); }, + /** + * Inform of page location update + * + * @param {location} new_location The new location of the page + */ + location_updated: function(new_location){ + + //Check if the url change has already been handled or not + if(new_location.href.toString() != this._current_url) + + //Open the page using url detection + this.refresh_current_page(); + + }, + /** * Prepare a template load by specifiying datas * diff --git a/assets/js/common/system.js b/assets/js/common/system.js index b01e7868..f6cd2025 100644 --- a/assets/js/common/system.js +++ b/assets/js/common/system.js @@ -24,6 +24,11 @@ ComunicWeb.common.system = { $(document.body).tooltip("disable"); }); + //Enable page URLs detection + window.location.changed = function(e){ + ComunicWeb.common.page.location_updated(e); + } + /** * Prepare login */ diff --git a/assets/js/common/utils.js b/assets/js/common/utils.js index 659d104c..bd05e3d4 100644 --- a/assets/js/common/utils.js +++ b/assets/js/common/utils.js @@ -398,4 +398,25 @@ function add_space(target){ innerHTML: " " }); -} \ No newline at end of file +} + + +/** + * Page URL update detection + * + * @source https://stackoverflow.com/a/1931090/3781411 + */ +window.location.changed = function(e){}; + +(function() //create a scope so 'location' is not global +{ + var m_loc = window.location.href; + setInterval(function() + { + if(m_loc != window.location.href) + { + m_loc = window.location.href; + window.location.changed(window.location); + } + }, 900); +})(); \ No newline at end of file