mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Auto-refresh page when the user open the previous page
This commit is contained in:
		@@ -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
 | 
			
		||||
			 */
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
     * 
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
		 */
 | 
			
		||||
 
 | 
			
		||||
@@ -399,3 +399,24 @@ function add_space(target){
 | 
			
		||||
	});
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 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);
 | 
			
		||||
})();
 | 
			
		||||
		Reference in New Issue
	
	Block a user