From 1bb34d8d601fc437fdd67cbcfb0865d568397dcd Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 28 Nov 2016 20:08:08 +0300 Subject: [PATCH] refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/base.js | 24 +++++++++++++++++------- ui (gen4)/features/core.js | 6 ++++++ ui (gen4)/features/ui-chrome.js | 4 ++-- ui (gen4)/features/ui.js | 8 ++++++++ ui (gen4)/imagegrid/data.js | 15 +++++++++++++-- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index d08bbc77..6050acb2 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -99,7 +99,7 @@ actions.Actions({ // Base ribbon... get base(){ - return this.data == null ? null : this.data.base + return this.data.base }, set base(value){ this.setBaseRibbon(value) @@ -107,7 +107,7 @@ actions.Actions({ // Current image... get current(){ - return this.data == null ? null : this.data.current + return this.data.current }, set current(value){ this.focusImage(value) @@ -115,7 +115,7 @@ actions.Actions({ // Current ribbon... get currentRibbon(){ - return this.data == null ? null : this.data.getRibbon() + return this.data.getRibbon() }, set currentRibbon(value){ this.focusRibbon(value) @@ -275,8 +275,7 @@ actions.Actions({ // basic navigation... // focusImage: ['- Navigate/Focus image', - function(img, list){ - this.data.focusImage(img, list) }], + function(img, list){ this.data.focusImage(img, list) }], // Focuses a ribbon by selecting an image in it... // // modes supported: @@ -290,6 +289,10 @@ actions.Actions({ focusRibbon: ['- Navigate/Focus Ribbon', function(target, mode){ var data = this.data + if(data == null){ + return + } + var r = data.getRibbon(target) if(r == null){ return @@ -741,7 +744,7 @@ module.TagsActions = actions.Actions({ function(source, mode){ // can't do anything if either .data or .images are not // defined... - if(this.data == null || this.images == null){ + if(this.images == null){ return } @@ -838,6 +841,10 @@ module.CropActions = actions.Actions({ // crop: ['- Crop/Crop image list', function(list, flatten){ + if(this.data.length == 0){ + return + } + //list = list || this.data.order list = list || this.data.getImages() @@ -929,8 +936,11 @@ module.CropActions = actions.Actions({ ribbon = ribbon || this.data.getRibbon() var data = this.data - var that = this + if(data == null){ + return + } + var that = this var i = data.ribbon_order.indexOf(ribbon) var ribbons = data.ribbon_order.slice(0, i) var images = ribbons diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index b6ebc704..86a83581 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -18,6 +18,8 @@ var actions = require('lib/actions') var features = require('lib/features') var toggler = require('lib/toggler') +var data = require('imagegrid/data') + /*********************************************************************/ @@ -80,6 +82,10 @@ function(attr, states, a, b){ // var 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... // isToggler: actions.doWithRootAction(function(action){ diff --git a/ui (gen4)/features/ui-chrome.js b/ui (gen4)/features/ui-chrome.js index 4811b585..77737e0d 100755 --- a/ui (gen4)/features/ui-chrome.js +++ b/ui (gen4)/features/ui-chrome.js @@ -20,9 +20,9 @@ var core = require('features/core') // helper... function didAdvance(indicator){ return function(){ - var img = this.data.current + var img = this.data ? this.data.current : null return function(){ - if(img == this.data.current){ + if(img == null || img == this.data.current){ this.flashIndicator(indicator) } } diff --git a/ui (gen4)/features/ui.js b/ui (gen4)/features/ui.js index 8230d64a..d6638042 100755 --- a/ui (gen4)/features/ui.js +++ b/ui (gen4)/features/ui.js @@ -429,6 +429,10 @@ module.ViewerActions = actions.Actions({ var ribbons = this.ribbons var data = this.data + if(data == null){ + return + } + // XXX handle raw dom elements... var gid = target instanceof jQuery ? ribbons.getElemGID(target) @@ -490,6 +494,10 @@ module.ViewerActions = actions.Actions({ var ribbons = this.ribbons var data = this.data + if(data == null){ + return + } + // XXX handle raw dom elements... var gid = target instanceof jQuery ? ribbons.getElemGID(target) diff --git a/ui (gen4)/imagegrid/data.js b/ui (gen4)/imagegrid/data.js index 5f8549b2..cc8a450e 100755 --- a/ui (gen4)/imagegrid/data.js +++ b/ui (gen4)/imagegrid/data.js @@ -1568,6 +1568,9 @@ var DataPrototype = { // XXX needs better docs... shiftImage: function(from, target, mode, direction){ from = from == null || from == 'current' ? this.current : from + if(from == null){ + return + } from = from.constructor !== Array ? [from] : from var place @@ -1613,7 +1616,8 @@ var DataPrototype = { // NOTE: if base ribbon is removed this will try and reset it to the // ribbon above or the top ribbon... 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) // check if we need to create a ribbon here... if(r == 0){ @@ -1621,6 +1625,9 @@ var DataPrototype = { this.newRibbon(g) } var res = this.shiftImage(gid, r-1, 'vertical') + if(res == null){ + return + } // clear empty ribbon... r = r == 0 ? 1 : r if(this.ribbons[this.ribbon_order[r]].len == 0){ @@ -1629,13 +1636,17 @@ var DataPrototype = { return res }, 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) // check if we need to create a ribbon here... if(r == this.ribbon_order.length-1){ this.newRibbon(g, 'below') } var res = this.shiftImage(gid, r+1, 'vertical') + if(res == null){ + return + } // clear empty ribbon... if(this.ribbons[this.ribbon_order[r]].len == 0){ this.clear(this.ribbon_order[r])