diff --git a/mkrfile.js b/mkrfile.js index a9344cae..ae9c4b44 100644 --- a/mkrfile.js +++ b/mkrfile.js @@ -14,21 +14,19 @@ var build = path.join(root, 'build'); var mapSrc = $.map.p(src, build).s('.less', '.css').s('.jade', ''); var mapRoot = $.map.p(root, path.join(build, '_h5ai')); - // bad hack -var getBuildSuffix = function (callback) { - var child_process = require('child_process'); +function getBuildSuffix(callback) { - child_process.exec('git rev-list v' + pkg.version + '..HEAD', {cwd: root}, function (err, out) { + require('child_process').exec('git rev-list v' + pkg.version + '..HEAD', {cwd: root}, function (err, out) { - try { - var lines = out.trim().split(/\r?\n/); - callback('+' + ('000' + lines.length).substr(-3) + '~' + lines[0].substring(0, 7)); - } catch (e) { - callback('+X'); - } - }); - }; + try { + var lines = out.trim().split(/\r?\n/); + callback('+' + ('000' + lines.length).substr(-3) + '~' + lines[0].substring(0, 7)); + } catch (e) { + callback('+X'); + } + }); +} $.plugin('fquery-cssmin'); @@ -96,10 +94,10 @@ module.exports = function (suite) { }); - suite.target('build', ['check-version'], 'build all updated files').task(function () { + suite.target('build', ['check-version', 'lint'], 'build all updated files').task(function () { - var env = {pkg: pkg}; var header = '/* ' + pkg.name + ' ' + pkg.version + ' - ' + pkg.homepage + ' */\n'; + var env = {pkg: pkg}; $(src + ': _h5ai/client/js/*.js') .newerThan(mapSrc, $(src + ': _h5ai/client/js/**')) @@ -136,10 +134,10 @@ module.exports = function (suite) { }); - suite.target('build-uncompressed', ['check-version'], 'build all updated files').task(function () { + suite.target('build-uncompressed', ['check-version', 'lint'], 'build all updated files').task(function () { - var env = {pkg: pkg}; var header = '/* ' + pkg.name + ' ' + pkg.version + ' - ' + pkg.homepage + ' */\n'; + var env = {pkg: pkg}; $(src + ': _h5ai/client/js/*.js') .newerThan(mapSrc, $(src + ': _h5ai/client/js/**')) diff --git a/src/_h5ai/client/js/inc/core/event.js b/src/_h5ai/client/js/inc/core/event.js index c3ffdf0e..8d5f60d9 100644 --- a/src/_h5ai/client/js/inc/core/event.js +++ b/src/_h5ai/client/js/inc/core/event.js @@ -1,41 +1,42 @@ - modulejs.define('core/event', ['_'], function (_) { - var slice = Array.prototype.slice, - subscriptions = {}, + var slice = Array.prototype.slice; + var subscriptions = {}; - sub = function (topic, callback) { - if (_.isString(topic) && _.isFunction(callback)) { + function sub(topic, callback) { - if (!subscriptions[topic]) { - subscriptions[topic] = []; - } - subscriptions[topic].push(callback); + if (_.isString(topic) && _.isFunction(callback)) { + + if (!subscriptions[topic]) { + subscriptions[topic] = []; } - }, + subscriptions[topic].push(callback); + } + } - unsub = function (topic, callback) { + function unsub(topic, callback) { - if (_.isString(topic) && _.isFunction(callback) && subscriptions[topic]) { + if (_.isString(topic) && _.isFunction(callback) && subscriptions[topic]) { - subscriptions[topic] = _.without(subscriptions[topic], callback); - } - }, + subscriptions[topic] = _.without(subscriptions[topic], callback); + } + } - pub = function (topic, data) { + function pub(topic, data) { - var args = slice.call(arguments, 1); + var args = slice.call(arguments, 1); - // console.log('EVENT PUB', topic, args); - if (_.isString(topic) && subscriptions[topic]) { + // console.log('EVENT PUB', topic, args); + if (_.isString(topic) && subscriptions[topic]) { - _.each(subscriptions[topic], function (callback) { + _.each(subscriptions[topic], function (callback) { + + callback.apply(topic, args); + }); + } + } - callback.apply(topic, args); - }); - } - }; return { sub: sub, diff --git a/src/_h5ai/client/js/inc/core/format.js b/src/_h5ai/client/js/inc/core/format.js index ca745876..82175dcb 100644 --- a/src/_h5ai/client/js/inc/core/format.js +++ b/src/_h5ai/client/js/inc/core/format.js @@ -1,51 +1,52 @@ - modulejs.define('core/format', ['_', 'moment'], function (_, moment) { var decimalMetric = { t: 1000.0, k: 1000.0, u: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] - }, - binaryMetric = { + }; + var binaryMetric = { t: 1024.0, k: 1024.0, u: ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] - }, - defaultMetric = decimalMetric, - defaultDateFormat = 'YYYY-MM-DD HH:mm', - - setDefaultMetric = function (useBinaryMetric) { - - defaultMetric = useBinaryMetric ? binaryMetric : decimalMetric; - }, - - formatSize = function (size, metric) { - - metric = metric || defaultMetric; - - if (!_.isNumber(size) || size < 0) { - return ''; - } - - var i = 0, - maxI = metric.u.length - 1; - - while (size >= metric.t && i < maxI) { - size /= metric.k; - i += 1; - } - return (i <= 1 ? Math.round(size) : size.toFixed(1)).toString() + ' ' + metric.u[i]; - }, - - setDefaultDateFormat = function (dateFormat) { - - defaultDateFormat = dateFormat; - }, - - formatDate = function (millis) { - - return _.isNumber(millis) && millis ? moment(millis).format(defaultDateFormat) : ''; }; + var defaultMetric = decimalMetric; + var defaultDateFormat = 'YYYY-MM-DD HH:mm'; + + + function setDefaultMetric(useBinaryMetric) { + + defaultMetric = useBinaryMetric ? binaryMetric : decimalMetric; + } + + function formatSize(size, metric) { + + metric = metric || defaultMetric; + + if (!_.isNumber(size) || size < 0) { + return ''; + } + + var i = 0; + var maxI = metric.u.length - 1; + + while (size >= metric.t && i < maxI) { + size /= metric.k; + i += 1; + } + return (i <= 1 ? Math.round(size) : size.toFixed(1)).toString() + ' ' + metric.u[i]; + } + + function setDefaultDateFormat(dateFormat) { + + defaultDateFormat = dateFormat; + } + + function formatDate(millis) { + + return _.isNumber(millis) && millis ? moment(millis).format(defaultDateFormat) : ''; + } + return { setDefaultMetric: setDefaultMetric, diff --git a/src/_h5ai/client/js/inc/core/langs.js b/src/_h5ai/client/js/inc/core/langs.js index 7555d5c1..ec3e21be 100644 --- a/src/_h5ai/client/js/inc/core/langs.js +++ b/src/_h5ai/client/js/inc/core/langs.js @@ -1,4 +1,3 @@ - modulejs.define('core/langs', ['config', '_'], function (config, _) { return _.extend({}, config.langs); diff --git a/src/_h5ai/client/js/inc/core/location.js b/src/_h5ai/client/js/inc/core/location.js index b2252879..b178d3fe 100644 --- a/src/_h5ai/client/js/inc/core/location.js +++ b/src/_h5ai/client/js/inc/core/location.js @@ -1,184 +1,180 @@ - modulejs.define('core/location', ['_', 'modernizr', 'core/settings', 'core/event', 'core/notify'], function (_, modernizr, allsettings, event, notify) { var settings = _.extend({ smartBrowsing: true, unmanagedInNewWindow: true - }, allsettings.view), + }, allsettings.view); + var doc = document; + var history = settings.smartBrowsing && modernizr.history ? window.history : null; + var reUriToPathname = /^.*:\/\/[^\/]*|[^\/]*$/g; + var absHref = null; - doc = document, - history = settings.smartBrowsing && modernizr.history ? window.history : null, + function forceEncoding(href) { - forceEncoding = function (href) { + return href + .replace(/\/+/g, '/') - return href - .replace(/\/+/g, '/') + .replace(/ /g, '%20') + .replace(/!/g, '%21') + .replace(/#/g, '%23') + .replace(/\$/g, '%24') + .replace(/&/g, '%26') + .replace(/'/g, '%27') + .replace(/\(/g, '%28') + .replace(/\)/g, '%29') + .replace(/\*/g, '%2A') + .replace(/\+/g, '%2B') + .replace(/\,/g, '%2C') + // .replace(/\//g, '%2F') + .replace(/:/g, '%3A') + .replace(/;/g, '%3B') + .replace(/=/g, '%3D') + .replace(/\?/g, '%3F') + .replace(/@/g, '%40') + .replace(/\[/g, '%5B') + .replace(/\]/g, '%5D'); + } - .replace(/ /g, '%20') - .replace(/!/g, '%21') - .replace(/#/g, '%23') - .replace(/\$/g, '%24') - .replace(/&/g, '%26') - .replace(/'/g, '%27') - .replace(/\(/g, '%28') - .replace(/\)/g, '%29') - .replace(/\*/g, '%2A') - .replace(/\+/g, '%2B') - .replace(/\,/g, '%2C') - // .replace(/\//g, '%2F') - .replace(/:/g, '%3A') - .replace(/;/g, '%3B') - .replace(/=/g, '%3D') - .replace(/\?/g, '%3F') - .replace(/@/g, '%40') - .replace(/\[/g, '%5B') - .replace(/\]/g, '%5D'); - }, + function uriToPathname(uri) { - reUriToPathname = /^.*:\/\/[^\/]*|[^\/]*$/g, - uriToPathname = function (uri) { + return uri.replace(reUriToPathname, ''); + } - return uri.replace(reUriToPathname, ''); - }, + var hrefsAreDecoded = (function () { - hrefsAreDecoded = (function () { - - var testpathname = '/a b', - a = doc.createElement('a'); + var testpathname = '/a b'; + var a = doc.createElement('a'); a.href = testpathname; return uriToPathname(a.href) === testpathname; - }()), + }()); - encodedHref = function (href) { + function encodedHref(href) { - var a = doc.createElement('a'), - location; + var a = doc.createElement('a'); + var location; - a.href = href; - location = uriToPathname(a.href); + a.href = href; + location = uriToPathname(a.href); - if (hrefsAreDecoded) { - location = encodeURIComponent(location).replace(/%2F/ig, '/'); - } + if (hrefsAreDecoded) { + location = encodeURIComponent(location).replace(/%2F/ig, '/'); + } - return forceEncoding(location); - }; + return forceEncoding(location); + } + function getDomain() { - var absHref = null, + return doc.domain; + } - getDomain = function () { + function getAbsHref() { - return doc.domain; - }, + return absHref; + } - getAbsHref = function () { + function getItem() { - return absHref; - }, + return modulejs.require('model/item').get(absHref); + } - getItem = function () { + function load(callback) { - return modulejs.require('model/item').get(absHref); - }, + modulejs.require('core/server').request({action: 'get', items: true, itemsHref: absHref, itemsWhat: 1}, function (json) { - load = function (callback) { + var Item = modulejs.require('model/item'); + var item = Item.get(absHref); - modulejs.require('core/server').request({action: 'get', items: true, itemsHref: absHref, itemsWhat: 1}, function (json) { + if (json) { - var Item = modulejs.require('model/item'), - item = Item.get(absHref); + var found = {}; - if (json) { + _.each(json.items, function (jsonItem) { - var found = {}; + var e = Item.get(jsonItem.absHref, jsonItem.time, jsonItem.size, jsonItem.is_managed, jsonItem.content, jsonItem.md5, jsonItem.sha1); + found[e.absHref] = true; + }); - _.each(json.items, function (jsonItem) { + _.each(item.content, function (e) { - var e = Item.get(jsonItem.absHref, jsonItem.time, jsonItem.size, jsonItem.is_managed, jsonItem.content, jsonItem.md5, jsonItem.sha1); - found[e.absHref] = true; - }); - - _.each(item.content, function (e) { - - if (!found[e.absHref]) { - Item.remove(e.absHref); - } - }); - } - if (_.isFunction(callback)) { - callback(item); - } - }); - }, - - setLocation = function (newAbsHref, keepBrowserUrl) { - - event.pub('location.beforeChange'); - - newAbsHref = encodedHref(newAbsHref); - - if (absHref !== newAbsHref) { - absHref = newAbsHref; - - if (history) { - if (keepBrowserUrl) { - history.replaceState({absHref: absHref}, '', absHref); - } else { - history.pushState({absHref: absHref}, '', absHref); + if (!found[e.absHref]) { + Item.remove(e.absHref); } + }); + } + if (_.isFunction(callback)) { + callback(item); + } + }); + } + + function setLocation(newAbsHref, keepBrowserUrl) { + + event.pub('location.beforeChange'); + + newAbsHref = encodedHref(newAbsHref); + + if (absHref !== newAbsHref) { + absHref = newAbsHref; + + if (history) { + if (keepBrowserUrl) { + history.replaceState({absHref: absHref}, '', absHref); + } else { + history.pushState({absHref: absHref}, '', absHref); } } + } - var item = getItem(); - if (item.isLoaded) { - event.pub('location.changed', item); - refresh(); - } else { - notify.set('loading...'); - load(function () { - item.isLoaded = true; - notify.set(); - event.pub('location.changed', item); - }); - } - }, - - refresh = function () { - - var item = getItem(), - oldItems = _.values(item.content); - - event.pub('location.beforeRefresh'); - + var item = getItem(); + if (item.isLoaded) { + event.pub('location.changed', item); + refresh(); + } else { + notify.set('loading...'); load(function () { - - var newItems = _.values(item.content), - added = _.difference(newItems, oldItems), - removed = _.difference(oldItems, newItems); - - event.pub('location.refreshed', item, added, removed); + item.isLoaded = true; + notify.set(); + event.pub('location.changed', item); }); - }, + } + } - setLink = function ($el, item) { + function refresh() { - $el.attr('href', item.absHref); + var item = getItem(); + var oldItems = _.values(item.content); - if (history && item.isFolder() && item.isManaged) { - $el.on('click', function () { + event.pub('location.beforeRefresh'); - setLocation(item.absHref); - return false; - }); - } + load(function () { - if (settings.unmanagedInNewWindow && !item.isManaged) { - $el.attr('target', '_blank'); - } - }; + var newItems = _.values(item.content); + var added = _.difference(newItems, oldItems); + var removed = _.difference(oldItems, newItems); + + event.pub('location.refreshed', item, added, removed); + }); + } + + function setLink($el, item) { + + $el.attr('href', item.absHref); + + if (history && item.isFolder() && item.isManaged) { + $el.on('click', function () { + + setLocation(item.absHref); + return false; + }); + } + + if (settings.unmanagedInNewWindow && !item.isManaged) { + $el.attr('target', '_blank'); + } + } if (history) { @@ -190,7 +186,6 @@ modulejs.define('core/location', ['_', 'modernizr', 'core/settings', 'core/event }; } - event.sub('ready', function () { setLocation(document.location.href, true); diff --git a/src/_h5ai/client/js/inc/core/notify.js b/src/_h5ai/client/js/inc/core/notify.js index cbdb71a7..281908ad 100644 --- a/src/_h5ai/client/js/inc/core/notify.js +++ b/src/_h5ai/client/js/inc/core/notify.js @@ -1,23 +1,17 @@ - modulejs.define('core/notify', ['$'], function ($) { - var template = '
', + var template = '
'; - set = function (content) { + function set(content) { - if (content) { - $('#notify').stop(true, true).html(content).fadeIn(400); - } else { - $('#notify').stop(true, true).fadeOut(400); - } - }, + if (content) { + $('#notify').stop(true, true).html(content).fadeIn(400); + } else { + $('#notify').stop(true, true).fadeOut(400); + } + } - init = function () { - - $(template).hide().appendTo('body'); - }; - - init(); + $(template).hide().appendTo('body'); return { set: set diff --git a/src/_h5ai/client/js/inc/core/resource.js b/src/_h5ai/client/js/inc/core/resource.js index 0b44a904..3534e747 100644 --- a/src/_h5ai/client/js/inc/core/resource.js +++ b/src/_h5ai/client/js/inc/core/resource.js @@ -1,38 +1,38 @@ - modulejs.define('core/resource', ['_', '$', 'config', 'core/settings'], function (_, $, config, settings) { - 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'], + var win = window; + var appHref = settings.appHref; + var imagesHref = appHref + 'client/images/'; + var fallbackHref = appHref + 'client/images/fallback/'; + var themesHref = appHref + 'client/themes/'; + var scriptsHref = appHref + 'client/js/'; + var fallbacks = ['file', 'folder', 'folder-page', 'folder-parent', 'ar', 'aud', 'bin', 'img', 'txt', 'vid']; - image = function (id) { - return imagesHref + id + '.svg'; - }, + function image(id) { - icon = function (id) { + return imagesHref + id + '.svg'; + } - var baseId = id.split('-')[0], - href = config.theme[id] || config.theme[baseId]; + function icon(id) { - if (href) { - return themesHref + href; - } + var baseId = id.split('-')[0], + href = config.theme[id] || config.theme[baseId]; - if (_.indexOf(fallbacks, id) >= 0) { - return fallbackHref + id + '.svg'; - } + if (href) { + return themesHref + href; + } - if (_.indexOf(fallbacks, baseId) >= 0) { - return fallbackHref + baseId + '.svg'; - } + if (_.indexOf(fallbacks, id) >= 0) { + return fallbackHref + id + '.svg'; + } - return fallbackHref + 'file.svg'; - }; + if (_.indexOf(fallbacks, baseId) >= 0) { + return fallbackHref + baseId + '.svg'; + } + + return fallbackHref + 'file.svg'; + } return { diff --git a/src/_h5ai/client/js/inc/core/server.js b/src/_h5ai/client/js/inc/core/server.js index 7c16a3e5..861f7c58 100644 --- a/src/_h5ai/client/js/inc/core/server.js +++ b/src/_h5ai/client/js/inc/core/server.js @@ -1,4 +1,3 @@ - modulejs.define('core/server', ['$', '_', 'config', 'core/location'], function ($, _, config, location) { var server = { diff --git a/src/_h5ai/client/js/inc/core/settings.js b/src/_h5ai/client/js/inc/core/settings.js index 4abaec47..e7efb006 100644 --- a/src/_h5ai/client/js/inc/core/settings.js +++ b/src/_h5ai/client/js/inc/core/settings.js @@ -1,4 +1,3 @@ - modulejs.define('core/settings', ['config', '_'], function (config, _) { return _.extend({}, config.options, { diff --git a/src/_h5ai/client/js/inc/core/store.js b/src/_h5ai/client/js/inc/core/store.js index 728bfce4..66812742 100644 --- a/src/_h5ai/client/js/inc/core/store.js +++ b/src/_h5ai/client/js/inc/core/store.js @@ -1,38 +1,38 @@ - modulejs.define('core/store', ['modernizr'], function (modernizr) { - var store = modernizr.localstorage ? window.localStorage : null, + var store = modernizr.localstorage ? window.localStorage : null; + var key = '_h5ai'; - key = '_h5ai', - load = function () { + function load() { - if (store) { - try { - return JSON.parse(store[key]); - } catch (e) {} - } - return {}; - }, + if (store) { + try { + return JSON.parse(store[key]); + } catch (e) {} + } + return {}; + } - save = function (obj) { + function save(obj) { - if (store) { - store[key] = JSON.stringify(obj); - } - }, + if (store) { + store[key] = JSON.stringify(obj); + } + } - put = function (key, value) { + function put(key, value) { - var obj = load(); - obj[key] = value; - return save(obj); - }, + var obj = load(); + obj[key] = value; + return save(obj); + } - get = function (key) { + function get(key) { + + return load()[key]; + } - return load()[key]; - }; return { put: put, diff --git a/src/_h5ai/client/js/inc/core/types.js b/src/_h5ai/client/js/inc/core/types.js index 84430f03..bd99f4a3 100644 --- a/src/_h5ai/client/js/inc/core/types.js +++ b/src/_h5ai/client/js/inc/core/types.js @@ -1,43 +1,44 @@ - modulejs.define('core/types', ['config', '_'], function (config, _) { - var reEndsWithSlash = /\/$/, - regexps = {}, + var reEndsWithSlash = /\/$/; + var regexps = {}; - escapeRegExp = function (sequence) { - return sequence.replace(/[\-\[\]\/\{\}\(\)\+\?\.\\\^\$]/g, "\\$&"); - // return sequence.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); - }, + function escapeRegExp(sequence) { - parse = function (types) { + return sequence.replace(/[\-\[\]\/\{\}\(\)\+\?\.\\\^\$]/g, "\\$&"); + // return sequence.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } - _.each(types, function (patterns, type) { + function parse(types) { - var pattern = '^(' + _.map(patterns, function (p) { return '(' + escapeRegExp(p).replace(/\*/g, '.*') + ')'; }).join('|') + ')$'; - regexps[type] = new RegExp(pattern, 'i'); - }); - }, + _.each(types, function (patterns, type) { - getType = function (sequence) { + var pattern = '^(' + _.map(patterns, function (p) { return '(' + escapeRegExp(p).replace(/\*/g, '.*') + ')'; }).join('|') + ')$'; + regexps[type] = new RegExp(pattern, 'i'); + }); + } - if (reEndsWithSlash.test(sequence)) { - return 'folder'; - } + function getType(sequence) { - var slashidx = sequence.lastIndexOf('/'), - name = slashidx >= 0 ? sequence.substr(slashidx + 1) : sequence; + if (reEndsWithSlash.test(sequence)) { + return 'folder'; + } - for (var type in regexps) { - if (regexps.hasOwnProperty(type)) { - if (regexps[type].test(name)) { - return type; - } + var slashidx = sequence.lastIndexOf('/'); + var name = slashidx >= 0 ? sequence.substr(slashidx + 1) : sequence; + + for (var type in regexps) { + if (regexps.hasOwnProperty(type)) { + if (regexps[type].test(name)) { + return type; } } + } + + return 'file'; + } - return 'file'; - }; parse(_.extend({}, config.types)); diff --git a/src/_h5ai/client/js/inc/ext/autorefresh.js b/src/_h5ai/client/js/inc/ext/autorefresh.js index cc0b6d77..ef260d7c 100644 --- a/src/_h5ai/client/js/inc/ext/autorefresh.js +++ b/src/_h5ai/client/js/inc/ext/autorefresh.js @@ -1,42 +1,42 @@ - modulejs.define('ext/autorefresh', ['_', '$', 'core/settings', 'core/event', 'core/location'], function (_, $, allsettings, event, location) { var settings = _.extend({ enabled: false, interval: 5000 - }, allsettings.autorefresh), + }, allsettings.autorefresh); + var timeoutId = null; - timeoutId = null, - heartbeat = function () { + function heartbeat() { - location.refresh(); - }, + location.refresh(); + } - before = function () { + function before() { - clearTimeout(timeoutId); - }, + clearTimeout(timeoutId); + } - after = function () { + function after() { - clearTimeout(timeoutId); - timeoutId = setTimeout(heartbeat, settings.interval); - }, + clearTimeout(timeoutId); + timeoutId = setTimeout(heartbeat, settings.interval); + } - init = function () { + function init() { - if (!settings.enabled) { - return; - } + if (!settings.enabled) { + return; + } - settings.interval = Math.max(1000, settings.interval); + settings.interval = Math.max(1000, settings.interval); + + event.sub('location.beforeChange', before); + event.sub('location.beforeRefresh', before); + event.sub('location.changed', after); + event.sub('location.refreshed', after); + } - event.sub('location.beforeChange', before); - event.sub('location.beforeRefresh', before); - event.sub('location.changed', after); - event.sub('location.refreshed', after); - }; init(); }); diff --git a/src/_h5ai/client/js/inc/ext/crumb.js b/src/_h5ai/client/js/inc/ext/crumb.js index 065a2e6b..a560cff9 100644 --- a/src/_h5ai/client/js/inc/ext/crumb.js +++ b/src/_h5ai/client/js/inc/ext/crumb.js @@ -1,96 +1,96 @@ - modulejs.define('ext/crumb', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/location'], function (_, $, allsettings, resource, event, location) { var settings = _.extend({ enabled: false - }, allsettings.crumb), - - template = + }, allsettings.crumb); + var template = '
  • ' + '' + '>' + '' + '' + - '
  • ', - pageHintTemplate = 'has index page', - statusHintTemplate = '', + ''; + var pageHintTemplate = 'has index page'; + var statusHintTemplate = ''; - update = function (item, force) { - if (!force && item.$crumb) { - return item.$crumb; - } + function update(item, force) { - var $html = $(template), - $a = $html.find('a'); + if (!force && item.$crumb) { + return item.$crumb; + } - $html - .addClass(item.isFolder() ? 'folder' : 'file') - .data('item', item); + var $html = $(template); + var $a = $html.find('a'); - location.setLink($a, item); - $a.find('span').text(item.label).end(); + $html + .addClass(item.isFolder() ? 'folder' : 'file') + .data('item', item); - if (item.isDomain()) { - $html.addClass('domain'); - $a.find('img').attr('src', resource.image('home')); - } + location.setLink($a, item); + $a.find('span').text(item.label).end(); - if (item.isRoot()) { - $html.addClass('root'); - $a.find('img').attr('src', resource.image('home')); - } + if (item.isDomain()) { + $html.addClass('domain'); + $a.find('img').attr('src', resource.image('home')); + } - if (item.isCurrentFolder()) { + if (item.isRoot()) { + $html.addClass('root'); + $a.find('img').attr('src', resource.image('home')); + } + + if (item.isCurrentFolder()) { + $html.addClass('current'); + } + + if (!item.isManaged) { + $a.append($(pageHintTemplate)); + } + + if (item.$crumb) { + item.$crumb.replaceWith($html); + } + item.$crumb = $html; + + return $html; + } + + function onLocationChanged(item) { + + var crumb = item.getCrumb(); + var $ul = $('#navbar'); + var found = false; + + $ul.find('.crumb').each(function () { + + var $html = $(this); + if ($html.data('item') === item) { + found = true; $html.addClass('current'); + } else { + $html.removeClass('current'); } + }); - if (!item.isManaged) { - $a.append($(pageHintTemplate)); - } + if (!found) { + $ul.find('.crumb').remove(); + _.each(crumb, function (e) { - if (item.$crumb) { - item.$crumb.replaceWith($html); - } - item.$crumb = $html; - - return $html; - }, - - onLocationChanged = function (item) { - - var crumb = item.getCrumb(), - $ul = $('#navbar'), - found = false; - - $ul.find('.crumb').each(function () { - - var $html = $(this); - if ($html.data('item') === item) { - found = true; - $html.addClass('current'); - } else { - $html.removeClass('current'); - } + $ul.append(update(e, true)); }); + } + } - if (!found) { - $ul.find('.crumb').remove(); - _.each(crumb, function (e) { + function init() { - $ul.append(update(e, true)); - }); - } - }, + if (!settings.enabled) { + return; + } - init = function () { + event.sub('location.changed', onLocationChanged); + } - if (!settings.enabled) { - return; - } - - event.sub('location.changed', onLocationChanged); - }; init(); }); diff --git a/src/_h5ai/client/js/inc/ext/custom.js b/src/_h5ai/client/js/inc/ext/custom.js index 3b6e166e..384c815e 100644 --- a/src/_h5ai/client/js/inc/ext/custom.js +++ b/src/_h5ai/client/js/inc/ext/custom.js @@ -1,61 +1,61 @@ - modulejs.define('ext/custom', ['_', '$', 'marked', 'core/settings', 'core/server', 'core/event', 'core/resource'], function (_, $, marked, allsettings, server, event, resource) { var settings = _.extend({ enabled: false - }, allsettings.custom), + }, allsettings.custom); + var $header, $footer; + var duration = 200; - $header, $footer, - duration = 200, - onLocationChanged = function (item) { + function onLocationChanged(item) { - server.request({action: 'get', custom: true, customHref: item.absHref}, function (response) { + server.request({action: 'get', custom: true, customHref: item.absHref}, function (response) { - var has_header, has_footer, data, content; + var has_header, has_footer, data, content; - if (response) { - data = response.custom; + if (response) { + data = response.custom; - if (data.header) { - content = data.header; - if (data.header_type === 'md') { - content = marked(content); - } - $header.html(content).stop().slideDown(duration); - has_header = true; + if (data.header) { + content = data.header; + if (data.header_type === 'md') { + content = marked(content); } + $header.html(content).stop().slideDown(duration); + has_header = true; + } - if (data.footer) { - content = data.footer; - if (data.footer_type === 'md') { - content = marked(content); - } - $footer.html(content).stop().slideDown(duration); - has_footer = true; + if (data.footer) { + content = data.footer; + if (data.footer_type === 'md') { + content = marked(content); } + $footer.html(content).stop().slideDown(duration); + has_footer = true; } - - if (!has_header) { - $header.stop().slideUp(duration); - } - if (!has_footer) { - $footer.stop().slideUp(duration); - } - }); - }, - - init = function () { - - if (!settings.enabled) { - return; } - $header = $('
    ').hide().prependTo('#content'); - $footer = $('