From bd78c4a789ea2ae03526e7468591847159f90f52 Mon Sep 17 00:00:00 2001 From: Yoz Grahame Date: Sun, 23 Jun 2013 19:06:08 -0700 Subject: [PATCH 1/2] onHighlight() adds to an array of callbacks rather than overwriting previous --- js/rainbow.js | 11 ++++++----- tests/api.html | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/js/rainbow.js b/js/rainbow.js index c6d5f517..c502a907 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(i=0; iAPI 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); From c7430c9a46f15d4e12e84500134f8e8f21ac19a1 Mon Sep 17 00:00:00 2001 From: Yoz Grahame Date: Mon, 24 Jun 2013 16:22:42 -0700 Subject: [PATCH 2/2] Fix for-loop variable collision --- js/rainbow.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/rainbow.js b/js/rainbow.js index c502a907..4671d432 100644 --- a/js/rainbow.js +++ b/js/rainbow.js @@ -632,8 +632,8 @@ window['Rainbow'] = (function() { // if you have a listener attached tell it that this block is now highlighted if (onHighlight.length > 0) { - for(i=0; i