mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
working to simplify the action architecture...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
cf6273fbe4
commit
9ed14ba3b8
@ -182,14 +182,17 @@ module.BASE_ACTIONS = {
|
|||||||
shiftImageDown:
|
shiftImageDown:
|
||||||
'Shift image to the ribbon below current, creating one if '
|
'Shift image to the ribbon below current, creating one if '
|
||||||
+'it does not exist',
|
+'it does not exist',
|
||||||
shiftImageUpNewRibbon: '',
|
shiftImageUpNewRibbon:
|
||||||
shiftImageDownNewRibbon: '',
|
'Create an empty ribbon above and shift the image into it',
|
||||||
|
shiftImageDownNewRibbon:
|
||||||
|
'Create an empty ribbon below and shift the image into it',
|
||||||
shiftImageLeft: 'Shift image to the left',
|
shiftImageLeft: 'Shift image to the left',
|
||||||
shiftImageRight: 'Shift image to the right',
|
shiftImageRight: 'Shift image to the right',
|
||||||
|
|
||||||
moveRibbonUp: 'Move current ribbon one position up',
|
shiftRibbonUp: 'Move current ribbon one position up',
|
||||||
moveRibbonDown: 'Move current ribbon one position down',
|
shiftRibbonDown: 'Move current ribbon one position down',
|
||||||
|
|
||||||
|
// XXX
|
||||||
sortImages: '',
|
sortImages: '',
|
||||||
reverseImages: '',
|
reverseImages: '',
|
||||||
setAsBaseRibbon: '',
|
setAsBaseRibbon: '',
|
||||||
|
|||||||
@ -7,41 +7,100 @@
|
|||||||
//var DEBUG = DEBUG != null ? DEBUG : true
|
//var DEBUG = DEBUG != null ? DEBUG : true
|
||||||
|
|
||||||
define(function(require){ var module = {}
|
define(function(require){ var module = {}
|
||||||
console.log('>>> ui')
|
console.log('>>> client')
|
||||||
|
|
||||||
doc = require('keyboard').doc
|
doc = require('lib/keyboard').doc
|
||||||
|
|
||||||
data = require('data')
|
data = require('data')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************************/
|
||||||
|
|
||||||
|
// XXX add a callback here...
|
||||||
function proxy(attr, name){
|
function proxy(attr, name){
|
||||||
return function(){
|
return function(){
|
||||||
this[attr][name].apply(this[attr], arguments)
|
attr = this[attr]
|
||||||
|
attr[name].apply(attr, arguments)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function proxyMethods(obj, map){
|
||||||
|
var txt = ''
|
||||||
|
|
||||||
|
for(var attr in map){
|
||||||
|
var methods = map[attr]
|
||||||
|
for(var name in methods){
|
||||||
|
var txt = methods[name]
|
||||||
|
if(txt == null){
|
||||||
|
obj[name] = proxy(attr, name)
|
||||||
|
} else {
|
||||||
|
obj[name] = doc(txt, proxy(attr, name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
var CLIENT_ACTIONS = {
|
// This will:
|
||||||
|
// - provide an abstraction layer to data (proxy)
|
||||||
|
// - provide API docs usable for doc generation...
|
||||||
|
// - provide callbacks (???)
|
||||||
|
//
|
||||||
|
var ClientClassPrototype = {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var ClientPrototype = {
|
||||||
// this expects the folowing attrs:
|
// this expects the folowing attrs:
|
||||||
//
|
//
|
||||||
// .data
|
// .data
|
||||||
//
|
//
|
||||||
|
|
||||||
focusImage: doc('Focus Image',
|
// XXX client-specific API...
|
||||||
proxy('data', 'focusImage')),
|
// XXX
|
||||||
focusRibbon: doc('Focus ribbon',
|
|
||||||
proxy('data', 'focusRibbon')),
|
|
||||||
firstImage: doc('',
|
|
||||||
proxy('data', 'firstImage')),
|
|
||||||
lastImage: doc('',
|
|
||||||
proxy('data', 'lastImage')),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setup the proxy methods...
|
||||||
|
var ClientPrototype = proxyMethods(
|
||||||
|
ClientPrototype,
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
focusImage: 'Focus image',
|
||||||
|
focusRibbon: 'Focus ribbon',
|
||||||
|
|
||||||
|
firstImage: 'Focus first image in current ribbon',
|
||||||
|
lastImage: 'Focus last image in current ribbon',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
var Client =
|
||||||
|
module.Client =
|
||||||
|
function Client(){
|
||||||
|
// in case this is called as a function (without new)...
|
||||||
|
if(this.constructor.name != 'Client'){
|
||||||
|
return new Client()
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX setup initial state...
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
Client.__proto__ = ClientClassPrototype
|
||||||
|
Client.prototype = ClientPrototype
|
||||||
|
Client.prototype.constructor = Client
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -721,6 +721,9 @@ module.DataPrototype = {
|
|||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Focus a ribbon -- focus an image in that ribbon
|
||||||
|
//
|
||||||
|
// NOTE: target must be .getRibbon(..) compatible.
|
||||||
focusRibbon: function(target){
|
focusRibbon: function(target){
|
||||||
var cur = this.getRibbonOrder()
|
var cur = this.getRibbonOrder()
|
||||||
var ribbon = this.getRibbon(target)
|
var ribbon = this.getRibbon(target)
|
||||||
@ -737,6 +740,7 @@ module.DataPrototype = {
|
|||||||
|
|
||||||
var img = this.getImage(ribbon, direction)
|
var img = this.getImage(ribbon, direction)
|
||||||
|
|
||||||
|
// first/last image...
|
||||||
if(img == null){
|
if(img == null){
|
||||||
img = direction == 'before'
|
img = direction == 'before'
|
||||||
? this.getImage('first', ribbon)
|
? this.getImage('first', ribbon)
|
||||||
@ -837,6 +841,7 @@ module.DataPrototype = {
|
|||||||
// Sort images in ribbons via .order...
|
// Sort images in ribbons via .order...
|
||||||
//
|
//
|
||||||
// NOTE: this sorts in-place
|
// NOTE: this sorts in-place
|
||||||
|
// NOTE: this will not change image order
|
||||||
sortImages: function(){
|
sortImages: function(){
|
||||||
var ribbons = this.ribbons
|
var ribbons = this.ribbons
|
||||||
for(k in ribbons){
|
for(k in ribbons){
|
||||||
@ -1512,17 +1517,6 @@ Data.prototype.constructor = Data
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
|
||||||
|
|
||||||
// XXX keep this here or move this to a different module???
|
|
||||||
module.setupActionHandlers = function(context){
|
|
||||||
// XXX
|
|
||||||
context.on('focusImage', function(evt, img){
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* vim:set ts=4 sw=4 : */
|
* vim:set ts=4 sw=4 : */
|
||||||
return module })
|
return module })
|
||||||
|
|||||||
@ -140,6 +140,9 @@ module.calcRelativeRotation = function(from, to){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************************/
|
||||||
|
|
||||||
// cmp functions...
|
// cmp functions...
|
||||||
// XXX is this the right way to seporate these???
|
// XXX is this the right way to seporate these???
|
||||||
|
|
||||||
|
|||||||
@ -272,7 +272,7 @@ module.RibbonsPrototype = {
|
|||||||
},
|
},
|
||||||
// Like .getRibbon(..) but returns ribbon index instead of the actual
|
// Like .getRibbon(..) but returns ribbon index instead of the actual
|
||||||
// ribbon object...
|
// ribbon object...
|
||||||
getRibbonIndex: function(target){
|
getRibbonOrder: function(target){
|
||||||
return this.viewer.find('.ribbon').index(this.getRibbon(target))
|
return this.viewer.find('.ribbon').index(this.getRibbon(target))
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -411,7 +411,7 @@ module.RibbonsPrototype = {
|
|||||||
placeRibbon: function(target, position){
|
placeRibbon: function(target, position){
|
||||||
// get create the ribbon...
|
// get create the ribbon...
|
||||||
var ribbon = this.getRibbon(target)
|
var ribbon = this.getRibbon(target)
|
||||||
var i = this.getRibbonIndex(ribbon)
|
var i = this.getRibbonOrder(ribbon)
|
||||||
ribbon = ribbon.length == 0 ? this.createRibbon(target) : ribbon
|
ribbon = ribbon.length == 0 ? this.createRibbon(target) : ribbon
|
||||||
|
|
||||||
var ribbons = this.viewer.find('.ribbon')
|
var ribbons = this.viewer.find('.ribbon')
|
||||||
@ -420,7 +420,7 @@ module.RibbonsPrototype = {
|
|||||||
position = position < 0 ? ribbons.length + position + 1 : position
|
position = position < 0 ? ribbons.length + position + 1 : position
|
||||||
position = position < 0 ? 0 : position
|
position = position < 0 ? 0 : position
|
||||||
} else {
|
} else {
|
||||||
var p = this.getRibbonIndex(position)
|
var p = this.getRibbonOrder(position)
|
||||||
// XXX what do we do if the target does not exist, i.e. p == -1 ????
|
// XXX what do we do if the target does not exist, i.e. p == -1 ????
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,6 +544,8 @@ module.RibbonsPrototype = {
|
|||||||
// If this is set to true image previews will be loaded synchronously...
|
// If this is set to true image previews will be loaded synchronously...
|
||||||
load_img_sync: false,
|
load_img_sync: false,
|
||||||
//
|
//
|
||||||
|
// XXX this depends on .images...
|
||||||
|
// ...a good candidate to move to images, but not yet sure...
|
||||||
updateImage: function(image, gid, size, sync){
|
updateImage: function(image, gid, size, sync){
|
||||||
image = (image == '*' ? this.viewer.find('.image')
|
image = (image == '*' ? this.viewer.find('.image')
|
||||||
: image == null
|
: image == null
|
||||||
|
|||||||
@ -33,6 +33,9 @@ var ribbons = require('ribbons')
|
|||||||
var testing = require('testing')
|
var testing = require('testing')
|
||||||
|
|
||||||
|
|
||||||
|
var client = require('client')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user