javascript - Switch between .bind() and .on() - dynamically -
i want this, because working third-party scripts releated internet marketing. of them may contain jquery library included within , interfere recent or latest jquery library included on website.
hence, i'd switch between .on() , .bind() dynamically upon website load of variable.
for example, let's have global variable:
var incjs = false;
and depending of third-party script, know if have older lib included i'd use this.
function tpnetwork () { incjs = true; startgateway('xxxxx'); $('#fancybox-outer') .delay(1000) .fadeto(300, 1); preventgtw(); widgetstyle(); }
now may see there's function @ bottom widgetstyle()
that function contain loads of things, important part following:
$(window).on('resize', function () { if ($('.widget_wrap').length) widgetcenter_horizontal(); });
it has .on() method there. not supported in old jquery that's been used third-party network. i'd switch every single .on() .bind() don't know how to, without duplicating things. did this, it's duplicate , believe there's easier way.
if (!incjs) { $(window).on('resize', function () { if ($('.widget_wrap').length) widgetcenter_horizontal(); }); } else { $(window).bind('resize', function () { if ($('.widget_wrap').length) widgetcenter_horizontal(); }); }
any kind of tips/help appreciated. out of ideas , doing researches found nothing.
what about:
$(function(){ if(!$.fn.on) $.fn.on = $.fn.bind; });
of course, excluding delegation support.
Comments
Post a Comment