I am (very) slowly becoming a massive static file site, updating with all the latest goodies. I use yepnope (bundled with the new version of Modernizr.load) to handle async dependency loading, and I need this to be backward compatible with the current code base at the same time.
This requires me to either wrap every single jQuery sitewide call (too large a task to be done in the near future) in the yepnope() shell, or a more creative solution for the jQuery ready() proxy function through my own, and to delay execution of any code $ until the callback from yepnope is ready ... The jQuery actual ready() function will be the handler when the yepnope test is satisfied with jQuery's preparation. It makes sense?
Question at hand:
Am I creating a disaster here? Is this a suitable solution for my short-term problem of poorly implemented confusion of spaghetti DOM-oriented code?
update # 3
A more thoughtful approach that also takes into account unavailability when an anonymous function is simply passed directly to jQuery. This is the third attempt to make as little as possible in order to save only the function calls $(function(){}) , as well as calls $(document).ready() .
(function( window, undefined ) { var jQuery = (function(fn) { if (typeof fn === 'function') { yepnope({ test: window.jQuery.length, complete: function() { fn(); } }); } var jQuery = _jQuery = window.jQuery, _$ = window.$; jQuery = jQuery.prototype = { constructor: jQuery, ready: function( fn ) { yepnope({ test: window.jQuery.length, complete: function() { fn(); } }); } }; return jQuery; }); window.jQuery = window.$ = jQuery; })(window);
This is pretty sexy because when it duplicates the jQuery loading behavior, it has no length, in fact ... using yepnope to test window.jQuery.length , it will only return true after jQuery loads the REAL (the proxy has no length )!
I am sincerely looking for any criticism - especially from Alex Sexton :) lol
source share