-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (52 loc) · 1.85 KB
/
index.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
var libxmljs = require('libxmljs'),
css2xpath = require('css2xpath'),
EventTarget = require('./lib/EventTarget.js'),
Window = require('./lib/Window.js')(libxmljs),
XMLDocument = libxmljs.Document.prototype,
XMLElement = libxmljs.Element.prototype;
libxmljs.css2xpath = css2xpath;
extend(Window.prototype, EventTarget);
libxmljs.Window = Window;
XMLDocument.css2xpath = libxmljs.css2xpath;
XMLDocument.doc = function () {
return this;
};
XMLElement.css2xpath = libxmljs.css2xpath;
XMLElement.__childNodes = XMLElement.childNodes;
XMLElement.__nextSibling = XMLElement.nextSibling;
XMLElement.__name = XMLElement.name;
XMLElement.__type = XMLElement.type;
delete XMLElement.childNodes;
var Node = require('./lib/Node.js');
var Element = extend(require('./lib/Element.js'), Node, true);
extend(XMLElement, Element, true);
extend(XMLElement, EventTarget);
var Document = extend(require('./lib/Document.js')(libxmljs), Node, true);
extend(XMLDocument, Document, true);
extend(XMLDocument, EventTarget);
function extend(parent, child, replace) {
for (var key in child) {
if (parent.hasOwnProperty(key) && replace !== true) continue;
var desc = Object.getOwnPropertyDescriptor(child, key);
if (desc.value !== undefined) {
parent[key] = child[key];
} else {
Object.defineProperty(parent, key, { get: desc.get, set: desc.set, enumerable: true, configurable: true });
}
}
return parent;
}
var readFileSync = require('fs').readFileSync;
var jQueryFile = __dirname + '/lib/jquery.js';
var jQuery = null;
Object.defineProperty(libxmljs, 'jQuery', {
get: function () {
if (jQuery === null)
jQuery = readFileSync(jQueryFile).toString();
return jQuery;
},
set: function () {
}
});
module.exports = libxmljs;