diff --git a/src/_h5ai/client/js/inc/core/entry.js b/src/_h5ai/client/js/inc/core/entry.js deleted file mode 100644 index 03e374a4..00000000 --- a/src/_h5ai/client/js/inc/core/entry.js +++ /dev/null @@ -1,5 +0,0 @@ - -modulejs.define('core/entry', ['core/location'], function (location) { - - return location.getItem(); -}); diff --git a/src/_h5ai/client/js/inc/core/location.js b/src/_h5ai/client/js/inc/core/location.js index 8a870525..4e12a2a2 100644 --- a/src/_h5ai/client/js/inc/core/location.js +++ b/src/_h5ai/client/js/inc/core/location.js @@ -76,7 +76,7 @@ modulejs.define('core/location', ['_', 'modernizr', 'core/settings', 'core/event newAbsHref = encodedHref(newAbsHref); if (absHref !== newAbsHref) { absHref = newAbsHref; - event.pub('location.changed', absHref); + event.pub('location.changed', getItem()); notify.set('loading...'); modulejs.require('core/refresh')(function () { notify.set(); }); diff --git a/src/_h5ai/client/js/inc/ext/crumb.js b/src/_h5ai/client/js/inc/ext/crumb.js index 72ebfbd3..b4656b50 100644 --- a/src/_h5ai/client/js/inc/ext/crumb.js +++ b/src/_h5ai/client/js/inc/ext/crumb.js @@ -105,12 +105,7 @@ modulejs.define('ext/crumb', ['_', '$', 'core/settings', 'core/resource', 'core/ // event.sub('entry.removed', onContentChanged); event.sub('entry.changed', onContentChanged); - event.sub('location.changed', function () { - - onLocationChanged(location.getItem()); - }); - - onLocationChanged(location.getItem()); + 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 649fcc70..33df86e8 100644 --- a/src/_h5ai/client/js/inc/ext/custom.js +++ b/src/_h5ai/client/js/inc/ext/custom.js @@ -34,8 +34,6 @@ modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/e $('
').hide().appendTo('#content'); event.sub('location.changed', onLocationChanged); - - onLocationChanged(); }; init(); diff --git a/src/_h5ai/client/js/inc/ext/download.js b/src/_h5ai/client/js/inc/ext/download.js index fbab9e5a..bd9c43cd 100644 --- a/src/_h5ai/client/js/inc/ext/download.js +++ b/src/_h5ai/client/js/inc/ext/download.js @@ -1,5 +1,5 @@ -modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/server', 'core/entry'], function (_, $, allsettings, resource, event, server, entry) { +modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/server', 'core/location'], function (_, $, allsettings, resource, event, server, location) { var settings = _.extend({ enabled: false, @@ -36,7 +36,7 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co if (json && json.code === 0) { setTimeout(function () { // wait here so the img above can be updated in time - window.location = '?action=getArchive&id=' + json.id + '&as=' + (settings.packageName || entry.label) + '.' + settings.format; + window.location = '?action=getArchive&id=' + json.id + '&as=' + (settings.packageName || location.getItem().label) + '.' + settings.format; }, 200); } else { failed(); diff --git a/src/_h5ai/client/js/inc/ext/dropbox.js b/src/_h5ai/client/js/inc/ext/dropbox.js index e0d8caad..2d45a5b2 100644 --- a/src/_h5ai/client/js/inc/ext/dropbox.js +++ b/src/_h5ai/client/js/inc/ext/dropbox.js @@ -1,5 +1,5 @@ -modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry', 'core/refresh', 'core/server'], function (_, $, allsettings, entry, refresh, server) { +modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/location', 'core/refresh', 'core/server'], function (_, $, allsettings, location, refresh, server) { var settings = _.extend({ enabled: false, @@ -50,7 +50,7 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry', 'core/r url: server.api, data: { action: 'upload', - href: entry.absHref + href: location.getAbsHref() }, docEnter: function () { diff --git a/src/_h5ai/client/js/inc/ext/preview-img.js b/src/_h5ai/client/js/inc/ext/preview-img.js index 78ea5fd9..c4a140e1 100644 --- a/src/_h5ai/client/js/inc/ext/preview-img.js +++ b/src/_h5ai/client/js/inc/ext/preview-img.js @@ -1,5 +1,5 @@ -modulejs.define('ext/preview-img', ['_', '$', 'core/settings', 'core/resource', 'core/store', 'core/event', 'core/entry'], function (_, $, allsettings, resource, store, event, entry) { +modulejs.define('ext/preview-img', ['_', '$', 'core/settings', 'core/resource', 'core/store', 'core/event', 'core/location'], function (_, $, allsettings, resource, store, event, location) { var settings = _.extend({ enabled: false, @@ -219,14 +219,17 @@ modulejs.define('ext/preview-img', ['_', '$', 'core/settings', 'core/resource', } }, - init = function (entry) { + onLocationChanged = function (item) { + + _.each(item.content, initEntry); + }, + + init = function () { if (!settings.enabled) { return; } - _.each(entry.content, initEntry); - $(template).appendTo('body'); $('#pv-img-bar-prev, #pv-img-prev').on('click', onPrevious); $('#pv-img-bar-next, #pv-img-next').on('click', onNext); @@ -276,10 +279,11 @@ modulejs.define('ext/preview-img', ['_', '$', 'core/settings', 'core/resource', event.stopImmediatePropagation(); }); + event.sub('location.changed', onLocationChanged); event.sub('entry.created', initEntry); $(window).on('resize load', adjustSize); }; - init(entry); + init(); }); diff --git a/src/_h5ai/client/js/inc/ext/preview-txt.js b/src/_h5ai/client/js/inc/ext/preview-txt.js index e80afde7..eed57ba3 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/resource', 'core/store', 'core/event', 'core/entry'], function (_, $, allsettings, resource, store, event, entry) { +modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/resource', 'core/store', 'core/event', 'core/location'], function (_, $, allsettings, resource, store, event, location) { var settings = _.extend({ enabled: false, @@ -224,14 +224,17 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/resource', } }, - init = function (entry) { + onLocationChanged = function (item) { + + _.each(item.content, initEntry); + }, + + init = function () { if (!settings.enabled) { return; } - _.each(entry.content, initEntry); - $(template).appendTo('body'); $('#pv-txt-bar-prev').on('click', onPrevious); $('#pv-txt-bar-next').on('click', onNext); @@ -253,10 +256,11 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/resource', event.stopImmediatePropagation(); }); + event.sub('location.changed', onLocationChanged); event.sub('entry.created', initEntry); $(window).on('resize load', adjustSize); }; - init(entry); + init(); }); diff --git a/src/_h5ai/client/js/inc/ext/statusbar.js b/src/_h5ai/client/js/inc/ext/statusbar.js index c292525b..09edfd47 100644 --- a/src/_h5ai/client/js/inc/ext/statusbar.js +++ b/src/_h5ai/client/js/inc/ext/statusbar.js @@ -1,5 +1,5 @@ -modulejs.define('ext/statusbar', ['_', '$', 'core/settings', 'core/format', 'core/event', 'core/entry'], function (_, $, allsettings, format, event, entry) { +modulejs.define('ext/statusbar', ['_', '$', 'core/settings', 'core/format', 'core/event', 'core/location'], function (_, $, allsettings, format, event, location) { var settings = _.extend({ enabled: false @@ -29,7 +29,7 @@ modulejs.define('ext/statusbar', ['_', '$', 'core/settings', 'core/format', 'cor } }, - init = function (entry) { + init = function () { if (!settings.enabled) { return; @@ -42,25 +42,28 @@ modulejs.define('ext/statusbar', ['_', '$', 'core/settings', 'core/format', 'cor $statusDefault = $statusbar.find('.status.default'); $statusDynamic = $statusbar.find('.status.dynamic'); - var stats = entry.getStats(); - $folderTotal.text(stats.folders); - $fileTotal.text(stats.files); + event.sub('location.changed', function (item) { - update(); + var stats = item.getStats(); + $folderTotal.text(stats.folders); + $fileTotal.text(stats.files); + + update(); + }); event.sub('statusbar', update); $('#bottombar > .center').append($statusbar); event.sub('entry.created', function () { - var stats = entry.getStats(); + var stats = location.getItem().getStats(); $folderTotal.text(stats.folders); $fileTotal.text(stats.files); }); event.sub('entry.removed', function () { - var stats = entry.getStats(); + var stats = location.getItem().getStats(); $folderTotal.text(stats.folders); $fileTotal.text(stats.files); }); @@ -89,5 +92,5 @@ modulejs.define('ext/statusbar', ['_', '$', 'core/settings', 'core/format', 'cor }); }; - init(entry); + init(); }); diff --git a/src/_h5ai/client/js/inc/ext/thumbnails.js b/src/_h5ai/client/js/inc/ext/thumbnails.js index f399f5db..61e80086 100644 --- a/src/_h5ai/client/js/inc/ext/thumbnails.js +++ b/src/_h5ai/client/js/inc/ext/thumbnails.js @@ -1,5 +1,5 @@ -modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/event', 'core/server'], function (_, allsettings, entry, event, server) { +modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/event', 'core/server'], function (_, allsettings, event, server) { var settings = _.extend({ enabled: false, @@ -56,22 +56,26 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/eve } }, - init = function (entry) { + onLocationChanged = function (item) { + + setTimeout(function () { + + _.each(item.content, checkEntry); + }, settings.delay); + }, + + init = function () { if (!settings.enabled || !server.api) { return; } - setTimeout(function () { - - _.each(entry.content, checkEntry); - }, settings.delay); - + event.sub('location.changed', onLocationChanged); event.sub('entry.created', function (entry) { checkEntry(entry); }); }; - init(entry); + init(); }); diff --git a/src/_h5ai/client/js/inc/ext/title.js b/src/_h5ai/client/js/inc/ext/title.js index f9da90a9..f2946080 100644 --- a/src/_h5ai/client/js/inc/ext/title.js +++ b/src/_h5ai/client/js/inc/ext/title.js @@ -1,17 +1,13 @@ -modulejs.define('ext/title', ['_', 'core/settings', 'core/entry'], function (_, allsettings, entry) { +modulejs.define('ext/title', ['_', 'core/settings', 'core/event'], function (_, allsettings, event) { var settings = _.extend({ enabled: false }, allsettings.title), - init = function (entry) { + onLocationChanged = function (item) { - if (!settings.enabled) { - return; - } - - var labels = _.pluck(entry.getCrumb(), 'label'), + var labels = _.pluck(item.getCrumb(), 'label'), title = labels.join(' > '); if (labels.length > 1) { @@ -19,7 +15,16 @@ modulejs.define('ext/title', ['_', 'core/settings', 'core/entry'], function (_, } document.title = title; + }, + + init = function () { + + if (!settings.enabled) { + return; + } + + event.sub('location.changed', onLocationChanged); }; - init(entry); + init(); }); diff --git a/src/_h5ai/client/js/inc/ext/tree.js b/src/_h5ai/client/js/inc/ext/tree.js index 7271b752..00afc7f2 100644 --- a/src/_h5ai/client/js/inc/ext/tree.js +++ b/src/_h5ai/client/js/inc/ext/tree.js @@ -1,5 +1,5 @@ -modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/entry'], function (_, $, allsettings, resource, event, entry) { +modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/location'], function (_, $, allsettings, resource, event, location) { var settings = _.extend({ enabled: false, @@ -34,7 +34,7 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e .data('entry', entry) .data('status', entry.status); - $a.attr('href', entry.absHref); + location.setLink($a, entry); $img.attr('src', resource.icon(entry.type)); $label.text(entry.label); @@ -207,10 +207,24 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e } update(entry); + adjustSpacing(); + shiftTree(false, true); + }, + + onLocationChanged = function (item) { + + fetchTree(item, function (root) { + + $('#tree') + .find('.sp-container').append(update(root)).end() + .show(); + adjustSpacing(); + shiftTree(false, true); + }); }, // creates the complete tree from entry down to the root - init = function (entry) { + init = function () { if (!settings.enabled) { return; @@ -229,23 +243,15 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e shiftTree(); }); - fetchTree(entry, function (root) { - - $tree - .find('.sp-container').append(update(root)).end() - .show(); - - adjustSpacing(); - shiftTree(false, true); - }); - - event.sub('ready', adjustSpacing); + event.sub('location.changed', onLocationChanged); // strong negative performance impact in aai mode // event.sub('entry.changed', onContentChanged); // event.sub('entry.created', onContentChanged); // event.sub('entry.removed', onContentChanged); + event.sub('ready', adjustSpacing); + $(window).on('resize', function () { adjustSpacing(); @@ -253,5 +259,5 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e }); }; - init(entry); + init(); }); diff --git a/src/_h5ai/client/js/inc/main.js b/src/_h5ai/client/js/inc/main.js index 04e7a1cd..8e92d494 100644 --- a/src/_h5ai/client/js/inc/main.js +++ b/src/_h5ai/client/js/inc/main.js @@ -7,8 +7,6 @@ modulejs.define('main', ['_', 'core/event'], function (_, event) { modulejs.require('view/spacing'); modulejs.require('view/viewmode'); - modulejs.require('core/location').setLocation(document.location.href, true); - event.pub('beforeExt'); _.each(modulejs.state(), function (state, id) { @@ -18,5 +16,7 @@ modulejs.define('main', ['_', 'core/event'], function (_, event) { } }); + modulejs.require('core/location').setLocation(document.location.href, true); + event.pub('ready'); }); diff --git a/src/_h5ai/client/js/inc/view/items.js b/src/_h5ai/client/js/inc/view/items.js index 506bd301..702ae024 100644 --- a/src/_h5ai/client/js/inc/view/items.js +++ b/src/_h5ai/client/js/inc/view/items.js @@ -163,10 +163,7 @@ modulejs.define('view/items', ['_', '$', 'core/settings', 'core/resource', 'core } }); - event.sub('location.changed', function () { - - onLocationChanged(location.getItem()); - }); + event.sub('location.changed', onLocationChanged); $content.appendTo('body'); };