标签:
因为使用SyntaxHighlighter的时候会使用到多种语言,一次必载入全部的语言配置文件下载的东西会比较多,所以SyntaxHighlighter提供了一个shAutoloader.js脚本。本站正在使用,本站代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<script type= "text/javascript" src= "/Themes/BootStrap/scripts/Syntaxhighlighter/scripts/shCore.js" ></script> <script type= "text/javascript" src= "/Themes/BootStrap/scripts/Syntaxhighlighter/scripts/shAutoloader.js" ></script> <link type= "text/css" rel= "stylesheet" href= "/Themes/BootStrap/scripts/Syntaxhighlighter/styles/shCoreDefault.css" /> <script type= "text/javascript" > function path() { var args = arguments, result = []; for ( var i = 0; i < args.length; i++) result.push(args[i].replace( ‘$‘ , ‘/Themes/BootStrap/scripts/Syntaxhighlighter/scripts/‘ )); return result } $( function () { SyntaxHighlighter.autoloader.apply( null , path( ‘applescript $shBrushAppleScript.js‘ , ‘actionscript3 as3 $shBrushAS3.js‘ , ‘bash shell $shBrushBash.js‘ , ‘coldfusion cf $shBrushColdFusion.js‘ , ‘cpp c $shBrushCpp.js‘ , ‘c# c-sharp csharp $shBrushCSharp.js‘ , ‘css $shBrushCss.js‘ , ‘delphi pascal $shBrushDelphi.js‘ , ‘diff patch pas $shBrushDiff.js‘ , ‘erl erlang $shBrushErlang.js‘ , ‘groovy $shBrushGroovy.js‘ , ‘java $shBrushJava.js‘ , ‘jfx javafx $shBrushJavaFX.js‘ , ‘js jscript javascript $shBrushJScript.js‘ , ‘perl pl $shBrushPerl.js‘ , ‘php $shBrushPhp.js‘ , ‘text plain $shBrushPlain.js‘ , ‘py python $shBrushPython.js‘ , ‘ruby rails ror rb $shBrushRuby.js‘ , ‘sass scss $shBrushSass.js‘ , ‘scala $shBrushScala.js‘ , ‘sql $shBrushSql.js‘ , ‘vb vbnet $shBrushVb.js‘ , ‘xml xhtml xslt html $shBrushXml.js‘ )); SyntaxHighlighter.all(); } </script> |
但文章详细页面经常不会有任何代码,所以这些js文件以及js代码需要判断是否执行:
1
2
3
4
5
6
7
|
//判断文章是否需要加载代码高亮插件 var isCode = Model.Html.ToString().Contains( "<pre class=\"brush:" ); @{ if (isCode){ //这里放置上面的js文件链接以及js代码。 } } |
本文来自:http://www.itdos.com/JavaScript/20150303/0135261.html 转载请保留此文字,谢谢!
SyntaxHighlighter-Autoloader(自动加载)
标签:
原文地址:http://www.cnblogs.com/itdos/p/4310219.html