diff --git a/src/_h5ai/client/js/inc/core/resource.js b/src/_h5ai/client/js/inc/core/resource.js index 384aeae7..9aef9fd3 100644 --- a/src/_h5ai/client/js/inc/core/resource.js +++ b/src/_h5ai/client/js/inc/core/resource.js @@ -1,5 +1,5 @@ -modulejs.define('core/resource', ['_', 'config', 'core/settings'], function (_, config, settings) { +modulejs.define('core/resource', ['_', '$', 'config', 'core/settings'], function (_, $, config, settings) { var imagesHref = settings.appHref + 'client/images/', fallbackHref = settings.appHref + 'client/images/fallback/', @@ -32,37 +32,49 @@ modulejs.define('core/resource', ['_', 'config', 'core/settings'], function (_, return fallbackHref + 'file.svg'; }, - loadScript = function (url, globalId, callback) { + loadScript = function (filename, callback) { + + $.ajax({ + url: scriptsHref + filename, + dataType: 'script', + complete: function () { callback(); } + }); + }, + + loadScriptGlob = function (filename, globalId, callback) { if (window[globalId]) { callback(window[globalId]); } else { - $.ajax({ - url: url, - dataType: 'script', - complete: function () { - - callback(window[globalId]); - } - }); + loadScript(filename, function () { callback(window[globalId]); }); } }, - loadSyntaxhighlighter = function (callback) { + ensureQRCode = function (callback) { - loadScript(scriptsHref + 'syntaxhighlighter.js', 'SyntaxHighlighter', callback); + if ($.fn.qrcode) { + callback(); + } else { + loadScript('qrcode.js', callback); + } }, - loadMarkdown = function (callback) { + ensureSH = function (callback) { - loadScript(scriptsHref + 'markdown.js', 'markdown', callback); + loadScriptGlob('syntaxhighlighter.js', 'SyntaxHighlighter', callback); + }, + + ensureMarkdown = function (callback) { + + loadScriptGlob('markdown.js', 'markdown', callback); }; return { image: image, icon: icon, - loadSyntaxhighlighter: loadSyntaxhighlighter, - loadMarkdown: loadMarkdown + ensureMarkdown: ensureMarkdown, + ensureQRCode: ensureQRCode, + ensureSH: ensureSH, }; }); diff --git a/src/_h5ai/client/js/inc/ext/custom.js b/src/_h5ai/client/js/inc/ext/custom.js index 1be3fcdd..c50733cc 100644 --- a/src/_h5ai/client/js/inc/ext/custom.js +++ b/src/_h5ai/client/js/inc/ext/custom.js @@ -12,7 +12,7 @@ modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/e var has_header, has_footer, data, content; if (response) { - resource.loadMarkdown(function (md) { + resource.ensureMarkdown(function (md) { data = response.custom; diff --git a/src/_h5ai/client/js/inc/ext/preview-txt.js b/src/_h5ai/client/js/inc/ext/preview-txt.js index c001b7a2..39202edb 100644 --- a/src/_h5ai/client/js/inc/ext/preview-txt.js +++ b/src/_h5ai/client/js/inc/ext/preview-txt.js @@ -108,7 +108,7 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/event', 'co $text = $(templateMarkdown).text(textContent); - resource.loadMarkdown(function (md) { + resource.ensureMarkdown(function (md) { if (md) { $text.html(md.toHTML(textContent)); @@ -118,7 +118,7 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/event', 'co $text = $(templateText).text(textContent); - resource.loadSyntaxhighlighter(function (sh) { + resource.ensureSH(function (sh) { if (sh) { var $table = $('