avoid errors in old ie from code highlighting
authorHakim El Hattab <hakim.elhattab@gmail.com>
Sun, 28 Apr 2013 18:12:31 +0000 (14:12 -0400)
committerHakim El Hattab <hakim.elhattab@gmail.com>
Sun, 28 Apr 2013 18:12:31 +0000 (14:12 -0400)
plugin/highlight/highlight.js

index af769dbe7a1bdc9c9b805c9521fddc877a122768..67563591a83765cbd6e561f1347874bb51911a04 100644 (file)
@@ -1,16 +1,22 @@
 // START CUSTOM REVEAL.JS INTEGRATION
 (function() {
-       [].slice.call( document.querySelectorAll( 'pre code' ) ).forEach( function( element ) {
-               // trim whitespace if data-trim attribute is present
-               if( element.hasAttribute( 'data-trim' ) && typeof element.innerHTML.trim === 'function' ) {
-                       element.innerHTML = element.innerHTML.trim();
-               }
+       if( typeof window.addEventListener === 'function' ) {
+               var hljs_nodes = document.querySelectorAll( 'pre code' );
+
+               for( var i = 0, len = hljs_nodes.length; i < len; i++ ) {
+                       var element = hljs_nodes[i];
 
-               // re-highlight when focus is lost (for edited code)
-               element.addEventListener( 'focusout', function( event ) {
-                       hljs.highlightBlock( event.currentTarget );
-               }, false );
-       } );
+                       // trim whitespace if data-trim attribute is present
+                       if( element.hasAttribute( 'data-trim' ) && typeof element.innerHTML.trim === 'function' ) {
+                               element.innerHTML = element.innerHTML.trim();
+                       }
+
+                       // re-highlight when focus is lost (for edited code)
+                       element.addEventListener( 'focusout', function( event ) {
+                               hljs.highlightBlock( event.currentTarget );
+                       }, false );
+               }
+       }
 })();
 // END CUSTOM REVEAL.JS INTEGRATION