Skip to content

Commit

Permalink
Merge codeeditor and master changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Apr 13, 2012
1 parent c88a97c commit a125817
Show file tree
Hide file tree
Showing 12 changed files with 44,664 additions and 44,597 deletions.
105 changes: 5 additions & 100 deletions client/apf/elements/codeeditor.js
Expand Up @@ -43,7 +43,6 @@ var EditSession = require("ace/edit_session").EditSession;
var VirtualRenderer = require("ace/virtual_renderer").VirtualRenderer;
var UndoManager = require("ace/undomanager").UndoManager;
var Range = require("ace/range").Range;
var net = require("ace/lib/net");
require("ace/lib/fixoldbrowsers");


Expand Down Expand Up @@ -300,107 +299,15 @@ apf.codeeditor = module.exports = function(struct, tagName) {
};

this.$propHandlers["syntax"] = function(value) {
var _self = this;
this.getMode(value, function(mode) {
// the syntax could have changed while loading the mode
if (_self.syntax == value)
_self.$editor.getSession().setMode(mode);
});
this.$editor.getSession().setMode(this.getMode(value));
};

this.$modes = {};

this.$basePath = "";
this.$guessBasePath = function() {
if (this.$basePath)
return this.$basePath;

var scripts = document.getElementsByTagName("script");
for (var i=0; i<scripts.length; i++) {
var script = scripts[i];

var src = script.src || script.getAttribute("src");
if (!src)
continue;

var m = src.match(/^(?:(.*\/)ace\.js|(.*\/)ace(-uncompressed)?(-noconflict)?\.js)(?:\?|$)/);
if (m) {
this.$basePath = m[1] || m[2];
break;
}

m = src.match(/^(?:(.*\/)packed\.js(?:\?|$))/); // this is the packaged version, and there's no ace script
if (m) {
this.$basePath = m[1] + "mode/";
break;
}
}

return this.$basePath;
};

/**
* Looks up an object by ID from a cache. If the item is not in the cache it is
* created on demand using the factory function. Intermitted calls to the same
* id are pooled until the object is created
*/
this._lazyCreate = function(id, cache, callbackStore, factory, callback) {
var item = cache[id];
if (item)
return callback(null, item);

if (callbackStore[id]) {
callbackStore[id].push(callback);
return;
}

callbackStore[id] = [callback];

factory(id, function(err, item) {
var callbacks = callbackStore[id];
delete callbackStore[id];

cache[id] = item;

callbacks.forEach(function(cb) {
cb(err, item);
});
});
};

this.$modeCallbacks = {};
this.getMode = function(syntax, callback) {
var _self = this;

this.getMode = function(syntax) {
syntax = (syntax || "text").toLowerCase();
if (syntax.indexOf("/") == -1)
syntax = "ace/mode/" + syntax;

this._lazyCreate(syntax, this.$modes, this.$modeCallbacks, function(syntax, callback) {
// load packaged version
if (define.packaged) {
var base = syntax.split("/").pop();
var fileName = _self.$guessBasePath() + "mode-" + base + ".js";
net.loadScript(fileName, afterPreload);
}
else
afterPreload();

function afterPreload() {
require([syntax], function(modeModule) {
// #ifdef __DEBUG
if (typeof modeModule.Mode != "function") {
apf.console.error("Unkown syntax type: '" + syntax + "'");
return callback("Unkown syntax type: '" + syntax + "'");
}
// #endif
_self.$modes[syntax] = new modeModule.Mode();
callback(null, _self.$modes[syntax]);
});
}
}, function(err, mode) {
callback(mode);
});

return syntax;
};

this.$propHandlers["activeline"] = function(value) {
Expand Down Expand Up @@ -704,8 +611,6 @@ apf.codeeditor = module.exports = function(struct, tagName) {
ed.addEventListener("gutterdblclick", function(e) {
_self.dispatchEvent("gutterdblclick", e);
});

//apf.sanitizeTextbox(ed.renderer.container.getElementsByTagName("textarea")[0]);
};

this.$loadAml = function(){
Expand Down Expand Up @@ -771,4 +676,4 @@ apf.config.$inheritProperties["initial-message"] = 1;
apf.aml.setElement("codeeditor", apf.codeeditor);

});
// #endif
// #endif

0 comments on commit a125817

Please sign in to comment.