How can I make Xui JS x$('') work with existing jquery code $('')?
I suspect this is ridiculously simple, but I can't figure it out.
We have some simple code that we've written using jQuery, but I suspect it would work fine with xui, and since this is a mobile app saving the bits to download and the time to load all of the extra js in jQuery would be fantastic.
jQuery of courses uses $('') as the select, but xui开发者_开发知识库 uses x$(''). Is there a technique I can use, so that I can just swap the js libraries and have it work?
Is it as simple as: var $ = x$;
at the start of my script?
I haven't tested this, but after the initial variable declarations in xui.js, there's a declaration for x$ that looks like this:
window.x$ = window.xui = xui = function(q, context) {
return new xui.fn.find(q, context);
};
You can probably change it to this so that you can seamlessly test it against your code written for jQuery, since other than in the comments, x$ is not referenced in the xui.js code itself:
window.$ = window.xui = xui = function(q, context) {
return new xui.fn.find(q, context);
};
of if you wanted to leave x$ in there and just add $ as another selector, you can add it to the assignment like this:
window.x$ = window.$ = window.xui = xui = function(q, context) {
return new xui.fn.find(q, context);
};
I think, just adding window.$ = window.x$
or even only $ = x$
, after loading xui should be sufficient.
精彩评论