Default JavaScript Variable

From MapbenderWiki

Jump to: navigation, search

Some GUI elements need JavaScript variables, which you can define with the Element vars.

If the Element vars are not defined, the script should still work. This is why you have to check whether the var is there. If not, a default value has to be set.

(If the variable is optional, throw a warning, if it is mandatory, throw an exception.)

try{
 if (mod_copyright_text){}
}
catch(e){
   mod_copyright_text = "mapbender.org"
   var e = new Mb_warning("<file name>: <function name>: mod_copyright_text is not set, see 'edit element vars'.");
}


You should also check whether the Element Vars are correct. For example, if you expect numeric values, try something like this

try{
   if (open_tab){
      open_tab = Number(open_tab);

      if (isNaN(open_tab)) {
         var e = new Mb_warning("mod_tab.js: tab_init: open_tab must be a number.");
      }
   }
}
catch(e){
   open_tab = "";
   var e = new Mb_warning("mod_tab.js: tab_init: open_tab is not set, see 'edit element vars'.");
}
Personal tools