-
Notifications
You must be signed in to change notification settings - Fork 6
/
isotope-fitColumns-v1.1.4.js
72 lines (58 loc) · 1.58 KB
/
isotope-fitColumns-v1.1.4.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
/*!
* fitColumns layout mode for Isotope
* v1.1.4
* https://isotope.metafizzy.co/layout-modes/fitcolumns.html
*/
/*jshint browser: true, devel: false, strict: true, undef: true, unused: true */
( function( window, factory ) {
// universal module definition
/* jshint strict: false */ /*globals define, module, require */
if ( typeof define === 'function' && define.amd ) {
// AMD
define( [
'isotope-layout/js/layout-mode'
],
factory );
} else if ( typeof exports === 'object' ) {
// CommonJS
module.exports = factory(
require('isotope-layout/js/layout-mode')
);
} else {
// browser global
factory(
window.Isotope.LayoutMode
);
}
}( window, function factory( LayoutMode ) {
'use strict';
var FitColumns = LayoutMode.create('fitColumns');
var proto = FitColumns.prototype;
proto._resetLayout = function() {
this.x = 0;
this.y = 0;
this.maxX = 0;
};
proto._getItemLayoutPosition = function( item ) {
item.getSize();
// if this element cannot fit in the current row
if ( this.y !== 0 && item.size.outerHeight + this.y > this.isotope.size.innerHeight ) {
this.y = 0;
this.x = this.maxX;
}
var position = {
x: this.x,
y: this.y
};
this.maxX = Math.max( this.maxX, this.x + item.size.outerWidth );
this.y += item.size.outerHeight;
return position;
};
proto._getContainerSize = function() {
return { width: this.maxX };
};
proto.needsResizeLayout = function() {
return this.needsVerticalResizeLayout();
};
return FitColumns;
}));