-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.js
147 lines (121 loc) · 3.84 KB
/
item.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//Overriding to add height and width to transitionProps.
( function( window, factory ) {
'use strict';
// universal module definition
// browser global
window.AnyGrid = window.AnyGrid || {};
window.AnyGrid.Item = factory(
window.Outlayer
);
}( window, function factory( Outlayer ) {
'use strict';
// -------------------------- Item -------------------------- //
var transitionProperty = getStyleProperty('transition');
var transformProperty = getStyleProperty('transform');
var supportsCSS3 = transitionProperty && transformProperty;
var is3d = !!getStyleProperty('perspective');
var transitionEndEvent = {
WebkitTransition: 'webkitTransitionEnd',
MozTransition: 'transitionend',
OTransition: 'otransitionend',
transition: 'transitionend'
}[ transitionProperty ];
// properties that could have vendor prefix
var prefixableProperties = [
'transform',
'transition',
'transitionDuration',
'transitionProperty'
];
// cache all vendor properties
var vendorProperties = ( function() {
var cache = {};
for ( var i=0, len = prefixableProperties.length; i < len; i++ ) {
var prop = prefixableProperties[i];
var supportedProp = getStyleProperty( prop );
if ( supportedProp && supportedProp !== prop ) {
cache[ prop ] = supportedProp;
}
}
return cache;
})();
// sub-class Outlayer Item
function Item() {
Outlayer.Item.apply( this, arguments );
}
Item.prototype = new Outlayer.Item();
// dash before all cap letters, including first for
// WebkitTransform => -webkit-transform
function toDashedAll( str ) {
return str.replace( /([A-Z])/g, function( $1 ) {
return '-' + $1.toLowerCase();
});
}
var transitionProps = 'opacity, height, width, padding,' +
toDashedAll( vendorProperties.transform || 'transform' );
Item.prototype.moveTo = function( x, y, force) {
if (!supportsCSS3) {
this.goTo(x, y);
return;
}
this.getPosition();
// get current x & y from top/left
var curX = this.position.x;
var curY = this.position.y;
var compareX = parseInt( x, 10 );
var compareY = parseInt( y, 10 );
var didNotMove = compareX === this.position.x && compareY === this.position.y;
// save end position
this.setPosition( x, y );
// if did not move and not transitioning, just go to layout
if ( !force && didNotMove && !this.isTransitioning ) {
this.layoutPosition();
return;
}
var transX = x - curX;
var transY = y - curY;
var transitionStyle = {};
transitionStyle.transform = this.getTranslate( transX, transY );
this.transition({
to: transitionStyle,
onTransitionEnd: {
transform: this.layoutPosition
},
isCleaning: true
});
};
Item.prototype.setPosition = function( x, y ) {
this.position.x = Number(Math.round(x + 'e2') + 'e-2');
this.position.y = Number(Math.round(y + 'e2') + 'e-2')
};
Item.prototype.enableTransition = function(/* style */) {
// HACK changing transitionProperty during a transition
// will cause transition to jump
if ( this.isTransitioning ) {
return;
}
// make `transition: foo, bar, baz` from style object
// HACK un-comment this when enableTransition can work
// while a transition is happening
// var transitionValues = [];
// for ( var prop in style ) {
// // dash-ify camelCased properties like WebkitTransition
// prop = vendorProperties[ prop ] || prop;
// transitionValues.push( toDashedAll( prop ) );
// }
// enable transition styles
this.css({
transitionProperty: transitionProps,
transitionDuration: this.layout.options.transitionDuration
});
// listen for transition end event
this.element.addEventListener( transitionEndEvent, this, false );
};
// Item.prototype._create = function() {
// // assign id, used for original-order sorting
// this.id = this.layout.itemGUID++;
// Outlayer.Item.prototype._create.call( this );
// this.sortData = {};
// };
return Item;
}));