javascript - How to create a custom event listener for Respond.js -
i'm using respond.js ensure bootstrap 3 compatibility 1 of projects in ie8.
i'm loading large css file respond.proxy.js. after css has been loaded , ripped respond, i'd have initialize jquery plugins rely on css.
i'd able jquery $(document).ready()
.
is possible create custom event listener eg. $(respond).finished(...)
gets called after respond has finished it's work? need initialize plugins in different scripts , files.
since respond.js doesn't trigger events or provide way of applying callback function, option modify respond.js have trigger event.
i suggest modifying line:
https://github.com/scottjehl/respond/blob/master/src/respond.js#l298
if (requestqueue.length) { var thisrequest = requestqueue.shift(); ajax(thisrequest.href, function (styles) { translate(styles, thisrequest.href, thisrequest.media); parsedsheets[thisrequest.href] = true; // wrapping recursive function call in settimeout // prevent "stack overflow" error in ie7 w.settimeout(function () { makerequests(); }, 0); }); }/* here on added*/ else { var event = new event("respondfinished"); document.dispatchevent(event); }
now can add event listener document in scripts need it.
if (window.respond.mediaqueriessupported) { dosomething(); } else { $(document).on("respondfinished", dosomething); }
you'll want add event handler possible, preferably before document ready ensure event gets bound before respond.js finishes.
Comments
Post a Comment