Example #1
0
 clearCache: function () {
   tml.config.getCache().clear();
 }
Example #2
0
      initApplication: function (options, callback) {
        var t0 = new Date();

        var cookie = helpers.getCookie(options.key);

        var cache_version = null;

        if (options.cache && options.cache.version)
          cache_version = options.cache.version;

        tml.config.registerApiAdapter('ajax', require('./api_adapters/ajax'));
        tml.config.api = 'ajax';

        tml.config.registerCacheAdapters({
          inline: require('./cache_adapters/inline'),
          browser: require('./cache_adapters/browser')
        });

        options = tml.utils.merge(tml.config, {
          delayed_flush: true,
          api: "ajax",
          current_source: helpers.getCurrentSource(options),
          current_locale: helpers.getCurrentLocale(options.key, options.current_locale),
          current_translator: cookie.translator ? new tml.Translator(cookie.translator) : null,
          accepted_locales: window.navigator.languages,
          cache: {
            enabled: true,
            adapter: "browser",
            version: cache_version,
            version_check_interval: options.version_check_interval || 60 // browser will default to every 60 sec
          }
        }, options);

        options.fetch_version = (options.cache.adapter == 'browser' && !cache_version);

        tml.config.initCache(options.key);
        // console.log(options);

        tml.app = new tml.Application({
          key: options.key,
          token: cookie.oauth ? cookie.oauth.token : null,
          host: options.host,
          cdn_host: options.cdn_host
        });

        tml.app.init(options, function (err) {

          if ((options.translateBody || options.translate_body) && mutationObserver) {
            tml.translateElement(document);
          }

          tml.domReady(function () {

            if ((options.translateBody || options.translate_body) && !mutationObserver) {
              tml.translateElement(document.body);
            }

            var t1 = new Date();
            tml.logger.debug("page render took " + (t1 - t0) + " mls");

            if ((options.translateTitle || options.translate_title) && document.title !== "") {
              document.title = tml.translateLabel(document.title);
            }

            if (!options.agent) options.agent = {};

            if (options.language_selector) {
              helpers.includeLs(options.language_selector);
            }

            helpers.includeAgent(tml.app, {
              host: options.agent.host,
              cache: options.agent.cache || 864000000,
              domains: options.agent.domains || {},
              locale: tml.app.current_locale,
              source: tml.app.current_source,
              sdk: options.sdk || 'tml-js v' + tml.version,
              css: tml.app.css,
              languages: tml.app.languages
            }, function () {
              if (typeof(options.onLoad) == "function") {
                options.onLoad(tml.app);
              }
              tml.emit('load');
              if (callback) callback();
            });
          });
        });
      },