meta100/mColorPicker — Issue #5: Live Event Issues
Author: pwc1011
Created: 2011-10-17 16:57:27+00:00
State: open

Hello meta100,

We've been using mColorPicker for a while, and we just updated to the newest version. It seems there is a problem with the use of "live" for the keyup and click events. More specifically, it's where live is used.

Each time the code goes through and initializes an object (given the call to colorPicker is done more than once) the live events is bound again.

Instead, you can use the live in document ready, and it is only bound once when the script is loaded. Even better, add a die to the objects before the live event is bound.

$('.mColorPicker').die().live('keyup', function () {

try {

$(this).css({
'background-color': $(this).val()
}).css({
'color': $.fn.mColorPicker.textColor($(this).css('background-color'))
}).trigger('change');
} catch (r) { }
});

$('.mColorPickerTrigger').die().live('click', function () {

$.fn.mColorPicker.colorShow($(this).attr('id').replace('icp_', ''));
});

To test for the problem before the above changes...

1) create multiple inputs with a class of "mcp"
2) loop through each and call mColorPicker...
$(".mcp").each(function() {
$(this).mColorPicker();
$(this).bind("colorPicked",function(event) {alert('color picked'); });
});
3) use color picked and count how many times the alert is fired.

Regards,
Patrick