decidim-gallery 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE-AGPLv3.txt +661 -0
- data/README.md +30 -0
- data/Rakefile +9 -0
- data/app/cells/decidim/gallery/main/image.erb +51 -0
- data/app/cells/decidim/gallery/main/image_collection.erb +13 -0
- data/app/cells/decidim/gallery/main/image_list.erb +9 -0
- data/app/cells/decidim/gallery/main/video.erb +20 -0
- data/app/cells/decidim/gallery/main/video_collection.erb +3 -0
- data/app/cells/decidim/gallery/main_cell.rb +88 -0
- data/app/cells/decidim/gallery/video/show.erb +6 -0
- data/app/cells/decidim/gallery/video_cell.rb +96 -0
- data/app/commands/decidim/gallery/admin/create_gallery_item.rb +50 -0
- data/app/commands/decidim/gallery/admin/publish_gallery_item.rb +38 -0
- data/app/commands/decidim/gallery/admin/unpublish_gallery_item.rb +38 -0
- data/app/commands/decidim/gallery/admin/update_gallery_item.rb +44 -0
- data/app/controllers/decidim/gallery/admin/application_controller.rb +24 -0
- data/app/controllers/decidim/gallery/admin/gallery_item_controller.rb +104 -0
- data/app/controllers/decidim/gallery/application_controller.rb +8 -0
- data/app/controllers/decidim/gallery/gallery_controller.rb +9 -0
- data/app/forms/decidim/gallery/admin/gallery_item_form.rb +17 -0
- data/app/forms/decidim/gallery/admin/gallery_item_image_form.rb +14 -0
- data/app/forms/decidim/gallery/admin/gallery_item_video_form.rb +12 -0
- data/app/helpers/decidim/gallery/admin/application_helper.rb +18 -0
- data/app/model/decidim/gallery/application_record.rb +10 -0
- data/app/model/decidim/gallery/gallery_item.rb +38 -0
- data/app/overrides/decidim/admin/static_pages/edit/add_gallery.html.erb.deface +11 -0
- data/app/overrides/decidim/pages/_standalone/add_content_blocks.html.erb.deface +7 -0
- data/app/overrides/decidim/pages/_tabbed/add_content_blocks.html.erb.deface +5 -0
- data/app/packs/entrypoints/decidim_gallery.js +3 -0
- data/app/packs/images/decidim/gallery/icon.svg +1 -0
- data/app/packs/src/decidim/gallery/gallery.js +42 -0
- data/app/packs/src/decidim/gallery/masonry/EvEmitter.js +85 -0
- data/app/packs/src/decidim/gallery/masonry/getSize.js +181 -0
- data/app/packs/src/decidim/gallery/masonry/jQueryBridget.js +109 -0
- data/app/packs/src/decidim/gallery/masonry/masonry.js +202 -0
- data/app/packs/src/decidim/gallery/masonry/matchesSelector.js +25 -0
- data/app/packs/src/decidim/gallery/masonry/outlayer.js +885 -0
- data/app/packs/src/decidim/gallery/masonry/outlayerItem.js +522 -0
- data/app/packs/src/decidim/gallery/masonry/utils.js +203 -0
- data/app/packs/stylesheets/decidim/gallery/_gallery.scss +3 -0
- data/app/permissions/decidim/gallery/admin/permissions.rb +18 -0
- data/app/permissions/decidim/gallery/permissions.rb +17 -0
- data/app/views/decidim/gallery/admin/gallery_item/_form_image.html.erb +16 -0
- data/app/views/decidim/gallery/admin/gallery_item/_form_video.html.erb +16 -0
- data/app/views/decidim/gallery/admin/gallery_item/edit.html.erb +9 -0
- data/app/views/decidim/gallery/admin/gallery_item/index.html.erb +52 -0
- data/app/views/decidim/gallery/admin/gallery_item/new.html.erb +9 -0
- data/app/views/decidim/gallery/gallery/index.html.erb +11 -0
- data/config/assets.rb +9 -0
- data/config/i18n-tasks.yml +22 -0
- data/config/locales/en.yml +79 -0
- data/config/locales/fr.yml +79 -0
- data/config/locales/ro.yml +79 -0
- data/lib/decidim/gallery/admin/static_pages/command.rb +15 -0
- data/lib/decidim/gallery/admin/static_pages/form.rb +21 -0
- data/lib/decidim/gallery/admin.rb +14 -0
- data/lib/decidim/gallery/admin_engine.rb +27 -0
- data/lib/decidim/gallery/component.rb +47 -0
- data/lib/decidim/gallery/engine.rb +60 -0
- data/lib/decidim/gallery/test/factories.rb +58 -0
- data/lib/decidim/gallery/version.rb +14 -0
- data/lib/decidim/gallery.rb +14 -0
- data/lib/tasks/decidim_gallery.rake +16 -0
- metadata +163 -0
@@ -0,0 +1,202 @@
|
|
1
|
+
import getSize from "./getSize";
|
2
|
+
import Outlayer from "./outlayer";
|
3
|
+
|
4
|
+
// create an Outlayer layout class
|
5
|
+
var Masonry = Outlayer.create('masonry');
|
6
|
+
// isFitWidth -> fitWidth
|
7
|
+
Masonry.compatOptions.fitWidth = 'isFitWidth';
|
8
|
+
|
9
|
+
var proto = Masonry.prototype;
|
10
|
+
|
11
|
+
proto._resetLayout = function() {
|
12
|
+
this.getSize();
|
13
|
+
this._getMeasurement( 'columnWidth', 'outerWidth' );
|
14
|
+
this._getMeasurement( 'gutter', 'outerWidth' );
|
15
|
+
this.measureColumns();
|
16
|
+
|
17
|
+
// reset column Y
|
18
|
+
this.colYs = [];
|
19
|
+
for ( var i=0; i < this.cols; i++ ) {
|
20
|
+
this.colYs.push( 0 );
|
21
|
+
}
|
22
|
+
|
23
|
+
this.maxY = 0;
|
24
|
+
this.horizontalColIndex = 0;
|
25
|
+
};
|
26
|
+
|
27
|
+
proto.measureColumns = function() {
|
28
|
+
this.getContainerWidth();
|
29
|
+
// if columnWidth is 0, default to outerWidth of first item
|
30
|
+
if ( !this.columnWidth ) {
|
31
|
+
var firstItem = this.items[0];
|
32
|
+
var firstItemElem = firstItem && firstItem.element;
|
33
|
+
// columnWidth fall back to item of first element
|
34
|
+
this.columnWidth = firstItemElem && getSize( firstItemElem ).outerWidth ||
|
35
|
+
// if first elem has no width, default to size of container
|
36
|
+
this.containerWidth;
|
37
|
+
}
|
38
|
+
|
39
|
+
var columnWidth = this.columnWidth += this.gutter;
|
40
|
+
|
41
|
+
// calculate columns
|
42
|
+
var containerWidth = this.containerWidth + this.gutter;
|
43
|
+
var cols = containerWidth / columnWidth;
|
44
|
+
// fix rounding errors, typically with gutters
|
45
|
+
var excess = columnWidth - containerWidth % columnWidth;
|
46
|
+
// if overshoot is less than a pixel, round up, otherwise floor it
|
47
|
+
var mathMethod = excess && excess < 1 ? 'round' : 'floor';
|
48
|
+
cols = Math[ mathMethod ]( cols );
|
49
|
+
this.cols = Math.max( cols, 1 );
|
50
|
+
};
|
51
|
+
|
52
|
+
proto.getContainerWidth = function() {
|
53
|
+
// container is parent if fit width
|
54
|
+
var isFitWidth = this._getOption('fitWidth');
|
55
|
+
var container = isFitWidth ? this.element.parentNode : this.element;
|
56
|
+
// check that this.size and size are there
|
57
|
+
// IE8 triggers resize on body size change, so they might not be
|
58
|
+
var size = getSize( container );
|
59
|
+
this.containerWidth = size && size.innerWidth;
|
60
|
+
};
|
61
|
+
|
62
|
+
proto._getItemLayoutPosition = function( item ) {
|
63
|
+
item.getSize();
|
64
|
+
// how many columns does this brick span
|
65
|
+
var remainder = item.size.outerWidth % this.columnWidth;
|
66
|
+
var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
|
67
|
+
// round if off by 1 pixel, otherwise use ceil
|
68
|
+
var colSpan = Math[ mathMethod ]( item.size.outerWidth / this.columnWidth );
|
69
|
+
colSpan = Math.min( colSpan, this.cols );
|
70
|
+
// use horizontal or top column position
|
71
|
+
var colPosMethod = this.options.horizontalOrder ?
|
72
|
+
'_getHorizontalColPosition' : '_getTopColPosition';
|
73
|
+
var colPosition = this[ colPosMethod ]( colSpan, item );
|
74
|
+
// position the brick
|
75
|
+
var position = {
|
76
|
+
x: this.columnWidth * colPosition.col,
|
77
|
+
y: colPosition.y
|
78
|
+
};
|
79
|
+
// apply setHeight to necessary columns
|
80
|
+
var setHeight = colPosition.y + item.size.outerHeight;
|
81
|
+
var setMax = colSpan + colPosition.col;
|
82
|
+
for ( var i = colPosition.col; i < setMax; i++ ) {
|
83
|
+
this.colYs[i] = setHeight;
|
84
|
+
}
|
85
|
+
|
86
|
+
return position;
|
87
|
+
};
|
88
|
+
|
89
|
+
proto._getTopColPosition = function( colSpan ) {
|
90
|
+
var colGroup = this._getTopColGroup( colSpan );
|
91
|
+
// get the minimum Y value from the columns
|
92
|
+
var minimumY = Math.min.apply( Math, colGroup );
|
93
|
+
|
94
|
+
return {
|
95
|
+
col: colGroup.indexOf( minimumY ),
|
96
|
+
y: minimumY,
|
97
|
+
};
|
98
|
+
};
|
99
|
+
|
100
|
+
/**
|
101
|
+
* @param {Number} colSpan - number of columns the element spans
|
102
|
+
* @returns {Array} colGroup
|
103
|
+
*/
|
104
|
+
proto._getTopColGroup = function( colSpan ) {
|
105
|
+
if ( colSpan < 2 ) {
|
106
|
+
// if brick spans only one column, use all the column Ys
|
107
|
+
return this.colYs;
|
108
|
+
}
|
109
|
+
|
110
|
+
var colGroup = [];
|
111
|
+
// how many different places could this brick fit horizontally
|
112
|
+
var groupCount = this.cols + 1 - colSpan;
|
113
|
+
// for each group potential horizontal position
|
114
|
+
for ( var i = 0; i < groupCount; i++ ) {
|
115
|
+
colGroup[i] = this._getColGroupY( i, colSpan );
|
116
|
+
}
|
117
|
+
return colGroup;
|
118
|
+
};
|
119
|
+
|
120
|
+
proto._getColGroupY = function( col, colSpan ) {
|
121
|
+
if ( colSpan < 2 ) {
|
122
|
+
return this.colYs[ col ];
|
123
|
+
}
|
124
|
+
// make an array of colY values for that one group
|
125
|
+
var groupColYs = this.colYs.slice( col, col + colSpan );
|
126
|
+
// and get the max value of the array
|
127
|
+
return Math.max.apply( Math, groupColYs );
|
128
|
+
};
|
129
|
+
|
130
|
+
// get column position based on horizontal index. #873
|
131
|
+
proto._getHorizontalColPosition = function( colSpan, item ) {
|
132
|
+
var col = this.horizontalColIndex % this.cols;
|
133
|
+
var isOver = colSpan > 1 && col + colSpan > this.cols;
|
134
|
+
// shift to next row if item can't fit on current row
|
135
|
+
col = isOver ? 0 : col;
|
136
|
+
// don't let zero-size items take up space
|
137
|
+
var hasSize = item.size.outerWidth && item.size.outerHeight;
|
138
|
+
this.horizontalColIndex = hasSize ? col + colSpan : this.horizontalColIndex;
|
139
|
+
|
140
|
+
return {
|
141
|
+
col: col,
|
142
|
+
y: this._getColGroupY( col, colSpan ),
|
143
|
+
};
|
144
|
+
};
|
145
|
+
|
146
|
+
proto._manageStamp = function( stamp ) {
|
147
|
+
var stampSize = getSize( stamp );
|
148
|
+
var offset = this._getElementOffset( stamp );
|
149
|
+
// get the columns that this stamp affects
|
150
|
+
var isOriginLeft = this._getOption('originLeft');
|
151
|
+
var firstX = isOriginLeft ? offset.left : offset.right;
|
152
|
+
var lastX = firstX + stampSize.outerWidth;
|
153
|
+
var firstCol = Math.floor( firstX / this.columnWidth );
|
154
|
+
firstCol = Math.max( 0, firstCol );
|
155
|
+
var lastCol = Math.floor( lastX / this.columnWidth );
|
156
|
+
// lastCol should not go over if multiple of columnWidth #425
|
157
|
+
lastCol -= lastX % this.columnWidth ? 0 : 1;
|
158
|
+
lastCol = Math.min( this.cols - 1, lastCol );
|
159
|
+
// set colYs to bottom of the stamp
|
160
|
+
|
161
|
+
var isOriginTop = this._getOption('originTop');
|
162
|
+
var stampMaxY = ( isOriginTop ? offset.top : offset.bottom ) +
|
163
|
+
stampSize.outerHeight;
|
164
|
+
for ( var i = firstCol; i <= lastCol; i++ ) {
|
165
|
+
this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
|
166
|
+
}
|
167
|
+
};
|
168
|
+
|
169
|
+
proto._getContainerSize = function() {
|
170
|
+
this.maxY = Math.max.apply( Math, this.colYs );
|
171
|
+
var size = {
|
172
|
+
height: this.maxY
|
173
|
+
};
|
174
|
+
|
175
|
+
if ( this._getOption('fitWidth') ) {
|
176
|
+
size.width = this._getContainerFitWidth();
|
177
|
+
}
|
178
|
+
|
179
|
+
return size;
|
180
|
+
};
|
181
|
+
|
182
|
+
proto._getContainerFitWidth = function() {
|
183
|
+
var unusedCols = 0;
|
184
|
+
// count unused columns
|
185
|
+
var i = this.cols;
|
186
|
+
while ( --i ) {
|
187
|
+
if ( this.colYs[i] !== 0 ) {
|
188
|
+
break;
|
189
|
+
}
|
190
|
+
unusedCols++;
|
191
|
+
}
|
192
|
+
// fit container to columns that have been used
|
193
|
+
return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
|
194
|
+
};
|
195
|
+
|
196
|
+
proto.needsResizeLayout = function() {
|
197
|
+
var previousWidth = this.containerWidth;
|
198
|
+
this.getContainerWidth();
|
199
|
+
return previousWidth != this.containerWidth;
|
200
|
+
};
|
201
|
+
|
202
|
+
export default Masonry;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
var matchesMethod = ( function() {
|
2
|
+
var ElemProto = window.Element.prototype;
|
3
|
+
// check for the standard method name first
|
4
|
+
if ( ElemProto.matches ) {
|
5
|
+
return 'matches';
|
6
|
+
}
|
7
|
+
// check un-prefixed
|
8
|
+
if ( ElemProto.matchesSelector ) {
|
9
|
+
return 'matchesSelector';
|
10
|
+
}
|
11
|
+
// check vendor prefixes
|
12
|
+
var prefixes = [ 'webkit', 'moz', 'ms', 'o' ];
|
13
|
+
|
14
|
+
for ( var i=0; i < prefixes.length; i++ ) {
|
15
|
+
var prefix = prefixes[i];
|
16
|
+
var method = prefix + 'MatchesSelector';
|
17
|
+
if ( ElemProto[ method ] ) {
|
18
|
+
return method;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
})();
|
22
|
+
|
23
|
+
export default function matchesSelector( elem, selector ) {
|
24
|
+
return elem[ matchesMethod ]( selector );
|
25
|
+
}
|