More changes to enable smart browsing.

This commit is contained in:
Lars Jung 2012-10-18 23:08:48 +02:00
parent 499013f4fb
commit e956a49680
14 changed files with 85 additions and 74 deletions

View file

@ -1,5 +0,0 @@
modulejs.define('core/entry', ['core/location'], function (location) {
return location.getItem();
});

View file

@ -76,7 +76,7 @@ modulejs.define('core/location', ['_', 'modernizr', 'core/settings', 'core/event
newAbsHref = encodedHref(newAbsHref); newAbsHref = encodedHref(newAbsHref);
if (absHref !== newAbsHref) { if (absHref !== newAbsHref) {
absHref = newAbsHref; absHref = newAbsHref;
event.pub('location.changed', absHref); event.pub('location.changed', getItem());
notify.set('loading...'); notify.set('loading...');
modulejs.require('core/refresh')(function () { notify.set(); }); modulejs.require('core/refresh')(function () { notify.set(); });

View file

@ -105,12 +105,7 @@ modulejs.define('ext/crumb', ['_', '$', 'core/settings', 'core/resource', 'core/
// event.sub('entry.removed', onContentChanged); // event.sub('entry.removed', onContentChanged);
event.sub('entry.changed', onContentChanged); event.sub('entry.changed', onContentChanged);
event.sub('location.changed', function () { event.sub('location.changed', onLocationChanged);
onLocationChanged(location.getItem());
});
onLocationChanged(location.getItem());
}; };
init(); init();

View file

@ -34,8 +34,6 @@ modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/e
$('<div id="content-footer"/>').hide().appendTo('#content'); $('<div id="content-footer"/>').hide().appendTo('#content');
event.sub('location.changed', onLocationChanged); event.sub('location.changed', onLocationChanged);
onLocationChanged();
}; };
init(); init();

View file

@ -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({ var settings = _.extend({
enabled: false, enabled: false,
@ -36,7 +36,7 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co
if (json && json.code === 0) { if (json && json.code === 0) {
setTimeout(function () { // wait here so the img above can be updated in time 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); }, 200);
} else { } else {
failed(); failed();

View file

@ -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({ var settings = _.extend({
enabled: false, enabled: false,
@ -50,7 +50,7 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry', 'core/r
url: server.api, url: server.api,
data: { data: {
action: 'upload', action: 'upload',
href: entry.absHref href: location.getAbsHref()
}, },
docEnter: function () { docEnter: function () {

View file

@ -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({ var settings = _.extend({
enabled: false, 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) { if (!settings.enabled) {
return; return;
} }
_.each(entry.content, initEntry);
$(template).appendTo('body'); $(template).appendTo('body');
$('#pv-img-bar-prev, #pv-img-prev').on('click', onPrevious); $('#pv-img-bar-prev, #pv-img-prev').on('click', onPrevious);
$('#pv-img-bar-next, #pv-img-next').on('click', onNext); $('#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.stopImmediatePropagation();
}); });
event.sub('location.changed', onLocationChanged);
event.sub('entry.created', initEntry); event.sub('entry.created', initEntry);
$(window).on('resize load', adjustSize); $(window).on('resize load', adjustSize);
}; };
init(entry); init();
}); });

View file

@ -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({ var settings = _.extend({
enabled: false, 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) { if (!settings.enabled) {
return; return;
} }
_.each(entry.content, initEntry);
$(template).appendTo('body'); $(template).appendTo('body');
$('#pv-txt-bar-prev').on('click', onPrevious); $('#pv-txt-bar-prev').on('click', onPrevious);
$('#pv-txt-bar-next').on('click', onNext); $('#pv-txt-bar-next').on('click', onNext);
@ -253,10 +256,11 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/resource',
event.stopImmediatePropagation(); event.stopImmediatePropagation();
}); });
event.sub('location.changed', onLocationChanged);
event.sub('entry.created', initEntry); event.sub('entry.created', initEntry);
$(window).on('resize load', adjustSize); $(window).on('resize load', adjustSize);
}; };
init(entry); init();
}); });

View file

@ -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({ var settings = _.extend({
enabled: false enabled: false
@ -29,7 +29,7 @@ modulejs.define('ext/statusbar', ['_', '$', 'core/settings', 'core/format', 'cor
} }
}, },
init = function (entry) { init = function () {
if (!settings.enabled) { if (!settings.enabled) {
return; return;
@ -42,25 +42,28 @@ modulejs.define('ext/statusbar', ['_', '$', 'core/settings', 'core/format', 'cor
$statusDefault = $statusbar.find('.status.default'); $statusDefault = $statusbar.find('.status.default');
$statusDynamic = $statusbar.find('.status.dynamic'); $statusDynamic = $statusbar.find('.status.dynamic');
var stats = entry.getStats(); event.sub('location.changed', function (item) {
$folderTotal.text(stats.folders);
$fileTotal.text(stats.files);
update(); var stats = item.getStats();
$folderTotal.text(stats.folders);
$fileTotal.text(stats.files);
update();
});
event.sub('statusbar', update); event.sub('statusbar', update);
$('#bottombar > .center').append($statusbar); $('#bottombar > .center').append($statusbar);
event.sub('entry.created', function () { event.sub('entry.created', function () {
var stats = entry.getStats(); var stats = location.getItem().getStats();
$folderTotal.text(stats.folders); $folderTotal.text(stats.folders);
$fileTotal.text(stats.files); $fileTotal.text(stats.files);
}); });
event.sub('entry.removed', function () { event.sub('entry.removed', function () {
var stats = entry.getStats(); var stats = location.getItem().getStats();
$folderTotal.text(stats.folders); $folderTotal.text(stats.folders);
$fileTotal.text(stats.files); $fileTotal.text(stats.files);
}); });
@ -89,5 +92,5 @@ modulejs.define('ext/statusbar', ['_', '$', 'core/settings', 'core/format', 'cor
}); });
}; };
init(entry); init();
}); });

View file

@ -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({ var settings = _.extend({
enabled: false, 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) { if (!settings.enabled || !server.api) {
return; return;
} }
setTimeout(function () { event.sub('location.changed', onLocationChanged);
_.each(entry.content, checkEntry);
}, settings.delay);
event.sub('entry.created', function (entry) { event.sub('entry.created', function (entry) {
checkEntry(entry); checkEntry(entry);
}); });
}; };
init(entry); init();
}); });

View file

@ -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({ var settings = _.extend({
enabled: false enabled: false
}, allsettings.title), }, allsettings.title),
init = function (entry) { onLocationChanged = function (item) {
if (!settings.enabled) { var labels = _.pluck(item.getCrumb(), 'label'),
return;
}
var labels = _.pluck(entry.getCrumb(), 'label'),
title = labels.join(' > '); title = labels.join(' > ');
if (labels.length > 1) { if (labels.length > 1) {
@ -19,7 +15,16 @@ modulejs.define('ext/title', ['_', 'core/settings', 'core/entry'], function (_,
} }
document.title = title; document.title = title;
},
init = function () {
if (!settings.enabled) {
return;
}
event.sub('location.changed', onLocationChanged);
}; };
init(entry); init();
}); });

View file

@ -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({ var settings = _.extend({
enabled: false, enabled: false,
@ -34,7 +34,7 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
.data('entry', entry) .data('entry', entry)
.data('status', entry.status); .data('status', entry.status);
$a.attr('href', entry.absHref); location.setLink($a, entry);
$img.attr('src', resource.icon(entry.type)); $img.attr('src', resource.icon(entry.type));
$label.text(entry.label); $label.text(entry.label);
@ -207,10 +207,24 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
} }
update(entry); 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 // creates the complete tree from entry down to the root
init = function (entry) { init = function () {
if (!settings.enabled) { if (!settings.enabled) {
return; return;
@ -229,23 +243,15 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
shiftTree(); shiftTree();
}); });
fetchTree(entry, function (root) { event.sub('location.changed', onLocationChanged);
$tree
.find('.sp-container').append(update(root)).end()
.show();
adjustSpacing();
shiftTree(false, true);
});
event.sub('ready', adjustSpacing);
// strong negative performance impact in aai mode // strong negative performance impact in aai mode
// event.sub('entry.changed', onContentChanged); // event.sub('entry.changed', onContentChanged);
// event.sub('entry.created', onContentChanged); // event.sub('entry.created', onContentChanged);
// event.sub('entry.removed', onContentChanged); // event.sub('entry.removed', onContentChanged);
event.sub('ready', adjustSpacing);
$(window).on('resize', function () { $(window).on('resize', function () {
adjustSpacing(); adjustSpacing();
@ -253,5 +259,5 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
}); });
}; };
init(entry); init();
}); });

View file

@ -7,8 +7,6 @@ modulejs.define('main', ['_', 'core/event'], function (_, event) {
modulejs.require('view/spacing'); modulejs.require('view/spacing');
modulejs.require('view/viewmode'); modulejs.require('view/viewmode');
modulejs.require('core/location').setLocation(document.location.href, true);
event.pub('beforeExt'); event.pub('beforeExt');
_.each(modulejs.state(), function (state, id) { _.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'); event.pub('ready');
}); });

View file

@ -163,10 +163,7 @@ modulejs.define('view/items', ['_', '$', 'core/settings', 'core/resource', 'core
} }
}); });
event.sub('location.changed', function () { event.sub('location.changed', onLocationChanged);
onLocationChanged(location.getItem());
});
$content.appendTo('body'); $content.appendTo('body');
}; };