mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-11-01 03:40:09 +00:00
rewritten .placeImage(..)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9056834c07
commit
cc43b7c4eb
@ -248,57 +248,58 @@ module.RibbonsPrototype = {
|
|||||||
|
|
||||||
// Place an image...
|
// Place an image...
|
||||||
//
|
//
|
||||||
// Place gid at image position and image ribbon:
|
// Place gid at at offset from current position:
|
||||||
|
// .placeImage(gid, offset)
|
||||||
|
// -> image
|
||||||
|
//
|
||||||
|
// Place gid at image position:
|
||||||
// .placeImage(gid, image)
|
// .placeImage(gid, image)
|
||||||
// -> image
|
// .placeImage(gid, image, 'before')
|
||||||
//
|
// .placeImage(gid, image, 'after')
|
||||||
// Place gid at index in current ribbon:
|
|
||||||
// .placeImage(gid, position)
|
|
||||||
// -> image
|
|
||||||
//
|
|
||||||
// Place gid at position in ribbon:
|
|
||||||
// .placeImage(gid, ribbon, position)
|
|
||||||
// -> image
|
// -> image
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
// NOTE: mode is defaults to 'before'.
|
||||||
// NOTE: if image gid does not exist it will be created.
|
// NOTE: if image gid does not exist it will be created.
|
||||||
// NOTE: index can be negative indicating the position from the tail.
|
//
|
||||||
// NOTE: if index is an image or a gid then the ribbon argument will
|
|
||||||
// be ignored and the actual ribbon will be derived from the
|
|
||||||
// image given.
|
|
||||||
// XXX interaction animation...
|
// XXX interaction animation...
|
||||||
placeImage: function(target, ribbon, position){
|
// XXX mode is ugly...
|
||||||
// get/create the image...
|
placeImage: function(target, to, mode){
|
||||||
|
mode = mode == null ? 'before' : mode
|
||||||
var img = this.getImage(target)
|
var img = this.getImage(target)
|
||||||
img = img.length == 0 ? this.createImage(target) : img
|
img = img.length == 0 ? this.createImage(target) : img
|
||||||
|
|
||||||
// normalize the position, ribbon and images...
|
// offset on same ribbon...
|
||||||
if(position == null){
|
if(typeof(to) == typeof(123)){
|
||||||
position = ribbon
|
if(to == 0){
|
||||||
ribbon = null
|
return target
|
||||||
|
}
|
||||||
|
var i = to
|
||||||
|
var images = img[i > 0 ? 'nextAll' : 'prevAll']('.image')
|
||||||
|
to = images.length > 0
|
||||||
|
? images.eq(Math.min(Math.abs(i), images.length)-1)
|
||||||
|
: img
|
||||||
|
// relative to image...
|
||||||
|
} else {
|
||||||
|
var i = mode == 'before' ? -1 : 1
|
||||||
|
to = this.getImage(to)
|
||||||
|
var images = to[mode]('.image')
|
||||||
}
|
}
|
||||||
var p = this.getImage(position)
|
|
||||||
ribbon = p.hasClass('image')
|
|
||||||
? p.parents('.ribbon').first()
|
|
||||||
: this.getRibbon(ribbon)
|
|
||||||
var images = ribbon.find('.image')
|
|
||||||
position = p.hasClass('image') ? images.index(p) : position
|
|
||||||
position = position < 0 ? images.length + position + 1 : position
|
|
||||||
position = position < 0 ? 0 : position
|
|
||||||
|
|
||||||
// place the image...
|
// place the image...
|
||||||
if(images.length == 0 || images.length <= position){
|
if(images.length <= i){
|
||||||
ribbon.append(img)
|
to.parents('.ribbon').append(img)
|
||||||
|
// after...
|
||||||
|
} else if(i > 0){
|
||||||
|
to.next('.image').before(img)
|
||||||
|
// before...
|
||||||
} else {
|
} else {
|
||||||
images.eq(position).before(img)
|
to.before(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
return _UPDATE_IMAGE ? image.updateImage(img) : img
|
return _UPDATE_IMAGE ? image.updateImage(img) : img
|
||||||
},
|
},
|
||||||
|
|
||||||
// XXX do we need shorthands like shiftImageUp/shiftImageDown/... here?
|
|
||||||
|
|
||||||
|
|
||||||
// Bulk manipulation...
|
// Bulk manipulation...
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user