[xmljs-users] Using XMLJS instead of DOM embedded into browsers with jQuery
Brought to you by:
djoham,
witchhunter
From: Fedor T. <fed...@gm...> - 2012-06-05 15:58:04
|
Hi all! I'm trying to get some functionality of jQuery working without access to window and DOM implementation embedded into browsers (Chromium for instance). I used jquery-nodom (https://github.com/kpozin/jquery-nodom) as a starting point and added attributes, selector and traversing. XMLJS (W3C version) replaces embedded DOM. To do that I've added the following lines before loading jQuery: var global = this; global.window = global.window || global; global.window.DOMParser = function() { var self = this; var domImpl = new DOMImplementation(); var parseFromString = function(str, type) { return domImpl.loadXML(str); }; self.parseFromString = parseFromString; }; global.window.document = global.window.document || new DOMDocument(global.window.DOMParser); global.window.document.documentElement = global.window.document.createElement('HTML'); Surprisingly some features started to work immediately. But! jQuery assumes that it's possible to access nodes in the NodeList simply by index (myNodeList[i], where 0 <= i < myNodeList.length). Unfortunately this is not working with DOMNodeList implementation from XMLJS. In some places jQuery (or better to say Sizzle) uses makeArray function to convert NodeList into array. So I modified it to be able to convert DOMNodeList from XMLJS into Array. By this I got more functionality working, but not all, since makeArray is called only from some places (don't know why). Did anyone try to solve this? What would be the best approach? I did not modify XMLJS, so I don't know if here is the best place for my question, but anyway... any help is very welcome. Fedor |