From edea39a2dee9355da0e30cce15c2fafe79c245cb Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 22 Oct 2014 01:23:56 +0400 Subject: [PATCH] some refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/data.js | 16 ++++++------ ui (gen4)/images.js | 10 +++---- ui (gen4)/lib/keyboard.js | 13 +++------ ui (gen4)/ribbons.js | 51 +++--------------------------------- ui (gen4)/ui.js | 7 ++--- ui (gen4)/viewer.js | 55 ++++++++++++++++++--------------------- 6 files changed, 48 insertions(+), 104 deletions(-) diff --git a/ui (gen4)/data.js b/ui (gen4)/data.js index 637a70b3..c9243f5a 100755 --- a/ui (gen4)/data.js +++ b/ui (gen4)/data.js @@ -390,7 +390,7 @@ module.DataPrototype = { // normalize mode... if(mode != null - && mode.constructor.name == 'Array' + && mode.constructor === Array || mode in this.ribbons){ list = mode mode = null @@ -568,7 +568,7 @@ module.DataPrototype = { target = null // filter out the unloaded gids from given list... - } else if(target != null && target.constructor.name == 'Array'){ + } else if(target != null && target.constructor === Array){ var loaded = this.getImages('loaded') list = target.filter(function(e){ return loaded.indexOf(e) >= 0 @@ -943,7 +943,7 @@ module.DataPrototype = { shiftImage: function(from, target, mode){ from = from == null ? this.current : from from = from == 'current' ? this.current : from - from = from.constructor.name != 'Array' ? [from] : from + from = from.constructor !== Array ? [from] : from mode = mode == null ? 'after' : mode var ribbons = this.ribbons var order = this.order @@ -1060,7 +1060,7 @@ module.DataPrototype = { shiftImageLeft: function(gid){ return this.shiftImage(gid, -1, 'offset') }, // Gen2 shiftImageRight: function(gid){ return this.shiftImage(gid, 1, 'offset') }, // Gen2 shiftImageUp: function(gid){ - var g = gid.constructor.name == 'Array' ? gid[0] : gid + var g = gid.constructor === Array ? gid[0] : gid var r = this.getRibbonOrder(g) // check if we need to create a ribbon here... if(r == 0){ @@ -1075,7 +1075,7 @@ module.DataPrototype = { return res }, shiftImageDown: function(gid){ - var g = gid.constructor.name == 'Array' ? gid[0] : gid + var g = 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){ @@ -1174,7 +1174,7 @@ module.DataPrototype = { if(arguments.length > 1){ target = Array.apply(null, arguments) } else if(target == null - || target.constructor.name != 'Array'){ + || target.constructor !== Array){ target = [ target ] } var res = [] @@ -1230,7 +1230,7 @@ module.DataPrototype = { join: function(){ var args = Array.apply(null, arguments) var align = typeof(args[0]) == typeof('str') ? args.splice(0, 1)[0] : 'base' - args = args[0].constructor.name == 'Array' ? args[0] : args + args = args[0].constructor === Array ? args[0] : args var base = this @@ -1605,7 +1605,7 @@ var Data = module.Data = function Data(json){ // in case this is called as a function (without new)... - if(this.constructor.name != 'Data'){ + if(this.constructor !== Data){ return new Data(json) } diff --git a/ui (gen4)/images.js b/ui (gen4)/images.js index b2e6279c..ecf6fbc4 100755 --- a/ui (gen4)/images.js +++ b/ui (gen4)/images.js @@ -286,7 +286,7 @@ module.ImagesPrototype = { // XXX test out the attr list functionality... makeIndex: function(attr){ var res = {} - attr = attr.constructor.name != 'Array' ? [attr] : attr + attr = attr.constructor !== Array ? [attr] : attr // buld the index... var that = this @@ -360,7 +360,7 @@ module.ImagesPrototype = { gids = gids == null ? Object.keys(this) : gids cmp = cmp == null ? module.makeImageDateCmp(this) : cmp - cmp = cmp.constructor.name == 'Array' ? chainCmp(cmp) : cmp + cmp = cmp.constructor === Array ? chainCmp(cmp) : cmp gids = gids.sort(cmp) gids = reverse ? gids.reverse() : gids @@ -408,7 +408,7 @@ module.ImagesPrototype = { // // NOTE: target can be a gid or a list of gids... rotateImage: function(gids, direction){ - gids = gids.constructor.name != 'Array' ? [gids] : gids + gids = gids.constructor !== Array ? [gids] : gids // validate direction... if(module.calcRelativeRotation(direction) == null){ return this @@ -441,7 +441,7 @@ module.ImagesPrototype = { // -> images // flipImage: function(gids, direction){ - gids = gids.constructor.name != 'Array' ? [gids] : gids + gids = gids.constructor !== Array ? [gids] : gids var that = this gids.forEach(function(key){ var img = that[key] @@ -492,7 +492,7 @@ var Images = module.Images = function Images(json){ // in case this is called as a function (without new)... - if(this.constructor.name != 'Images'){ + if(this.constructor !== Images){ return new Images(json) } diff --git a/ui (gen4)/lib/keyboard.js b/ui (gen4)/lib/keyboard.js index 23931d6f..2d3005db 100755 --- a/ui (gen4)/lib/keyboard.js +++ b/ui (gen4)/lib/keyboard.js @@ -151,7 +151,7 @@ function doc(text, func){ var normalizeModifiers = module.normalizeModifiers = function normalizeModifiers(c, a, s){ - if(c != null && c.constructor.name == 'Array'){ + if(c != null && c.constructor === Array){ a = c[1] s = c[2] c = c[0] @@ -331,12 +331,7 @@ function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys, action // alias... // XXX should this be before after or combined with ignore handling... - while( handler != null - && typeof(handler) != 'function'){ - //&& (typeof(handler) == typeof(123) - // || typeof(handler) == typeof('str') - // || typeof(handler) == typeof({}) - // && handler.constructor.name == 'Object') ){ + while( handler != null && typeof(handler) != 'function'){ // do the complex handler aliases... if(handler != null && handler.constructor == Object){ @@ -688,7 +683,7 @@ function buildKeybindingsHelp(keybindings, shifted_keys, actions){ var handler = getKeyHandlers(key, mod, keybindings, 'all', null, actions)[pattern] - if(handler.constructor.name == 'Array' && handler[1] == 'IGNORE NEXT'){ + if(handler.constructor === Array && handler[1] == 'IGNORE NEXT'){ handler = handler[0] } @@ -697,7 +692,7 @@ function buildKeybindingsHelp(keybindings, shifted_keys, actions){ var doc = handler.doc // lisp style... - } else if(handler.constructor.name == 'Array'){ + } else if(handler.constructor === Array){ var doc = handler[1] // no doc... diff --git a/ui (gen4)/ribbons.js b/ui (gen4)/ribbons.js index 235ab4f1..c8bafd51 100755 --- a/ui (gen4)/ribbons.js +++ b/ui (gen4)/ribbons.js @@ -23,49 +23,6 @@ var IMAGE_UPDATERS = module.IMAGE_UPDATERS = [] -/*********************************************************************/ - -// XXX add inheritance... -var makeObject = -module.makeObject = -function makeObject(name, cls, obj){ - // NOTE: we are using eval here to name the function correctly as - // simply assigning .name does not work... - // XXX think of a cleaner way... - var O = function OBJECT(){ - if(this.constructor.name != name){ - return new (Function.prototype.bind.apply( - OBJECT, - arguments.length == 1 ? [null, arguments[0]] - : [null].concat(Array.apply(null, arguments)))) - } - - if(this.__init__ != null){ - this.__init__.apply(this, arguments) - } - - return this - } - - if(name != null){ - O = eval(O - .toString() - .replace(/OBJRCT/g, name)) - } - - if(cls != null){ - O.__proto__ = cls - } - if(obj != null){ - O.prototype = obj - } - O.prototype.constructor = O - - return O -} - - - /*********************************************************************/ // // This expects the following HTML structure... @@ -1165,7 +1122,7 @@ module.RibbonsPrototype = { // clear one or more gids... } else { - gids = gids.constructor.name != 'Array' ? [gids] : gids + gids = gids.constructor !== Array ? [gids] : gids var that = this gids.forEach(function(g){ that.viewer.find('[gid='+JSON.stringify(g)+']').remove() @@ -1255,7 +1212,7 @@ module.RibbonsPrototype = { image = null } image = this.getImage(image) - cls = cls.constructor.name != 'Array' ? [cls] : cls + cls = cls.constructor !== Array ? [cls] : cls action = action == null ? 'toggle' : action // no image is loaded... @@ -1361,7 +1318,7 @@ module.RibbonsPrototype = { // loaded images vertically. flipImage: function(target, direction){ target = this.getImage(target) - var set_state = direction.constructor.name == 'Array' ? direction : null + var set_state = direction.constructor === Array ? direction : null target.each(function(i, e){ var img = $(this) @@ -1566,7 +1523,7 @@ var Ribbons = module.Ribbons = function Ribbons(viewer, images){ // in case this is called as a function (without new)... - if(this.constructor.name != 'Ribbons'){ + if(this.constructor !== Ribbons){ return new Ribbons(viewer, images) } diff --git a/ui (gen4)/ui.js b/ui (gen4)/ui.js index 864e0529..08d090df 100755 --- a/ui (gen4)/ui.js +++ b/ui (gen4)/ui.js @@ -83,10 +83,7 @@ module.GLOBAL_KEYBOARD = { // NOTE: this is handled by the wrapper at this point, so we do // not have to do anything here... - F11: doc('Toggle full screen view', function(){ - toggleFullscreenMode() - return false - }), + F11: 'toggleFullScreen', F: { ctrl: 'F11', }, @@ -155,7 +152,7 @@ $(function(){ window.a = testing.setupActions() - viewer.Animation.setup(a) + viewer.ShiftAnimation.setup(a) viewer.BoundsIndicators.setup(a) // this publishes all the actions... diff --git a/ui (gen4)/viewer.js b/ui (gen4)/viewer.js index ba133461..f6ed17b6 100755 --- a/ui (gen4)/viewer.js +++ b/ui (gen4)/viewer.js @@ -395,6 +395,29 @@ actions.Actions({ function(){ // XXX }], + + cropRibbon: ['Crop current ribbon', + function(ribbon, flatten){ + ribbon = ribbon || 'current' + this.crop(this.data.getImages(ribbon), flatten) + }], + cropRibbonAndAbove: ['Crop current and above ribbons', + function(ribbon, flatten){ + ribbon = ribbon || this.data.getRibbon() + + var data = this.data + var that = this + + var i = data.ribbon_order.indexOf(ribbon) + var ribbons = data.ribbon_order.slice(0, i) + var images = ribbons + .reduce(function(a, b){ + return data.getImages(a).concat(data.getImages(b)) + }, data.getImages(ribbon)) + .compact() + + this.crop(data.getImages(images), flatten) + }], }) @@ -609,10 +632,6 @@ actions.Actions(Client, { shiftImageUp: [ reloadAfter() ], shiftImageDown: [ reloadAfter() ], - // NOTE: .shiftImageDownNewRibbon(..) and .shiftImageUpNewRibbon(..) - // are not needed here when doing a reload on vertical - // shifting... - shiftImageLeft: [ function(target){ this.ribbons.placeImage(target, -1) @@ -659,30 +678,6 @@ actions.Actions(Client, { crop: [ reloadAfter() ], uncrop: [ reloadAfter() ], - - // XXX need flat version of these... - cropRibbon: ['Crop current ribbon', - function(ribbon, flatten){ - ribbon = ribbon || 'current' - this.crop(this.data.getImages(ribbon), flatten) - }], - cropRibbonAndAbove: ['', - function(ribbon, flatten){ - ribbon = ribbon || this.data.getRibbon() - - var data = this.data - var that = this - - var i = data.ribbon_order.indexOf(ribbon) - var ribbons = data.ribbon_order.slice(0, i) - var images = ribbons - .reduce(function(a, b){ - return data.getImages(a).concat(data.getImages(b)) - }, data.getImages(ribbon)) - .compact() - - this.crop(data.getImages(images), flatten) - }], }) @@ -692,8 +687,8 @@ actions.Actions(Client, { // ...need something like: // Features(['feature_a', 'feature_b'], action).setup() -var Animation = -module.Animation = { +var ShiftAnimation = +module.ShiftAnimation = { tag: 'ui-animation', setup: function(actions){