add jslint example
This commit is contained in:
parent
faa155a20f
commit
1e4ee57d63
6 changed files with 101 additions and 25 deletions
|
|
@ -59,7 +59,7 @@ exports.launch = function(env) {
|
|||
var emacs = require("ace/keyboard/keybinding/emacs").Emacs;
|
||||
var HashHandler = require("ace/keyboard/hash_handler").HashHandler;
|
||||
|
||||
var WorkerClient = require("ace/worker/WorkerClient").WorkerClient;
|
||||
var WorkerClient = require("ace/worker/worker_client").WorkerClient;
|
||||
|
||||
var docs = {};
|
||||
|
||||
|
|
@ -67,9 +67,37 @@ exports.launch = function(env) {
|
|||
docs.js.setMode(new JavaScriptMode());
|
||||
docs.js.setUndoManager(new UndoManager());
|
||||
|
||||
var worker = new WorkerClient("../..", ["ace", "pilot"], "ace/worker/demo", "Demo");
|
||||
worker.send("juhu");
|
||||
|
||||
var worker = new WorkerClient("../..", ["ace", "pilot"], "ace/worker/mirror", "Mirror");
|
||||
worker.call("setValue", [docs.js.getValue()]);
|
||||
|
||||
docs.js.getDocument().on("change", function(e) {
|
||||
e.range = {
|
||||
start: e.data.range.start,
|
||||
end: e.data.range.end
|
||||
};
|
||||
worker.emit("change", e);
|
||||
});
|
||||
|
||||
worker.on("jslint", function(results) {
|
||||
console.log("jslint", results);
|
||||
|
||||
var rows = [];
|
||||
for (var i=0; i<results.data.length; i++) {
|
||||
var error = results.data[i];
|
||||
if (error)
|
||||
rows.push(error.line-1);
|
||||
}
|
||||
|
||||
docs.js.clearBreakpoints();
|
||||
docs.js.setBreakpoints(rows)
|
||||
});
|
||||
|
||||
window.mirror = function() {
|
||||
worker.call("getValue", [], function(value) {
|
||||
console.log(value)
|
||||
});
|
||||
}
|
||||
|
||||
docs.css = new EditSession(document.getElementById("csstext").innerHTML);
|
||||
docs.css.setMode(new CssMode());
|
||||
docs.css.setUndoManager(new UndoManager());
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@
|
|||
height: 100%;
|
||||
}
|
||||
|
||||
.ace_gutter-cell.ace_breakpoint {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.ace_editor .ace_sb {
|
||||
position: absolute;
|
||||
overflow-x: hidden;
|
||||
|
|
|
|||
|
|
@ -10,14 +10,13 @@ var window = {
|
|||
var require = function(name) {
|
||||
if (require.modules[name])
|
||||
return require.modules[name].exports;
|
||||
|
||||
require.id = name;
|
||||
|
||||
var chunks = name.split("/");
|
||||
chunks[0] = require.tlns[chunks[0]] || chunks[0];
|
||||
path = require.baseUrl + "/" + chunks.join("/") + ".js"
|
||||
|
||||
importScripts(path);
|
||||
require.id = name;
|
||||
importScripts(path);
|
||||
return require.modules[name].exports;
|
||||
};
|
||||
require.modules = {};
|
||||
|
|
@ -27,13 +26,14 @@ require.baseUrl;
|
|||
var define = function(factory) {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
var returnExports = factory(require, module.exports, module);
|
||||
if (returnExports) {
|
||||
module.exports = exports;
|
||||
}
|
||||
};
|
||||
|
||||
require.modules[require.id] = module;
|
||||
var name = require.id;
|
||||
var returnExports = factory(require, module.exports, module);
|
||||
if (returnExports)
|
||||
module.exports = exports;
|
||||
|
||||
require.modules[name] = module;
|
||||
};
|
||||
|
||||
function initBaseUrls(baseUrl, topLevelNamespaces) {
|
||||
|
|
@ -60,7 +60,7 @@ function initSender() {
|
|||
});
|
||||
},
|
||||
|
||||
this.event = function(name, data) {
|
||||
this.emit = function(name, data) {
|
||||
postMessage({
|
||||
type: "event",
|
||||
name: name,
|
||||
|
|
@ -85,6 +85,6 @@ onmessage = function(e) {
|
|||
var clazz = require(msg.module)[msg.classname];
|
||||
main = new clazz(sender);
|
||||
} else if (msg.event) {
|
||||
|
||||
sender._dispatchEvent(msg.event, msg.data);
|
||||
}
|
||||
};
|
||||
|
|
@ -276,8 +276,8 @@ SOFTWARE.
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
exports.lint = (function () {
|
||||
"use strict";
|
||||
var JSLINT = exports.JSLINT = (function () {
|
||||
//"use strict";
|
||||
|
||||
var adsafe_id, // The widget's ADsafe id.
|
||||
adsafe_may, // The widget may load approved scripts.
|
||||
|
|
@ -3820,9 +3820,9 @@ loop: for (;;) {
|
|||
advance('(');
|
||||
spaces(this, t);
|
||||
no_space();
|
||||
if (nexttoken.id === 'var') {
|
||||
error("Move all 'var' declarations to the top of the function.");
|
||||
}
|
||||
// if (nexttoken.id === 'var') {
|
||||
// error("Move all 'var' declarations to the top of the function.");
|
||||
// }
|
||||
if (peek(0).id === 'in') {
|
||||
v = nexttoken;
|
||||
switch (funct[v.value]) {
|
||||
|
|
|
|||
38
lib/ace/worker/mirror.js
Normal file
38
lib/ace/worker/mirror.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var Document = require("ace/document").Document;
|
||||
var lint = require("ace/worker/jslint").JSLINT;
|
||||
var lang = require("pilot/lang");
|
||||
|
||||
var Mirror = exports.Mirror = function(sender) {
|
||||
this.sender = sender;
|
||||
var doc = this.doc = new Document("");
|
||||
|
||||
var deferredUpdate = this.deferredUpdate = lang.deferredCall(this.onUpdate.bind(this));
|
||||
|
||||
sender.on("change", function(e) {
|
||||
doc.applyDeltas([e.data]);
|
||||
deferredUpdate.schedule(500);
|
||||
})
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
||||
this.setValue = function(value) {
|
||||
this.doc.setValue(value);
|
||||
this.deferredUpdate.schedule(500);
|
||||
};
|
||||
|
||||
this.getValue = function(callbackId) {
|
||||
this.sender.callback(this.doc.getValue(), callbackId);
|
||||
};
|
||||
|
||||
this.onUpdate = function() {
|
||||
lint(this.doc.getValue(), {undef: false, onevar: false, passfail: false});
|
||||
this.sender.emit("jslint", lint.errors);
|
||||
}
|
||||
|
||||
}).call(Mirror.prototype);
|
||||
|
||||
});
|
||||
|
|
@ -46,7 +46,7 @@ var WorkerClient = function(baseUrl, topLevelNamespaces, module, classname) {
|
|||
break;
|
||||
|
||||
case "event":
|
||||
_self.$dispatchEvent(msg.name, {data: msg.data});
|
||||
_self._dispatchEvent(msg.name, {data: msg.data});
|
||||
break;
|
||||
|
||||
case "call":
|
||||
|
|
@ -69,10 +69,16 @@ var WorkerClient = function(baseUrl, topLevelNamespaces, module, classname) {
|
|||
};
|
||||
|
||||
this.call = function(cmd, args, callback) {
|
||||
var id = this.callbackId++;
|
||||
this.callbacks[id] = callback;
|
||||
args.push(id);
|
||||
this.$send(cmd, args);
|
||||
if (callback) {
|
||||
var id = this.callbackId++;
|
||||
this.callbacks[id] = callback;
|
||||
args.push(id);
|
||||
}
|
||||
this.send(cmd, args);
|
||||
};
|
||||
|
||||
this.emit = function(event, data) {
|
||||
this.$worker.postMessage({event: event, data: data});
|
||||
};
|
||||
|
||||
}).call(WorkerClient.prototype);
|
||||
Loading…
Add table
Add a link
Reference in a new issue