jetpack unbind

0 views
Skip to first unread message

ydarcy60

unread,
Feb 8, 2010, 11:33:50 PM2/8/10
to mozilla-labs-jetpack
Is the flaw in the code below easily identified?
Intention is to stop (unbind) the coloring after setting blue, (or
just reset the eventhandler to
the dummy function. Coloring will not seem to stop, and the dummy
does get added to
eventhandler list:

jetpack.future.import("selection");

jetpack.tabs.onReady( function(widget){
console.log("onReady");
jetpack.selection.onSelection(colorit);
});

// A list of colors
var colors = "red,green,blue,purple".split(/,/);
// Color selected text with the next color
function colorit() {
var tcolor = colors.shift(); // extract first and move remaining left

if(tcolor=="blue") unlisten(colorit); // this does not seem to
disconnect the eh
if(tcolor=="purple") unlisten(dummy);

colors.push(tcolor); // making a 'ring' of our colors
jetpack.selection.html = colorme(jetpack.selection.html,tcolor);
}

function unlisten(eh){
console.log("unbind="+jetpack.selection.onSelection+"\n"+eh);
jetpack.selection.onSelection(dummy);
jetpack.selection.onSelection.unbind(eh);
}
function dummy(){
console.log("dummy");
}
function colorme(txt,c){
var spret="<span style='color: " + c + "'>"+txt+"</span>";
console.log("colorme="+c)
return spret;
}

Reply all
Reply to author
Forward
0 new messages