From fb5d93a8a382555153c2eba9cee2ff1c120b87df Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Mon, 13 Sep 2010 10:46:00 +0200 Subject: [PATCH 01/12] o3 fixes --- experiments/o3.html | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/experiments/o3.html b/experiments/o3.html index cba22570..b944fae0 100644 --- a/experiments/o3.html +++ b/experiments/o3.html @@ -8,16 +8,23 @@ + + From 39bfb96fde3d5339710353e0e02784a367b66c72 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Mon, 13 Sep 2010 15:13:03 +0200 Subject: [PATCH 02/12] fix text selection for documents with tabs --- src/ace/Range.js | 7 +++++++ src/ace/VirtualRenderer.js | 12 ++---------- src/ace/layer/Cursor.js | 6 +++++- src/ace/layer/Marker.js | 2 ++ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/ace/Range.js b/src/ace/Range.js index 84f6e6c0..45e93c79 100644 --- a/src/ace/Range.js +++ b/src/ace/Range.js @@ -101,6 +101,13 @@ ace.Range = function(startRow, startColumn, endRow, endColumn) { return ace.Range.fromPoints(this.start, this.end); }; + this.toScreenRange = function(doc) { + return new ace.Range( + this.start.row, doc.documentToScreenColumn(this.start.row, this.start.column), + this.end.row, doc.documentToScreenColumn(this.end.row, this.end.column) + ); + }; + }).call(ace.Range.prototype); diff --git a/src/ace/VirtualRenderer.js b/src/ace/VirtualRenderer.js index 35f017c5..1076d7cb 100644 --- a/src/ace/VirtualRenderer.js +++ b/src/ace/VirtualRenderer.js @@ -59,6 +59,7 @@ ace.VirtualRenderer = function(container) { this.setDocument = function(doc) { this.lines = doc.lines; this.doc = doc; + this.$cursorLayer.setDocument(doc); this.$markerLayer.setDocument(doc); this.$textLayer.setDocument(doc); }; @@ -229,8 +230,6 @@ ace.VirtualRenderer = function(container) { this.addMarker = function(range, clazz, type) { - range.start = this.$documentToScreenPosition(range.start); - range.end = this.$documentToScreenPosition(range.end); return this.$markerLayer.addMarker(range, clazz, type); }; @@ -243,17 +242,10 @@ ace.VirtualRenderer = function(container) { }; this.updateCursor = function(position, overwrite) { - this.$cursorLayer.setCursor(this.$documentToScreenPosition(position), overwrite); + this.$cursorLayer.setCursor(position, overwrite); this.$cursorLayer.update(this.layerConfig); }; - this.$documentToScreenPosition = function(pos) { - return { - row: pos.row, - column: this.doc.documentToScreenColumn(pos.row, pos.column) - }; - }; - this.hideCursor = function() { this.$cursorLayer.hideCursor(); }; diff --git a/src/ace/layer/Cursor.js b/src/ace/layer/Cursor.js index 06480a7f..cc96d598 100644 --- a/src/ace/layer/Cursor.js +++ b/src/ace/layer/Cursor.js @@ -13,10 +13,14 @@ ace.layer.Cursor = function(parentEl) { (function() { + this.setDocument = function(doc) { + this.doc = doc; + }; + this.setCursor = function(position, overwrite) { this.position = { row : position.row, - column : position.column + column : this.doc.documentToScreenColumn(position.row, position.column) }; if (overwrite) { ace.addCssClass(this.cursor, "ace_overwrite"); diff --git a/src/ace/layer/Marker.js b/src/ace/layer/Marker.js index dcac23bc..8376dcfe 100644 --- a/src/ace/layer/Marker.js +++ b/src/ace/layer/Marker.js @@ -84,6 +84,7 @@ ace.layer.Marker = function(parentEl) { }; this.drawMultiLineMarker = function(stringBuilder, range, clazz, layerConfig) { + var range = range.toScreenRange(this.doc); // from selection start to the end of the line var height = layerConfig.lineHeight; @@ -125,6 +126,7 @@ ace.layer.Marker = function(parentEl) { }; this.drawSingleLineMarker = function(stringBuilder, range, clazz, layerConfig) { + var range = range.toScreenRange(this.doc); var height = layerConfig.lineHeight; var width = Math.round((range.end.column - range.start.column) * layerConfig.characterWidth); From 3378043072e9d576fde06c3d05fe2936399c7f92 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Mon, 13 Sep 2010 15:33:02 +0200 Subject: [PATCH 03/12] fix horizontal scrolling for documents with tabs --- src/ace/Document.js | 25 +++++++++++++++++++++++-- src/ace/VirtualRenderer.js | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/ace/Document.js b/src/ace/Document.js index 810fdf6f..2d866199 100644 --- a/src/ace/Document.js +++ b/src/ace/Document.js @@ -102,6 +102,7 @@ ace.Document = function(text, mode) { this.setTabSize = function(tabSize) { if (this.$tabSize === tabSize) return; + this.modified = true; this.$tabSize = tabSize; this.$dispatchEvent("changeTabSize"); }; @@ -199,17 +200,37 @@ ace.Document = function(text, mode) { }; this.getWidth = function() { + this.$computeWidth(); + return this.width; + }; + + this.getScreenWidth = function() { + this.$computeWidth(); + return this.screenWith; + }; + + this.$computeWidth = function() { if (this.modified) { this.modified = false; var lines = this.lines; var longestLine = 0; + var longestScreenLine = 0; + var tabSize = this.getTabSize(); + for ( var i = 0; i < lines.length; i++) { - longestLine = Math.max(longestLine, lines[i].length); + var len = lines[i].length; + longestLine = Math.max(longestLine, len); + + lines[i].replace("\t", function(m) { + len += tabSize-1; + return m; + }); + longestScreenLine = Math.max(longestScreenLine, len); } this.width = longestLine; + this.screenWith = longestScreenLine; } - return this.width; }; this.getLine = function(row) { diff --git a/src/ace/VirtualRenderer.js b/src/ace/VirtualRenderer.js index 1076d7cb..cf7912ff 100644 --- a/src/ace/VirtualRenderer.js +++ b/src/ace/VirtualRenderer.js @@ -191,7 +191,7 @@ ace.VirtualRenderer = function(container) { var offset = this.scrollTop % this.lineHeight; var minHeight = this.scroller.clientHeight + offset; - var charCount = this.doc.getWidth(); + var charCount = this.doc.getScreenWidth(); if (this.$showInvisibles) charCount += 1; From 117e1ad7aae6a3f92dc44782ff4071291cec8b39 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Mon, 13 Sep 2010 16:30:09 +0200 Subject: [PATCH 04/12] improve CSS mode --- src/ace/lib/lang.js | 9 +++ src/ace/mode/CssHighlightRules.js | 101 +++++++++++++++--------------- 2 files changed, 61 insertions(+), 49 deletions(-) diff --git a/src/ace/lib/lang.js b/src/ace/lib/lang.js index 73ea7720..3aa82a18 100644 --- a/src/ace/lib/lang.js +++ b/src/ace/lib/lang.js @@ -32,6 +32,15 @@ return copy; }; + this.arrayToMap = function(arr) { + var map = {}; + for (var i=0; i the first match is used From 5222fa63b1a26f5f286fa17730f5a0f247e54ff6 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Mon, 13 Sep 2010 16:30:20 +0200 Subject: [PATCH 05/12] improve outdent --- src/ace/Editor.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ace/Editor.js b/src/ace/Editor.js index b6408992..3950db62 100644 --- a/src/ace/Editor.js +++ b/src/ace/Editor.js @@ -505,6 +505,10 @@ ace.Editor = function(renderer, doc) { var indentString = indentString || this.doc.getTabString(); var addedColumns = this.doc.outdentRows(this.getSelectionRange(), indentString); + // besides the indent string also outdent tabs + if (addedColumns == 0 && indentString != "\t") + var addedColumns = this.doc.outdentRows(this.getSelectionRange(), "\t"); + this.selection.shiftSelection(addedColumns); this.$updateDesiredColumn(); }; From f5a7040620a213a4ebe1be9e32a62cdb76394b0e Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Fri, 17 Sep 2010 09:50:45 +0200 Subject: [PATCH 06/12] remove obsolete code --- experiments/o3debugger.html | 532 ------------------------------------ 1 file changed, 532 deletions(-) delete mode 100644 experiments/o3debugger.html diff --git a/experiments/o3debugger.html b/experiments/o3debugger.html deleted file mode 100644 index d26ba98d..00000000 --- a/experiments/o3debugger.html +++ /dev/null @@ -1,532 +0,0 @@ - - - - - - - - - -

- - - - From c432a451c24415f0c565dbd781b0109bee1f842c Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Fri, 17 Sep 2010 09:51:02 +0200 Subject: [PATCH 07/12] build custom web socket debugger service From 773e4df04e024c61851188074b358161ff1408a3 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Fri, 17 Sep 2010 09:51:12 +0200 Subject: [PATCH 08/12] indentation fixes --- src/ace/Document.js | 10 +++++----- src/ace/KeyBinding.js | 6 ++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/ace/Document.js b/src/ace/Document.js index 2d866199..511b5b33 100644 --- a/src/ace/Document.js +++ b/src/ace/Document.js @@ -530,11 +530,11 @@ ace.Document = function(text, mode) { }; this.indentRows = function(range, indentString) { - for (var row=range.start.row; row<= range.end.row; row++) { - this.$insert({row: row, column:0}, indentString); - } - this.fireChangeEvent(range.start.row, range.end.row); - return indentString.length; + for (var row=range.start.row; row<= range.end.row; row++) { + this.$insert({row: row, column:0}, indentString); + } + this.fireChangeEvent(range.start.row, range.end.row); + return indentString.length; }; this.outdentRows = function(range, indentString) { diff --git a/src/ace/KeyBinding.js b/src/ace/KeyBinding.js index 276c05be..3232b957 100644 --- a/src/ace/KeyBinding.js +++ b/src/ace/KeyBinding.js @@ -237,12 +237,10 @@ ace.KeyBinding = function(element, editor) { }; this["Tab"] = function() { - if (this.selection.isMultiLine()) { + if (this.selection.isMultiLine()) this.editor.blockIndent(); - } - else { + else this.editor.onTextInput("\t"); - } }; }).call(ace.KeyBinding.prototype); \ No newline at end of file From fe837c321a2c1fba90ca62cc77386ed6cd7532c5 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Mon, 26 Apr 2010 11:34:34 +0200 Subject: [PATCH 09/12] use requireJS as loader --- css/eclipse.css | 97 ++ demo/editor.html | 95 +- demo/require.js | 1246 ++++++++++++++++++++++ src/ace/BackgroundTokenizer.js | 11 +- src/ace/Document.js | 30 +- src/ace/Editor.js | 39 +- src/ace/KeyBinding.js | 10 +- src/ace/MEventEmitter.js | 14 +- src/ace/Range.js | 23 +- src/ace/ScrollBar.js | 12 +- src/ace/Search.js | 19 +- src/ace/Selection.js | 19 +- src/ace/TextInput.js | 9 +- src/ace/Tokenizer.js | 9 +- src/ace/UndoManager.js | 9 +- src/ace/VirtualRenderer.js | 27 +- src/ace/ace.js | 18 + src/ace/conf/keybindings/default_mac.js | 6 +- src/ace/conf/keybindings/default_win.js | 6 +- src/ace/layer/Cursor.js | 9 +- src/ace/layer/Gutter.js | 9 +- src/ace/layer/Marker.js | 9 +- src/ace/layer/Text.js | 11 +- src/ace/lib/core.js | 19 +- src/ace/lib/dom.js | 38 +- src/ace/lib/event.js | 68 +- src/ace/lib/lang.js | 23 +- src/ace/lib/oop.js | 15 +- src/ace/mode/Css.js | 22 +- src/ace/mode/CssHighlightRules.js | 13 +- src/ace/mode/DocCommentHighlightRules.js | 15 +- src/ace/mode/Html.js | 25 +- src/ace/mode/HtmlHighlightRules.js | 20 +- src/ace/mode/JavaScript.js | 22 +- src/ace/mode/JavaScriptHighlightRules.js | 19 +- src/ace/mode/MatchingBraceOutdent.js | 9 +- src/ace/mode/Text.js | 15 +- src/ace/mode/TextHighlightRules.js | 9 +- src/ace/mode/Xml.js | 20 +- src/ace/mode/XmlHighlightRules.js | 14 +- 40 files changed, 1817 insertions(+), 286 deletions(-) create mode 100644 css/eclipse.css create mode 100644 demo/require.js create mode 100644 src/ace/ace.js diff --git a/css/eclipse.css b/css/eclipse.css new file mode 100644 index 00000000..5206e22a --- /dev/null +++ b/css/eclipse.css @@ -0,0 +1,97 @@ +.editor { + border: 2px solid rgb(159, 159, 159); +} + +.editor.focus { + border: 2px solid #327fbd;; +} + +.gutter { + width: 40px; + background: rgb(227, 227, 227); + border-right: 1px solid rgb(159, 159, 159); + color: rgb(136, 136, 136); + font-family: Monaco, "Courier New"; + font-size: 11px; +} + +.gutter-layer { + right: 10px; + text-align: right; +} + +.text-layer { + font-family: Monaco, "Courier New", monospace; + font-size: 11px; + cursor: text; +} + +.cursor { + width: 1px; + background: black; +} + +.line .keyword { + color: rgb(127, 0, 85); +} + +.line .buildin-constant { + color: rgb(88, 72, 246); +} + +.line .library-constant { + color: rgb(6, 150, 14); +} + +.line .buildin-function { + color: rgb(60, 76, 114); +} + +.line .string { + color: rgb(42, 0, 255); +} + +.line .comment { + color: rgb(63, 127, 95); +} + +.line .doc-comment { + color: rgb(63, 95, 191); +} + +.line .doc-comment-tag { + color: rgb(127, 159, 191); +} + +.line .number { +} + +.line .tag { + color: rgb(63, 127, 127); +} + +.line .attribute { + color: rbg(127, 0, 127); +} + +.line .attribute-value { + font-style: italic; + color: rbg(42, 0, 255); +} + +.line .xml_pe { + color: rgb(104, 104, 91); +} + +.marker-layer .selection { + background: rgb(181, 213, 255); +} + +.marker-layer .bracket { + margin: -1px 0 0 -1px; + border: 1px solid rgb(192, 192, 192); +} + +.marker-layer .active_line { + background: rgb(232, 242, 254); +} \ No newline at end of file diff --git a/demo/editor.html b/demo/editor.html index 57ec722e..ef92a14c 100644 --- a/demo/editor.html +++ b/demo/editor.html @@ -38,44 +38,11 @@ height: 55px; } + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -149,18 +116,34 @@ diff --git a/demo/require.js b/demo/require.js new file mode 100644 index 00000000..0fcc6900 --- /dev/null +++ b/demo/require.js @@ -0,0 +1,1246 @@ +/** + * @license RequireJS Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + * Available via the MIT, GPL or new BSD license. + * see: http://github.com/jrburke/requirejs for details + */ +//laxbreak is true to allow build pragmas to change some statements. +/*jslint plusplus: false, laxbreak: true */ +/*global window: false, document: false, navigator: false, +setTimeout: false, traceDeps: true, clearInterval: false, self: false, +setInterval: false */ + +//>>includeStart("useStrict", pragmas.useStrict); +"use strict"; +//>>includeEnd("useStrict"); + +var require; +(function () { + //Change this version number for each release. + var version = "0.10.0", + empty = {}, s, + i, defContextName = "_", contextLoads = [], + scripts, script, rePkg, src, m, cfg, setReadyState, + readyRegExp = /^(complete|loaded)$/, + isBrowser = !!(typeof window !== "undefined" && navigator && document), + ostring = Object.prototype.toString, scrollIntervalId; + + function isFunction(it) { + return ostring.call(it) === "[object Function]"; + } + + //Check for an existing version of require. If so, then exit out. Only allow + //one version of require to be active in a page. However, allow for a require + //config object, just exit quickly if require is an actual function. + if (typeof require !== "undefined") { + if (isFunction(require)) { + return; + } else { + //assume it is a config object. + cfg = require; + } + } + + //>>excludeStart("requireExcludeContext", pragmas.requireExcludeContext); + function makeContextFunc(name, contextName, force) { + return function () { + //A version of a require function that uses the current context. + //If last arg is a string, then it is a context. + //If last arg is not a string, then add context to it. + var args = [].concat(Array.prototype.slice.call(arguments, 0)); + if (force || typeof arguments[arguments.length - 1] !== "string") { + args.push(contextName); + } + return (name ? require[name] : require).apply(null, args); + }; + } + //>>excludeEnd("requireExcludeContext"); + + //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin); + /** + * Calls a method on a plugin. The obj object should have two property, + * name: the name of the method to call on the plugin + * args: the arguments to pass to the plugin method. + */ + function callPlugin(prefix, context, obj) { + //Call the plugin, or load it. + var plugin = s.plugins.defined[prefix], waiting; + if (plugin) { + plugin[obj.name].apply(null, obj.args); + } else { + //Put the call in the waiting call BEFORE requiring the module, + //since the require could be synchronous in some environments, + //like builds + waiting = s.plugins.waiting[prefix] || (s.plugins.waiting[prefix] = []); + waiting.push(obj); + + //Load the module + context.defined.require(["require/" + prefix]); + } + } + //>>excludeEnd("requireExcludePlugin"); + + /** + * Main entry point. + * + * If the only argument to require is a string, then the module that + * is represented by that string is fetched for the appropriate context. + * + * If the first argument is an array, then it will be treated as an array + * of dependency string names to fetch. An optional function callback can + * be specified to execute when all of those dependencies are available. + */ + require = function (deps, callback, contextName) { + if (typeof deps === "string" && !isFunction(callback)) { + //Just return the module wanted. In this scenario, the + //second arg (if passed) is just the contextName. + return require.get(deps, callback); + } + + //Do more work, either + return require.def.apply(require, arguments); + }; + + /** + * The function that handles definitions of modules. Differs from + * require() in that a string for the module should be the first argument, + * and the function to execute after dependencies are loaded should + * return a value to define the module corresponding to the first argument's + * name. + */ + require.def = function (name, deps, callback, contextName) { + var config = null, context, newContext, contextRequire, loaded, + canSetContext, prop, newLength, outDeps, + mods, pluginPrefix, paths, index, i; + + //Normalize the arguments. + if (typeof name === "string") { + //Defining a module. First, pull off any plugin prefix. + index = name.indexOf("!"); + if (index !== -1) { + pluginPrefix = name.substring(0, index); + name = name.substring(index + 1, name.length); + } + + //Check if there are no dependencies, and adjust args. + if (!require.isArray(deps)) { + contextName = callback; + callback = deps; + deps = []; + } + + contextName = contextName || s.ctxName; + + //If module already defined for context, or already waiting to be + //evaluated, leave. + context = s.contexts[contextName]; + if (context && (context.defined[name] || context.waiting[name])) { + return require; + } + } else if (require.isArray(name)) { + //Just some code that has dependencies. Adjust args accordingly. + contextName = callback; + callback = deps; + deps = name; + name = null; + } else if (require.isFunction(name)) { + //Just a function that does not define a module and + //does not have dependencies. Useful if just want to wait + //for whatever modules are in flight and execute some code after + //those modules load. + callback = name; + contextName = deps; + name = null; + deps = []; + } else { + //name is a config object. + config = name; + name = null; + //Adjust args if no dependencies. + if (require.isFunction(deps)) { + contextName = callback; + callback = deps; + deps = []; + } + + contextName = contextName || config.context; + } + + contextName = contextName || s.ctxName; + + //>>excludeStart("requireExcludeContext", pragmas.requireExcludeContext); + if (contextName !== s.ctxName) { + //If nothing is waiting on being loaded in the current context, + //then switch s.ctxName to current contextName. + loaded = (s.contexts[s.ctxName] && s.contexts[s.ctxName].loaded); + canSetContext = true; + if (loaded) { + for (prop in loaded) { + if (!(prop in empty)) { + if (!loaded[prop]) { + canSetContext = false; + break; + } + } + } + } + if (canSetContext) { + s.ctxName = contextName; + } + } + //>>excludeEnd("requireExcludeContext"); + + //Grab the context, or create a new one for the given context name. + context = s.contexts[contextName]; + if (!context) { + newContext = { + contextName: contextName, + config: { + waitSeconds: 7, + baseUrl: s.baseUrl || "./", + paths: {} + }, + waiting: [], + specified: { + "require": true, + "exports": true, + "module": true + }, + loaded: { + "require": true + }, + defined: {}, + modifiers: {} + }; + + //Define require for this context. + //>>includeStart("requireExcludeContext", pragmas.requireExcludeContext); + //A placeholder for build pragmas. + newContext.defined.require = require; + //>>includeEnd("requireExcludeContext"); + //>>excludeStart("requireExcludeContext", pragmas.requireExcludeContext); + newContext.defined.require = contextRequire = makeContextFunc(null, contextName); + require.mixin(contextRequire, { + //>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify); + modify: makeContextFunc("modify", contextName), + def: makeContextFunc("def", contextName), + //>>excludeEnd("requireExcludeModify"); + get: makeContextFunc("get", contextName, true), + nameToUrl: makeContextFunc("nameToUrl", contextName, true), + ready: require.ready, + context: newContext, + config: newContext.config, + isBrowser: s.isBrowser + }); + //>>excludeEnd("requireExcludeContext"); + + //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin); + if (s.plugins.newContext) { + s.plugins.newContext(newContext); + } + //>>excludeEnd("requireExcludePlugin"); + + context = s.contexts[contextName] = newContext; + } + + //If have a config object, update the context's config object with + //the config values. + if (config) { + //Make sure the baseUrl ends in a slash. + if (config.baseUrl) { + if (config.baseUrl.charAt(config.baseUrl.length - 1) !== "/") { + config.baseUrl += "/"; + } + } + + //Save off the paths since they require special processing, + //they are additive. + paths = context.config.paths; + + //Mix in the config values, favoring the new values over + //existing ones in context.config. + require.mixin(context.config, config, true); + + //Adjust paths if necessary. + if (config.paths) { + for (prop in config.paths) { + if (!(prop in empty)) { + paths[prop] = config.paths[prop]; + } + } + context.config.paths = paths; + } + + //If a deps array or a config callback is specified, then call + //require with those args. This is useful when require is defined as a + //config object before require.js is loaded. + if (config.deps || config.callback) { + require(config.deps || [], config.callback); + } + + //>>excludeStart("requireExcludePageLoad", pragmas.requireExcludePageLoad); + //Set up ready callback, if asked. Useful when require is defined as a + //config object before require.js is loaded. + if (config.ready) { + require.ready(config.ready); + } + //>>excludeEnd("requireExcludePageLoad"); + + //If it is just a config block, nothing else, + //then return. + if (!deps) { + return require; + } + } + + //Normalize dependency strings: need to determine if they have + //prefixes and to also normalize any relative paths. Replace the deps + //array of strings with an array of objects. + if (deps) { + outDeps = deps; + deps = []; + for (i = 0; i < outDeps.length; i++) { + deps[i] = require.splitPrefix(outDeps[i], name); + } + } + + //Store the module for later evaluation + newLength = context.waiting.push({ + name: name, + deps: deps, + callback: callback + }); + + if (name) { + //Store index of insertion for quick lookup + context.waiting[name] = newLength - 1; + + //Mark the module as specified: not loaded yet, but in the process, + //so no need to fetch it again. Important to do it here for the + //pause/resume case where there are multiple modules in a file. + context.specified[name] = true; + + //>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify); + //Load any modifiers for the module. + mods = context.modifiers[name]; + if (mods) { + require(mods, contextName); + } + //>>excludeEnd("requireExcludeModify"); + } + + //If the callback is not an actual function, it means it already + //has the definition of the module as a literal value. + if (name && callback && !require.isFunction(callback)) { + context.defined[name] = callback; + } + + //If a pluginPrefix is available, call the plugin, or load it. + //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin); + if (pluginPrefix) { + callPlugin(pluginPrefix, context, { + name: "require", + args: [name, deps, callback, context] + }); + } + //>>excludeEnd("requireExcludePlugin"); + + //See if all is loaded. If paused, then do not check the dependencies + //of the module yet. + if (s.paused) { + s.paused.push([pluginPrefix, name, deps, context]); + } else { + require.checkDeps(pluginPrefix, name, deps, context); + require.checkLoaded(contextName); + } + + return require; + }; + + /** + * Simple function to mix in properties from source into target, + * but only if target does not already have a property of the same name. + */ + require.mixin = function (target, source, override) { + for (var prop in source) { + if (!(prop in empty) && (!(prop in target) || override)) { + target[prop] = source[prop]; + } + } + return require; + }; + + require.version = version; + + //Set up page state. + s = require.s = { + ctxName: defContextName, + contexts: {}, + //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin); + plugins: { + defined: {}, + callbacks: {}, + waiting: {} + }, + //>>excludeEnd("requireExcludePlugin"); + isBrowser: isBrowser, + isPageLoaded: !isBrowser, + readyCalls: [], + doc: isBrowser ? document : null + }; + + require.isBrowser = s.isBrowser; + s.head = isBrowser ? document.getElementsByTagName("head")[0] : null; + + //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin); + /** + * Sets up a plugin callback name. Want to make it easy to test if a plugin + * needs to be called for a certain lifecycle event by testing for + * if (s.plugins.onLifeCyleEvent) so only define the lifecycle event + * if there is a real plugin that registers for it. + */ + function makePluginCallback(name, returnOnTrue) { + var cbs = s.plugins.callbacks[name] = []; + s.plugins[name] = function () { + for (var i = 0, cb; (cb = cbs[i]); i++) { + if (cb.apply(null, arguments) === true && returnOnTrue) { + return true; + } + } + return false; + }; + } + + /** + * Registers a new plugin for require. + */ + require.plugin = function (obj) { + var i, prop, call, prefix = obj.prefix, cbs = s.plugins.callbacks, + waiting = s.plugins.waiting[prefix], generics, + defined = s.plugins.defined, contexts = s.contexts, context; + + //Do not allow redefinition of a plugin, there may be internal + //state in the plugin that could be lost. + if (defined[prefix]) { + return require; + } + + //Save the plugin. + defined[prefix] = obj; + + //Set up plugin callbacks for methods that need to be generic to + //require, for lifecycle cases where it does not care about a particular + //plugin, but just that some plugin work needs to be done. + generics = ["newContext", "isWaiting", "orderDeps"]; + for (i = 0; (prop = generics[i]); i++) { + if (!s.plugins[prop]) { + makePluginCallback(prop, prop === "isWaiting"); + } + cbs[prop].push(obj[prop]); + } + + //Call newContext for any contexts that were already created. + if (obj.newContext) { + for (prop in contexts) { + if (!(prop in empty)) { + context = contexts[prop]; + obj.newContext(context); + } + } + } + + //If there are waiting requests for a plugin, execute them now. + if (waiting) { + for (i = 0; (call = waiting[i]); i++) { + if (obj[call.name]) { + obj[call.name].apply(null, call.args); + } + } + delete s.plugins.waiting[prefix]; + } + + return require; + }; + //>>excludeEnd("requireExcludePlugin"); + + /** + * Pauses the tracing of dependencies. Useful in a build scenario when + * multiple modules are bundled into one file, and they all need to be + * require before figuring out what is left still to load. + */ + require.pause = function () { + if (!s.paused) { + s.paused = []; + } + }; + + /** + * Resumes the tracing of dependencies. Useful in a build scenario when + * multiple modules are bundled into one file. This method is related + * to require.pause() and should only be called if require.pause() was called first. + */ + require.resume = function () { + var i, args, paused; + if (s.paused) { + paused = s.paused; + delete s.paused; + for (i = 0; (args = paused[i]); i++) { + require.checkDeps.apply(require, args); + } + } + require.checkLoaded(s.ctxName); + }; + + /** + * Trace down the dependencies to see if they are loaded. If not, trigger + * the load. + * @param {String} pluginPrefix the plugin prefix, if any associated with the name. + * + * @param {String} name: the name of the module that has the dependencies. + * + * @param {Array} deps array of dependencies. + * + * @param {Object} context: the loading context. + * + * @private + */ + require.checkDeps = function (pluginPrefix, name, deps, context) { + //Figure out if all the modules are loaded. If the module is not + //being loaded or already loaded, add it to the "to load" list, + //and request it to be loaded. + var i, dep, index, depPrefix, split; + + if (pluginPrefix) { + //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin); + callPlugin(pluginPrefix, context, { + name: "checkDeps", + args: [name, deps, context] + }); + //>>excludeEnd("requireExcludePlugin"); + } else { + for (i = 0; (dep = deps[i]); i++) { + if (!context.specified[dep.fullName]) { + context.specified[dep.fullName] = true; + + //If a plugin, call its load method. + if (dep.prefix) { + //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin); + callPlugin(dep.prefix, context, { + name: "load", + args: [dep.name, context.contextName] + }); + //>>excludeEnd("requireExcludePlugin"); + } else { + require.load(dep.name, context.contextName); + } + } + } + } + }; + + //>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify); + /** + * Register a module that modifies another module. The modifier will + * only be called once the target module has been loaded. + * + * First syntax: + * + * require.modify({ + * "some/target1": "my/modifier1", + * "some/target2": "my/modifier2", + * }); + * + * With this syntax, the my/modifier1 will only be loaded when + * "some/target1" is loaded. + * + * Second syntax, defining a modifier. + * + * require.modify("some/target1", "my/modifier", + * ["some/target1", "some/other"], + * function (target, other) { + * //Modify properties of target here. + * Only properties of target can be modified, but + * target cannot be replaced. + * } + * ); + */ + require.modify = function (target, name, deps, callback, contextName) { + var prop, modifier, list, + cName = (typeof target === "string" ? contextName : name) || s.ctxName, + context = s.contexts[cName], + mods = context.modifiers; + + if (typeof target === "string") { + //A modifier module. + //First store that it is a modifier. + list = mods[target] || (mods[target] = []); + if (!list[name]) { + list.push(name); + list[name] = true; + } + + //Trigger the normal module definition logic. + require.def(name, deps, callback, contextName); + } else { + //A list of modifiers. Save them for future reference. + for (prop in target) { + if (!(prop in empty)) { + //Store the modifier for future use. + modifier = target[prop]; + list = context.modifiers[prop] || (context.modifiers[prop] = []); + if (!list[modifier]) { + list.push(modifier); + list[modifier] = true; + + if (context.specified[prop]) { + //Load the modifier right away. + require([modifier], cName); + } + } + } + } + } + }; + //>>excludeEnd("requireExcludeModify"); + + require.isArray = function (it) { + return ostring.call(it) === "[object Array]"; + }; + + require.isFunction = isFunction; + + /** + * Gets one module's exported value. This method is used by require(). + * It is broken out as a separate function to allow a host environment + * shim to overwrite this function with something appropriate for that + * environment. + * + * @param {String} moduleName the name of the module. + * @param {String} [contextName] the name of the context to use. Uses + * default context if no contextName is provided. + * + * @returns {Object} the exported module value. + */ + require.get = function (moduleName, contextName) { + if (moduleName === "exports" || moduleName === "module") { + throw new Error("require of " + moduleName + " is not allowed."); + } + contextName = contextName || s.ctxName; + var ret = s.contexts[contextName].defined[moduleName]; + if (ret === undefined) { + throw new Error("require: module name '" + + moduleName + + "' has not been loaded yet for context: " + + contextName); + } + return ret; + }; + + /** + * Makes the request to load a module. May be an async load depending on + * the environment and the circumstance of the load call. Override this + * method in a host environment shim to do something specific for that + * environment. + * + * @param {String} moduleName the name of the module. + * @param {String} contextName the name of the context to use. + */ + require.load = function (moduleName, contextName) { + var context = s.contexts[contextName], url; + s.isDone = false; + context.loaded[moduleName] = false; + //>>excludeStart("requireExcludeContext", pragmas.requireExcludeContext); + if (contextName !== s.ctxName) { + //Not in the right context now, hold on to it until + //the current context finishes all its loading. + contextLoads.push(arguments); + } else { + //>>excludeEnd("requireExcludeContext"); + //First derive the path name for the module. + url = require.nameToUrl(moduleName, null, contextName); + require.attach(url, contextName, moduleName); + context.startTime = (new Date()).getTime(); + //>>excludeStart("requireExcludeContext", pragmas.requireExcludeContext); + } + //>>excludeEnd("requireExcludeContext"); + }; + + require.jsExtRegExp = /\.js$/; + + + /** + * Given a relative module name, like ./something, normalize it to + * a real name that can be mapped to a path. + * @param {String} name the relative name + * @param {String} baseName a real name that the name arg is relative + * to. + * @returns {String} normalized name + */ + require.normalizeName = function (name, baseName) { + //Adjust any relative paths. + var part; + if (name.charAt(0) === ".") { + //Convert baseName to array, and lop off the last part, + //so that . matches that "directory" and not name of the baseName's + //module. For instance, baseName of "one/two/three", maps to + //"one/two/three.js", but we want the directory, "one/two" for + //this normalization. + baseName = baseName.split("/"); + baseName = baseName.slice(0, baseName.length - 1); + + name = baseName.concat(name.split("/")); + for (i = 0; (part = name[i]); i++) { + if (part === ".") { + name.splice(i, 1); + i -= 1; + } else if (part === "..") { + name.splice(i - 1, 2); + i -= 2; + } + } + name = name.join("/"); + } + return name; + }; + + /** + * Splits a name into a possible plugin prefix and + * the module name. If baseName is provided it will + * also normalize the name via require.normalizeName() + * + * @param {String} name the module name + * @param {String} [baseName] base name that name is + * relative to. + * + * @returns {Object} with properties, 'prefix' (which + * may be null), 'name' and 'fullName', which is a combination + * of the prefix (if it exists) and the name. + */ + require.splitPrefix = function (name, baseName) { + var index = name.indexOf("!"), prefix = null; + if (index !== -1) { + prefix = name.substring(0, index); + name = name.substring(index + 1, name.length); + } + + //Account for relative paths if there is a base name. + if (baseName) { + name = require.normalizeName(name, baseName); + } + + return { + prefix: prefix, + name: name, + fullName: prefix ? prefix + "!" + name : name + }; + }; + + /** + * Converts a module name to a file path. + */ + require.nameToUrl = function (moduleName, ext, contextName) { + var paths, syms, i, parentModule, url, + config = s.contexts[contextName].config; + + //If a colon is in the URL, it indicates a protocol is used and it is just + //an URL to a file, or if it starts with a slash or ends with .js, it is just a plain file. + //The slash is important for protocol-less URLs as well as full paths. + if (moduleName.indexOf(":") !== -1 || moduleName.charAt(0) === '/' || require.jsExtRegExp.test(moduleName)) { + //Just a plain path, not module name lookup, so just return it. + return moduleName; + } else if (moduleName.charAt(0) === ".") { + throw new Error("require.nameToUrl does not handle relative module names (ones that start with '.' or '..')"); + } else { + //A module that needs to be converted to a path. + paths = config.paths; + + syms = moduleName.split("/"); + //For each module name segment, see if there is a path + //registered for it. Start with most specific name + //and work up from it. + for (i = syms.length; i > 0; i--) { + parentModule = syms.slice(0, i).join("/"); + if (paths[parentModule]) { + syms.splice(0, i, paths[parentModule]); + break; + } + } + + //Join the path parts together, then figure out if baseUrl is needed. + url = syms.join("/") + (ext || ".js"); + return ((url.charAt(0) === '/' || url.match(/^\w+:/)) ? "" : config.baseUrl) + url; + } + }; + + /** + * Checks if all modules for a context are loaded, and if so, evaluates the + * new ones in right dependency order. + * + * @private + */ + require.checkLoaded = function (contextName) { + var context = s.contexts[contextName || s.ctxName], + waitInterval = context.config.waitSeconds * 1000, + //It is possible to disable the wait interval by using waitSeconds of 0. + expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(), + loaded = context.loaded, defined = context.defined, + modifiers = context.modifiers, waiting = context.waiting, noLoads = "", + hasLoadedProp = false, stillLoading = false, prop, + + //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin); + pIsWaiting = s.plugins.isWaiting, pOrderDeps = s.plugins.orderDeps, + //>>excludeEnd("requireExcludePlugin"); + + i, module, allDone, loads, loadArgs, + traced = {}; + + //If already doing a checkLoaded call, + //then do not bother checking loaded state. + if (context.isCheckLoaded) { + return; + } + + //Signal that checkLoaded is being require, so other calls that could be triggered + //by calling a waiting callback that then calls require and then this function + //should not proceed. At the end of this function, if there are still things + //waiting, then checkLoaded will be called again. + context.isCheckLoaded = true; + + //See if anything is still in flight. + for (prop in loaded) { + if (!(prop in empty)) { + hasLoadedProp = true; + if (!loaded[prop]) { + if (expired) { + noLoads += prop + " "; + } else { + stillLoading = true; + break; + } + } + } + } + + //Check for exit conditions. + if (!hasLoadedProp && !waiting.length + //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin); + && (!pIsWaiting || !pIsWaiting(context)) + //>>excludeEnd("requireExcludePlugin"); + ) { + //If the loaded object had no items, then the rest of + //the work below does not need to be done. + context.isCheckLoaded = false; + return; + } + if (expired && noLoads) { + //If wait time expired, throw error of unloaded modules. + throw new Error("require.js load timeout for modules: " + noLoads); + } + if (stillLoading) { + //Something is still waiting to load. Wait for it. + context.isCheckLoaded = false; + if (require.isBrowser) { + setTimeout(function () { + require.checkLoaded(contextName); + }, 50); + } + return; + } + + //Order the dependencies. Also clean up state because the evaluation + //of modules might create new loading tasks, so need to reset. + //Be sure to call plugins too. + context.waiting = []; + context.loaded = {}; + + //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin); + //Call plugins to order their dependencies, do their + //module definitions. + if (pOrderDeps) { + pOrderDeps(context); + } + //>>excludeEnd("requireExcludePlugin"); + + //>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify); + //Before defining the modules, give priority treatment to any modifiers + //for modules that are already defined. + for (prop in modifiers) { + if (!(prop in empty)) { + if (defined[prop]) { + require.execModifiers(prop, traced, waiting, context); + } + } + } + //>>excludeEnd("requireExcludeModify"); + + //Define the modules, doing a depth first search. + for (i = 0; (module = waiting[i]); i++) { + require.exec(module, traced, waiting, context); + } + + //Indicate checkLoaded is now done. + context.isCheckLoaded = false; + + if (context.waiting.length + //>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin); + || (pIsWaiting && pIsWaiting(context)) + //>>excludeEnd("requireExcludePlugin"); + ) { + //More things in this context are waiting to load. They were probably + //added while doing the work above in checkLoaded, calling module + //callbacks that triggered other require calls. + require.checkLoaded(contextName); + } else if (contextLoads.length) { + //>>excludeStart("requireExcludeContext", pragmas.requireExcludeContext); + //Check for other contexts that need to load things. + //First, make sure current context has no more things to + //load. After defining the modules above, new require calls + //could have been made. + loaded = context.loaded; + allDone = true; + for (prop in loaded) { + if (!(prop in empty)) { + if (!loaded[prop]) { + allDone = false; + break; + } + } + } + + if (allDone) { + s.ctxName = contextLoads[0][1]; + loads = contextLoads; + //Reset contextLoads in case some of the waiting loads + //are for yet another context. + contextLoads = []; + for (i = 0; (loadArgs = loads[i]); i++) { + require.load.apply(require, loadArgs); + } + } + //>>excludeEnd("requireExcludeContext"); + } else { + //Make sure we reset to default context. + s.ctxName = defContextName; + s.isDone = true; + if (require.callReady) { + require.callReady(); + } + } + }; + + /** + * Executes the modules in the correct order. + * + * @private + */ + require.exec = function (module, traced, waiting, context) { + //Some modules are just plain script files, abddo not have a formal + //module definition, + if (!module) { + return undefined; + } + + var name = module.name, cb = module.callback, deps = module.deps, j, dep, + defined = context.defined, ret, args = [], prefix, depModule, + usingExports = false, depName; + + //If already traced or defined, do not bother a second time. + if (name) { + if (traced[name] || defined[name]) { + return defined[name]; + } + + //Mark this module as being traced, so that it is not retraced (as in a circular + //dependency) + traced[name] = true; + } + + if (deps) { + for (j = 0; (dep = deps[j]); j++) { + depName = dep.name; + if (depName === "exports") { + //CommonJS module spec 1.1 + depModule = defined[name] = {}; + usingExports = true; + } else if (depName === "module") { + //CommonJS module spec 1.1 + depModule = { + id: name, + uri: name ? require.nameToUrl(name, null, context.contextName) : undefined + }; + } else { + //Get dependent module. It could not exist, for a circular + //dependency or if the loaded dependency does not actually call + //require. Favor not throwing an error here if undefined because + //we want to allow code that does not use require as a module + //definition framework to still work -- allow a web site to + //gradually update to contained modules. That is more + //important than forcing a throw for the circular dependency case. + depModule = depName in defined ? defined[depName] : (traced[depName] ? undefined : require.exec(waiting[waiting[depName]], traced, waiting, context)); + } + + args.push(depModule); + } + } + + //Call the callback to define the module, if necessary. + cb = module.callback; + if (cb && require.isFunction(cb)) { + ret = require.execCb(name, cb, args); + if (name) { + if (usingExports) { + ret = defined[name]; + } else { + if (name in defined) { + throw new Error(name + " has already been defined"); + } else { + defined[name] = ret; + } + } + } + } + + //>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify); + //Execute modifiers, if they exist. + require.execModifiers(name, traced, waiting, context); + //>>excludeEnd("requireExcludeModify"); + + return ret; + }; + + /** + * Executes a module callack function. Broken out as a separate function + * solely to allow the build system to sequence the files in the built + * layer in the right sequence. + * @param {String} name the module name. + * @param {Function} cb the module callback/definition function. + * @param {Array} args The arguments (dependent modules) to pass to callback. + * + * @private + */ + require.execCb = function (name, cb, args) { + return cb.apply(null, args); + }; + + //>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify); + /** + * Executes modifiers for the given module name. + * @param {String} target + * @param {Object} traced + * @param {Object} context + * + * @private + */ + require.execModifiers = function (target, traced, waiting, context) { + var modifiers = context.modifiers, mods = modifiers[target], mod, i; + if (mods) { + for (i = 0; i < mods.length; i++) { + mod = mods[i]; + //Not all modifiers define a module, they might collect other modules. + //If it is just a collection it will not be in waiting. + if (mod in waiting) { + require.exec(waiting[waiting[mod]], traced, waiting, context); + } + } + delete modifiers[target]; + } + }; + //>>excludeEnd("requireExcludeModify"); + + /** + * callback for script loads, used to check status of loading. + * + * @param {Event} evt the event from the browser for the script + * that was loaded. + * + * @private + */ + require.onScriptLoad = function (evt) { + var node = evt.target || evt.srcElement, contextName, moduleName; + if (evt.type === "load" || readyRegExp.test(node.readyState)) { + //Pull out the name of the module and the context. + contextName = node.getAttribute("data-requirecontext"); + moduleName = node.getAttribute("data-requiremodule"); + + //Mark the module loaded. + s.contexts[contextName].loaded[moduleName] = true; + + require.checkLoaded(contextName); + + //Clean up script binding. + if (node.removeEventListener) { + node.removeEventListener("load", require.onScriptLoad, false); + } else { + //Probably IE. + node.detachEvent("onreadystatechange", require.onScriptLoad); + } + } + }; + + /** + * Attaches the script represented by the URL to the current + * environment. Right now only supports browser loading, + * but can be redefined in other environments to do the right thing. + */ + require.attach = function (url, contextName, moduleName) { + if (require.isBrowser) { + var node = document.createElement("script"); + node.type = "text/javascript"; + node.charset = "utf-8"; + node.setAttribute("data-requirecontext", contextName); + node.setAttribute("data-requiremodule", moduleName); + + //Set up load listener. + if (node.addEventListener) { + node.addEventListener("load", require.onScriptLoad, false); + } else { + //Probably IE. + node.attachEvent("onreadystatechange", require.onScriptLoad); + } + node.src = url; + + return s.head.appendChild(node); + } + return null; + }; + + //Determine what baseUrl should be if not already defined via a require config object + s.baseUrl = cfg && cfg.baseUrl; + if (require.isBrowser && (!s.baseUrl || !s.head)) { + //Figure out baseUrl. Get it from the script tag with require.js in it. + scripts = document.getElementsByTagName("script"); + if (cfg && cfg.baseUrlMatch) { + rePkg = cfg.baseUrlMatch; + } else { + //>>includeStart("jquery", pragmas.jquery); + rePkg = /(requireplugins-|require-)?jquery[\-\d\.]*(min)?\.js(\W|$)/i; + //>>includeEnd("jquery"); + + //>>includeStart("dojoConvert", pragmas.dojoConvert); + rePkg = /dojo\.js(\W|$)/i; + //>>includeEnd("dojoConvert"); + + //>>excludeStart("dojoConvert", pragmas.dojoConvert); + + //>>excludeStart("jquery", pragmas.jquery); + rePkg = /(allplugins-)?require\.js(\W|$)/i; + //>>excludeEnd("jquery"); + + //>>excludeEnd("dojoConvert"); + } + + for (i = scripts.length - 1; i > -1 && (script = scripts[i]); i--) { + //Set the "head" where we can append children by + //using the script's parent. + if (!s.head) { + s.head = script.parentNode; + } + //Using .src instead of getAttribute to get an absolute URL. + //While using a relative URL will be fine for script tags, other + //URLs used for text! resources that use XHR calls might benefit + //from an absolute URL. + src = script.src; + if (src) { + m = src.match(rePkg); + if (m) { + s.baseUrl = src.substring(0, m.index); + break; + } + } + } + } + + //>>excludeStart("requireExcludePageLoad", pragmas.requireExcludePageLoad); + //****** START page load functionality **************** + /** + * Sets the page as loaded and triggers check for all modules loaded. + */ + require.pageLoaded = function () { + if (!s.isPageLoaded) { + s.isPageLoaded = true; + if (scrollIntervalId) { + clearInterval(scrollIntervalId); + } + + //Part of a fix for FF < 3.6 where readyState was not set to + //complete so libraries like jQuery that check for readyState + //after page load where not getting initialized correctly. + //Original approach suggested by Andrea Giammarchi: + //http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html + //see other setReadyState reference for the rest of the fix. + if (setReadyState) { + document.readyState = "complete"; + } + + require.callReady(); + } + }; + + /** + * Internal function that calls back any ready functions. If you are + * integrating RequireJS with another library without require.ready support, + * you can define this method to call your page ready code instead. + */ + require.callReady = function () { + var callbacks = s.readyCalls, i, callback; + + if (s.isPageLoaded && s.isDone && callbacks.length) { + s.readyCalls = []; + for (i = 0; (callback = callbacks[i]); i++) { + callback(); + } + } + }; + + /** + * Registers functions to call when the page is loaded + */ + require.ready = function (callback) { + if (s.isPageLoaded && s.isDone) { + callback(); + } else { + s.readyCalls.push(callback); + } + return require; + }; + + if (require.isBrowser) { + if (document.addEventListener) { + //Standards. Hooray! Assumption here that if standards based, + //it knows about DOMContentLoaded. + document.addEventListener("DOMContentLoaded", require.pageLoaded, false); + window.addEventListener("load", require.pageLoaded, false); + //Part of FF < 3.6 readystate fix (see setReadyState refs for more info) + if (!document.readyState) { + setReadyState = true; + document.readyState = "loading"; + } + } else if (window.attachEvent) { + window.attachEvent("onload", require.pageLoaded); + + //DOMContentLoaded approximation, as found by Diego Perini: + //http://javascript.nwbox.com/IEContentLoaded/ + if (self === self.top) { + scrollIntervalId = setInterval(function () { + try { + document.documentElement.doScroll("left"); + require.pageLoaded(); + } catch (e) {} + }, 30); + } + } + + //Check if document already complete, and if so, just trigger page load + //listeners. NOTE: does not work with Firefox before 3.6. To support + //those browsers, manually call require.pageLoaded(). + if (document.readyState === "complete") { + require.pageLoaded(); + } + } + //****** END page load functionality **************** + //>>excludeEnd("requireExcludePageLoad"); + + //Set up default context. If require was a configuration object, use that as base config. + if (cfg) { + require(cfg); + } +}()); diff --git a/src/ace/BackgroundTokenizer.js b/src/ace/BackgroundTokenizer.js index c521e026..0f3cb5cc 100644 --- a/src/ace/BackgroundTokenizer.js +++ b/src/ace/BackgroundTokenizer.js @@ -1,6 +1,6 @@ -ace.provide("ace.BackgroundTokenizer"); +require.def("ace/BackgroundTokenizer", ["ace/ace", "ace/MEventEmitter"], function(ace, MEventEmitter) { -ace.BackgroundTokenizer = function(tokenizer) { +var BackgroundTokenizer = function(tokenizer) { this.running = false; this.textLines = []; this.lines = []; @@ -37,7 +37,7 @@ ace.BackgroundTokenizer = function(tokenizer) { (function(){ - ace.implement(this, ace.MEventEmitter); + ace.implement(this, MEventEmitter); this.setTokenizer = function(tokenizer) { this.tokenizer = tokenizer; @@ -102,4 +102,7 @@ ace.BackgroundTokenizer = function(tokenizer) { return this.lines[row]; }; -}).call(ace.BackgroundTokenizer.prototype); \ No newline at end of file +}).call(BackgroundTokenizer.prototype); + +return BackgroundTokenizer; +}); diff --git a/src/ace/Document.js b/src/ace/Document.js index 511b5b33..67b61967 100644 --- a/src/ace/Document.js +++ b/src/ace/Document.js @@ -1,10 +1,17 @@ -ace.provide("ace.Document"); +require.def("ace/Document", + [ + "ace/ace", + "ace/MEventEmitter", + "ace/Selection", + "ace/mode/Text", + "ace/Range" + ], function(ace, MEventEmitter, Selection, TextMode, Range) { -ace.Document = function(text, mode) { +var Document = function(text, mode) { this.modified = true; this.lines = []; - this.selection = new ace.Selection(this); - this.$breakpoints = []; + this.selection = new Selection(this); + this.$breakpoints = []; this.listeners = []; if (mode) { @@ -20,7 +27,7 @@ ace.Document = function(text, mode) { (function() { - ace.implement(this, ace.MEventEmitter); + ace.implement(this, MEventEmitter); this.$undoManager = null; @@ -182,7 +189,7 @@ ace.Document = function(text, mode) { this.getMode = function() { if (!this.$mode) { - this.$mode = new ace.mode.Text(); + this.$mode = new TextMode(); } return this.$mode; }; @@ -370,7 +377,7 @@ ace.Document = function(text, mode) { var nl = this.$getNewLineCharacter(); this.$deltas.push({ action: "insertText", - range: new ace.Range(row, 0, row + lines.length, 0), + range: new Range(row, 0, row + lines.length, 0), text: lines.join(nl) + nl }); this.$informUndoManager.schedule(); @@ -430,7 +437,7 @@ ace.Document = function(text, mode) { var nl = this.$getNewLineCharacter(); this.$deltas.push({ action: "insertText", - range: ace.Range.fromPoints(position, end), + range: Range.fromPoints(position, end), text: text }); this.$informUndoManager.schedule(); @@ -546,7 +553,7 @@ ace.Document = function(text, mode) { } } - var deleteRange = new ace.Range(0, 0, 0, outdentLength); + var deleteRange = new Range(0, 0, 0, outdentLength); for (var i=range.start.row; i<= range.end.row; i++) { @@ -643,4 +650,7 @@ ace.Document = function(text, mode) { return docColumn; }; -}).call(ace.Document.prototype); +}).call(Document.prototype); + +return Document; +}); diff --git a/src/ace/Editor.js b/src/ace/Editor.js index 3950db62..3b0c0383 100644 --- a/src/ace/Editor.js +++ b/src/ace/Editor.js @@ -1,12 +1,21 @@ -ace.provide("ace.Editor"); +require.def("ace/Editor", + [ + "ace/ace", + "ace/TextInput", + "ace/KeyBinding", + "ace/Document", + "ace/Search", + "ace/BackgroundTokenizer", + "ace/Range", + ], function(ace, TextInput, KeyBinding, Document, Search, BackgroundTokenizer, Range) { -ace.Editor = function(renderer, doc) { +var Editor = function(renderer, doc) { var container = renderer.getContainerElement(); this.container = container; this.renderer = renderer; - this.textInput = new ace.TextInput(container, this); - new ace.KeyBinding(container, this); + this.textInput = new TextInput(container, this); + new KeyBinding(container, this); var self = this; ace.addListener(container, "mousedown", function(e) { setTimeout(function() {self.focus();}); @@ -26,11 +35,11 @@ ace.Editor = function(renderer, doc) { this.$highlightLineMarker = null; this.$blockScrolling = false; - this.$search = new ace.Search().set({ + this.$search = new Search().set({ wrap: true }); - this.setDocument(doc || new ace.Document("")); + this.setDocument(doc || new Document("")); }; (function(){ @@ -142,7 +151,7 @@ ace.Editor = function(renderer, doc) { var pos = self.doc.findMatchingBracket(self.getCursorPosition()); if (pos) { - var range = new ace.Range(pos.row, pos.column, pos.row, pos.column+1); + var range = new Range(pos.row, pos.column, pos.row, pos.column+1); self.$bracketHighlight = self.renderer.addMarker(range, "ace_bracket"); } }, 10); @@ -198,7 +207,7 @@ ace.Editor = function(renderer, doc) { if (this.getHighlightActiveLine() && !this.selection.isMultiLine()) { var cursor = this.getCursorPosition(); - var range = new ace.Range(cursor.row, 0, cursor.row+1, 0); + var range = new Range(cursor.row, 0, cursor.row+1, 0); this.$highlightLineMarker = this.renderer.addMarker(range, "ace_active_line", "line"); } }; @@ -230,7 +239,7 @@ ace.Editor = function(renderer, doc) { if (!this.bgTokenizer) { var onUpdate = ace.bind(this.onTokenizerUpdate, this); - this.bgTokenizer = new ace.BackgroundTokenizer(tokenizer); + this.bgTokenizer = new BackgroundTokenizer(tokenizer); this.bgTokenizer.addEventListener("update", onUpdate); } else { this.bgTokenizer.setTokenizer(tokenizer); @@ -349,7 +358,7 @@ ace.Editor = function(renderer, doc) { var cursor = this.doc.remove(this.getSelectionRange()); this.clearSelection(); } else if (this.$overwrite){ - var range = new ace.Range.fromPoints(cursor, cursor); + var range = new Range.fromPoints(cursor, cursor); range.end.column += text.length; this.doc.remove(range); } @@ -369,7 +378,7 @@ ace.Editor = function(renderer, doc) { if (row !== end.row) { var indent = this.mode.getNextLineIndent(lineState, line, this.doc.getTabString()); if (indent) { - var indentRange = new ace.Range(row+1, 0, end.row, end.column); + var indentRange = new Range(row+1, 0, end.row, end.column); end.column += this.doc.indentRows(indentRange, indent); } } else { @@ -519,7 +528,7 @@ ace.Editor = function(renderer, doc) { var rows = this.$getSelectedRows(); - var range = new ace.Range(rows.first, 0, rows.last, 0); + var range = new Range(rows.first, 0, rows.last, 0); var state = this.bgTokenizer.getState(this.getCursorPosition().row); var addedColumns = this.mode.toggleCommentLines(state, this.doc, range); @@ -871,4 +880,8 @@ ace.Editor = function(renderer, doc) { this.doc.getUndoManager().redo(); }; -}).call(ace.Editor.prototype); \ No newline at end of file +}).call(Editor.prototype); + + +return Editor; +}); diff --git a/src/ace/KeyBinding.js b/src/ace/KeyBinding.js index cbd939c7..74698ccf 100644 --- a/src/ace/KeyBinding.js +++ b/src/ace/KeyBinding.js @@ -1,7 +1,6 @@ -ace.provide("ace.KeyBinding"); - -ace.KeyBinding = function(element, editor, config) { +require.def("ace/KeyBinding", ["ace/ace"], function(ace) { +var KeyBinding = function(element, editor, config) { this.editor = editor; this.setConfig(config); var keys = this.keys; @@ -211,4 +210,7 @@ ace.KeyBinding = function(element, editor, config) { } }; -}).call(ace.KeyBinding.prototype); \ No newline at end of file +}).call(KeyBinding.prototype); + +return KeyBinding; +}); diff --git a/src/ace/MEventEmitter.js b/src/ace/MEventEmitter.js index cf72f70a..5626def8 100644 --- a/src/ace/MEventEmitter.js +++ b/src/ace/MEventEmitter.js @@ -1,8 +1,8 @@ -ace.provide("ace.MEventEmitter"); +require.def("ace/MEventEmitter", ["ace/ace"], function(ace) { -ace.MEventEmitter = function() { + var MEventEmitter = {} - this.$dispatchEvent = function(eventName, e) { + MEventEmitter.$dispatchEvent = function(eventName, e) { this.$eventRegistry = this.$eventRegistry || {}; var listeners = this.$eventRegistry[eventName]; @@ -16,7 +16,7 @@ ace.MEventEmitter = function() { } }; - this.addEventListener = function(eventName, callback) { + MEventEmitter.addEventListener = function(eventName, callback) { this.$eventRegistry = this.$eventRegistry || {}; var listeners = this.$eventRegistry[eventName]; @@ -28,7 +28,7 @@ ace.MEventEmitter = function() { } }; - this.removeEventListener = function(eventName, callback) { + MEventEmitter.removeEventListener = function(eventName, callback) { this.$eventRegistry = this.$eventRegistry || {}; var listeners = this.$eventRegistry[eventName]; @@ -40,4 +40,6 @@ ace.MEventEmitter = function() { listeners.splice(index, 1); } }; -}; + + return MEventEmitter; +}); diff --git a/src/ace/Range.js b/src/ace/Range.js index 45e93c79..76dbf88f 100644 --- a/src/ace/Range.js +++ b/src/ace/Range.js @@ -1,6 +1,6 @@ -ace.provide("ace.Range"); +require.def("ace/Range", function() { -ace.Range = function(startRow, startColumn, endRow, endColumn) { +var Range = function(startRow, startColumn, endRow, endColumn) { this.start = { row: startRow, column: startColumn @@ -73,7 +73,7 @@ ace.Range = function(startRow, startColumn, endRow, endColumn) { column: 0 }; } - return ace.Range.fromPoints(start || this.start, end || this.end); + return Range.fromPoints(start || this.start, end || this.end); }; this.extend = function(row, column) { @@ -86,7 +86,7 @@ ace.Range = function(startRow, startColumn, endRow, endColumn) { else var end = {row: row, column: column}; - return ace.Range.fromPoints(start || this.start, end || this.end); + return Range.fromPoints(start || this.start, end || this.end); }; this.isEmpty = function() { @@ -98,19 +98,22 @@ ace.Range = function(startRow, startColumn, endRow, endColumn) { }; this.clone = function() { - return ace.Range.fromPoints(this.start, this.end); + return Range.fromPoints(this.start, this.end); }; this.toScreenRange = function(doc) { - return new ace.Range( + return new Range( this.start.row, doc.documentToScreenColumn(this.start.row, this.start.column), this.end.row, doc.documentToScreenColumn(this.end.row, this.end.column) ); }; -}).call(ace.Range.prototype); +}).call(Range.prototype); -ace.Range.fromPoints = function(start, end) { - return new ace.Range(start.row, start.column, end.row, end.column); -}; \ No newline at end of file +Range.fromPoints = function(start, end) { + return new Range(start.row, start.column, end.row, end.column); +}; + +return Range; +}) diff --git a/src/ace/ScrollBar.js b/src/ace/ScrollBar.js index c652418a..bbbe6315 100644 --- a/src/ace/ScrollBar.js +++ b/src/ace/ScrollBar.js @@ -1,6 +1,6 @@ -ace.provide("ace.ScrollBar"); +require.def("ace/ScrollBar", ["ace/ace", "ace/MEventEmitter"], function(ace, MEventEmitter) { -ace.ScrollBar = function(parent) { +var ScrollBar = function(parent) { this.element = document.createElement("div"); this.element.className = "ace_sb"; @@ -16,8 +16,7 @@ ace.ScrollBar = function(parent) { }; (function() { - - ace.implement(this, ace.MEventEmitter); + ace.implement(this, MEventEmitter); this.onScroll = function() { this.$dispatchEvent("scroll", {data: this.element.scrollTop}); @@ -39,4 +38,7 @@ ace.ScrollBar = function(parent) { this.element.scrollTop = scrollTop; }; -}).call(ace.ScrollBar.prototype); \ No newline at end of file +}).call(ScrollBar.prototype); + +return ScrollBar; +}); diff --git a/src/ace/Search.js b/src/ace/Search.js index d14dd3f8..d5bf1924 100644 --- a/src/ace/Search.js +++ b/src/ace/Search.js @@ -1,19 +1,19 @@ -ace.provide("ace.Search"); +require.def("ace/Search", ["ace/ace"], function(ace) { -ace.Search = function() { +var Search = function() { this.$options = { needle: "", backwards: false, wrap: false, caseSensitive: false, wholeWord: false, - scope: ace.Search.ALL, + scope: Search.ALL, regExp: false }; }; -ace.Search.ALL = 1; -ace.Search.SELECTION = 2; +Search.ALL = 1; +Search.SELECTION = 2; (function() { @@ -166,7 +166,7 @@ ace.Search.SELECTION = 2; }; this.$forwardLineIterator = function(doc) { - var searchSelection = this.$options.scope == ace.Search.SELECTION; + var searchSelection = this.$options.scope == Search.SELECTION; var range = doc.getSelection().getRange(); var start = doc.getSelection().getCursor(); @@ -222,7 +222,7 @@ ace.Search.SELECTION = 2; }; this.$backwardLineIterator = function(doc) { - var searchSelection = this.$options.scope == ace.Search.SELECTION; + var searchSelection = this.$options.scope == Search.SELECTION; var range = doc.getSelection().getRange(); var start = searchSelection ? range.end : range.start; @@ -272,4 +272,7 @@ ace.Search.SELECTION = 2; }; }; -}).call(ace.Search.prototype); \ No newline at end of file +}).call(Search.prototype); + +return Search; +}); diff --git a/src/ace/Selection.js b/src/ace/Selection.js index f29cf1b8..b4386619 100644 --- a/src/ace/Selection.js +++ b/src/ace/Selection.js @@ -1,6 +1,10 @@ -ace.provide("ace.Selection"); +require.def("ace/Selection", [ + "ace/ace", + "ace/MEventEmitter", + "ace/Range" +], function(ace, MEventEmitter, Range) { -ace.Selection = function(doc) { +var Selection = function(doc) { this.doc = doc; this.clearSelection(); @@ -12,7 +16,7 @@ ace.Selection = function(doc) { (function() { - ace.implement(this, ace.MEventEmitter); + ace.implement(this, MEventEmitter); this.isEmpty = function() { return (!this.selectionAnchor || @@ -90,10 +94,10 @@ ace.Selection = function(doc) { var lead = this.selectionLead; if (this.$isBackwards()) { - return ace.Range.fromPoints(lead, anchor); + return Range.fromPoints(lead, anchor); } else { - return ace.Range.fromPoints(anchor, lead); + return Range.fromPoints(anchor, lead); } }; @@ -387,4 +391,7 @@ ace.Selection = function(doc) { }; }; -}).call(ace.Selection.prototype); \ No newline at end of file +}).call(Selection.prototype); + +return Selection; +}); diff --git a/src/ace/TextInput.js b/src/ace/TextInput.js index 0e4f26d2..c052beb8 100644 --- a/src/ace/TextInput.js +++ b/src/ace/TextInput.js @@ -1,6 +1,6 @@ -ace.provide("ace.TextInput"); +require.def("ace/TextInput", ["ace/ace"], function(ace) { -ace.TextInput = function(parentNode, host) { +var TextInput = function(parentNode, host) { var text = document.createElement("textarea"); var style = text.style; @@ -80,4 +80,7 @@ ace.TextInput = function(parentNode, host) { this.blur = function() { text.blur(); }; -}; \ No newline at end of file +}; + +return TextInput; +}); \ No newline at end of file diff --git a/src/ace/Tokenizer.js b/src/ace/Tokenizer.js index 02c93382..4d932486 100644 --- a/src/ace/Tokenizer.js +++ b/src/ace/Tokenizer.js @@ -1,6 +1,6 @@ -ace.provide("ace.Tokenizer"); +require.def("ace/Tokenizer", [], function() { -ace.Tokenizer = function(rules) { +var Tokenizer = function(rules) { this.rules = rules; this.regExps = {}; @@ -89,4 +89,7 @@ ace.Tokenizer = function(rules) { }; }; -}).call(ace.Tokenizer.prototype); \ No newline at end of file +}).call(Tokenizer.prototype); + +return Tokenizer; +}); \ No newline at end of file diff --git a/src/ace/UndoManager.js b/src/ace/UndoManager.js index 60543b28..53990829 100644 --- a/src/ace/UndoManager.js +++ b/src/ace/UndoManager.js @@ -1,6 +1,6 @@ -ace.provide("ace.UndoManager"); +require.def("ace/UndoManager", function() { -ace.UndoManager = function() { +var UndoManager = function() { this.$undoStack = []; this.$redoStack = []; }; @@ -32,4 +32,7 @@ ace.UndoManager = function() { } }; -}).call(ace.UndoManager.prototype); \ No newline at end of file +}).call(UndoManager.prototype); + +return UndoManager; +}); \ No newline at end of file diff --git a/src/ace/VirtualRenderer.js b/src/ace/VirtualRenderer.js index cf7912ff..b5d77073 100644 --- a/src/ace/VirtualRenderer.js +++ b/src/ace/VirtualRenderer.js @@ -1,6 +1,14 @@ -ace.provide("ace.VirtualRenderer"); +require.def("ace/VirtualRenderer", + [ + "ace/ace", + "ace/layer/Gutter", + "ace/layer/Marker", + "ace/layer/Text", + "ace/layer/Cursor", + "ace/ScrollBar" + ], function(ace, GutterLayer, MarkerLayer, TextLayer, CursorLayer, ScrollBar) { -ace.VirtualRenderer = function(container) { +var VirtualRenderer = function(container) { this.container = container; ace.addCssClass(this.container, "ace_editor"); @@ -16,20 +24,20 @@ ace.VirtualRenderer = function(container) { this.content.style.position = "absolute"; this.scroller.appendChild(this.content); - this.$gutterLayer = new ace.layer.Gutter(this.$gutter); - this.$markerLayer = new ace.layer.Marker(this.content); + this.$gutterLayer = new GutterLayer(this.$gutter); + this.$markerLayer = new MarkerLayer(this.content); - var textLayer = this.$textLayer = new ace.layer.Text(this.content); + var textLayer = this.$textLayer = new TextLayer(this.content); this.canvas = textLayer.element; this.characterWidth = textLayer.getCharacterWidth(); this.lineHeight = textLayer.getLineHeight(); - this.$cursorLayer = new ace.layer.Cursor(this.content); + this.$cursorLayer = new CursorLayer(this.content); this.layers = [ this.$markerLayer, textLayer, this.$cursorLayer ]; - this.scrollBar = new ace.ScrollBar(container); + this.scrollBar = new ScrollBar(container); this.scrollBar.addEventListener("scroll", ace.bind(this.onScroll, this)); this.scrollTop = 0; @@ -335,4 +343,7 @@ ace.VirtualRenderer = function(container) { this.hideComposition = function() { }; -}).call(ace.VirtualRenderer.prototype); \ No newline at end of file +}).call(VirtualRenderer.prototype); + +return VirtualRenderer; +}); diff --git a/src/ace/ace.js b/src/ace/ace.js new file mode 100644 index 00000000..2665afe8 --- /dev/null +++ b/src/ace/ace.js @@ -0,0 +1,18 @@ +require.def("ace/ace", [ + "ace/lib/core", + "ace/lib/dom", + "ace/lib/event", + "ace/lib/lang", + "ace/lib/oop" + ], function(core, dom, evt, lang, oop) { + + var ace = {}; + + oop.mixin(ace, core); + oop.mixin(ace, dom); + oop.mixin(ace, evt); + oop.mixin(ace, lang); + oop.mixin(ace, oop); + + return ace; +}); \ No newline at end of file diff --git a/src/ace/conf/keybindings/default_mac.js b/src/ace/conf/keybindings/default_mac.js index 6a6e6f7e..7d84e120 100644 --- a/src/ace/conf/keybindings/default_mac.js +++ b/src/ace/conf/keybindings/default_mac.js @@ -1,6 +1,6 @@ -ace.provide("ace.KeyBinding.default_mac"); +require.def("ace/conf/keybinding/default_mac", function() { -ace.KeyBinding.default_mac = { +return { "selectall": "Meta-A", "removeline": "Meta-D", "gotoline": "Meta-L", @@ -47,3 +47,5 @@ ace.KeyBinding.default_mac = { "outdent": "Shift-Tab", "indent": "Tab" }; + +}); \ No newline at end of file diff --git a/src/ace/conf/keybindings/default_win.js b/src/ace/conf/keybindings/default_win.js index 78c77a8d..c2c2a096 100644 --- a/src/ace/conf/keybindings/default_win.js +++ b/src/ace/conf/keybindings/default_win.js @@ -1,6 +1,6 @@ -ace.provide("ace.KeyBinding.default_win"); +require.def("ace/conf/keybinding/default_win", function() { -ace.KeyBinding.default_win = { +return { "selectall": "Control-A", "removeline": "Control-D", "gotoline": "Control-L", @@ -47,3 +47,5 @@ ace.KeyBinding.default_win = { "outdent": "Shift-Tab", "indent": "Tab" }; + +}); diff --git a/src/ace/layer/Cursor.js b/src/ace/layer/Cursor.js index cc96d598..4a9caf1e 100644 --- a/src/ace/layer/Cursor.js +++ b/src/ace/layer/Cursor.js @@ -1,6 +1,6 @@ -ace.provide("ace.layer.Cursor"); +require.def("ace/layer/Cursor", ["ace/ace"], function(ace) { -ace.layer.Cursor = function(parentEl) { +var Cursor = function(parentEl) { this.element = document.createElement("div"); this.element.className = "ace_layer ace_cursor-layer"; parentEl.appendChild(this.element); @@ -92,4 +92,7 @@ ace.layer.Cursor = function(parentEl) { this.restartTimer(); }; -}).call(ace.layer.Cursor.prototype); \ No newline at end of file +}).call(Cursor.prototype); + +return Cursor; +}); diff --git a/src/ace/layer/Gutter.js b/src/ace/layer/Gutter.js index 6b6def41..596c6bca 100644 --- a/src/ace/layer/Gutter.js +++ b/src/ace/layer/Gutter.js @@ -1,6 +1,6 @@ -ace.provide("ace.layer.Gutter"); +require.def("ace/layer/Gutter", [], function() { -ace.layer.Gutter = function(parentEl) { +var Gutter = function(parentEl) { this.element = document.createElement("div"); this.element.className = "ace_layer ace_gutter-layer"; parentEl.appendChild(this.element); @@ -32,4 +32,7 @@ ace.layer.Gutter = function(parentEl) { this.element.style.height = config.minHeight + "px"; }; -}).call(ace.layer.Gutter.prototype); \ No newline at end of file +}).call(Gutter.prototype); + +return Gutter; +}); diff --git a/src/ace/layer/Marker.js b/src/ace/layer/Marker.js index 8376dcfe..a4f97ff1 100644 --- a/src/ace/layer/Marker.js +++ b/src/ace/layer/Marker.js @@ -1,6 +1,6 @@ -ace.provide("ace.layer.Marker"); +require.def("ace/layer/Marker", [], function() { -ace.layer.Marker = function(parentEl) { +var Marker = function(parentEl) { this.element = document.createElement("div"); this.element.className = "ace_layer ace_marker-layer"; parentEl.appendChild(this.element); @@ -142,4 +142,7 @@ ace.layer.Marker = function(parentEl) { ); }; -}).call(ace.layer.Marker.prototype); \ No newline at end of file +}).call(Marker.prototype); + +return Marker; +}); diff --git a/src/ace/layer/Text.js b/src/ace/layer/Text.js index 507c1055..80656192 100644 --- a/src/ace/layer/Text.js +++ b/src/ace/layer/Text.js @@ -1,6 +1,6 @@ -ace.provide("ace.layer.Text"); +require.def("ace/layer/Text", ["ace/ace", "ace/MEventEmitter"], function(ace, MEventEmitter) { -ace.layer.Text = function(parentEl) { +var Text = function(parentEl) { this.element = document.createElement("div"); this.element.className = "ace_layer ace_text-layer"; parentEl.appendChild(this.element); @@ -11,7 +11,7 @@ ace.layer.Text = function(parentEl) { (function() { - ace.implement(this, ace.MEventEmitter); + ace.implement(this, MEventEmitter); this.EOF_CHAR = "¶"; this.EOL_CHAR = "¬"; @@ -180,4 +180,7 @@ ace.layer.Text = function(parentEl) { } }; -}).call(ace.layer.Text.prototype); \ No newline at end of file +}).call(Text.prototype); + +return Text; +}); diff --git a/src/ace/lib/core.js b/src/ace/lib/core.js index c58e1b98..e0c2c2c2 100644 --- a/src/ace/lib/core.js +++ b/src/ace/lib/core.js @@ -1,15 +1,14 @@ -if (!window.ace) - ace = {}; - -(function() { +require.def("ace/lib/core", function() { + var core = {}; var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase(); - this.isWin = (os == "win"); - this.isMac = (os == "mac"); - this.isLinux = (os == "linux"); + core.isWin = (os == "win"); + core.isMac = (os == "mac"); + core.isLinux = (os == "linux"); + core.isIE = ! + "\v1"; - this.provide = function(namespace) { + core.provide = function(namespace) { var parts = namespace.split("."); var obj = window; for (var i=0; i the first match is used @@ -113,7 +119,7 @@ ace.mode.HtmlHighlightRules = function() { } ] }; - var jsRules = new ace.mode.JavaScriptHighlightRules().getRules(); + var jsRules = new JavaScriptHighlightRules().getRules(); this.addRules(jsRules, "js-"); this.$rules["js-start"].unshift({ token: "text", @@ -121,7 +127,7 @@ ace.mode.HtmlHighlightRules = function() { next: "tag" }); - var cssRules = new ace.mode.CssHighlightRules().getRules(); + var cssRules = new CssHighlightRules().getRules(); this.addRules(cssRules, "css-"); this.$rules["css-start"].unshift({ token: "text", @@ -129,4 +135,8 @@ ace.mode.HtmlHighlightRules = function() { next: "tag" }); }; -ace.inherits(ace.mode.HtmlHighlightRules, ace.mode.TextHighlightRules); \ No newline at end of file + +ace.inherits(HtmlHighlightRules, TextHighlightRules); + +return HtmlHighlightRules; +}); \ No newline at end of file diff --git a/src/ace/mode/JavaScript.js b/src/ace/mode/JavaScript.js index e8076ab6..c9b271cd 100644 --- a/src/ace/mode/JavaScript.js +++ b/src/ace/mode/JavaScript.js @@ -1,10 +1,17 @@ -ace.provide("ace.mode.JavaScript"); +require.def("ace/mode/JavaScript", + [ + "ace/ace", + "ace/mode/Text", + "ace/Tokenizer", + "ace/mode/JavaScriptHighlightRules", + "ace/mode/MatchingBraceOutdent" + ], function(ace, TextMode, Tokenizer, JavaScriptHighlightRules, MatchingBraceOutdent) { -ace.mode.JavaScript = function() { - this.$tokenizer = new ace.Tokenizer(new ace.mode.JavaScriptHighlightRules().getRules()); - this.$outdent = new ace.mode.MatchingBraceOutdent(); +var JavaScript = function() { + this.$tokenizer = new Tokenizer(new JavaScriptHighlightRules().getRules()); + this.$outdent = new MatchingBraceOutdent(); }; -ace.inherits(ace.mode.JavaScript, ace.mode.Text); +ace.inherits(JavaScript, TextMode); (function() { @@ -77,4 +84,7 @@ ace.inherits(ace.mode.JavaScript, ace.mode.Text); return this.$outdent.autoOutdent(doc, row); }; -}).call(ace.mode.JavaScript.prototype); \ No newline at end of file +}).call(JavaScript.prototype); + +return JavaScript; +}); diff --git a/src/ace/mode/JavaScriptHighlightRules.js b/src/ace/mode/JavaScriptHighlightRules.js index c5a69a65..815512fc 100644 --- a/src/ace/mode/JavaScriptHighlightRules.js +++ b/src/ace/mode/JavaScriptHighlightRules.js @@ -1,8 +1,14 @@ -ace.provide("ace.mode.JavaScriptHighlightRules"); +require.def("ace/mode/JavaScriptHighlightRules", + [ + "ace/ace", + "ace/mode/DocCommentHighlightRules", + "ace/mode/TextHighlightRules" + ], function(ace, DocCommentHighlightRules, TextHighlightRules) { -ace.mode.JavaScriptHighlightRules = function() { - var docComment = new ace.mode.DocCommentHighlightRules(); +JavaScriptHighlightRules = function() { + + var docComment = new DocCommentHighlightRules(); var keywords = { "break" : 1, @@ -32,6 +38,7 @@ ace.mode.JavaScriptHighlightRules = function() { // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used + this.$rules = { "start" : [ { token : "comment", @@ -111,4 +118,8 @@ ace.mode.JavaScriptHighlightRules = function() { this.addRules(docComment.getRules(), "doc-"); this.$rules["doc-start"][0].next = "start"; }; -ace.inherits(ace.mode.JavaScriptHighlightRules, ace.mode.TextHighlightRules); \ No newline at end of file + +ace.inherits(JavaScriptHighlightRules, TextHighlightRules); + +return JavaScriptHighlightRules; +}); \ No newline at end of file diff --git a/src/ace/mode/MatchingBraceOutdent.js b/src/ace/mode/MatchingBraceOutdent.js index 62cf8954..ac08e0ec 100644 --- a/src/ace/mode/MatchingBraceOutdent.js +++ b/src/ace/mode/MatchingBraceOutdent.js @@ -1,6 +1,6 @@ -ace.provide("ace.mode.MatchingBraceOutdent"); +require.def("ace/mode/MatchingBraceOutdent", [], function() { -ace.mode.MatchingBraceOutdent = function() {}; +var MatchingBraceOutdent = function() {}; (function() { @@ -37,4 +37,7 @@ ace.mode.MatchingBraceOutdent = function() {}; return ""; }; -}).call(ace.mode.MatchingBraceOutdent.prototype); \ No newline at end of file +}).call(MatchingBraceOutdent.prototype); + +return MatchingBraceOutdent; +}); diff --git a/src/ace/mode/Text.js b/src/ace/mode/Text.js index e7ed42a0..faf90325 100644 --- a/src/ace/mode/Text.js +++ b/src/ace/mode/Text.js @@ -1,7 +1,11 @@ -ace.provide("ace.mode.Text"); +require.def("ace/mode/Text", + [ + "ace/Tokenizer", + "ace/mode/TextHighlightRules", + ], function(Tokenizer, TextHighlightRules) { -ace.mode.Text = function() { - this.$tokenizer = new ace.Tokenizer(new ace.mode.TextHighlightRules().getRules()); +var Text = function() { + this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules()); }; (function() { @@ -34,4 +38,7 @@ ace.mode.Text = function() { return ""; }; -}).call(ace.mode.Text.prototype); \ No newline at end of file +}).call(Text.prototype); + +return Text; +}); \ No newline at end of file diff --git a/src/ace/mode/TextHighlightRules.js b/src/ace/mode/TextHighlightRules.js index 81e0e130..15bc1e60 100644 --- a/src/ace/mode/TextHighlightRules.js +++ b/src/ace/mode/TextHighlightRules.js @@ -1,6 +1,6 @@ -ace.provide("ace.mode.TextHighlightRules"); +require.def("ace/mode/TextHighlightRules", [], function() { -ace.mode.TextHighlightRules = function() { +var TextHighlightRules = function() { // regexp must not have capturing parentheses // regexps are ordered -> the first match is used @@ -34,4 +34,7 @@ ace.mode.TextHighlightRules = function() { return this.$rules; }; -}).call(ace.mode.TextHighlightRules.prototype); \ No newline at end of file +}).call(TextHighlightRules.prototype); + +return TextHighlightRules; +}); \ No newline at end of file diff --git a/src/ace/mode/Xml.js b/src/ace/mode/Xml.js index a1097edf..994dfc2b 100644 --- a/src/ace/mode/Xml.js +++ b/src/ace/mode/Xml.js @@ -1,9 +1,16 @@ -ace.provide("ace.mode.Xml"); +require.def("ace/mode/Xml", + [ + "ace/ace", + "ace/mode/Text", + "ace/Tokenizer", + "ace/mode/XmlHighlightRules" + ], function(ace, TextMode, Tokenizer, XmlHighlightRules) { -ace.mode.Xml = function() { - this.$tokenizer = new ace.Tokenizer(new ace.mode.XmlHighlightRules().getRules()); +var Xml = function() { + this.$tokenizer = new Tokenizer(new XmlHighlightRules().getRules()); }; -ace.inherits(ace.mode.Xml, ace.mode.Text); + +ace.inherits(Xml, TextMode); (function() { @@ -11,4 +18,7 @@ ace.inherits(ace.mode.Xml, ace.mode.Text); return this.$getIndent(line); }; -}).call(ace.mode.Xml.prototype); \ No newline at end of file +}).call(Xml.prototype); + +return Xml; +}); \ No newline at end of file diff --git a/src/ace/mode/XmlHighlightRules.js b/src/ace/mode/XmlHighlightRules.js index b04e4010..61c92344 100644 --- a/src/ace/mode/XmlHighlightRules.js +++ b/src/ace/mode/XmlHighlightRules.js @@ -1,6 +1,10 @@ -ace.provide("ace.mode.XmlHighlightRules"); +require.def("ace/mode/XmlHighlightRules", + [ + "ace/ace", + "ace/mode/TextHighlightRules" + ], function(ace, TextHighlightRules) { -ace.mode.XmlHighlightRules = function() { +var XmlHighlightRules = function() { // regexp must not have capturing parentheses // regexps are ordered -> the first match is used @@ -69,4 +73,8 @@ ace.mode.XmlHighlightRules = function() { } ] }; }; -ace.inherits(ace.mode.XmlHighlightRules, ace.mode.TextHighlightRules); \ No newline at end of file + +ace.inherits(XmlHighlightRules, TextHighlightRules); + +return XmlHighlightRules; +}); \ No newline at end of file From 872afa690420b9d91e6ac3b0b6a4968ba9ec216d Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Fri, 17 Sep 2010 11:27:15 +0200 Subject: [PATCH 10/12] requireJS fixes for the editor --- src/ace/Editor.js | 5 +++-- src/ace/KeyBinding.js | 8 +++++--- src/ace/VirtualRenderer.js | 7 ++++--- src/ace/conf/keybindings/default_mac.js | 2 +- src/ace/conf/keybindings/default_win.js | 2 +- src/ace/lib/lang.js | 4 ++-- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/ace/Editor.js b/src/ace/Editor.js index 3b0c0383..b8cef49d 100644 --- a/src/ace/Editor.js +++ b/src/ace/Editor.js @@ -7,7 +7,8 @@ require.def("ace/Editor", "ace/Search", "ace/BackgroundTokenizer", "ace/Range", - ], function(ace, TextInput, KeyBinding, Document, Search, BackgroundTokenizer, Range) { + "ace/MEventEmitter" + ], function(ace, TextInput, KeyBinding, Document, Search, BackgroundTokenizer, Range, MEventEmitter) { var Editor = function(renderer, doc) { var container = renderer.getContainerElement(); @@ -44,7 +45,7 @@ var Editor = function(renderer, doc) { (function(){ - ace.implement(this, ace.MEventEmitter); + ace.implement(this, MEventEmitter); this.$forwardEvents = { gutterclick: 1, diff --git a/src/ace/KeyBinding.js b/src/ace/KeyBinding.js index 74698ccf..2888b9fc 100644 --- a/src/ace/KeyBinding.js +++ b/src/ace/KeyBinding.js @@ -1,4 +1,6 @@ -require.def("ace/KeyBinding", ["ace/ace"], function(ace) { +require.def("ace/KeyBinding", + ["ace/ace", "ace/conf/keybindings/default_mac", "ace/conf/keybindings/default_win"], + function(ace, default_mac, default_win) { var KeyBinding = function(element, editor, config) { this.editor = editor; @@ -53,8 +55,8 @@ var KeyBinding = function(element, editor, config) { this.setConfig = function(config) { this.config = config || ace.isMac - ? ace.KeyBinding.default_mac - : ace.KeyBinding.default_win; + ? default_mac + : default_win; if (typeof this.config.reverse == "undefined") this.config.reverse = ace.objectReverse(this.config, "|"); }; diff --git a/src/ace/VirtualRenderer.js b/src/ace/VirtualRenderer.js index b5d77073..5582d377 100644 --- a/src/ace/VirtualRenderer.js +++ b/src/ace/VirtualRenderer.js @@ -5,8 +5,9 @@ require.def("ace/VirtualRenderer", "ace/layer/Marker", "ace/layer/Text", "ace/layer/Cursor", - "ace/ScrollBar" - ], function(ace, GutterLayer, MarkerLayer, TextLayer, CursorLayer, ScrollBar) { + "ace/ScrollBar", + "ace/MEventEmitter" + ], function(ace, GutterLayer, MarkerLayer, TextLayer, CursorLayer, ScrollBar, MEventEmitter) { var VirtualRenderer = function(container) { this.container = container; @@ -62,7 +63,7 @@ var VirtualRenderer = function(container) { (function() { - ace.implement(this, ace.MEventEmitter); + ace.implement(this, MEventEmitter); this.setDocument = function(doc) { this.lines = doc.lines; diff --git a/src/ace/conf/keybindings/default_mac.js b/src/ace/conf/keybindings/default_mac.js index 7d84e120..8f8d3c30 100644 --- a/src/ace/conf/keybindings/default_mac.js +++ b/src/ace/conf/keybindings/default_mac.js @@ -1,4 +1,4 @@ -require.def("ace/conf/keybinding/default_mac", function() { +require.def("ace/conf/keybindings/default_mac", function() { return { "selectall": "Meta-A", diff --git a/src/ace/conf/keybindings/default_win.js b/src/ace/conf/keybindings/default_win.js index c2c2a096..b8ab3f4c 100644 --- a/src/ace/conf/keybindings/default_win.js +++ b/src/ace/conf/keybindings/default_win.js @@ -1,4 +1,4 @@ -require.def("ace/conf/keybinding/default_win", function() { +require.def("ace/conf/keybindings/default_win", function() { return { "selectall": "Control-A", diff --git a/src/ace/lib/lang.js b/src/ace/lib/lang.js index 1a1fb4e7..73d8149d 100644 --- a/src/ace/lib/lang.js +++ b/src/ace/lib/lang.js @@ -34,7 +34,7 @@ require.def("ace/lib/lang", function() { return copy; }; - this.arrayToMap = function(arr) { + lang.arrayToMap = function(arr) { var map = {}; for (var i=0; i Date: Fri, 17 Sep 2010 11:27:34 +0200 Subject: [PATCH 11/12] requireJS'ify the debugger code From 97a09df36d1061199fbe89f6bbe0934908a48fdd Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Fri, 17 Sep 2010 12:27:18 +0200 Subject: [PATCH 12/12] fix typo