Skip to content

Commit 9b2cc1c

Browse files
committed
Remove Hyperscript and change Hyperjson to work without it
1 parent 04f6334 commit 9b2cc1c

3 files changed

Lines changed: 27 additions & 424 deletions

File tree

src/xwiki/RTFrontend/LoadEditors/objects/XWiki.JavaScriptExtension_0/code.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ define(['jquery', 'xwiki-meta'], function($, xm) {
5555
RTFrontend_json_ot: "$document.getAttachmentURL('json-ot.js')",
5656

5757
RTFrontend_hyperjson: "$document.getAttachmentURL('hyperjson.js')",
58-
RTFrontend_hyperscript: "$document.getAttachmentURL('hyperscript.js')",
5958

6059
RTFrontend_diffDOM: "$document.getAttachmentURL('diffDOM.js')",
6160

src/xwiki/RTFrontend/WebHome/attachments/hyperjson.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
define([], function () {
2-
// this makes recursing a lot simpler
1+
(function () {
2+
var Hyperjson = {};
33
var isArray = function (A) {
44
return Object.prototype.toString.call(A)==='[object Array]';
55
};
66

7-
var callOnHyperJSON = function (hj, cb) {
7+
var isTruthy = function (x) {
8+
return x;
9+
};
10+
11+
var callOnHyperJSON = Hyperjson.callOn = function (hj, cb) {
812
var children;
913

1014
if (hj && hj[2]) {
@@ -27,11 +31,7 @@ define([], function () {
2731
return cb(hj[0], hj[1], children);
2832
};
2933

30-
var isTruthy = function (x) {
31-
return x;
32-
};
33-
34-
var DOM2HyperJSON = function(el, predicate, filter){
34+
var DOM2HyperJSON = Hyperjson.fromDOM = function(el, predicate, filter){
3535
if(!el.tagName && el.nodeType === Node.TEXT_NODE){
3636
return el.textContent;
3737
}
@@ -60,16 +60,7 @@ define([], function () {
6060

6161
// get the element type, id, and classes of the element
6262
// and push them to the result array
63-
var sel = el.tagName;
64-
65-
if(attributes.id){
66-
// we don't have to do much to validate IDs because the browser
67-
// will only permit one id to exist
68-
// unless we come across a strange browser in the wild
69-
sel = sel +'#'+ attributes.id;
70-
delete attributes.id;
71-
}
72-
result.push(sel);
63+
result.push(el.tagName);
7364

7465
// second element of the array is the element attributes
7566
result.push(attributes);
@@ -91,8 +82,22 @@ define([], function () {
9182
}
9283
};
9384

94-
return {
95-
fromDOM: DOM2HyperJSON,
96-
callOn: callOnHyperJSON
85+
var H = Hyperjson.toDOM = function(hj) {
86+
if (typeof(hj) === 'string') { return document.createTextNode(hj); }
87+
var e = document.createElement(hj[0]);
88+
for (var x in hj[1]) { e.setAttribute(x, hj[1][x]); }
89+
for (var i = 0; i < hj[2].length; i++) { e.appendChild(H(hj[2][i])); }
90+
return e;
9791
};
98-
});
92+
93+
if (typeof(module) !== 'undefined' && module.exports) {
94+
module.exports = Hyperjson;
95+
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
96+
define(function () {
97+
return Hyperjson;
98+
});
99+
} else {
100+
window.Hyperjson = Hyperjson;
101+
}
102+
}());
103+

0 commit comments

Comments
 (0)