mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-11-02 12:20:08 +00:00
added shadow recycling...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
15412b7cf5
commit
3a929ab7eb
@ -333,15 +333,55 @@ module.RibbonsPrototype = {
|
|||||||
// <delay> sets the delay before the shadow is removed and the target
|
// <delay> sets the delay before the shadow is removed and the target
|
||||||
// state is restored (default: 200).
|
// state is restored (default: 200).
|
||||||
//
|
//
|
||||||
|
//
|
||||||
|
// NOTE: if a previous shadow if the same image exists this will recycle
|
||||||
|
// the existing shadow and cancel it's removal.
|
||||||
|
//
|
||||||
// XXX make this work for multiple targets...
|
// XXX make this work for multiple targets...
|
||||||
|
// XXX do we need this to adapt to scaling???
|
||||||
|
// ...if so, then we'll need to place the shadow inside the
|
||||||
|
// ribbon-set...
|
||||||
makeShadow: function(target, animate, delay){
|
makeShadow: function(target, animate, delay){
|
||||||
delay = delay || 200
|
delay = delay || 200
|
||||||
var img = this.getImage(target)
|
var img = this.getImage(target)
|
||||||
var gid = this.getElemGID(img)
|
var gid = this.getElemGID(img)
|
||||||
var s = this.getScale()
|
var s = this.getScale()
|
||||||
var shadow = setElementScale($('<div>')
|
var vo = this.viewer.offset()
|
||||||
|
var io = img.offset()
|
||||||
|
|
||||||
|
// get the shadow if it exists...
|
||||||
|
var shadow = this.viewer.find('.shadow[gid="'+gid+'"]')
|
||||||
|
|
||||||
|
// recycle the shadow...
|
||||||
|
if(shadow.length > 0){
|
||||||
|
// cancel previous shadow removal ticket...
|
||||||
|
var ticket = shadow.attr('ticket') + 1
|
||||||
|
shadow
|
||||||
|
// reset ticket...
|
||||||
|
// NOTE: this is a possible race condition... (XXX)
|
||||||
|
.attr('ticket', ticket)
|
||||||
|
// place it over the current image...
|
||||||
|
.css({
|
||||||
|
top: io.top - vo.top,
|
||||||
|
left: io.left - vo.left,
|
||||||
|
})
|
||||||
|
|
||||||
|
// create a new shadow...
|
||||||
|
} else {
|
||||||
|
// removal ticket...
|
||||||
|
var ticket = 0
|
||||||
|
|
||||||
|
// make a shadow element...
|
||||||
|
// ...we need to scale it to the current scale...
|
||||||
|
var shadow = setElementScale(
|
||||||
|
$('<div>')
|
||||||
.addClass('shadow')
|
.addClass('shadow')
|
||||||
|
.attr({
|
||||||
|
gid: gid,
|
||||||
|
ticket: ticket,
|
||||||
|
})
|
||||||
.append(
|
.append(
|
||||||
|
// clone the target into the shadow..
|
||||||
img
|
img
|
||||||
.clone()
|
.clone()
|
||||||
.removeClass('current')
|
.removeClass('current')
|
||||||
@ -350,21 +390,42 @@ module.RibbonsPrototype = {
|
|||||||
width: img.width(),
|
width: img.width(),
|
||||||
height: img.height(),
|
height: img.height(),
|
||||||
}), s)
|
}), s)
|
||||||
.css(img.offset())
|
// place it over the current image...
|
||||||
|
.css({
|
||||||
|
top: io.top - vo.top,
|
||||||
|
left: io.left - vo.left,
|
||||||
|
})
|
||||||
|
// place in the viewer...
|
||||||
|
// NOTE: placing the shadow in the viewer is a compromise that
|
||||||
|
// lets us do simpler positioning
|
||||||
.appendTo(this.viewer)
|
.appendTo(this.viewer)
|
||||||
|
}
|
||||||
|
|
||||||
img.addClass('moving')
|
img.addClass('moving')
|
||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
|
// function to clear the shadow...
|
||||||
return function(){
|
return function(){
|
||||||
|
// remove only the item with the correct ticket...
|
||||||
|
if(ticket == shadow.attr('ticket')){
|
||||||
var s = that.getScale()
|
var s = that.getScale()
|
||||||
var img = that.getImage(gid)
|
var img = that.getImage(gid)
|
||||||
|
var vo = that.viewer.offset()
|
||||||
|
var io = img.offset()
|
||||||
if(animate){
|
if(animate){
|
||||||
shadow.css(img.offset())
|
shadow.css({
|
||||||
|
top: io.top - vo.top,
|
||||||
|
left: io.left - vo.left,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
|
// remove only the item with the correct ticket...
|
||||||
|
if(ticket == shadow.attr('ticket')){
|
||||||
img.removeClass('moving')
|
img.removeClass('moving')
|
||||||
shadow.remove()
|
shadow.remove()
|
||||||
|
}
|
||||||
}, delay)
|
}, delay)
|
||||||
|
}
|
||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user