diff --git a/js/rainbow.js b/js/rainbow.js index c6d5f517..4671d432 100644 --- a/js/rainbow.js +++ b/js/rainbow.js @@ -84,9 +84,9 @@ window['Rainbow'] = (function() { global_class, /** - * @type {null|Function} + * @type {Array} */ - onHighlight; + onHighlight = []; /** * cross browser get attribute for an element @@ -631,8 +631,9 @@ window['Rainbow'] = (function() { replacement_positions = {}; // if you have a listener attached tell it that this block is now highlighted - if (onHighlight) { - onHighlight(block, language); + if (onHighlight.length > 0) { + for(ohn=0; ohnAPI Test Page $("#stuff").append('

got callback

'); }); }, 1000); + + // Set an onHighlight() callback + setTimeout(function() { + Rainbow.onHighlight(function(){ + $("#stuff").append('

Got onHighlight() callback

') + }); + + $("#stuff").append('

code inserted dynamically with callback:

var html = $("#stuff").html();
'); + Rainbow.color(); + }, 1250); + + // Set multiple onHighlight() callbacks + setTimeout(function() { + Rainbow.onHighlight(function(){ + window._OHTest = 1; + }); + + Rainbow.onHighlight(function(){ + window._OHTest++; + $("#stuff").append('

This number should be 2: ' + + window._OHTest + '

'); + }); + + $("#stuff").append('

code inserted dynamically with callback:

var html = $("#stuff").html();
'); + Rainbow.color(); + }, 1500);