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???
|
// XXX do we need to call .syncTags(..) here???
|
||||||
load: ['- File|Interface/',
|
load: ['- File|Interface/',
|
||||||
function(d){
|
function(d){
|
||||||
|
this.clear()
|
||||||
|
|
||||||
this.images = images.Images(d.images)
|
this.images = images.Images(d.images)
|
||||||
this.data = data.Data(d.data)
|
this.data = data.Data(d.data)
|
||||||
}],
|
}],
|
||||||
@ -221,10 +223,12 @@ actions.Actions({
|
|||||||
// ...note if we use this it breaks, need to rethink...
|
// ...note if we use this it breaks, need to rethink...
|
||||||
loadURLs: ['File/Load a URL list',
|
loadURLs: ['File/Load a URL list',
|
||||||
function(lst, base){
|
function(lst, base){
|
||||||
this.clear()
|
var imgs = images.Images.fromArray(lst, base)
|
||||||
|
|
||||||
this.images = images.Images.fromArray(lst, base)
|
this.load({
|
||||||
this.data = data.Data.fromArray(this.images.keys())
|
images: imgs,
|
||||||
|
data: data.Data.fromArray(imgs.keys()),
|
||||||
|
})
|
||||||
}],
|
}],
|
||||||
|
|
||||||
// XXX experimental...
|
// XXX experimental...
|
||||||
|
|||||||
@ -196,6 +196,7 @@ var URLHistoryLocalStorageActions = actions.Actions({
|
|||||||
config: {
|
config: {
|
||||||
'url-history-local-storage-key': 'url-history',
|
'url-history-local-storage-key': 'url-history',
|
||||||
'url-history-loaded-local-storage-key': 'url-history-loaded',
|
'url-history-loaded-local-storage-key': 'url-history-loaded',
|
||||||
|
'url-history-load-current': true,
|
||||||
},
|
},
|
||||||
|
|
||||||
__url_history: null,
|
__url_history: null,
|
||||||
@ -268,6 +269,13 @@ var URLHistoryLocalStorageActions = actions.Actions({
|
|||||||
|
|
||||||
if(loaded && localStorage[loaded]){
|
if(loaded && localStorage[loaded]){
|
||||||
var l = JSON.parse(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)
|
this.openURLFromHistory(l.path, l.method)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -299,7 +307,7 @@ module.URLHistoryLocalStorage = core.ImageGridFeatures.Feature({
|
|||||||
function(){ this.saveURLHistory() }],
|
function(){ this.saveURLHistory() }],
|
||||||
|
|
||||||
// save base_path...
|
// save base_path...
|
||||||
['load loadURLs',
|
['load',
|
||||||
function(){ this.location && this.location.path && this.saveLocation() }],
|
function(){ this.location && this.location.path && this.saveLocation() }],
|
||||||
|
|
||||||
// save...
|
// save...
|
||||||
|
|||||||
@ -34,8 +34,6 @@ var LocationActions = actions.Actions({
|
|||||||
// {
|
// {
|
||||||
// path: <base-path>,
|
// path: <base-path>,
|
||||||
// method: <load-method>,
|
// method: <load-method>,
|
||||||
// // XXX current or hash???
|
|
||||||
// // XXX not yet supported...
|
|
||||||
// current: <current-gid>,
|
// current: <current-gid>,
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
@ -56,6 +54,11 @@ var LocationActions = actions.Actions({
|
|||||||
if(b){
|
if(b){
|
||||||
this.__location.path = b
|
this.__location.path = b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.__location.current == null){
|
||||||
|
this.__location.current = this.current
|
||||||
|
}
|
||||||
|
|
||||||
return this.__location
|
return this.__location
|
||||||
},
|
},
|
||||||
set location(value){
|
set location(value){
|
||||||
@ -86,10 +89,17 @@ var LocationActions = actions.Actions({
|
|||||||
current: cur,
|
current: cur,
|
||||||
}
|
}
|
||||||
|
|
||||||
this[value.method || 'loadIndex'](path)
|
var res = this[value.method || 'loadIndex'](path)
|
||||||
|
|
||||||
// XXX load current...
|
// 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...
|
// local storage + url...
|
||||||
'config-local-storage',
|
'config-local-storage',
|
||||||
// XXX make this browser-only...
|
|
||||||
'ui-url-hash',
|
'ui-url-hash',
|
||||||
'url-history-local-storage',
|
'url-history-local-storage',
|
||||||
'ui-single-image-view-local-storage',
|
'ui-single-image-view-local-storage',
|
||||||
|
|||||||
@ -193,18 +193,16 @@ actions.Actions({
|
|||||||
? this.ribbons.viewer
|
? this.ribbons.viewer
|
||||||
: viewer
|
: viewer
|
||||||
|
|
||||||
// XXX do we need to recycle the ribbons???
|
if(this.ribbons == null){
|
||||||
if(this.ribbons != null){
|
|
||||||
this.ribbons.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: this is done unconditionally to avoid manually
|
|
||||||
// setting images and other stuff in the future...
|
|
||||||
this.ribbons = ribbons.Ribbons(viewer, this.images)
|
this.ribbons = ribbons.Ribbons(viewer, this.images)
|
||||||
|
|
||||||
// XXX is this correct???
|
// XXX is this correct???
|
||||||
this.ribbons.__image_updaters = [this.updateImage.bind(this)]
|
this.ribbons.__image_updaters = [this.updateImage.bind(this)]
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.ribbons.clear()
|
||||||
|
this.ribbons.images = this.images
|
||||||
|
}
|
||||||
|
|
||||||
this.reload()
|
this.reload()
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
@ -250,7 +248,7 @@ actions.Actions({
|
|||||||
this.ribbons.updateImage(gids)
|
this.ribbons.updateImage(gids)
|
||||||
}],
|
}],
|
||||||
clear: [
|
clear: [
|
||||||
function(){ this.ribbons.clear() }],
|
function(){ this.ribbon && this.ribbons.clear() }],
|
||||||
clone: [function(full){
|
clone: [function(full){
|
||||||
return function(res){
|
return function(res){
|
||||||
if(this.ribbons){
|
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: [
|
replaceGid: [
|
||||||
function(from, to){
|
function(from, to){
|
||||||
return function(res){
|
return function(res){
|
||||||
@ -775,7 +747,7 @@ module.Viewer = core.ImageGridFeatures.Feature({
|
|||||||
var journalActions = {
|
var journalActions = {
|
||||||
clear: null,
|
clear: null,
|
||||||
load: null,
|
load: null,
|
||||||
loadURLs: null,
|
//loadURLs: null,
|
||||||
|
|
||||||
setBaseRibbon: null,
|
setBaseRibbon: null,
|
||||||
|
|
||||||
@ -1794,7 +1766,8 @@ module.SingleImageViewLocalStorage = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
handlers:[
|
handlers:[
|
||||||
// set scale...
|
// set scale...
|
||||||
['load loadURLs',
|
//['load loadURLs',
|
||||||
|
['load',
|
||||||
function(){
|
function(){
|
||||||
// prevent this from doing anything while no viewer...
|
// prevent this from doing anything while no viewer...
|
||||||
if(!this.ribbons || !this.ribbons.viewer || this.ribbons.viewer.length == 0){
|
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 =
|
var URLHash =
|
||||||
module.URLHash = core.ImageGridFeatures.Feature({
|
module.URLHash = core.ImageGridFeatures.Feature({
|
||||||
title: '',
|
title: '',
|
||||||
@ -2822,26 +2793,25 @@ module.URLHash = core.ImageGridFeatures.Feature({
|
|||||||
tag: 'ui-url-hash',
|
tag: 'ui-url-hash',
|
||||||
depends: ['ui'],
|
depends: ['ui'],
|
||||||
|
|
||||||
|
//isApplicable: function(){},
|
||||||
|
|
||||||
handlers: [
|
handlers: [
|
||||||
['focusImage',
|
['focusImage',
|
||||||
function(res, a){
|
function(res, a){
|
||||||
console.log('focus:', a)
|
|
||||||
if(this.current && this.current != ''){
|
if(this.current && this.current != ''){
|
||||||
location.hash = this.current
|
location.hash = this.current
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
// XXX this does not work for some reason...
|
['load.pre',
|
||||||
// ...likely because of the slow async load and sync set...
|
|
||||||
['start',
|
|
||||||
function(){
|
function(){
|
||||||
var h = location.hash
|
var h = location.hash
|
||||||
h = h.replace(/^#/, '')
|
h = h.replace(/^#/, '')
|
||||||
|
|
||||||
// for some odd reason this does not work...
|
return function(){
|
||||||
if(h != ''){
|
if(h != '' && this.data.getImageOrder(h) >= 0){
|
||||||
console.log('!!!!', h)
|
|
||||||
this.current = h
|
this.current = h
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
@ -291,14 +291,18 @@ module.ImagesClassPrototype = {
|
|||||||
//var base_pattern = base ? RegExp('^' + base) : null
|
//var base_pattern = base ? RegExp('^' + base) : null
|
||||||
var base_pattern = base ? RegExp('^' + quoteRegExp(base)) : null
|
var base_pattern = base ? RegExp('^' + quoteRegExp(base)) : null
|
||||||
data.forEach(function(path){
|
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...
|
// XXX populate the image doc better...
|
||||||
images[gid] = {
|
images[gid] = {
|
||||||
id: gid,
|
id: gid,
|
||||||
// XXX need to normalize path...
|
path: p,
|
||||||
path: (base_pattern ? path.replace(base_pattern, './') : path)
|
|
||||||
.replace(/([\/\\])\1+/g, '/'),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove only of base path is given and in path...
|
// remove only of base path is given and in path...
|
||||||
if(base && base_pattern.test(path)){
|
if(base && base_pattern.test(path)){
|
||||||
images[gid].base_path = base
|
images[gid].base_path = base
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user