mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
refactored loading (now one entry point only: .load(..)) + added location.hash fro current image and .location.current support...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9777ca7429
commit
c9400b83a0
@ -191,6 +191,8 @@ actions.Actions({
|
||||
// XXX do we need to call .syncTags(..) here???
|
||||
load: ['- File|Interface/',
|
||||
function(d){
|
||||
this.clear()
|
||||
|
||||
this.images = images.Images(d.images)
|
||||
this.data = data.Data(d.data)
|
||||
}],
|
||||
@ -221,10 +223,12 @@ actions.Actions({
|
||||
// ...note if we use this it breaks, need to rethink...
|
||||
loadURLs: ['File/Load a URL list',
|
||||
function(lst, base){
|
||||
this.clear()
|
||||
var imgs = images.Images.fromArray(lst, base)
|
||||
|
||||
this.images = images.Images.fromArray(lst, base)
|
||||
this.data = data.Data.fromArray(this.images.keys())
|
||||
this.load({
|
||||
images: imgs,
|
||||
data: data.Data.fromArray(imgs.keys()),
|
||||
})
|
||||
}],
|
||||
|
||||
// XXX experimental...
|
||||
|
||||
@ -196,6 +196,7 @@ var URLHistoryLocalStorageActions = actions.Actions({
|
||||
config: {
|
||||
'url-history-local-storage-key': 'url-history',
|
||||
'url-history-loaded-local-storage-key': 'url-history-loaded',
|
||||
'url-history-load-current': true,
|
||||
},
|
||||
|
||||
__url_history: null,
|
||||
@ -268,6 +269,13 @@ var URLHistoryLocalStorageActions = actions.Actions({
|
||||
|
||||
if(loaded && localStorage[loaded]){
|
||||
var l = JSON.parse(localStorage[loaded])
|
||||
|
||||
if(l.current != null && this.config['url-history-load-current']){
|
||||
this.one('load', function(){
|
||||
this.current = l.current
|
||||
})
|
||||
}
|
||||
|
||||
this.openURLFromHistory(l.path, l.method)
|
||||
|
||||
} else {
|
||||
@ -299,7 +307,7 @@ module.URLHistoryLocalStorage = core.ImageGridFeatures.Feature({
|
||||
function(){ this.saveURLHistory() }],
|
||||
|
||||
// save base_path...
|
||||
['load loadURLs',
|
||||
['load',
|
||||
function(){ this.location && this.location.path && this.saveLocation() }],
|
||||
|
||||
// save...
|
||||
|
||||
@ -34,8 +34,6 @@ var LocationActions = actions.Actions({
|
||||
// {
|
||||
// path: <base-path>,
|
||||
// method: <load-method>,
|
||||
// // XXX current or hash???
|
||||
// // XXX not yet supported...
|
||||
// current: <current-gid>,
|
||||
// }
|
||||
//
|
||||
@ -56,6 +54,11 @@ var LocationActions = actions.Actions({
|
||||
if(b){
|
||||
this.__location.path = b
|
||||
}
|
||||
|
||||
if(this.__location.current == null){
|
||||
this.__location.current = this.current
|
||||
}
|
||||
|
||||
return this.__location
|
||||
},
|
||||
set location(value){
|
||||
@ -86,10 +89,17 @@ var LocationActions = actions.Actions({
|
||||
current: cur,
|
||||
}
|
||||
|
||||
this[value.method || 'loadIndex'](path)
|
||||
var res = this[value.method || 'loadIndex'](path)
|
||||
|
||||
// XXX load current...
|
||||
// XXX
|
||||
if(res.then != null){
|
||||
res.then(function(){
|
||||
this.current = cur
|
||||
})
|
||||
|
||||
} else {
|
||||
this.current = cur
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@ -52,7 +52,6 @@ core.ImageGridFeatures.Feature('viewer-testing', [
|
||||
|
||||
// local storage + url...
|
||||
'config-local-storage',
|
||||
// XXX make this browser-only...
|
||||
'ui-url-hash',
|
||||
'url-history-local-storage',
|
||||
'ui-single-image-view-local-storage',
|
||||
|
||||
@ -193,18 +193,16 @@ actions.Actions({
|
||||
? this.ribbons.viewer
|
||||
: viewer
|
||||
|
||||
// XXX do we need to recycle the ribbons???
|
||||
if(this.ribbons != null){
|
||||
this.ribbons.clear()
|
||||
}
|
||||
|
||||
// NOTE: this is done unconditionally to avoid manually
|
||||
// setting images and other stuff in the future...
|
||||
if(this.ribbons == null){
|
||||
this.ribbons = ribbons.Ribbons(viewer, this.images)
|
||||
|
||||
// XXX is this correct???
|
||||
this.ribbons.__image_updaters = [this.updateImage.bind(this)]
|
||||
|
||||
} else {
|
||||
this.ribbons.clear()
|
||||
this.ribbons.images = this.images
|
||||
}
|
||||
|
||||
this.reload()
|
||||
}
|
||||
}],
|
||||
@ -250,7 +248,7 @@ actions.Actions({
|
||||
this.ribbons.updateImage(gids)
|
||||
}],
|
||||
clear: [
|
||||
function(){ this.ribbons.clear() }],
|
||||
function(){ this.ribbon && this.ribbons.clear() }],
|
||||
clone: [function(full){
|
||||
return function(res){
|
||||
if(this.ribbons){
|
||||
@ -263,32 +261,6 @@ actions.Actions({
|
||||
}],
|
||||
|
||||
|
||||
// XXX should this be an entry point???
|
||||
// ...IMO this should be more like .fromArray(..) and use .load(..)
|
||||
// internally...
|
||||
loadURLs: [
|
||||
function(){
|
||||
return function(){
|
||||
// recycle the viewer if one is not given specifically...
|
||||
var viewer = this.ribbons != null
|
||||
? this.ribbons.viewer
|
||||
: viewer
|
||||
|
||||
if(this.ribbons == null){
|
||||
this.ribbons = ribbons.Ribbons(viewer, this.images)
|
||||
// XXX is this correct???
|
||||
this.ribbons.__image_updaters = [this.updateImage.bind(this)]
|
||||
|
||||
} else {
|
||||
this.ribbons.clear()
|
||||
this.ribbons.images = this.images
|
||||
}
|
||||
|
||||
this.reload()
|
||||
}
|
||||
}],
|
||||
|
||||
|
||||
replaceGid: [
|
||||
function(from, to){
|
||||
return function(res){
|
||||
@ -775,7 +747,7 @@ module.Viewer = core.ImageGridFeatures.Feature({
|
||||
var journalActions = {
|
||||
clear: null,
|
||||
load: null,
|
||||
loadURLs: null,
|
||||
//loadURLs: null,
|
||||
|
||||
setBaseRibbon: null,
|
||||
|
||||
@ -1794,7 +1766,8 @@ module.SingleImageViewLocalStorage = core.ImageGridFeatures.Feature({
|
||||
|
||||
handlers:[
|
||||
// set scale...
|
||||
['load loadURLs',
|
||||
//['load loadURLs',
|
||||
['load',
|
||||
function(){
|
||||
// prevent this from doing anything while no viewer...
|
||||
if(!this.ribbons || !this.ribbons.viewer || this.ribbons.viewer.length == 0){
|
||||
@ -2810,10 +2783,8 @@ module.DirectControlGSAP = core.ImageGridFeatures.Feature({
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// XXX make this browser specific...
|
||||
// XXX BUG: loading of current gid from url for some reason is broken,
|
||||
// race?...
|
||||
|
||||
// XXX make this browser specific... (???)
|
||||
var URLHash =
|
||||
module.URLHash = core.ImageGridFeatures.Feature({
|
||||
title: '',
|
||||
@ -2822,26 +2793,25 @@ module.URLHash = core.ImageGridFeatures.Feature({
|
||||
tag: 'ui-url-hash',
|
||||
depends: ['ui'],
|
||||
|
||||
//isApplicable: function(){},
|
||||
|
||||
handlers: [
|
||||
['focusImage',
|
||||
function(res, a){
|
||||
console.log('focus:', a)
|
||||
if(this.current && this.current != ''){
|
||||
location.hash = this.current
|
||||
}
|
||||
}],
|
||||
// XXX this does not work for some reason...
|
||||
// ...likely because of the slow async load and sync set...
|
||||
['start',
|
||||
['load.pre',
|
||||
function(){
|
||||
var h = location.hash
|
||||
h = h.replace(/^#/, '')
|
||||
|
||||
// for some odd reason this does not work...
|
||||
if(h != ''){
|
||||
console.log('!!!!', h)
|
||||
return function(){
|
||||
if(h != '' && this.data.getImageOrder(h) >= 0){
|
||||
this.current = h
|
||||
}
|
||||
}
|
||||
}],
|
||||
],
|
||||
})
|
||||
|
||||
@ -291,14 +291,18 @@ module.ImagesClassPrototype = {
|
||||
//var base_pattern = base ? RegExp('^' + base) : null
|
||||
var base_pattern = base ? RegExp('^' + quoteRegExp(base)) : null
|
||||
data.forEach(function(path){
|
||||
var gid = hash('I'+i)
|
||||
// XXX need to normalize path...
|
||||
var p = (base_pattern ? path.replace(base_pattern, './') : path)
|
||||
.replace(/([\/\\])\1+/g, '/')
|
||||
// XXXX
|
||||
var gid = hash('I'+i+':'+p)
|
||||
|
||||
// XXX populate the image doc better...
|
||||
images[gid] = {
|
||||
id: gid,
|
||||
// XXX need to normalize path...
|
||||
path: (base_pattern ? path.replace(base_pattern, './') : path)
|
||||
.replace(/([\/\\])\1+/g, '/'),
|
||||
path: p,
|
||||
}
|
||||
|
||||
// remove only of base path is given and in path...
|
||||
if(base && base_pattern.test(path)){
|
||||
images[gid].base_path = base
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user