1/** 2 * SyntaxHighlighter 3 * http://alexgorbatchev.com/SyntaxHighlighter 4 * 5 * SyntaxHighlighter is donationware. If you are using it, please donate. 6 * http://alexgorbatchev.com/SyntaxHighlighter/donate.html 7 * 8 * @version 9 * 3.0.90 (Sat, 18 Jun 2016 21:01:41 GMT) 10 * 11 * @copyright 12 * Copyright (C) 2004-2013 Alex Gorbatchev. 13 * 14 * @license 15 * Dual licensed under the MIT and GPL licenses. 16 */ 17(function() { 18 19var sh = SyntaxHighlighter; 20 21/** 22 * Provides functionality to dynamically load only the brushes that a needed to render the current page. 23 * 24 * There are two syntaxes that autoload understands. For example: 25 * 26 * SyntaxHighlighter.autoloader( 27 * [ 'applescript', 'Scripts/shBrushAppleScript.js' ], 28 * [ 'actionscript3', 'as3', 'Scripts/shBrushAS3.js' ] 29 * ); 30 * 31 * or a more easily comprehendable one: 32 * 33 * SyntaxHighlighter.autoloader( 34 * 'applescript Scripts/shBrushAppleScript.js', 35 * 'actionscript3 as3 Scripts/shBrushAS3.js' 36 * ); 37 */ 38sh.autoloader = function() 39{ 40 var list = arguments, 41 elements = sh.findElements(), 42 brushes = {}, 43 scripts = {}, 44 all = SyntaxHighlighter.all, 45 allCalled = false, 46 allParams = null, 47 i 48 ; 49 50 SyntaxHighlighter.all = function(params) 51 { 52 allParams = params; 53 allCalled = true; 54 }; 55 56 function addBrush(aliases, url) 57 { 58 for (var i = 0; i < aliases.length; i++) 59 brushes[aliases[i]] = url; 60 }; 61 62 function getAliases(item) 63 { 64 return item.pop 65 ? item 66 : item.split(/\s+/) 67 ; 68 } 69 70 // create table of aliases and script urls 71 for (i = 0; i < list.length; i++) 72 { 73 var aliases = getAliases(list[i]), 74 url = aliases.pop() 75 ; 76 77 addBrush(aliases, url); 78 } 79 80 // dynamically add <script /> tags to the document body 81 for (i = 0; i < elements.length; i++) 82 { 83 var url = brushes[elements[i].params.brush]; 84 85 if(url && scripts[url] === undefined) 86 { 87 if(elements[i].params['html-script'] === 'true') 88 { 89 if(scripts[brushes['xml']] === undefined) { 90 loadScript(brushes['xml']); 91 scripts[url] = false; 92 } 93 } 94 95 scripts[url] = false; 96 loadScript(url); 97 } 98 } 99 100 function loadScript(url) 101 { 102 var script = document.createElement('script'), 103 done = false 104 ; 105 106 script.src = url; 107 script.type = 'text/javascript'; 108 script.language = 'javascript'; 109 script.onload = script.onreadystatechange = function() 110 { 111 if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) 112 { 113 done = true; 114 scripts[url] = true; 115 checkAll(); 116 117 // Handle memory leak in IE 118 script.onload = script.onreadystatechange = null; 119 script.parentNode.removeChild(script); 120 } 121 }; 122 123 // sync way of adding script tags to the page 124 document.body.appendChild(script); 125 }; 126 127 function checkAll() 128 { 129 for(var url in scripts) 130 if (scripts[url] == false) 131 return; 132 133 if (allCalled) 134 SyntaxHighlighter.highlight(allParams); 135 }; 136}; 137 138})(); 139