Eyal Golan schrieb:
hi Eyal
Hi all,I've created a small Wicket module for the lavalamp JQuery library
(some links below).
nice. why not on wicketstuff?
Please be kind and give me any suggestion and insights.
i just looked at it quickly, but two things strike me:
1st: afaik you should not use
$(document).ready(... as it would break compatibility with other JS
frameworks redefining the $
jQuery(document).ready(...
or
(function($) { /* some code that uses $ */ })(jQuery)
would be better. please keep in mind, you only contribute one component
to the page, so there might be a bunch of others ;)
2nd is more general and valid with about any wicket component that uses
a JS lib. I´m making the jQuery case here:
as it is a good practice to add functions (aka plugins) to the jQuery
object, including the jQuery script more than once in a page is not only
useless waste of bandwidth and lowers user experience, but does
severel harm (last wins).
so adding your component to a page potentially breaks most of the nice
other components that relied on plugins loaded before your (bundled)
jQuery script.
duh!
there is only one way out, i think. as we all know that wicket is clever
enough to sort out duplicate header contributors, we should make use of
them!
so, what we could do instead of bundling jquery with every damn
component whould be to just express the dependency to it.
i suggest to use wicketstuff-core/jslibraries in order to have a common
ground to create these header contributors.
so instead of
CompressedResourceReference JQUERY_JS = new
CompressedResourceReference( JQueryLavaLampBehavior.class, "jquery.js");
response.renderJavascriptReference(JQUERY_JS);
you could simply put
add(JSLib.getHeaderContribution(VersionDescriptor
.alwayLatest(Library.JQUERY));
into your component, and make our lives much easier.
<advertisment>
a good side effect is to give the user of your component a chance to use
a CDN instead of a bundled version to optimize loadtime
</advertisment>
cu uwe
oh, and PS: i don´t get LockButton/ResetButton/validate in the global
namespace?! (see jquery.lavalamp.js) :)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]