masonry-rails 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Isotope Item
3
+ **/
4
+
5
+ ( function( window ) {
6
+
7
+ 'use strict';
8
+
9
+ // -------------------------- Item -------------------------- //
10
+
11
+ function itemDefinition( Outlayer ) {
12
+
13
+ // sub-class Outlayer Item
14
+ function Item() {
15
+ Outlayer.Item.apply( this, arguments );
16
+ }
17
+
18
+ Item.prototype = new Outlayer.Item();
19
+
20
+ Item.prototype._create = function() {
21
+ // assign id, used for original-order sorting
22
+ this.id = this.layout.itemGUID++;
23
+ Outlayer.Item.prototype._create.call( this );
24
+ this.sortData = {};
25
+ };
26
+
27
+ Item.prototype.updateSortData = function() {
28
+ if ( this.isIgnored ) {
29
+ return;
30
+ }
31
+ // default sorters
32
+ this.sortData.id = this.id;
33
+ // for backward compatibility
34
+ this.sortData['original-order'] = this.id;
35
+ this.sortData.random = Math.random();
36
+ // go thru getSortData obj and apply the sorters
37
+ var getSortData = this.layout.options.getSortData;
38
+ var sorters = this.layout._sorters;
39
+ for ( var key in getSortData ) {
40
+ var sorter = sorters[ key ];
41
+ this.sortData[ key ] = sorter( this.element, this );
42
+ }
43
+ };
44
+
45
+ var _destroy = Item.prototype.destroy;
46
+ Item.prototype.destroy = function() {
47
+ // call super
48
+ _destroy.apply( this, arguments );
49
+ // reset display, #741
50
+ this.css({
51
+ display: ''
52
+ });
53
+ };
54
+
55
+ return Item;
56
+
57
+ }
58
+
59
+ // -------------------------- transport -------------------------- //
60
+
61
+ if ( typeof define === 'function' && define.amd ) {
62
+ // AMD
63
+ define( [
64
+ 'outlayer/outlayer'
65
+ ],
66
+ itemDefinition );
67
+ } else {
68
+ // browser global
69
+ window.Isotope = window.Isotope || {};
70
+ window.Isotope.Item = itemDefinition(
71
+ window.Outlayer
72
+ );
73
+ }
74
+
75
+ })( window );
@@ -0,0 +1,156 @@
1
+ ( function( window ) {
2
+
3
+ 'use strict';
4
+
5
+ // -------------------------- -------------------------- //
6
+
7
+ function layoutModeDefinition( getSize, Outlayer ) {
8
+
9
+ // layout mode class
10
+ function LayoutMode( isotope ) {
11
+ this.isotope = isotope;
12
+ // link properties
13
+ if ( isotope ) {
14
+ this.options = isotope.options[ this.namespace ];
15
+ this.element = isotope.element;
16
+ this.items = isotope.filteredItems;
17
+ this.size = isotope.size;
18
+ }
19
+ }
20
+
21
+ /**
22
+ * some methods should just defer to default Outlayer method
23
+ * and reference the Isotope instance as `this`
24
+ **/
25
+ ( function() {
26
+ var facadeMethods = [
27
+ '_resetLayout',
28
+ '_getItemLayoutPosition',
29
+ '_manageStamp',
30
+ '_getContainerSize',
31
+ '_getElementOffset',
32
+ 'needsResizeLayout'
33
+ ];
34
+
35
+ for ( var i=0, len = facadeMethods.length; i < len; i++ ) {
36
+ var methodName = facadeMethods[i];
37
+ LayoutMode.prototype[ methodName ] = getOutlayerMethod( methodName );
38
+ }
39
+
40
+ function getOutlayerMethod( methodName ) {
41
+ return function() {
42
+ return Outlayer.prototype[ methodName ].apply( this.isotope, arguments );
43
+ };
44
+ }
45
+ })();
46
+
47
+ // ----- ----- //
48
+
49
+ // for horizontal layout modes, check vertical size
50
+ LayoutMode.prototype.needsVerticalResizeLayout = function() {
51
+ // don't trigger if size did not change
52
+ var size = getSize( this.isotope.element );
53
+ // check that this.size and size are there
54
+ // IE8 triggers resize on body size change, so they might not be
55
+ var hasSizes = this.isotope.size && size;
56
+ return hasSizes && size.innerHeight !== this.isotope.size.innerHeight;
57
+ };
58
+
59
+ // ----- measurements ----- //
60
+
61
+ LayoutMode.prototype._getMeasurement = function() {
62
+ this.isotope._getMeasurement.apply( this, arguments );
63
+ };
64
+
65
+ LayoutMode.prototype.getColumnWidth = function() {
66
+ this.getSegmentSize( 'column', 'Width' );
67
+ };
68
+
69
+ LayoutMode.prototype.getRowHeight = function() {
70
+ this.getSegmentSize( 'row', 'Height' );
71
+ };
72
+
73
+ /**
74
+ * get columnWidth or rowHeight
75
+ * segment: 'column' or 'row'
76
+ * size 'Width' or 'Height'
77
+ **/
78
+ LayoutMode.prototype.getSegmentSize = function( segment, size ) {
79
+ var segmentName = segment + size;
80
+ var outerSize = 'outer' + size;
81
+ // columnWidth / outerWidth // rowHeight / outerHeight
82
+ this._getMeasurement( segmentName, outerSize );
83
+ // got rowHeight or columnWidth, we can chill
84
+ if ( this[ segmentName ] ) {
85
+ return;
86
+ }
87
+ // fall back to item of first element
88
+ var firstItemSize = this.getFirstItemSize();
89
+ this[ segmentName ] = firstItemSize && firstItemSize[ outerSize ] ||
90
+ // or size of container
91
+ this.isotope.size[ 'inner' + size ];
92
+ };
93
+
94
+ LayoutMode.prototype.getFirstItemSize = function() {
95
+ var firstItem = this.isotope.filteredItems[0];
96
+ return firstItem && firstItem.element && getSize( firstItem.element );
97
+ };
98
+
99
+ // ----- methods that should reference isotope ----- //
100
+
101
+ LayoutMode.prototype.layout = function() {
102
+ this.isotope.layout.apply( this.isotope, arguments );
103
+ };
104
+
105
+ LayoutMode.prototype.getSize = function() {
106
+ this.isotope.getSize();
107
+ this.size = this.isotope.size;
108
+ };
109
+
110
+ // -------------------------- create -------------------------- //
111
+
112
+ LayoutMode.modes = {};
113
+
114
+ LayoutMode.create = function( namespace, options ) {
115
+
116
+ function Mode() {
117
+ LayoutMode.apply( this, arguments );
118
+ }
119
+
120
+ Mode.prototype = new LayoutMode();
121
+
122
+ // default options
123
+ if ( options ) {
124
+ Mode.options = options;
125
+ }
126
+
127
+ Mode.prototype.namespace = namespace;
128
+ // register in Isotope
129
+ LayoutMode.modes[ namespace ] = Mode;
130
+
131
+ return Mode;
132
+ };
133
+
134
+
135
+ return LayoutMode;
136
+
137
+ }
138
+
139
+ if ( typeof define === 'function' && define.amd ) {
140
+ // AMD
141
+ define( [
142
+ 'get-size/get-size',
143
+ 'outlayer/outlayer'
144
+ ],
145
+ layoutModeDefinition );
146
+ } else {
147
+ // browser global
148
+ window.Isotope = window.Isotope || {};
149
+ window.Isotope.LayoutMode = layoutModeDefinition(
150
+ window.getSize,
151
+ window.Outlayer
152
+ );
153
+ }
154
+
155
+
156
+ })( window );
@@ -0,0 +1,64 @@
1
+ /*!
2
+ * cellsByColumn layout mode for Isotope
3
+ * http://isotope.metafizzy.co
4
+ */
5
+
6
+ ( function( window ) {
7
+
8
+ 'use strict';
9
+
10
+ function cellsByColumnDefinition( LayoutMode ) {
11
+
12
+ var CellsByColumn = LayoutMode.create( 'cellsByColumn' );
13
+
14
+ CellsByColumn.prototype._resetLayout = function() {
15
+ // reset properties
16
+ this.itemIndex = 0;
17
+ // measurements
18
+ this.getColumnWidth();
19
+ this.getRowHeight();
20
+ // set rows
21
+ this.rows = Math.floor( this.isotope.size.innerHeight / this.rowHeight );
22
+ this.rows = Math.max( this.rows, 1 );
23
+ };
24
+
25
+ CellsByColumn.prototype._getItemLayoutPosition = function( item ) {
26
+ item.getSize();
27
+ var col = Math.floor( this.itemIndex / this.rows );
28
+ var row = this.itemIndex % this.rows;
29
+ // center item within cell
30
+ var x = ( col + 0.5 ) * this.columnWidth - item.size.outerWidth / 2;
31
+ var y = ( row + 0.5 ) * this.rowHeight - item.size.outerHeight / 2;
32
+ this.itemIndex++;
33
+ return { x: x, y: y };
34
+ };
35
+
36
+ CellsByColumn.prototype._getContainerSize = function() {
37
+ return {
38
+ width: Math.ceil( this.itemIndex / this.rows ) * this.columnWidth
39
+ };
40
+ };
41
+
42
+ CellsByColumn.prototype.needsResizeLayout = function() {
43
+ return this.needsVerticalResizeLayout();
44
+ };
45
+
46
+ return CellsByColumn;
47
+
48
+ }
49
+
50
+ if ( typeof define === 'function' && define.amd ) {
51
+ // AMD
52
+ define( [
53
+ 'isotope/js/layout-mode'
54
+ ],
55
+ cellsByColumnDefinition );
56
+ } else {
57
+ // browser global
58
+ cellsByColumnDefinition(
59
+ window.Isotope.LayoutMode
60
+ );
61
+ }
62
+
63
+
64
+ })( window );
@@ -0,0 +1,59 @@
1
+ /*!
2
+ * cellsByRows layout mode for Isotope
3
+ * http://isotope.metafizzy.co
4
+ */
5
+
6
+ ( function( window ) {
7
+
8
+ 'use strict';
9
+
10
+ function cellsByRowDefinition( LayoutMode ) {
11
+
12
+ var CellsByRow = LayoutMode.create( 'cellsByRow' );
13
+
14
+ CellsByRow.prototype._resetLayout = function() {
15
+ // reset properties
16
+ this.itemIndex = 0;
17
+ // measurements
18
+ this.getColumnWidth();
19
+ this.getRowHeight();
20
+ // set cols
21
+ this.cols = Math.floor( this.isotope.size.innerWidth / this.columnWidth );
22
+ this.cols = Math.max( this.cols, 1 );
23
+ };
24
+
25
+ CellsByRow.prototype._getItemLayoutPosition = function( item ) {
26
+ item.getSize();
27
+ var col = this.itemIndex % this.cols;
28
+ var row = Math.floor( this.itemIndex / this.cols );
29
+ // center item within cell
30
+ var x = ( col + 0.5 ) * this.columnWidth - item.size.outerWidth / 2;
31
+ var y = ( row + 0.5 ) * this.rowHeight - item.size.outerHeight / 2;
32
+ this.itemIndex++;
33
+ return { x: x, y: y };
34
+ };
35
+
36
+ CellsByRow.prototype._getContainerSize = function() {
37
+ return {
38
+ height: Math.ceil( this.itemIndex / this.cols ) * this.rowHeight
39
+ };
40
+ };
41
+
42
+ return CellsByRow;
43
+
44
+ }
45
+
46
+ if ( typeof define === 'function' && define.amd ) {
47
+ // AMD
48
+ define( [
49
+ 'isotope/js/layout-mode'
50
+ ],
51
+ cellsByRowDefinition );
52
+ } else {
53
+ // browser global
54
+ cellsByRowDefinition(
55
+ window.Isotope.LayoutMode
56
+ );
57
+ }
58
+
59
+ })( window );
@@ -0,0 +1,65 @@
1
+ /*!
2
+ * fitColumns layout mode for Isotope
3
+ * http://isotope.metafizzy.co
4
+ */
5
+
6
+ ( function( window ) {
7
+
8
+ 'use strict';
9
+
10
+ function fitColumnsDefinition( LayoutMode ) {
11
+
12
+ var FitColumns = LayoutMode.create('fitColumns');
13
+
14
+ FitColumns.prototype._resetLayout = function() {
15
+ this.x = 0;
16
+ this.y = 0;
17
+ this.maxX = 0;
18
+ };
19
+
20
+ FitColumns.prototype._getItemLayoutPosition = function( item ) {
21
+ item.getSize();
22
+
23
+ // if this element cannot fit in the current row
24
+ if ( this.y !== 0 && item.size.outerHeight + this.y > this.isotope.size.innerHeight ) {
25
+ this.y = 0;
26
+ this.x = this.maxX;
27
+ }
28
+
29
+ var position = {
30
+ x: this.x,
31
+ y: this.y
32
+ };
33
+
34
+ this.maxX = Math.max( this.maxX, this.x + item.size.outerWidth );
35
+ this.y += item.size.outerHeight;
36
+
37
+ return position;
38
+ };
39
+
40
+ FitColumns.prototype._getContainerSize = function() {
41
+ return { width: this.maxX };
42
+ };
43
+
44
+ FitColumns.prototype.needsResizeLayout = function() {
45
+ return this.needsVerticalResizeLayout();
46
+ };
47
+
48
+ return FitColumns;
49
+
50
+ }
51
+
52
+ if ( typeof define === 'function' && define.amd ) {
53
+ // AMD
54
+ define( [
55
+ 'isotope/js/layout-mode'
56
+ ],
57
+ fitColumnsDefinition );
58
+ } else {
59
+ // browser global
60
+ fitColumnsDefinition(
61
+ window.Isotope.LayoutMode
62
+ );
63
+ }
64
+
65
+ })( window );
@@ -0,0 +1,54 @@
1
+ /*!
2
+ * horizontal layout mode for Isotope
3
+ * http://isotope.metafizzy.co
4
+ */
5
+
6
+ ( function( window ) {
7
+
8
+ 'use strict';
9
+
10
+ function horizontalDefinition( LayoutMode ) {
11
+
12
+ var Horizontal = LayoutMode.create( 'horizontal', {
13
+ verticalAlignment: 0
14
+ });
15
+
16
+ Horizontal.prototype._resetLayout = function() {
17
+ this.x = 0;
18
+ };
19
+
20
+ Horizontal.prototype._getItemLayoutPosition = function( item ) {
21
+ item.getSize();
22
+ var y = ( this.isotope.size.innerHeight - item.size.outerHeight ) *
23
+ this.options.verticalAlignment;
24
+ var x = this.x;
25
+ this.x += item.size.outerWidth;
26
+ return { x: x, y: y };
27
+ };
28
+
29
+ Horizontal.prototype._getContainerSize = function() {
30
+ return { width: this.x };
31
+ };
32
+
33
+ Horizontal.prototype.needsResizeLayout = function() {
34
+ return this.needsVerticalResizeLayout();
35
+ };
36
+
37
+ return Horizontal;
38
+
39
+ }
40
+
41
+ if ( typeof define === 'function' && define.amd ) {
42
+ // AMD
43
+ define( [
44
+ 'isotope/js/layout-mode'
45
+ ],
46
+ horizontalDefinition );
47
+ } else {
48
+ // browser global
49
+ horizontalDefinition(
50
+ window.Isotope.LayoutMode
51
+ );
52
+ }
53
+
54
+ })( window );