Hi Chris,
We have a one-page app where we have built a search, results and
ordering/filtering of results on top of Claypool.
All works well and the code is much easier to write and read as a
result of using the MVC model, rather than hacking up a whole bunch of
$().click()'s with nested anonymous methods on Ajax callbacks... you
know, all the usual nonsense! So all good - Claypool rocks. etc. Yay!
So we then had to "inject" our search app into 3rd party sites
(Xdomain) using much the same techniques as those used by Google Maps
- adding a bootstrap script to the page which then adds all the
dependencies (inc claypool) by adding scripts to the head and finally
booting our app.
Our clients often choose add our scripts AFTER their page load fires,
so we do'nt slow down their initial page load times. Our app worked
fine in these cases, but we were seeing the events already hooked up
in the 3rd party site, button clicks, rollovers etc, were not working
once our app had been injected.
We traced this down to the fact that Claypool replaces - and
overwrites - jQueries cache. As you know - jQuery uses the cache as
part of it's event mechanism and so although DOM elements have data
IDs still attached the IDs are no longer found in the (new claypool)
cache and therefore the handlers are not found and to all intents, the
event no longer works.
This happens here around line 177 of
http://github.com/thatcher/jquery-claypool/blob/master/src/core/plugin.js
$.extend($$, plugins);
$.extend($, plugins);
We hacked it 2 ways... the first was to do this...
$.extend($$, plugins);
// CACHE PATCH
var tcache = jQuery.cache;
$.extend($, plugins);
jQuery.cache = tcache;
// CACHE PATCH
(told you it was a hack !)
The second was to insert around line 34 of
http://github.com/thatcher/jquery-claypool/blob/master/src/core/cache.js
(function($, $$){
/**
* @constructor
*/
$$.SimpleCachingStrategy = function(options){
$.extend(true, this, options);
this.logger = new $$.Logging.NullLogger();
this.clear();
//CACHE PATCH
//if claypool is lazy loaded it will hose the existing
jQuery.cache so this copies its contents over on init.
me = this;
jQuery.each(jQuery.cache,function(i,n){
me.add(i,n);
});
//ENDCACHE PATCH
return this;
};
.
Which would you suggest we proceed with? Do you think it's something
you might be able to patch into the trunk?
Without the hack, we can't use claypool as-is as a framework for
building "plugged in" apps that are lazy loaded after the initial page
load fires - and various DOM elems have already been wired up.
What do you think?
Cheers.
Olly.