From 21d2b96bdce638603231ab3f2d2ca29cdd012f0b Mon Sep 17 00:00:00 2001 From: Vjeux Date: Fri, 31 May 2013 00:31:46 +0200 Subject: [PATCH 1/2] JSFiddle integration This is a small snippet that exploits the fact that we can run custom script on jsfiddle before the Javascript1.7 transpiler is executed. We change the script type to text/jsx to run our transpiler pipeline instead. http://facebook.github.io/react/js/JSFiddleIntegration.js --- docs/js/JSFiddleIntegration.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/js/JSFiddleIntegration.js diff --git a/docs/js/JSFiddleIntegration.js b/docs/js/JSFiddleIntegration.js new file mode 100644 index 0000000000000..5b080a5815463 --- /dev/null +++ b/docs/js/JSFiddleIntegration.js @@ -0,0 +1,3 @@ +var tag = document.querySelector('script[type="application/javascript;version=1.7"]'); +tag.setAttribute('type', 'text/jsx'); +tag.textContent = '/** @jsx React.DOM */' + tag.textContent.substr(12, tag.textContent.length - 17); From 09301416bdc372467a51c295e3060edbd174f056 Mon Sep 17 00:00:00 2001 From: Vjeux Date: Fri, 31 May 2013 01:43:31 +0200 Subject: [PATCH 2/2] Alert if the default JSFiddle configuration is used Now using .replace instead of hardcoded numbers for readability I had a version without document.querySelector but JSFiddle doesn't work for IE7 and IE8 :x --- docs/js/JSFiddleIntegration.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/js/JSFiddleIntegration.js b/docs/js/JSFiddleIntegration.js index 5b080a5815463..462d96c2d4ff2 100644 --- a/docs/js/JSFiddleIntegration.js +++ b/docs/js/JSFiddleIntegration.js @@ -1,3 +1,10 @@ -var tag = document.querySelector('script[type="application/javascript;version=1.7"]'); +(function() { +var tag = document.querySelector( + 'script[type="application/javascript;version=1.7"]' +); +if (!tag || tag.textContent.indexOf('window.onload=function(){') !== -1) { + alert('Bad JSFiddle configuration, please fork the original React JSFiddle'); +} tag.setAttribute('type', 'text/jsx'); -tag.textContent = '/** @jsx React.DOM */' + tag.textContent.substr(12, tag.textContent.length - 17); +tag.textContent = tag.textContent.replace(/^\/\/