mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-31 07:18:21 -04:00
Improves event system.
This commit is contained in:
parent
34eed09537
commit
2819fd8496
9 changed files with 75 additions and 50 deletions
|
@ -6,10 +6,22 @@ modulejs.define('ext/autorefresh', ['_', '$', 'core/settings', 'core/event', 'co
|
|||
interval: 5000
|
||||
}, allsettings.autorefresh),
|
||||
|
||||
timeoutId = null,
|
||||
|
||||
heartbeat = function () {
|
||||
|
||||
location.refresh();
|
||||
setTimeout(heartbeat, settings.interval);
|
||||
},
|
||||
|
||||
before = function () {
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
},
|
||||
|
||||
after = function () {
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(heartbeat, settings.interval);
|
||||
},
|
||||
|
||||
init = function () {
|
||||
|
@ -20,10 +32,10 @@ modulejs.define('ext/autorefresh', ['_', '$', 'core/settings', 'core/event', 'co
|
|||
|
||||
settings.interval = Math.max(1000, settings.interval);
|
||||
|
||||
event.sub('ready', function () {
|
||||
|
||||
setTimeout(heartbeat, settings.interval);
|
||||
});
|
||||
event.sub('location.beforeChange', before);
|
||||
event.sub('location.beforeRefresh', before);
|
||||
event.sub('location.changed', after);
|
||||
event.sub('location.refreshed', after);
|
||||
};
|
||||
|
||||
init();
|
||||
|
|
|
@ -224,6 +224,11 @@ modulejs.define('ext/preview-img', ['_', '$', 'core/settings', 'core/resource',
|
|||
_.each(item.content, initEntry);
|
||||
},
|
||||
|
||||
onLocationRefreshed = function (item, added, removed) {
|
||||
|
||||
_.each(added, initEntry);
|
||||
},
|
||||
|
||||
init = function () {
|
||||
|
||||
if (!settings.enabled) {
|
||||
|
@ -280,7 +285,7 @@ modulejs.define('ext/preview-img', ['_', '$', 'core/settings', 'core/resource',
|
|||
});
|
||||
|
||||
event.sub('location.changed', onLocationChanged);
|
||||
event.sub('entry.created', initEntry);
|
||||
event.sub('location.refreshed', onLocationRefreshed);
|
||||
|
||||
$(window).on('resize load', adjustSize);
|
||||
};
|
||||
|
|
|
@ -275,6 +275,11 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/resource',
|
|||
_.each(item.content, initEntry);
|
||||
},
|
||||
|
||||
onLocationRefreshed = function (item, added, removed) {
|
||||
|
||||
_.each(added, initEntry);
|
||||
},
|
||||
|
||||
init = function () {
|
||||
|
||||
if (!settings.enabled) {
|
||||
|
@ -303,7 +308,7 @@ modulejs.define('ext/preview-txt', ['_', '$', 'core/settings', 'core/resource',
|
|||
});
|
||||
|
||||
event.sub('location.changed', onLocationChanged);
|
||||
event.sub('entry.created', initEntry);
|
||||
event.sub('location.refreshed', onLocationRefreshed);
|
||||
|
||||
$(window).on('resize load', adjustSize);
|
||||
};
|
||||
|
|
|
@ -111,6 +111,23 @@ modulejs.define('ext/select', ['_', '$', 'core/settings', 'core/event'], functio
|
|||
}
|
||||
},
|
||||
|
||||
onLocationRefreshed = function (item, added, removed) {
|
||||
|
||||
var selectionChanged = false;
|
||||
|
||||
_.each(removed, function (item) {
|
||||
|
||||
if (item.$extended && item.$extended.hasClass('selected')) {
|
||||
item.$extended.removeClass('selected');
|
||||
selectionChanged = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (selectionChanged) {
|
||||
publish();
|
||||
}
|
||||
},
|
||||
|
||||
init = function () {
|
||||
|
||||
if (!settings.enabled) {
|
||||
|
@ -119,13 +136,7 @@ modulejs.define('ext/select', ['_', '$', 'core/settings', 'core/event'], functio
|
|||
|
||||
$selectionRect.hide().appendTo('body');
|
||||
|
||||
event.sub('entry.removed', function (entry) {
|
||||
|
||||
if (entry.$extended && entry.$extended.hasClass('selected')) {
|
||||
entry.$extended.removeClass('selected');
|
||||
publish();
|
||||
}
|
||||
});
|
||||
event.sub('location.refreshed', onLocationRefreshed);
|
||||
|
||||
$document
|
||||
.on('mousedown', '.noSelection', noSelection)
|
||||
|
|
|
@ -61,6 +61,11 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/event', 'core/ser
|
|||
}, settings.delay);
|
||||
},
|
||||
|
||||
onLocationRefreshed = function (item, added, removed) {
|
||||
|
||||
_.each(added, checkEntry);
|
||||
},
|
||||
|
||||
init = function () {
|
||||
|
||||
if (!settings.enabled || !server.api) {
|
||||
|
@ -68,10 +73,7 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/event', 'core/ser
|
|||
}
|
||||
|
||||
event.sub('location.changed', onLocationChanged);
|
||||
event.sub('entry.created', function (entry) {
|
||||
|
||||
checkEntry(entry);
|
||||
});
|
||||
event.sub('location.refreshed', onLocationRefreshed);
|
||||
};
|
||||
|
||||
init();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue