Auto-refresh page when the user open the previous page

This commit is contained in:
Pierre 2018-03-14 19:41:45 +01:00
parent cebbc4afdf
commit cf3207ddc9
4 changed files with 56 additions and 1 deletions

View File

@ -176,6 +176,11 @@ var ComunicWeb = {
*/ */
refresh_current_page: function(){}, refresh_current_page: function(){},
/**
* Inform of page location update
*/
location_updated: function(new_location){},
/** /**
* Prepare a template load by specifying datas * Prepare a template load by specifying datas
*/ */

View File

@ -5,6 +5,12 @@
*/ */
ComunicWeb.common.page = { ComunicWeb.common.page = {
/**
* Save the current page url
*/
_current_url: "",
/** /**
* Empty current page content * Empty current page content
* *
@ -183,6 +189,9 @@ ComunicWeb.common.page = {
//Change page URL //Change page URL
ComunicWeb.common.url.changeURI(document.title, pageURI); ComunicWeb.common.url.changeURI(document.title, pageURI);
//Save new url
this._current_url = window.location.href.toString();
//Get the main contener of the page //Get the main contener of the page
var mainContenerElem = byId("wrapper"); var mainContenerElem = byId("wrapper");
@ -263,6 +272,21 @@ ComunicWeb.common.page = {
this.openPage(currentPage); 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 * Prepare a template load by specifiying datas
* *

View File

@ -24,6 +24,11 @@ ComunicWeb.common.system = {
$(document.body).tooltip("disable"); $(document.body).tooltip("disable");
}); });
//Enable page URLs detection
window.location.changed = function(e){
ComunicWeb.common.page.location_updated(e);
}
/** /**
* Prepare login * Prepare login
*/ */

View File

@ -398,4 +398,25 @@ function add_space(target){
innerHTML: " " innerHTML: " "
}); });
} }
/**
* 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);
})();