diff --git a/src/_h5ai/client/js/inc/core/resource.js b/src/_h5ai/client/js/inc/core/resource.js index 64a8797e..44675880 100644 --- a/src/_h5ai/client/js/inc/core/resource.js +++ b/src/_h5ai/client/js/inc/core/resource.js @@ -1,10 +1,12 @@ modulejs.define('core/resource', ['_', '$', 'config', 'core/settings'], function (_, $, config, settings) { - var imagesHref = settings.appHref + 'client/images/', - fallbackHref = settings.appHref + 'client/images/fallback/', - themesHref = settings.appHref + 'client/themes/', - scriptsHref = settings.appHref + 'client/js/', + var win = window, + appHref = settings.appHref, + imagesHref = appHref + 'client/images/', + fallbackHref = appHref + 'client/images/fallback/', + themesHref = appHref + 'client/themes/', + scriptsHref = appHref + 'client/js/', fallbacks = ['file', 'folder', 'folder-page', 'folder-parent', 'ar', 'aud', 'bin', 'img', 'txt', 'vid'], image = function (id) { @@ -43,38 +45,22 @@ modulejs.define('core/resource', ['_', '$', 'config', 'core/settings'], function loadScriptGlob = function (filename, globalId, callback) { - if (window[globalId]) { - callback(window[globalId]); + if (win[globalId]) { + callback(win[globalId]); } else { - loadScript(filename, function () { callback(window[globalId]); }); - } - }, - - ensureQRCode = function (callback) { - - if ($.fn.qrcode) { - callback(); - } else { - loadScript('qrcode.js', callback); + loadScript(filename, function () { callback(win[globalId]); }); } }, ensureSH = function (callback) { loadScriptGlob('syntaxhighlighter.js', 'SyntaxHighlighter', callback); - }, - - ensureMarkdown = function (callback) { - - loadScriptGlob('markdown.js', 'markdown', callback); }; return { image: image, icon: icon, - 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 c50733cc..c4f60dc2 100644 --- a/src/_h5ai/client/js/inc/ext/custom.js +++ b/src/_h5ai/client/js/inc/ext/custom.js @@ -1,10 +1,13 @@ -modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/event', 'core/resource'], function (_, $, allsettings, server, event, resource) { +modulejs.define('ext/custom', ['_', '$', 'markdown', 'core/settings', 'core/server', 'core/event', 'core/resource'], function (_, $, markdown, allsettings, server, event, resource) { var settings = _.extend({ enabled: false }, allsettings.custom), + $header, $footer, + duration = 200, + onLocationChanged = function (item) { server.request({action: 'get', custom: true, customHref: item.absHref}, function (response) { @@ -12,35 +15,32 @@ modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/e var has_header, has_footer, data, content; if (response) { - resource.ensureMarkdown(function (md) { + data = response.custom; - data = response.custom; - - if (data.header) { - content = data.header; - if (md && data.header_type === 'md') { - content = md.toHTML(content); - } - $('#content-header').html(content).stop().slideDown(200); - has_header = true; + if (data.header) { + content = data.header; + if (data.header_type === 'md') { + content = markdown.toHTML(content); } + $header.html(content).stop().slideDown(duration); + has_header = true; + } - if (data.footer) { - content = data.footer; - if (md && data.footer_type === 'md') { - content = md.toHTML(content); - } - $('#content-footer').html(content).stop().slideDown(200); - has_footer = true; + if (data.footer) { + content = data.footer; + if (data.footer_type === 'md') { + content = markdown.toHTML(content); } - }); + $footer.html(content).stop().slideDown(duration); + has_footer = true; + } } if (!has_header) { - $('#content-header').stop().slideUp(200); + $header.stop().slideUp(duration); } if (!has_footer) { - $('#content-footer').stop().slideUp(200); + $footer.stop().slideUp(duration); } }); }, @@ -51,8 +51,8 @@ modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/e return; } - $('
').hide().prependTo('#content'); - $('').hide().appendTo('#content'); + $header = $('').hide().prependTo('#content'); + $footer = $('').hide().appendTo('#content'); event.sub('location.changed', onLocationChanged); }; diff --git a/src/_h5ai/client/js/inc/ext/preview-txt.js b/src/_h5ai/client/js/inc/ext/preview-txt.js index 39202edb..d6f4f572 100644 --- a/src/_h5ai/client/js/inc/ext/preview-txt.js +++ b/src/_h5ai/client/js/inc/ext/preview-txt.js @@ -1,5 +1,5 @@ -modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/event', 'core/resource', 'ext/preview'], function (_, $, allsettings, event, resource, preview) { +modulejs.define('ext/preview-txt', ['_', '$', 'markdown', 'core/settings', 'core/event', 'core/resource', 'ext/preview'], function (_, $, markdown, allsettings, event, resource, preview) { var settings = _.extend({ enabled: false, @@ -106,14 +106,7 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/event', 'co } else if (settings.types[currentItem.type] === 'markdown') { - $text = $(templateMarkdown).text(textContent); - - resource.ensureMarkdown(function (md) { - - if (md) { - $text.html(md.toHTML(textContent)); - } - }); + $text = $(templateMarkdown).html(markdown.toHTML(textContent)); } else { $text = $(templateText).text(textContent); diff --git a/src/_h5ai/client/js/inc/ext/qrcode.js b/src/_h5ai/client/js/inc/ext/qrcode.js index 72c1303e..dce00374 100644 --- a/src/_h5ai/client/js/inc/ext/qrcode.js +++ b/src/_h5ai/client/js/inc/ext/qrcode.js @@ -1,5 +1,5 @@ -modulejs.define('ext/qrcode', ['_', '$', 'modernizr', 'core/settings', 'core/event', 'core/resource'], function (_, $, modernizr, allsettings, event, resource) { +modulejs.define('ext/qrcode', ['_', '$', 'modernizr', 'core/settings', 'core/event'], function (_, $, modernizr, allsettings, event) { var settings = _.extend({ enabled: false, @@ -12,15 +12,13 @@ modulejs.define('ext/qrcode', ['_', '$', 'modernizr', 'core/settings', 'core/eve update = function (item) { - resource.ensureQRCode(function () { - $qrcode.empty().qrcode({ - render: modernizr.canvas ? 'canvas' : 'div', - width: settings.size, - height: settings.size, - color: '#333', - bgColor: '#fff', - text: window.location.protocol + '//' + window.location.host + item.absHref - }); + $qrcode.empty().qrcode({ + render: modernizr.canvas ? 'canvas' : 'div', + width: settings.size, + height: settings.size, + color: '#333', + bgColor: '#fff', + text: window.location.protocol + '//' + window.location.host + item.absHref }); }, diff --git a/src/_h5ai/client/js/inc/view/ensure.js b/src/_h5ai/client/js/inc/view/ensure.js index 7b83416a..986ddbf1 100644 --- a/src/_h5ai/client/js/inc/view/ensure.js +++ b/src/_h5ai/client/js/inc/view/ensure.js @@ -13,9 +13,9 @@ modulejs.define('view/ensure', ['$', 'core/event'], function ($, event) { ensure = function () { if ( - $(selr).filter(isVisible).length != 1 || - $(sela).filter(isVisible).length != 1 || - $(selr).text() != sequence + $(selr).filter(isVisible).length !== 1 || + $(sela).filter(isVisible).length !== 1 || + $(selr).text() !== sequence ) { $(selr).remove(); $('') diff --git a/src/_h5ai/client/js/markdown.js b/src/_h5ai/client/js/markdown.js deleted file mode 100644 index 27be65e6..00000000 --- a/src/_h5ai/client/js/markdown.js +++ /dev/null @@ -1,2 +0,0 @@ - -// @include "lib/markdown-*.js" diff --git a/src/_h5ai/client/js/qrcode.js b/src/_h5ai/client/js/qrcode.js deleted file mode 100644 index 1608743f..00000000 --- a/src/_h5ai/client/js/qrcode.js +++ /dev/null @@ -1,2 +0,0 @@ - -// @include "lib/jquery.qrcode-*.js" diff --git a/src/_h5ai/client/js/scripts.js b/src/_h5ai/client/js/scripts.js index 814b7484..f2a6b68e 100644 --- a/src/_h5ai/client/js/scripts.js +++ b/src/_h5ai/client/js/scripts.js @@ -4,6 +4,7 @@ // @include "lib/modernizr-*.js" if (window.attachEvent && !window.addEventListener) { throw 'no-browser'; } // @include "lib/underscore-*.js" +// @include "lib/markdown-*.js" // @include "lib/modulejs-*.js" // @include "lib/moment-*.js" // @include "lib/json2-*.js" @@ -13,6 +14,7 @@ if (window.attachEvent && !window.addEventListener) { throw 'no-browser'; } // @include "lib/jquery-*.js" // @include "lib/jquery.fracs-*.js" // @include "lib/jquery.mousewheel-*.js" +// @include "lib/jquery.qrcode-*.js" // @include "lib/jquery.scrollpanel-*.js" // app @@ -22,6 +24,7 @@ if (window.attachEvent && !window.addEventListener) { throw 'no-browser'; } /*global jQuery, Modernizr, moment, _ */ modulejs.define('$', function () { return jQuery; }); + modulejs.define('markdown', function () { return markdown; }); modulejs.define('modernizr', function () { return Modernizr; }); modulejs.define('moment', function () { return moment; }); modulejs.define('_', function () { return _; });