All Downloads are FREE. Search and download functionalities are using the official Maven repository.

client.js.otp.core.Webapp.js Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
/* This program is free software: you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public License
   as published by the Free Software Foundation, either version 3 of
   the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see .
*/

otp.namespace("otp.core");

otp.core.Webapp = otp.Class({

    map     : null,

    modules : [ ],
    moduleMenu : null,

    activeModule : null,

    widgetManager   : null,
    infoWidgets     : { },

    geocoders : [ ],

    indexApi : null,

    urlParams : null,

    initialize : function() {


        // misc. housekeeping

        if(typeof console == 'undefined') console = { log: function(str) {} };
        $.support.cors = true;
        var this_ = this;

        otp.config.resourcePath = otp.config.resourcePath || "";


        // set the urlRoot variable, if needed
        /*if(!otp.config.urlRoot) {
            otp.config.urlRoot = window.location.pathname;
            if(otp.util.Text.endsWith(otp.config.urlRoot, "index.html"))
                otp.config.urlRoot = otp.config.urlRoot.substring(0, otp.config.urlRoot.length-10);
        }
        if(!otp.util.Text.endsWith(otp.config.urlRoot, "/"))
            otp.config.urlRoot += "/";
        console.log("urlRoot "+otp.config.urlRoot);*/

        // init url params
        this.urlParams = { };
        var match,
            pl     = /\+/g,  // Regex for replacing addition symbol with a space
            search = /([^&=]+)=?([^&]*)/g,
            decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
            query  = window.location.search.substring(1);

        //Parser URL query string
        while (match = search.exec(query)) {
            var currentKey = decode(match[1]);
            //Same key already appeared in parameters
            //We need to change values from string to to list of values
            if (currentKey in this.urlParams) {
                var tmpValues = this.urlParams[currentKey];
                if ($.isArray(tmpValues)) {
                    tmpValues.push(decode(match[2]));
                } else {
                    tmpValues = [tmpValues, decode(match[2])];
                }
                this.urlParams[currentKey] = tmpValues;
            } else {
                this.urlParams[currentKey] = decode(match[2]);
            }
        }


        // init siteUrl, if necessary

        if(typeof otp.config.siteUrl === 'undefined') {
            otp.config.siteUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
        }

        // Set Debug options
        if (this.urlParams.debug === 'false') {
            otp.debug.disable();
        } else if (otp.config.debug || this.urlParams.debug === 'true' || window.localStorage['otpDebug'] === 'true') {
            otp.debug.enable();
        } else if (this.urlParams.debug === 'false') {
            otp.debug.disable();
        }

        // Enables/disables showing of debug layers overlays
        if (this.urlParams.debug_layers === 'false') {
            delete window.localStorage['otpDebugLayers']; // Reset the debug value
        } else if (otp.config.debug_layers || this.urlParams.debug_layers === 'true' || window.localStorage["otpDebugLayers"] === 'true') {
            console.info('Debug layers enabled (persistent).');
            console.info('    To disable put debug_layers=false in the url parameters');
            window.localStorage['otpDebugLayers'] = 'true'; // Save in localstorage to make it persistant!
            otp.config.debug_layers = true;
        }



        // set the logo & title

        if(otp.config.showLogo) {
          //$('').appendTo('#branding');
            $(Mustache.render(otp.templates.img, { 
                src : otp.config.logoGraphic,
                style : 'height:100%',
                wrapLink : true,
                linkHref : otp.config.siteUrl,
                wrapDiv : true,
                divId : 'logo'
            })).appendTo('#branding');
            //console.log(img);
            //$(img).appendTo('#branding');
            /*$(Mustache.render(otp.templates.div, { id : 'logo' }))
            .append(Mustache.render(otp.templates.img, { src : otp.config.logoGraphic }))
            .appendTo('#branding');          */

        }

        if(otp.config.siteName !== undefined) {
            document.title = otp.config.siteName;
            if(otp.config.showTitle) {
                $("").appendTo('#branding');
            }
        }

        // create the Webapp-owned objects

        this.map = new otp.core.Map(this);
        this.indexApi = new otp.core.IndexApi(this);
        this.widgetManager = new otp.widgets.WidgetManager();


        if(otp.config.geocoders) {
            for(var i=0; i\n';
            addThisHtml += '\n';
            addThisHtml += '\n';
            addThisHtml += '\n';
            addThisHtml += '\n';
            addThisHtml += '\n';
            addThisHtml += '\n';
            addThisHtml += '
'; $(addThisHtml).appendTo('#branding'); addthis_config = { pubid: otp.config.addThisPubId, data_track_clickback: false }; $.getScript("http://s7.addthis.com/js/250/addthis_widget.js#pubid="+otp.config.addThisPubId); } // create the widget manager menu & icon this.widgetManagerMenu = new otp.core.WidgetManagerMenu(this); var widgetManagerIcon = $('
') .appendTo('#branding') .click(function(event) { this_.widgetManagerMenu.show(); // showWidgetManagerMenu(); }); // create the info widgets and links along header bar if(otp.config.infoWidgets !== undefined && otp.config.infoWidgets.length > 0) { var nav = $('