In my HTML5 mobile application, I use some jquery to hide or show some user controls depending on whether the user is logged in or not:
Basically, the code looks like this:
-> one function 'createCustomControls' is responsible for calling several times the other function createCustomControl (without 's').
function createCustomControls(map){
createCustomControl("about", map);
if(!authenticated()){createCustomControl("login", map);}
if(authenticated()){ createCustomControl("menu", map);}
if(authenticated()) {createCustomControl("list", map);}
}
function createCustomControl(type, map){
var controlDiv = document.createElement('DIV');
controlDiv.style.padding = '2px';
controlDiv.index = 1;
var controlUI = document.createElement('DIV');
controlUI.style.backgroundColor = '#FFF';
controlUI.style.borderStyle = 'solid';
controlUI.style.borderWidth = '1px';
controlUI.style.cursor = 'pointer';
controlUI.style.textAlign = 'center';
controlUI.title = type.capitalize();
controlDiv.appendChild(controlUI);
var controlText = document.createElement('DIV');
controlText.style.fontFamily = 'Arial,sans-serif';
controlText.style.fontSize = '18px';
controlText.style.paddingLeft = '4px';
controlText.style.paddingRight = '4px';
controlText.innerHTML = type.capitalize();
controlUI.appendChild(controlText);
if(type == "list"){
google.maps.event.addDomListener(controlUI, 'click', function() {
....some stuff
});
}
if((type == "menu") || (type == "login") || (type == "about")){
google.maps.event.addDomListener(controlUI, 'click', function() {
$.mobile.changePage("#" + type, "slideup");
});
}
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlDiv);
}
This works correctly the first time I call createCustomControls:
-> 'login' and 'about' are configured controls.
, createCustomControls. (, , ) "login" "about".
, TOP_RIGHT, "login" "about", "", "" "", .
?