Skip to content

Commit

Permalink
Tidied some global object-related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim committed Aug 27, 2014
1 parent b01bb7c commit 7ccef38
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
10 changes: 4 additions & 6 deletions builder/build.js
Expand Up @@ -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");
Expand All @@ -170,19 +168,19 @@ 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);',
' } else if (typeof module != "undefined" && typeof exports == "object") {',
' // 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);
Expand Down
2 changes: 1 addition & 1 deletion 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",
Expand Down
10 changes: 5 additions & 5 deletions src/core/core.js
Expand Up @@ -8,16 +8,16 @@
* Build date: %%build:date%%
*/

(function(factory, global) {
(function(factory, root) {
if (typeof define == "function" && define.amd) {
// AMD. Register as an anonymous module.
define(factory);
} else if (typeof module != "undefined" && typeof exports == "object") {
// 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");
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/wrappedrange.js
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/rangy-serializer.js
Expand Up @@ -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
Expand Down

0 comments on commit 7ccef38

Please sign in to comment.