javascript - Add callback function to library -
i using color.js, , i'm trying add callback function setcolor
. added following code before line #177:
if (_instance.options.setcolorcallback) { _instance.options.setcolorcallback(convertcolors(type, save ? colors : undefined)); }
that works fine , well, problem when try using setcolor
using lab
color format. when that, callback function doesn't execute. here's how setcolor
using lab
color space: (source)
if (type === 'lab') { var factor = (e.clientx - startpoint.left) / currenttargetwidth; factor = factor > 1 ? 1 : factor < 0 ? 0 : factor; mycolor.colors.lab[mode] = (mode === 'l') ? factor * 100 : (factor * 255) - 128; mycolor.setcolor(null, 'lab'); }
how can add callback function setcolor
?
although it's bad practice modify libraries that, if have decided instead @ line#177 @ line#204, , replace
function convertcolors(type, colorobj) {
with
function convertcolors(type, colorobj) { var convertresult = __convertcolors(type, colorobj); if (_instance.options.aftercolorsconvert) { _instance.options.aftercolorsconvert(convertresult); } return convertresult; } function __convertcolors(type, colorobj) {
this because setcolor wrapped @ line#76 , in both code definitions of setcolor, convertcolors used, better extend convertcolors functionality.
Comments
Post a Comment