Loads SyntaxHighlighter on demand.

This commit is contained in:
Lars Jung 2012-08-05 22:01:40 +02:00
parent d4a213beac
commit 298d2e2efd
5 changed files with 57 additions and 22 deletions

View file

@ -6,7 +6,7 @@ var path = require('path'),
child_process = require('child_process'); child_process = require('child_process');
var version = '0.21-dev-43', var version = '0.21-dev-45',
root = path.resolve(__dirname), root = path.resolve(__dirname),
src = path.join(root, 'src'), src = path.join(root, 'src'),

View file

@ -1,5 +1,5 @@
modulejs.define('ext/preview-txt', ['_', '$', 'sh', 'core/settings', 'core/resource', 'core/store', 'core/entry'], function (_, $, SH, allsettings, resource, store, entry) { modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/resource', 'core/store', 'core/entry'], function (_, $, allsettings, resource, store, entry) {
var defaults = { var defaults = {
enabled: false, enabled: false,
@ -34,6 +34,24 @@ modulejs.define('ext/preview-txt', ['_', '$', 'sh', 'core/settings', 'core/resou
currentEntries = [], currentEntries = [],
currentIdx = 0, currentIdx = 0,
loadSyntaxhighlighter = function (callback) {
var id = 'SyntaxHighlighter';
if (window[id]) {
callback(window[id]);
} else {
$.ajax({
url: allsettings.h5aiAbsHref + 'js/syntaxhighlighter.js',
dataType: 'script',
complete: function () {
callback(window[id]);
}
});
}
},
adjustSize = function () { adjustSize = function () {
var rect = $(window).fracs('viewport'), var rect = $(window).fracs('viewport'),
@ -94,7 +112,12 @@ modulejs.define('ext/preview-txt', ['_', '$', 'sh', 'core/settings', 'core/resou
var $nText = $(templateText).hide().addClass('toolbar: false; brush:').addClass(settings.types[current.type] || 'plain').text(content); var $nText = $(templateText).hide().addClass('toolbar: false; brush:').addClass(settings.types[current.type] || 'plain').text(content);
$text.replaceWith($nText); $text.replaceWith($nText);
SH.highlight({}, $nText[0]); loadSyntaxhighlighter(function (sh) {
if (sh) {
sh.highlight({}, $nText[0]);
}
});
$nText.fadeIn(200); $nText.fadeIn(200);
adjustSize(); adjustSize();

View file

@ -47,7 +47,7 @@
$(function () { $(function () {
/*global H5AI_CONFIG, amplify, Base64, jQuery, Modernizr, moment, SyntaxHighlighter, _ */ /*global H5AI_CONFIG, amplify, Base64, jQuery, Modernizr, moment, _ */
// Register predefined globals on doc ready, so the script order inside // Register predefined globals on doc ready, so the script order inside
// the document doesn't matter. `jQuery`, `moment` and `underscore` are // the document doesn't matter. `jQuery`, `moment` and `underscore` are
@ -59,7 +59,6 @@
modulejs.define('$', function () { return jQuery; }); modulejs.define('$', function () { return jQuery; });
modulejs.define('modernizr', Modernizr); modulejs.define('modernizr', Modernizr);
modulejs.define('moment', function () { return moment; }); modulejs.define('moment', function () { return moment; });
modulejs.define('sh', SyntaxHighlighter);
modulejs.define('_', function () { return _; }); modulejs.define('_', function () { return _; });
modulejs.require($('body').attr('id')); modulejs.require($('body').attr('id'));

View file

@ -17,23 +17,6 @@
// @include "lib/base64.js" // @include "lib/base64.js"
// @include "lib/spin-1.2.5.min.js" // @include "lib/spin-1.2.5.min.js"
// @include "lib/sh/shCore.js"
// @include "lib/sh/shBrushBash.js"
// @include "lib/sh/shBrushCSharp.js"
// @include "lib/sh/shBrushCpp.js"
// @include "lib/sh/shBrushCss.js"
// @include "lib/sh/shBrushDiff.js"
// @include "lib/sh/shBrushJScript.js"
// @include "lib/sh/shBrushJava.js"
// @include "lib/sh/shBrushPerl.js"
// @include "lib/sh/shBrushPhp.js"
// @include "lib/sh/shBrushPlain.js"
// @include "lib/sh/shBrushPython.js"
// @include "lib/sh/shBrushRuby.js"
// @include "lib/sh/shBrushSass.js"
// @include "lib/sh/shBrushXml.js"
// h5ai // h5ai
// ---- // ----
// @include "inc/main.js" // @include "inc/main.js"

View file

@ -0,0 +1,30 @@
// @include "lib/sh/shCore.js"
// @-include "lib/sh/shLegacy.js"
// @-include "lib/sh/shAutoloader.js"
// @include "lib/sh/shBrushAS3.js"
// @include "lib/sh/shBrushAppleScript.js"
// @include "lib/sh/shBrushBash.js"
// @include "lib/sh/shBrushCSharp.js"
// @include "lib/sh/shBrushColdFusion.js"
// @include "lib/sh/shBrushCpp.js"
// @include "lib/sh/shBrushCss.js"
// @include "lib/sh/shBrushDelphi.js"
// @include "lib/sh/shBrushDiff.js"
// @include "lib/sh/shBrushErlang.js"
// @include "lib/sh/shBrushGroovy.js"
// @include "lib/sh/shBrushJScript.js"
// @include "lib/sh/shBrushJava.js"
// @include "lib/sh/shBrushJavaFX.js"
// @include "lib/sh/shBrushPerl.js"
// @include "lib/sh/shBrushPhp.js"
// @include "lib/sh/shBrushPlain.js"
// @include "lib/sh/shBrushPowerShell.js"
// @include "lib/sh/shBrushPython.js"
// @include "lib/sh/shBrushRuby.js"
// @include "lib/sh/shBrushSass.js"
// @include "lib/sh/shBrushScala.js"
// @include "lib/sh/shBrushSql.js"
// @include "lib/sh/shBrushVb.js"
// @include "lib/sh/shBrushXml.js"