<?xml version="1.0" encoding="UTF-8"?>
<Module>
  <ModulePrefs title="Sandbox Status">
    <Require feature="opensocial-0.8"/>
    <Require feature="views" />
    <Require feature="dynamic-height" />
  </ModulePrefs>
  <Content type="html" view="home,profile,canvas">
    <![CDATA[
      <script type="text/javascript">
        function checkStatus() {
          try {
            var e = opensocial.getEnvironment();
            renderStatus('', 'Leave');
          } catch (e) {
            try {
              gadgets.util.adjustIFrameHeight();
              renderStatus(' not', 'Enter');
            } catch (e2) {
              if (isRenderedBySandbox()) {
                renderError();
              } else {
                renderStatus(' not', 'Enter');
              }
            }
          }
        }
        
        function getSandboxUrl() {
          return _args()['parent'] + '/ig/sandbox';
        }
        
        function isRenderedBySandbox() {
          var re = RegExp('[0-9]+.ig.gmodules.com');
          var match = re.exec(window.location);
          if (match == null) {
            return false;
          } else {
            return true;
          }
        }
        
        function renderError() {
          document.getElementById('status').innerHTML = 'It appears that you are in the sandbox, but neither opensocial.* nor gadgets.* are defined. This may be a bug.';
        }
        
        function renderStatus(modifier, verb) {
          var html = [];
          html.push('You are');
          html.push(modifier);
          html.push(' in the sandbox. ');
          html.push('<a href="javascript:void;" onclick="self.parent.location=\'');
          html.push(getSandboxUrl());
          html.push('\';">');
          html.push(verb);
          html.push(' the sandbox</a>');
          document.getElementById('status').innerHTML = html.join('');
          _IG_AdjustIFrameHeight();
        }

        // Checks whether you're in the sandbox when the gadget finishes loading.
        //_IG_RegisterOnloadHandler(checkStatus);
      </script>
      <div id="status">This gadget is temporarily disabled, but an update will be along shortly.</div>
    ]]>
  </Content>
</Module>


