Skip to content

Commit

Permalink
Wrap all modules in AMD and CommonJS-supporting shims
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Jan 23, 2014
1 parent 451c9a8 commit 38073cd
Show file tree
Hide file tree
Showing 134 changed files with 1,640 additions and 363 deletions.
11 changes: 9 additions & 2 deletions addon/comment/comment.js
@@ -1,4 +1,11 @@
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

var noOptions = {};
Expand Down Expand Up @@ -159,4 +166,4 @@
});
return true;
});
})();
});
11 changes: 9 additions & 2 deletions addon/comment/continuecomment.js
@@ -1,4 +1,11 @@
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
var modes = ["clike", "css", "javascript"];
for (var i = 0; i < modes.length; ++i)
CodeMirror.extendMode(modes[i], {blockCommentContinue: " * "});
Expand Down Expand Up @@ -59,4 +66,4 @@
cm.addKeyMap(map);
}
});
})();
});
11 changes: 9 additions & 2 deletions addon/dialog/dialog.js
@@ -1,6 +1,13 @@
// Open simple dialogs on top of an editor. Relies on dialog.css.

(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
function dialogDiv(cm, template, bottom) {
var wrap = cm.getWrapperElement();
var dialog;
Expand Down Expand Up @@ -119,4 +126,4 @@
if (duration)
doneTimer = setTimeout(close, options.duration);
});
})();
});
11 changes: 9 additions & 2 deletions addon/display/fullscreen.js
@@ -1,4 +1,11 @@
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

CodeMirror.defineOption("fullScreen", false, function(cm, val, old) {
Expand Down Expand Up @@ -28,4 +35,4 @@
window.scrollTo(info.scrollLeft, info.scrollTop);
cm.refresh();
}
})();
});
11 changes: 9 additions & 2 deletions addon/display/placeholder.js
@@ -1,4 +1,11 @@
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
var prev = old && old != CodeMirror.Init;
if (val && !prev) {
Expand Down Expand Up @@ -45,4 +52,4 @@
function isEmpty(cm) {
return (cm.lineCount() === 1) && (cm.getLine(0) === "");
}
})();
});
11 changes: 9 additions & 2 deletions addon/edit/closebrackets.js
@@ -1,4 +1,11 @@
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
var DEFAULT_BRACKETS = "()[]{}''\"\"";
var DEFAULT_EXPLODE_ON_ENTER = "[]{}";
var SPACE_CHAR_REGEX = /\s/;
Expand Down Expand Up @@ -112,4 +119,4 @@
});
};
}
})();
});
11 changes: 9 additions & 2 deletions addon/edit/closetag.js
Expand Up @@ -22,7 +22,14 @@
* See demos/closetag.html for a usage example.
*/

(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../fold/xml-fold"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
CodeMirror.defineOption("autoCloseTags", false, function(cm, val, old) {
if (old != CodeMirror.Init && old)
cm.removeKeyMap("autoCloseTags");
Expand Down Expand Up @@ -106,4 +113,4 @@
if (collection[i] == elt) return i;
return -1;
}
})();
});
11 changes: 9 additions & 2 deletions addon/edit/continuelist.js
@@ -1,4 +1,11 @@
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

var listRE = /^(\s*)([*+-]|(\d+)\.)(\s*)/,
Expand All @@ -25,4 +32,4 @@

cm.replaceSelections(replacements, null, "+insert");
};
}());
});
11 changes: 9 additions & 2 deletions addon/edit/matchbrackets.js
@@ -1,4 +1,11 @@
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
(document.documentMode == null || document.documentMode < 8);

Expand Down Expand Up @@ -93,4 +100,4 @@
CodeMirror.defineExtension("findMatchingBracket", function(pos, strict){
return findMatchingBracket(this, pos, strict);
});
})();
});
11 changes: 9 additions & 2 deletions addon/edit/matchtags.js
@@ -1,4 +1,11 @@
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../fold/xml-fold"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

CodeMirror.defineOption("matchTags", false, function(cm, val, old) {
Expand Down Expand Up @@ -53,4 +60,4 @@
if (other) cm.setSelection(other.to, other.from);
}
};
})();
});
37 changes: 23 additions & 14 deletions addon/edit/trailingspace.js
@@ -1,15 +1,24 @@
CodeMirror.defineOption("showTrailingSpace", false, function(cm, val, prev) {
if (prev == CodeMirror.Init) prev = false;
if (prev && !val)
cm.removeOverlay("trailingspace");
else if (!prev && val)
cm.addOverlay({
token: function(stream) {
for (var l = stream.string.length, i = l; i && /\s/.test(stream.string.charAt(i - 1)); --i) {}
if (i > stream.pos) { stream.pos = i; return null; }
stream.pos = l;
return "trailingspace";
},
name: "trailingspace"
});
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
CodeMirror.defineOption("showTrailingSpace", false, function(cm, val, prev) {
if (prev == CodeMirror.Init) prev = false;
if (prev && !val)
cm.removeOverlay("trailingspace");
else if (!prev && val)
cm.addOverlay({
token: function(stream) {
for (var l = stream.string.length, i = l; i && /\s/.test(stream.string.charAt(i - 1)); --i) {}
if (i > stream.pos) { stream.pos = i; return null; }
stream.pos = l;
return "trailingspace";
},
name: "trailingspace"
});
});
});
15 changes: 12 additions & 3 deletions addon/fold/brace-fold.js
@@ -1,3 +1,13 @@
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

CodeMirror.registerHelper("fold", "brace", function(cm, start) {
var line = start.line, lineText = cm.getLine(line);
var startCh, tokenType;
Expand Down Expand Up @@ -45,7 +55,6 @@ CodeMirror.registerHelper("fold", "brace", function(cm, start) {
return {from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh)};
});
CodeMirror.braceRangeFinder = CodeMirror.fold.brace; // deprecated

CodeMirror.registerHelper("fold", "import", function(cm, start) {
function hasImport(line) {
Expand All @@ -70,7 +79,6 @@ CodeMirror.registerHelper("fold", "import", function(cm, start) {
}
return {from: cm.clipPos(CodeMirror.Pos(start, has.startCh + 1)), to: end};
});
CodeMirror.importRangeFinder = CodeMirror.fold["import"]; // deprecated

CodeMirror.registerHelper("fold", "include", function(cm, start) {
function hasInclude(line) {
Expand All @@ -90,4 +98,5 @@ CodeMirror.registerHelper("fold", "include", function(cm, start) {
return {from: CodeMirror.Pos(start, has + 1),
to: cm.clipPos(CodeMirror.Pos(end))};
});
CodeMirror.includeRangeFinder = CodeMirror.fold.include; // deprecated

});
12 changes: 12 additions & 0 deletions addon/fold/comment-fold.js
@@ -1,3 +1,13 @@
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

CodeMirror.registerGlobalHelper("fold", "comment", function(mode) {
return mode.blockCommentStart && mode.blockCommentEnd;
}, function(cm, start) {
Expand Down Expand Up @@ -40,3 +50,5 @@ CodeMirror.registerGlobalHelper("fold", "comment", function(mode) {
return {from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh)};
});

});
11 changes: 9 additions & 2 deletions addon/fold/foldcode.js
@@ -1,4 +1,11 @@
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

function doFold(cm, pos, options, force) {
Expand Down Expand Up @@ -83,4 +90,4 @@
if (cur) return cur;
}
});
})();
});
11 changes: 9 additions & 2 deletions addon/fold/foldgutter.js
@@ -1,4 +1,11 @@
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("./foldcode"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "./foldcode"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

CodeMirror.defineOption("foldGutter", false, function(cm, val, old) {
Expand Down Expand Up @@ -121,4 +128,4 @@
if (line >= state.from && line < state.to)
updateFoldInfo(cm, line, line + 1);
}
})();
});
13 changes: 12 additions & 1 deletion addon/fold/indent-fold.js
@@ -1,3 +1,13 @@
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

CodeMirror.registerHelper("fold", "indent", function(cm, start) {
var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
if (!/\S/.test(firstLine)) return;
Expand Down Expand Up @@ -27,4 +37,5 @@ CodeMirror.registerHelper("fold", "indent", function(cm, start) {
to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)
};
});
CodeMirror.indentRangeFinder = CodeMirror.fold.indent; // deprecated

});
13 changes: 9 additions & 4 deletions addon/fold/xml-fold.js
@@ -1,4 +1,11 @@
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

var Pos = CodeMirror.Pos;
Expand Down Expand Up @@ -136,8 +143,6 @@
}
}
});
CodeMirror.tagRangeFinder = CodeMirror.fold.xml; // deprecated

CodeMirror.findMatchingTag = function(cm, pos, range) {
var iter = new Iter(cm, pos.line, pos.ch, range);
if (iter.text.indexOf(">") == -1 && iter.text.indexOf("<") == -1) return;
Expand Down Expand Up @@ -170,4 +175,4 @@
var iter = new Iter(cm, pos.line, pos.ch, end ? {from: 0, to: end} : null);
return !!findMatchingClose(iter, name);
};
})();
});
11 changes: 9 additions & 2 deletions addon/hint/anyword-hint.js
@@ -1,4 +1,11 @@
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

var WORD = /[\w$]+/, RANGE = 500;
Expand Down Expand Up @@ -29,4 +36,4 @@
}
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
});
})();
});

0 comments on commit 38073cd

Please sign in to comment.