mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-12-17 08:41:40 +00:00
tweaking and testing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
d1f3b6e892
commit
88ae9d7e25
@ -81,7 +81,7 @@ core.ImageGridFeatures.Feature('viewer-testing', [
|
|||||||
// ui control...
|
// ui control...
|
||||||
'ui-clickable',
|
'ui-clickable',
|
||||||
//'ui-direct-control-jquery',
|
//'ui-direct-control-jquery',
|
||||||
'ui-direct-control-gsap',
|
//'ui-direct-control-gsap',
|
||||||
|
|
||||||
// experimental and optional features...
|
// experimental and optional features...
|
||||||
//'auto-single-image',
|
//'auto-single-image',
|
||||||
|
|||||||
@ -122,17 +122,21 @@ var transform2obj = function(str){
|
|||||||
// NOTE: this does not care about the actual semantics of the format,
|
// NOTE: this does not care about the actual semantics of the format,
|
||||||
// e.g. argument units or function names...
|
// e.g. argument units or function names...
|
||||||
var obj2transform = function(obj, filter){
|
var obj2transform = function(obj, filter){
|
||||||
|
// build the filters...
|
||||||
filter = filter || []
|
filter = filter || []
|
||||||
var keep = filter
|
var keep = filter
|
||||||
.filter(function(f){ return f[0] != '-' })
|
.filter(function(f){ return f[0] != '-' })
|
||||||
var remove = filter
|
var remove = filter
|
||||||
.filter(function(f){ return f[0] == '-' })
|
.filter(function(f){ return f[0] == '-' })
|
||||||
.map(function(f){ return f.slice(1) })
|
.map(function(f){ return f.slice(1) })
|
||||||
|
|
||||||
return Object.keys(obj)
|
return Object.keys(obj)
|
||||||
// keep...
|
// keep...
|
||||||
.filter(function(func){ return keep.length == 0 || keep.indexOf(func) >= 0 })
|
.filter(function(func){
|
||||||
|
return keep.length == 0 || keep.indexOf(func) >= 0 })
|
||||||
// remove...
|
// remove...
|
||||||
.filter(function(func){ return remove.indexOf(func) < 0 })
|
.filter(function(func){
|
||||||
|
return remove.indexOf(func) < 0 })
|
||||||
.map(function(func){
|
.map(function(func){
|
||||||
return func +'('+ obj[func].join(', ') + ')'
|
return func +'('+ obj[func].join(', ') + ')'
|
||||||
})
|
})
|
||||||
@ -175,13 +179,45 @@ var transformEditor = function(){
|
|||||||
|
|
||||||
|
|
||||||
// methods...
|
// methods...
|
||||||
toString: function(){ return obj2transform(this.data, args2array(arguments)) },
|
// XXX needs more work...
|
||||||
|
simplify: function(filter){
|
||||||
|
data = this.data
|
||||||
|
|
||||||
|
// scale...
|
||||||
|
if(data.scale){
|
||||||
|
if((data.scaleX||[])[0] == data.scale[0]){ delete data.scaleX }
|
||||||
|
if((data.scaleY||[])[0] == data.scale[1]){ delete data.scaleY }
|
||||||
|
if((data.scale||[])[0] == data.scale[1]){ data.scale = data.scale.slice(0, 1) }
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data.translate3d){
|
||||||
|
// XXX STUB
|
||||||
|
data.translate3d[0] = data.translate3d[0] || 0
|
||||||
|
data.translate3d[1] = data.translate3d[1] || 0
|
||||||
|
data.translate3d[2] = data.translate3d[2] || 0
|
||||||
|
|
||||||
|
// translate...
|
||||||
|
if(data.translate && data.translate3d){ delete data.translate }
|
||||||
|
|
||||||
|
// translate3d...
|
||||||
|
if((data.translateX||[])[0] == data.translate3d[0]){ delete data.translateX }
|
||||||
|
if((data.translateY||[])[0] == data.translate3d[1]){ delete data.translateY }
|
||||||
|
if((data.translateZ||[])[0] == data.translate3d[2]){ delete data.translateZ }
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.data
|
||||||
|
},
|
||||||
|
|
||||||
|
toString: function(){
|
||||||
|
//return obj2transform(this.data, args2array(arguments))
|
||||||
|
var args = args2array(arguments)
|
||||||
|
return obj2transform(this.simplify(args), args)
|
||||||
|
},
|
||||||
// NOTE: this will not build the alias data...
|
// NOTE: this will not build the alias data...
|
||||||
fromString: function(str){
|
fromString: function(str){
|
||||||
this.data = transform2obj(str)
|
this.data = transform2obj(str)
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
// XXX need to simplify first...
|
|
||||||
// XXX use vendor prefix...
|
// XXX use vendor prefix...
|
||||||
toElem: function(elem){
|
toElem: function(elem){
|
||||||
var origin = this.data.origin || ''
|
var origin = this.data.origin || ''
|
||||||
@ -191,9 +227,6 @@ var transformEditor = function(){
|
|||||||
: elem instanceof Array ? elem
|
: elem instanceof Array ? elem
|
||||||
: [elem]
|
: [elem]
|
||||||
|
|
||||||
// XXX simplify state...
|
|
||||||
// XXX
|
|
||||||
|
|
||||||
elem.forEach(function(e){
|
elem.forEach(function(e){
|
||||||
e.style.transformOrigin = origin.join ? origin.join(' ') : origin
|
e.style.transformOrigin = origin.join ? origin.join(' ') : origin
|
||||||
e.style.transform = transform
|
e.style.transform = transform
|
||||||
@ -202,6 +235,7 @@ var transformEditor = function(){
|
|||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// get data by attr names...
|
||||||
get: function(){
|
get: function(){
|
||||||
var that = this
|
var that = this
|
||||||
var attrs = arguments[0] instanceof Array ?
|
var attrs = arguments[0] instanceof Array ?
|
||||||
@ -227,7 +261,6 @@ var transformEditor = function(){
|
|||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
|
|
||||||
// XXX also load origin...
|
|
||||||
// XXX use vendor prefix...
|
// XXX use vendor prefix...
|
||||||
__init__: function(str){
|
__init__: function(str){
|
||||||
this.data = {}
|
this.data = {}
|
||||||
@ -299,22 +332,23 @@ var transformEditor = function(){
|
|||||||
// NOTE: this is the name of the called alias...
|
// NOTE: this is the name of the called alias...
|
||||||
var arg = args[spec[alias]]
|
var arg = args[spec[alias]]
|
||||||
|
|
||||||
// XXX get the correct return value...
|
|
||||||
return Object.keys(spec).map(function(k){
|
return Object.keys(spec).map(function(k){
|
||||||
var i = spec[k]
|
var i = spec[k]
|
||||||
|
|
||||||
if(args.length == 0){
|
if(args.length == 0){
|
||||||
return k in that.__direct ?
|
var res = k in that.__direct ?
|
||||||
that.__direct[k].call(that)
|
that.__direct[k].call(that)
|
||||||
: null
|
: null
|
||||||
|
return res != null ? res[i] : res
|
||||||
}
|
}
|
||||||
|
|
||||||
var a = []
|
var a = []
|
||||||
a[i] = arg
|
a[i] = arg
|
||||||
|
|
||||||
return k in that.__direct ?
|
var res = k in that.__direct ?
|
||||||
that.__direct[k].call(that, a)
|
that.__direct[k].call(that, a)
|
||||||
: null
|
: null
|
||||||
|
return res != null ? res[i] : res
|
||||||
})
|
})
|
||||||
.filter(function(e){ return e != null })
|
.filter(function(e){ return e != null })
|
||||||
.slice(-1)[0]
|
.slice(-1)[0]
|
||||||
@ -333,7 +367,7 @@ var transformEditor = function(){
|
|||||||
// wrap the original alias...
|
// wrap the original alias...
|
||||||
function(){
|
function(){
|
||||||
var args = args2array(arguments)
|
var args = args2array(arguments)
|
||||||
// XXX do a full search through the alias values...
|
// XXX do a full search through the alias values and merge results...
|
||||||
if(args.length == 0 && k in this.__direct){
|
if(args.length == 0 && k in this.__direct){
|
||||||
return this.__direct[k].call(this)
|
return this.__direct[k].call(this)
|
||||||
}
|
}
|
||||||
@ -364,13 +398,13 @@ var transformEditor = function(){
|
|||||||
alias({ translate3d: 2, translateZ: 0, z: 0, })
|
alias({ translate3d: 2, translateZ: 0, z: 0, })
|
||||||
|
|
||||||
func('scale', ['', ''])
|
func('scale', ['', ''])
|
||||||
func('scale3d', ['', '', ''])
|
//func('scale3d', ['', '', ''])
|
||||||
func('scaleX')
|
func('scaleX')
|
||||||
func('scaleY')
|
func('scaleY')
|
||||||
//func('scaleZ')
|
//func('scaleZ')
|
||||||
alias({ scale: 0, scale3d: 0, scaleX: 0, })
|
alias({ scale: 0, /*scale3d: 0,*/ scaleX: 0, })
|
||||||
alias({ scale: 1, scale3d: 1, scaleY: 0, })
|
alias({ scale: 1, /*scale3d: 1,*/ scaleY: 0, })
|
||||||
alias({ scale3d: 2, scaleZ: 0, })
|
//alias({ scale3d: 2, scaleZ: 0, })
|
||||||
|
|
||||||
// special case: single arg scale: scale(n) -> scale(n, n)
|
// special case: single arg scale: scale(n) -> scale(n, n)
|
||||||
editor._scale = editor.scale
|
editor._scale = editor.scale
|
||||||
@ -380,7 +414,9 @@ var transformEditor = function(){
|
|||||||
&& arguments[0] != '='){
|
&& arguments[0] != '='){
|
||||||
return this._scale.call(this, arguments[0], arguments[0])
|
return this._scale.call(this, arguments[0], arguments[0])
|
||||||
}
|
}
|
||||||
return this._scale.apply(this, arguments)
|
var res = this._scale.apply(this, arguments)
|
||||||
|
// is this correct here???
|
||||||
|
return res.length == 2 && res[0] == res[1] ? res[0] : res
|
||||||
}
|
}
|
||||||
|
|
||||||
func('rotate', ['deg'])
|
func('rotate', ['deg'])
|
||||||
@ -481,12 +517,21 @@ jQuery.fn.transform = function(){
|
|||||||
|
|
||||||
// shorthands...
|
// shorthands...
|
||||||
jQuery.fn.scale = function(value){
|
jQuery.fn.scale = function(value){
|
||||||
if(value){
|
if(arguments.length > 0){
|
||||||
return $(this).transform({scale: value})
|
return $(this).transform({scale: args2array(arguments)})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return $(this).transform('scale')
|
return $(this).transform('scale')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// get element scale...
|
||||||
|
jQuery.fn.getscale = function(){
|
||||||
|
var res = 1
|
||||||
|
$(this).parents().toArray().forEach(function(e){
|
||||||
|
res *= $(e).scale() || 1
|
||||||
|
})
|
||||||
|
return res
|
||||||
|
}
|
||||||
jQuery.fn.origin = function(a, b, c){
|
jQuery.fn.origin = function(a, b, c){
|
||||||
if(a != null && b != null){
|
if(a != null && b != null){
|
||||||
return $(this).transform({origin: [a, b, c == null ? 0 : c]})
|
return $(this).transform({origin: [a, b, c == null ? 0 : c]})
|
||||||
@ -501,6 +546,50 @@ jQuery.fn.origin = function(a, b, c){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
// XXX experiment
|
||||||
|
jQuery.fn._drag = function(){
|
||||||
|
var dragging = false
|
||||||
|
var s,
|
||||||
|
px, py
|
||||||
|
|
||||||
|
var elem = $(this)
|
||||||
|
.on('mousedown touchstart', function(evt){
|
||||||
|
dragging = true
|
||||||
|
px = evt.clientX
|
||||||
|
px = evt.clientY
|
||||||
|
|
||||||
|
s = elem.getscale()
|
||||||
|
})
|
||||||
|
.on('mousemove touchmove', function(evt){
|
||||||
|
if(!dragging){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var x = evt.clientX
|
||||||
|
var dx = px - x
|
||||||
|
px = x
|
||||||
|
|
||||||
|
var y = evt.clientY
|
||||||
|
var dy = py - y
|
||||||
|
py = y
|
||||||
|
|
||||||
|
elem
|
||||||
|
.velocity('stop')
|
||||||
|
.velocity({
|
||||||
|
translateX: '-=' + (dx / s),
|
||||||
|
translateY: '-=' + (dy / s),
|
||||||
|
}, 0)
|
||||||
|
})
|
||||||
|
.on('mouseup touchend', function(evt){
|
||||||
|
dragging = false
|
||||||
|
elem.velocity('stop')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* vim:set ts=4 sw=4 : */
|
* vim:set ts=4 sw=4 : */
|
||||||
return module })
|
return module })
|
||||||
|
|||||||
@ -62,26 +62,41 @@ var RIBBON = '.ribbon:not(.clone)'
|
|||||||
//
|
//
|
||||||
// XXX need to replace soemlegacy CSS API and make this compatible with
|
// XXX need to replace soemlegacy CSS API and make this compatible with
|
||||||
// modern libs like velocity.js...
|
// modern libs like velocity.js...
|
||||||
|
if(false){ // XXX still problems with translate...
|
||||||
// - jli.getElementOrigin(..)
|
// - jli.getElementOrigin(..)
|
||||||
|
getElementOrigin = function(elem){
|
||||||
|
var o = $(elem).origin() || [0, 0]
|
||||||
|
return { left: o[0], top: o[1], }
|
||||||
|
}
|
||||||
// <elem>.transform('origin')
|
// <elem>.transform('origin')
|
||||||
//
|
//
|
||||||
// - jli.getElementScale(..)
|
// - jli.getElementScale(..)
|
||||||
// <elem>.transform('scale')
|
getElementScale = function(elem){ return $(elem).scale() }
|
||||||
//
|
//
|
||||||
// - jli.getRelativeOffset(..)
|
// - jli.getRelativeOffset(..)
|
||||||
// XXX offset if x from y...
|
getElementOffset = function(elem){
|
||||||
|
var o = $(elem).transform('x', 'y')
|
||||||
|
return { left: o.x, top: o.y, }
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// - jli.setElementOffset(..)
|
// - jli.setElementOffset(..)
|
||||||
// <elem>.transform({x: <X>, y: <Y>, z: 0})
|
// // XXX still does not work for some reason...
|
||||||
// <elem>.velocity({translateX: <X>, translateY: <Y>, translateZ: 0})
|
setElementOffset = function(elem, l, t){
|
||||||
|
//return $(elem).velocity({translateX: l, translateY: t})
|
||||||
|
return $(elem).transform({x: l || 0, y: t || 0, z: 0})
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// - jli.setElementScale(..)
|
// - jli.setElementScale(..)
|
||||||
// <elem>.transform({scale, <scale>})
|
setElementScale = function(elem, scale){
|
||||||
// <elem>.velocity({scale, <scale>})
|
//return $(elem).velocity({scale: scale || 1}, 150)
|
||||||
|
return $(elem).scale(scale || 1)
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// - jli.shiftOriginTo(..)
|
// - jli.shiftOriginTo(..)
|
||||||
// XXX this sets origin and compensates for offsets...
|
// XXX this sets origin and compensates for offsets...
|
||||||
|
// ...to make shifting origin not affect element visual position...
|
||||||
//
|
//
|
||||||
|
}
|
||||||
// XXX think if a way to manage animation timings...
|
// XXX think if a way to manage animation timings...
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user