added reference support to image.flipImage(..)

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-11-25 03:34:46 +03:00
parent d0e2887ec1
commit 8e4bbfa970
3 changed files with 20 additions and 10 deletions

View File

@ -1755,18 +1755,22 @@ var DataPrototype = {
return this return this
}, },
// XXX if the group is collapsed there will be problems with uncropping... // Croup current group...
//
cropGroup: function(target){ cropGroup: function(target){
var target = this.getImage(target) var target = this.getImage(target)
var group = this.getGroup(target) var group = this.getGroup(target)
// not a group...
if(group == null){ if(group == null){
return return
} }
if(target == group){ // group is expanded -- all the images we need are loaded...
if(target != group){
var res = this.crop(this.groups[group]) var res = this.crop(this.groups[group])
// group collapsed -- need to get the elements manually...
} else { } else {
var r = this.getRibbon(target) var r = this.getRibbon(target)
var res = this.crop(this.groups[group]) var res = this.crop(this.groups[group])

View File

@ -549,24 +549,31 @@ module.ImagesPrototype = {
// .flipImage(target, 'vertical') // .flipImage(target, 'vertical')
// -> images // -> images
// //
// XXX add reference support...
flipImage: function(gids, direction, reference){ flipImage: function(gids, direction, reference){
gids = gids.constructor !== Array ? [gids] : gids gids = gids.constructor !== Array ? [gids] : gids
reference = reference || 'image' reference = reference || 'view'
var that = this var that = this
gids.forEach(function(key){ gids.forEach(function(key){
var img = that[key] var img = that[key]
var o = img.orientation
var d = direction
// flip relative to
if(reference == 'view' && (o == 90 || o == 270)){
d = d == 'horizontal' ? 'vertical' : 'horizontal'
}
if(img == null){ if(img == null){
img = that[key] = {} img = that[key] = {}
} }
var state = img.flipped var state = img.flipped
state = state == null ? [] : state state = state == null ? [] : state
// toggle the specific state... // toggle the specific state...
var i = state.indexOf(direction) var i = state.indexOf(d)
if(i >= 0){ if(i >= 0){
state.splice(i, 1) state.splice(i, 1)
} else { } else {
state.push(direction) state.push(d)
} }
if(state.length == 0){ if(state.length == 0){
delete img.flipped delete img.flipped

View File

@ -1619,7 +1619,7 @@ var RibbonsPrototype = {
// it's original orientation by default... // it's original orientation by default...
// ...this makes things consistent both visually and internally // ...this makes things consistent both visually and internally
flipImage: function(target, direction, reference){ flipImage: function(target, direction, reference){
reference = reference || 'image' reference = reference || 'view'
target = target == null || target.constructor !== Array ? [target] : target target = target == null || target.constructor !== Array ? [target] : target
var set_state = direction.constructor === Array ? direction : null var set_state = direction.constructor === Array ? direction : null
@ -1630,10 +1630,9 @@ var RibbonsPrototype = {
// update existing state... // update existing state...
if(set_state == null){ if(set_state == null){
var d = direction
if(reference == 'view' && [90, 270].indexOf(that.getImageRotation(img)) > -1){ if(reference == 'view' && [90, 270].indexOf(that.getImageRotation(img)) > -1){
var d = direction == 'vertical' ? 'horizontal' : 'vertical' d = direction == 'vertical' ? 'horizontal' : 'vertical'
} else {
var d = direction
} }
var state = img.attr('flipped') var state = img.attr('flipped')
state = (state == null ? '' : state) state = (state == null ? '' : state)