Adding claypool AFTER pageload event hoses already registered events.

2 views
Skip to first unread message

olly wenn

unread,
May 31, 2010, 2:23:31 PM5/31/10
to jquery-claypool
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.

chris thatcher

unread,
May 31, 2010, 4:29:33 PM5/31/10
to jquery-...@googlegroups.com
We can definitely get this into trunk, and on first look I actually like something like the first approach.  I'll work on this on my train ride in the morning and get it pushed out by lunch.  I want to take a quick peek at the jQuery src and see if there might be a thrid solution as well.

Thanks for identifying this,
Thatcher


--
You received this message because you are subscribed to the Google Groups "jquery-claypool" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to jquery-claypo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jquery-claypool?hl=en.




--
Christopher Thatcher

chris thatcher

unread,
Jun 1, 2010, 9:05:35 AM6/1/10
to jquery-...@googlegroups.com
So on a closer look the best solution is to deprecate $.cache defined by jQuery-claypool.  It was not a documented extension point in claypool, and never used internally which actually goes against they way claypool tries to define plugins.   

Unlike $.uuid which caused a similar conflict with 1.4.2 and was renamed to $.guid, I wont bother to provide a new name for it because it's existence really was an after thought that should have been removed earlier since its not really a good plugin in the jquery spirit.

Now that it conflicts with jQuery internals it's best to just remove it.  I noted you in the source for finding this, and will build a new version and push at lunch time!

Thanks again,
Thatcher
--
Christopher Thatcher

chris thatcher

unread,
Jun 1, 2010, 9:46:35 AM6/1/10
to jquery-...@googlegroups.com
pushed to trunk as build 1.1.6.

thanks again olly,
Thatcher
--
Christopher Thatcher
Reply all
Reply to author
Forward
0 new messages