I hope this can be included in the next release.
The purpose of the changes is to make the js in compliance with drupal behavior thus if this module is called via ajax and the caller invoke drupal attach behavior then the js will not broken.
/* $Id: avatar_selection.js,v 1.1.2.1.4.14 2009/06/07 23:34:23 snpower Exp $ */
Drupal.behaviors.AvatarSelection = function(context) {
function radio_button_handler() {
// handle radio buttons
$('div.user-avatar-select input.form-radio').hide();
$('div.user-avatar-select img').hover(
function(){
$(this).addClass("avatar-hover");
},
function(){
$(this).removeClass("avatar-hover");
}
);
}
function image_click_handler() {
$('div.user-avatar-select img').bind("click", function(){
$("div.user-avatar-select img.avatar-select").each(function(){
$(this).removeClass("avatar-select");
$(this).parent().children("input").attr("checked", "");
});
$(this).addClass("avatar-select");
$(this).parent().children("input").attr("checked", "checked");
});
}
if (Drupal.jsEnabled) {
// handle radio buttons
radio_button_handler();
// handle image selection
image_click_handler();
}
};
Comments
Comment #1
stella commentedThe existing code already uses Drupal.behaviours though, so unclear on how your code improves things. Also please provide patches in unified diff format, see http://drupal.org/patch/create
Comment #2
duckzland commentedThe only problem with the existing code is not having this line :
Which resulting in when the avatar selection module (eg. in user edit page) is called from ajax call, even though the ajax caller called drupal.attachBehavior() the avatar selection module js function won't get attached to the newly ajax fetched content.
By adding the above code when the ajax caller invoke drupal.attachBehavior then it will add Drupal.behaviors.AvatarSelection function to the newly ajax fetched content.
I'm sorry that I cannot provide proper patch for this, but surely it is easy enough to implement by just adding 2 line of code.
Comment #3
stella commentedDrupal behaviors, including the "context" param, were added to the dev version of the module ages ago. Admittedly it's not in the 6.x-1.6 release but has been in the dev version since 2009.