refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-11-28 20:08:08 +03:00
parent 07f881e2b8
commit 1bb34d8d60
5 changed files with 46 additions and 11 deletions

View File

@ -99,7 +99,7 @@ actions.Actions({
// Base ribbon... // Base ribbon...
get base(){ get base(){
return this.data == null ? null : this.data.base return this.data.base
}, },
set base(value){ set base(value){
this.setBaseRibbon(value) this.setBaseRibbon(value)
@ -107,7 +107,7 @@ actions.Actions({
// Current image... // Current image...
get current(){ get current(){
return this.data == null ? null : this.data.current return this.data.current
}, },
set current(value){ set current(value){
this.focusImage(value) this.focusImage(value)
@ -115,7 +115,7 @@ actions.Actions({
// Current ribbon... // Current ribbon...
get currentRibbon(){ get currentRibbon(){
return this.data == null ? null : this.data.getRibbon() return this.data.getRibbon()
}, },
set currentRibbon(value){ set currentRibbon(value){
this.focusRibbon(value) this.focusRibbon(value)
@ -275,8 +275,7 @@ actions.Actions({
// basic navigation... // basic navigation...
// //
focusImage: ['- Navigate/Focus image', focusImage: ['- Navigate/Focus image',
function(img, list){ function(img, list){ this.data.focusImage(img, list) }],
this.data.focusImage(img, list) }],
// Focuses a ribbon by selecting an image in it... // Focuses a ribbon by selecting an image in it...
// //
// modes supported: // modes supported:
@ -290,6 +289,10 @@ actions.Actions({
focusRibbon: ['- Navigate/Focus Ribbon', focusRibbon: ['- Navigate/Focus Ribbon',
function(target, mode){ function(target, mode){
var data = this.data var data = this.data
if(data == null){
return
}
var r = data.getRibbon(target) var r = data.getRibbon(target)
if(r == null){ if(r == null){
return return
@ -741,7 +744,7 @@ module.TagsActions = actions.Actions({
function(source, mode){ function(source, mode){
// can't do anything if either .data or .images are not // can't do anything if either .data or .images are not
// defined... // defined...
if(this.data == null || this.images == null){ if(this.images == null){
return return
} }
@ -838,6 +841,10 @@ module.CropActions = actions.Actions({
// //
crop: ['- Crop/Crop image list', crop: ['- Crop/Crop image list',
function(list, flatten){ function(list, flatten){
if(this.data.length == 0){
return
}
//list = list || this.data.order //list = list || this.data.order
list = list || this.data.getImages() list = list || this.data.getImages()
@ -929,8 +936,11 @@ module.CropActions = actions.Actions({
ribbon = ribbon || this.data.getRibbon() ribbon = ribbon || this.data.getRibbon()
var data = this.data var data = this.data
var that = this if(data == null){
return
}
var that = this
var i = data.ribbon_order.indexOf(ribbon) var i = data.ribbon_order.indexOf(ribbon)
var ribbons = data.ribbon_order.slice(0, i) var ribbons = data.ribbon_order.slice(0, i)
var images = ribbons var images = ribbons

View File

@ -18,6 +18,8 @@ var actions = require('lib/actions')
var features = require('lib/features') var features = require('lib/features')
var toggler = require('lib/toggler') var toggler = require('lib/toggler')
var data = require('imagegrid/data')
/*********************************************************************/ /*********************************************************************/
@ -80,6 +82,10 @@ function(attr, states, a, b){
// //
var ImageGridMetaActions = var ImageGridMetaActions =
module.ImageGridMetaActions = { module.ImageGridMetaActions = {
// XXX experimental...
get data(){ return this.__data || data.Data() },
set data(value){ this.__data = value },
// Test if the action is a Toggler... // Test if the action is a Toggler...
// //
isToggler: actions.doWithRootAction(function(action){ isToggler: actions.doWithRootAction(function(action){

View File

@ -20,9 +20,9 @@ var core = require('features/core')
// helper... // helper...
function didAdvance(indicator){ function didAdvance(indicator){
return function(){ return function(){
var img = this.data.current var img = this.data ? this.data.current : null
return function(){ return function(){
if(img == this.data.current){ if(img == null || img == this.data.current){
this.flashIndicator(indicator) this.flashIndicator(indicator)
} }
} }

View File

@ -429,6 +429,10 @@ module.ViewerActions = actions.Actions({
var ribbons = this.ribbons var ribbons = this.ribbons
var data = this.data var data = this.data
if(data == null){
return
}
// XXX handle raw dom elements... // XXX handle raw dom elements...
var gid = target instanceof jQuery var gid = target instanceof jQuery
? ribbons.getElemGID(target) ? ribbons.getElemGID(target)
@ -490,6 +494,10 @@ module.ViewerActions = actions.Actions({
var ribbons = this.ribbons var ribbons = this.ribbons
var data = this.data var data = this.data
if(data == null){
return
}
// XXX handle raw dom elements... // XXX handle raw dom elements...
var gid = target instanceof jQuery var gid = target instanceof jQuery
? ribbons.getElemGID(target) ? ribbons.getElemGID(target)

View File

@ -1568,6 +1568,9 @@ var DataPrototype = {
// XXX needs better docs... // XXX needs better docs...
shiftImage: function(from, target, mode, direction){ shiftImage: function(from, target, mode, direction){
from = from == null || from == 'current' ? this.current : from from = from == null || from == 'current' ? this.current : from
if(from == null){
return
}
from = from.constructor !== Array ? [from] : from from = from.constructor !== Array ? [from] : from
var place var place
@ -1613,7 +1616,8 @@ var DataPrototype = {
// NOTE: if base ribbon is removed this will try and reset it to the // NOTE: if base ribbon is removed this will try and reset it to the
// ribbon above or the top ribbon... // ribbon above or the top ribbon...
shiftImageUp: function(gid){ shiftImageUp: function(gid){
var g = gid.constructor === Array ? gid[0] : gid gid = gid || this.current
var g = gid && gid.constructor === Array ? gid[0] : gid
var r = this.getRibbonOrder(g) var r = this.getRibbonOrder(g)
// check if we need to create a ribbon here... // check if we need to create a ribbon here...
if(r == 0){ if(r == 0){
@ -1621,6 +1625,9 @@ var DataPrototype = {
this.newRibbon(g) this.newRibbon(g)
} }
var res = this.shiftImage(gid, r-1, 'vertical') var res = this.shiftImage(gid, r-1, 'vertical')
if(res == null){
return
}
// clear empty ribbon... // clear empty ribbon...
r = r == 0 ? 1 : r r = r == 0 ? 1 : r
if(this.ribbons[this.ribbon_order[r]].len == 0){ if(this.ribbons[this.ribbon_order[r]].len == 0){
@ -1629,13 +1636,17 @@ var DataPrototype = {
return res return res
}, },
shiftImageDown: function(gid){ shiftImageDown: function(gid){
var g = gid.constructor === Array ? gid[0] : gid gid = gid || this.current
var g = gid && gid.constructor === Array ? gid[0] : gid
var r = this.getRibbonOrder(g) var r = this.getRibbonOrder(g)
// check if we need to create a ribbon here... // check if we need to create a ribbon here...
if(r == this.ribbon_order.length-1){ if(r == this.ribbon_order.length-1){
this.newRibbon(g, 'below') this.newRibbon(g, 'below')
} }
var res = this.shiftImage(gid, r+1, 'vertical') var res = this.shiftImage(gid, r+1, 'vertical')
if(res == null){
return
}
// clear empty ribbon... // clear empty ribbon...
if(this.ribbons[this.ribbon_order[r]].len == 0){ if(this.ribbons[this.ribbon_order[r]].len == 0){
this.clear(this.ribbon_order[r]) this.clear(this.ribbon_order[r])