-
Notifications
You must be signed in to change notification settings - Fork 5
/
live-update.js
53 lines (49 loc) · 1.56 KB
/
live-update.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(function () {
"use strict";
$(document).on(":liveupdate", function () {
$(".macro-live").trigger(":liveupdateinternal");
});
Macro.add(['update', 'upd'], {
handler: function handler() {
$(document).trigger(":liveupdate");
}
});
Macro.add(['live', 'l', 'lh'], {
skipArgs: true,
handler: function handler() {
if (this.args.full.length === 0) {
return this.error('no expression specified');
}
try {
var statement = this.args.full;
var result = toStringOrDefault(Scripting.evalJavaScript(statement), null);
if (result !== null) {
var lh = this.name === "lh";
var $el = $("<span></span>").addClass("macro-live").wiki(lh ? Util.escape(result) : result).appendTo(this.output);
$el.on(":liveupdateinternal", this.createShadowWrapper(function (ev) {
var out = toStringOrDefault(Scripting.evalJavaScript(statement), null);
$el.empty().wiki(lh ? Util.escape(out) : out);
}));
}
} catch (ex) {
return this.error("bad evaluation: " + (_typeof(ex) === 'object' ? ex.message : ex));
}
}
});
Macro.add(['liveblock', 'lb'], {
tags: null,
handler: function handler() {
try {
var content = this.payload[0].contents.trim();
if (content) {
var $el = $("<span></span>").addClass("macro-live macro-live-block").wiki(content).appendTo(this.output);
$el.on(":liveupdateinternal", this.createShadowWrapper(function (ev) {
$el.empty().wiki(content);
}));
}
} catch (ex) {
return this.error("bad evaluation: " + (_typeof(ex) === 'object' ? ex.message : ex));
}
}
});
})();