From 7ccef38590c5064893ca8199531e52ed2847f981 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 27 Aug 2014 22:11:42 +0100 Subject: [PATCH] Tidied some global object-related stuff --- builder/build.js | 10 ++++------ package.json | 2 +- src/core/core.js | 10 +++++----- src/core/wrappedrange.js | 2 +- src/modules/rangy-serializer.js | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/builder/build.js b/builder/build.js index e0c40cc3..8b14abb4 100644 --- a/builder/build.js +++ b/builder/build.js @@ -154,8 +154,6 @@ function assembleCoreScript() { return indent(files[scriptName]); }); - combinedScript = combinedScript.replace(/\/\*\s?build:replaceWithGlobalObject\s?\*\/(?:.*)\/\*\s?build:replaceWithGlobalObjectEnd\s?\*\//g, globalObjectGetterCode); - fs.writeFileSync(uncompressedBuildDir + coreFilename, combinedScript, FILE_ENCODING); console.log("Assembled core script"); @@ -170,7 +168,7 @@ function copyModuleScripts() { moduleCode = moduleCode.replace(/\/\*\s?build:modularizeWithRangyDependency\s?\*\/([\s\S]*?)\/\*\s?build:modularizeEnd\s?\*\//gm, function(match, code) { //var dependenciesArray = eval(dependencies); return [ - '(function(factory, global) {', + '(function(factory, root) {', ' if (typeof define == "function" && define.amd) {', ' // AMD. Register as an anonymous module with a dependency on Rangy.', ' define(["./rangy-core"], factory);', @@ -178,11 +176,11 @@ function copyModuleScripts() { ' // Node/CommonJS style', ' module.exports = factory( require("rangy") );', ' } else {', - ' // No AMD or CommonJS support so we use the rangy global variable', - ' factory(global.rangy);', + ' // No AMD or CommonJS support so we use the rangy property of root (probably the global variable)', + ' factory(root.rangy);', ' }', '})(function(rangy) {' - ].join("\n") + indent(code) + "\n}, " + globalObjectGetterCode + ");"; + ].join("\n") + indent(code) + "\n}, this);"; }); fs.writeFileSync(uncompressedBuildDir + moduleFile, moduleCode, FILE_ENCODING); diff --git a/package.json b/package.json index da35cfeb..1a95fa59 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "rangy", "description": "A cross-browser DOM range and selection library", - "version": "1.3.0-alpha.20140825", + "version": "1.3.0-alpha.20140827", "author": { "name": "Tim Down", "email": "tim@timdown.co.uk", diff --git a/src/core/core.js b/src/core/core.js index 4adfc8cb..a2b92318 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -8,7 +8,7 @@ * Build date: %%build:date%% */ -(function(factory, global) { +(function(factory, root) { if (typeof define == "function" && define.amd) { // AMD. Register as an anonymous module. define(factory); @@ -16,8 +16,8 @@ // Node/CommonJS style module.exports = factory(); } else { - // No AMD or CommonJS support so we place Rangy in a global variable - global.rangy = factory(); + // No AMD or CommonJS support so we place Rangy in (probably) the global variable + root.rangy = factory(); } })(function() { var log = log4javascript.getLogger("rangy.core"); @@ -115,8 +115,8 @@ }; function consoleLog(msg) { - if (isHostObject(global, "console") && isHostMethod(global.console, "log")) { - global.console.log(msg); + if (typeof console != UNDEFINED && isHostMethod(console, "log")) { + console.log(msg); } } diff --git a/src/core/wrappedrange.js b/src/core/wrappedrange.js index 3affe841..15c9765d 100644 --- a/src/core/wrappedrange.js +++ b/src/core/wrappedrange.js @@ -579,7 +579,7 @@ // implementation to use by default. if (!api.features.implementsDomRange || api.config.preferTextRange) { // Add WrappedTextRange as the Range property of the global object to allow expression like Range.END_TO_END to work - var globalObj = (function() { return this; })(); + var globalObj = (function(f) { return f("return this;")(); })(Function); if (typeof globalObj.Range == "undefined") { globalObj.Range = WrappedTextRange; } diff --git a/src/modules/rangy-serializer.js b/src/modules/rangy-serializer.js index 01d47de0..41855542 100644 --- a/src/modules/rangy-serializer.js +++ b/src/modules/rangy-serializer.js @@ -19,7 +19,7 @@ rangy.createModule("Serializer", ["WrappedSelection"], function(api, module) { // encodeURIComponent and decodeURIComponent are required for cookie handling if (typeof encodeURIComponent == UNDEF || typeof decodeURIComponent == UNDEF) { - module.fail("Global object is missing encodeURIComponent and/or decodeURIComponent method"); + module.fail("encodeURIComponent and/or decodeURIComponent method is missing"); } // Checksum for checking whether range can be serialized