From 1fe8a0e8d69a057ce8923577ae8b0e0d805fbd80 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sun, 23 Aug 2015 00:36:25 -0400 Subject: [PATCH] Remove interactive.js jQuery dependency Importantly, this also removes loading from ajax.googleapis.com, which is a problem, because the domain must be allowed using NoScript, and hosts many other things. Why this was added to begin with is beyond me. Perhaps it demonstrates my novice abilities back in the day. --- doc/interactive.js | 72 ++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 48 deletions(-) diff --git a/doc/interactive.js b/doc/interactive.js index 795dc4c..f809eac 100644 --- a/doc/interactive.js +++ b/doc/interactive.js @@ -23,63 +23,39 @@ * in this page. */ -var head = document.getElementsByTagName( 'head' )[ 0 ], - sjquery = document.createElement( 'script' ), - sjquery_ui = document.createElement( 'script' ), - css = document.createElement( 'link' ); - -sjquery.type = sjquery_ui.type = 'text/javascript'; +var head = document.getElementsByTagName( 'head' )[ 0 ], + css = document.createElement( 'link' ); css.type = 'text/css'; css.rel = 'stylesheet'; -sjquery.src = - 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'; +// quick-n-dirty sub and super script impl (it is by no means +// perfect) +var vars = document.getElementsByTagName( 'var' ), + chk = /\\/; -head.appendChild( sjquery ); - -// will call callback when jQuery has been loaded -function jqueryCheck( callback ) +for ( var i in vars ) { - if ( typeof $ === 'undefined' ) - { - // check again in 50ms - setTimeout( function() - { - jqueryCheck( callback ); - }, 50 ); + var v = vars[ i ]; - return; + if ( !chk.test( v.innerHTML ) ) + { + continue; } - callback(); + v.innerHTML = v.innerHTML + .replace( /(\\.*)$/, '
$1
' ) + .replace( /\\_([^ \\]+)/, '$1' ) + .replace( /\\\^([^ \\]+)/, '$1' ) + .replace( /(<\/su[bp]>/, '$1 class="left">' ); } -jqueryCheck( function() +var hlnodes = document.querySelectorAll( + '.verbatim, .samp, .code, .example' +); + +// highlight code blocks +for ( var i in hlnodes ) { - $( document ).ready( function() - { - // syntax highlighting for code samples - $( '.verbatim, .samp, .code, .example' ).each( - function( i, element ) - { - hljs.highlightBlock( element, ' ' ); - } - ); - - // quick-n-dirty sub and super script impl (it is by no means - // perfect) - $( 'var:contains("\\")' ).each( function() - { - var $this = $( this ); - - $this.html( - $this.html().replace( /(\\.*)$/, '
$1
' ) - .replace( /\\_([^ \\]+)/, '$1' ) - .replace( /\\\^([^ \\]+)/, '$1' ) - .replace( /(<\/su[bp]>/, '$1 class="left">' ) - ); - } ); - } ); -} ); - + hljs.highlightBlock( hlnodes[ i ], ' ' ); +}