Update to latest jsonld.js, remove global JsonLdProcessor define.
authorDave Longley <dlongley@digitalbazaar.com>
Wed, 08 May 2013 15:56:38 -0400
changeset 1645 f507a5febc70
parent 1644 2c479b5337f6
child 1646 7469ada54695
Update to latest jsonld.js, remove global JsonLdProcessor define.
playground/jsonld.js
test-suite/idltest/index.html
--- a/playground/jsonld.js	Wed May 08 17:46:06 2013 +0200
+++ b/playground/jsonld.js	Wed May 08 15:56:38 2013 -0400
@@ -37,7 +37,21 @@
 
 // determine if in-browser or using node.js
 var _nodejs = (typeof module === 'object' && module.exports);
-var _browser = !_nodejs && window;
+var _browser = !_nodejs &&
+  (typeof window !== 'undefined' || typeof self !== 'undefined');
+if(_browser) {
+  if(typeof global === 'undefined') {
+    if(typeof window !== 'undefined') {
+      global = window;
+    }
+    else if(typeof self !== 'undefined') {
+      global = self;
+    }
+    else if(typeof $ !== 'undefined') {
+      global = $;
+    }
+  }
+}
 
 // attaches jsonld API to the given object
 var wrapper = function(jsonld) {
@@ -770,7 +784,7 @@
 /* Futures/Promises API */
 
 jsonld.futures = jsonld.promises = function() {
-  var Future = _nodejs ? require('./Future') : window.Future;
+  var Future = _nodejs ? require('./Future') : global.Future;
   var slice = Array.prototype.slice;
 
   // converts a node.js async op into a future w/boxed resolved value(s)
@@ -902,6 +916,20 @@
     value: JsonLdProcessor
   });
 }
+// setup browser global JsonLdProcessor
+if(_browser && typeof global.JsonLdProcessor === 'undefined') {
+  if(Object.defineProperty) {
+    Object.defineProperty(global, 'JsonLdProcessor', {
+      writable: true,
+      enumerable: false,
+      configurable: true,
+      value: JsonLdProcessor
+    });
+  }
+  else {
+    global.JsonLdProcessor = JsonLdProcessor;
+  }
+}
 
 /* Utility API */
 
@@ -6377,7 +6405,12 @@
 }
 // export simple browser API
 else if(_browser) {
-  window.jsonld = window.jsonld || factory;
+  if(typeof jsonld === 'undefined') {
+    jsonld = jsonldjs = factory;
+  }
+  else {
+    jsonldjs = factory;
+  }
 }
 
 })();
--- a/test-suite/idltest/index.html	Wed May 08 17:46:06 2013 +0200
+++ b/test-suite/idltest/index.html	Wed May 08 15:56:38 2013 -0400
@@ -96,16 +96,6 @@
 <script>
 
 (function() {
-  // setup JsonLdProcessor
-  if (Object.defineProperty) {
-    Object.defineProperty(window, 'JsonLdProcessor', {
-      writable: true,
-      enumerable: false,
-      configurable: true,
-      value: window.jsonld.JsonLdProcessor
-    });
-  }
-
   // Ensure that stringification tests are passed
   var toString = Object.prototype.toString;
   Object.prototype.toString = function() {