I am new to zepto, and am using it as a jQuery replacement for the mobile part of a website.
So zepto doesn't have $.fn.extend. Fine that's cool with me, but I need my pluggin to work regardless of jquery or zepto.
What is zepto's alterative to fn.extend? How would you go about making a cross library extension? I've yet to find any documentation on this.
$.fn.extend({
lineRedNAddClass : function(option){
$(this).css('border','red 1px solid').addClass(option);
}
});
can this be made to work with both from the same script?
in other words, to make some jquery plugins work with zepto, i've added these 2 lines to the end of my zepto.js:
jQuery = Zepto;
$.fn.extend = function(obj) {
$.extend($.fn, obj);
};
Zepto's extend function can be accessed via $.extend()
, which is also available in the jQuery API, so we can simply extend $.fn
using that.
Example:
$.extend($.fn, {
myFunc: function() {
$(this).css({
color: 'red'
});
}
});
And here's a demo. I've loaded both libraries in to the assets, so just switch the value of $ using the top two lines. There's a consle.log
included to prove that the correct library is loaded.
http://jsfiddle.net/WNTXY/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With