Add page URL auto change

This commit is contained in:
Pierre
2017-02-24 09:57:27 +01:00
parent 59004555ec
commit 07c57e965e
9 changed files with 139 additions and 9 deletions

View File

@ -88,6 +88,11 @@ var ComunicWeb = {
* Return current URL opened on the website
*/
getCurrentWebsiteURL: function(){},
/**
* Change the current website URI
*/
changeURI: function(newTitle, newURI){},
},
/**
@ -104,6 +109,11 @@ var ComunicWeb = {
*/
showWaitSplashScreen: function(){},
/**
* Show a transparent wait splash screen
*/
showTransparentWaitSplashScreen: function(){},
/**
* Open a page
*/
@ -301,6 +311,11 @@ var ComunicWeb = {
* Open login page
*/
openLoginPage: function(additionnalData, targetElement){},
/**
* Perform user login
*/
loginSubmit: function(){},
}
},

View File

@ -57,6 +57,28 @@ ComunicWeb.common.page = {
},
/**
* Show a transparent wait splash screen
*
* @returns {elem} The splash screen element to let it being deleted
*/
showTransparentWaitSplashScreen: function(){
//Create the element
var waitSplashScreen = document.createElement("div");
waitSplashScreen.className = "transparentWaitSplashScreen";
//Populate it
var imgElem = document.createElement("img");
imgElem.src = ComunicWeb.__config.assetsURL+"img/barProgress.gif";
waitSplashScreen.appendChild(imgElem);
//Apply splash screen
document.body.appendChild(waitSplashScreen);
//Return wait splash screen element
return waitSplashScreen;
},
/**
* Open a page
*
@ -68,7 +90,7 @@ ComunicWeb.common.page = {
ComunicWeb.debug.logMessage("Open the following page: " + pageURI);
//Extract the first part of the URL
var firstPartURI = pageURI;
var firstPartURI = pageURI.toString();
//Check if pageURI is empty
if(firstPartURI == ""){
@ -93,6 +115,9 @@ ComunicWeb.common.page = {
//Change page title
document.title = pageInfos.pageTitle;
//Change page URL
ComunicWeb.common.url.changeURI(document.title, pageURI);
//Get the main contener of the page
//var mainContenerElem = document.getElementById("wrapper");
@ -160,6 +185,26 @@ ComunicWeb.common.page = {
//Apply template source
targetElem.innerHTML = templateContent;
//Make a link live
var aElems = targetElem.getElementsByTagName("a");
for(num in aElems){
//Export current element
var currentElement = aElems[num];
//Check if it is a real html elements and if it contains a "target" attribute
if(currentElement.attributes){
if(currentElement.attributes.target){
//Change the onclick behavior of the elements
currentElement.onclick = (function() {
ComunicWeb.common.page.openPage(this.getAttribute("target"));
});
}
}
}
//Perform next action (if there is)
if(afterParsingHTMLtemplate)
afterParsingHTMLtemplate();

View File

@ -20,4 +20,23 @@ ComunicWeb.common.url = {
//Return result
return uripage;
},
/**
* Change the current website URI
*
* @param {String} newTitle New title for the page
* @param {String} newURI The new URI
* @return {Boolean} False if it fails
*/
changeURI: function(newTitle, newURI){
//Determine the new URL
var newURL = ComunicWeb.__config.siteURL + newURI;
//Apply it
window.history.pushState("object or string", newTitle, newURI);
//Everything is OK
return true;
},
};