Commit 2b8e9f2f59e510c3f40873fec43572c69c9ebc5d

Daniel Flint 2014-04-23T08:32:47

If loading a new language, don't attempt highlight until it's actually downloaded.

diff --git a/test.html b/test.html
index bdde7e1..d9524ae 100644
--- a/test.html
+++ b/test.html
@@ -84,7 +84,8 @@ textarea {
 <script>
 (function() {
 var form = $('form'), code = $('code', form),
-    languages = components.languages;
+    languages = components.languages,
+	highlightCode = function() { Prism.highlightElement(code); };
 
 for (var id in languages) {
 	if (id == 'meta') {
@@ -107,10 +108,11 @@ for (var id in languages) {
 						code.textContent = code.textContent;
 						
 						if (!Prism.languages[lang]) {
-							$u.script('components/prism-' + lang + '.js');
+							$u.script('components/prism-' + lang + '.js', highlightCode);
+						}
+						else {
+							highlightCode();
 						}
-						
-						Prism.highlightElement(code);
 					}
 				}
 			}, name
@@ -127,7 +129,7 @@ var textarea = $('textarea', form);
 
 (textarea.oninput = function() {
 	code.textContent = this.value || '';
-	Prism.highlightElement(code);
+	highlightCode();
 }).call(textarea);
 
 })();