You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by "Davies,Douglas" <da...@oclc.org> on 2011/06/03 00:20:40 UTC

initializeGlobalVars

Could someone explain the initializeGlobalVars code?  It looks for the
last script tag and assumes it was the one doing the gadget javascript
include (why???).  I noticed issue SHINDIG-1533 addresses this by
providing __CONTAINER_SCRIPT_ID to identify the correct script tag.
However in YUI where I load dynamically (Y.Get.script) I have no control
over the id beforehand.  Is there a more fullproof way of doing this?
I'm having issues with __CONTAINER, __API_URL, etc. being initialized
properly and I'm having to override them after loading the javascript,
which makes me very uncomfortable.

 

  function initializeGlobalVars() {

    window.__CONTAINER_URI = shindig.uri(window.location.href);

 

    window.__API_URI = null;

    var scriptEl = null;

    if (window.__CONTAINER_SCRIPT_ID) {

      scriptEl = document.getElementById(window.__CONTAINER_SCRIPT_ID);

    } else {

      var scriptEls = document.getElementsByTagName('script');

      if (scriptEls.length > 0) {

        scriptEl = scriptEls[scriptEls.length - 1];

      }

    }

 

    if (scriptEl) {

      window.__API_URI = shindig.uri(scriptEl.src);

      // In case script URI is relative, resolve (make absolute) with
container.

      window.__API_URI.resolve(window.__CONTAINER_URI);

    }

 

    window.__CONTAINER = window.__API_URI

        ? window.__API_URI.getQP('container')

        : 'default';

  }

 

Thanks,

Doug