Skip to content

Commit 95539f5

Browse files
committed
Masonry bugfix: the containerStyle value must be an object.
1 parent 6a82a47 commit 95539f5

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/pat/masonry/documentation.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ fitting stones in a wall. You’ve probably seen it in use all over the Internet
1212

1313
| Property | Default Value | Description |
1414
|---------------------|---------------------------------------------|---------------------- |
15-
| column-width | `240` | The width of a column of a horizontal grid |
16-
| container-style | `{ position: 'relative' }` | CSS styles to be applied to the container element |
15+
| column-width | `240` | The width of a column of a horizontal grid |
16+
| container-style | `{ "position": "relative" }` | CSS styles to be applied to the container element. Note, Masonry expects an object to be passed in as value, but Patterns' property values are strings. This means that the passed in string must be in valid JSON format, so that it can be parsed and converted to an object before it's passed on to Masonry. |
1717
| gutter | `10` | Horizontal space between item elements |
1818
| hidden-style | `{ opacity: 0, transform: 'scale(0.001)' }` | Style applied to hide elements |
19-
| is-fit-width | `false` | Set the width of the element to fit the available number of columns |
20-
| is-origin-left | `true` | Controls the horizontal flow of the layout. By default, item elements start positioning at |the left. |
21-
| is-origin-top | `true` | Controls the vertical flow of the layout. By default, item elements start positioning at the top. |
22-
| item-selector | `.item` | Specifies the child elements to be used as item elements. |
19+
| is-fit-width | `false` | Set the width of the element to fit the available number of columns |
20+
| is-origin-left | `true` | Controls the horizontal flow of the layout. By default, item elements start positioning at |the left. |
21+
| is-origin-top | `true` | Controls the vertical flow of the layout. By default, item elements start positioning at the top. |
22+
| item-selector | `.item` | Specifies the child elements to be used as item elements. |
2323
| stamp | "" | Specifies which elements are stamped (fixed) within the layout. |
24-
| transition-duration | `0.4s` | Length of time during which elements change layout. |
24+
| transition-duration | `0.4s` | Length of time during which elements change layout. |
2525
| visible-style | `{ opacity: 1, transform: 'scale(1)' }` | Style applied to reveal hidden elements. |
2626

src/pat/masonry/masonry.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
if (typeof define === "function" && define.amd) {
88
define([
99
"jquery",
10+
"pat-logger",
1011
"pat-registry",
1112
"pat-parser",
1213
"pat-base",
@@ -19,11 +20,12 @@
1920
} else {
2021
factory(root.$, root.patterns, root.patterns.Parser, root.Base, root.Masonry, root.imagesLoaded);
2122
}
22-
}(this, function($, registry, Parser, Base, utils, Masonry, imagesLoaded) {
23+
}(this, function($, logger, registry, Parser, Base, utils, Masonry, imagesLoaded) {
2324
"use strict";
25+
var log = logger.getLogger("pat.masonry");
2426
var parser = new Parser("masonry");
2527
parser.addArgument("column-width");
26-
parser.addArgument("container-style", "{ position: 'relative' }");
28+
parser.addArgument("container-style", '{ "position": "relative" }');
2729
parser.addArgument("gutter");
2830
parser.addArgument("hidden-style", "{ opacity: 0, transform: 'scale(0.001)' }");
2931
parser.addArgument("is-fit-width", false);
@@ -50,9 +52,19 @@
5052
},
5153

5254
initMasonry: function () {
55+
var containerStyle;
56+
try {
57+
containerStyle = JSON.parse(this.options.containerStyle);
58+
} catch (e) {
59+
containerStyle = { "position": "relative" };
60+
log.warn(
61+
"Invalid value passed in as containerStyle. Needs to "+
62+
"be valid JSON so that it can be converted to an object for Masonry."
63+
);
64+
}
5365
this.msnry = new Masonry(this.$el[0], {
5466
columnWidth: this.getTypeCastedValue(this.options.columnWidth),
55-
containerStyle: this.options.containerStyle,
67+
containerStyle: containerStyle,
5668
gutter: this.getTypeCastedValue(this.options.gutter),
5769
hiddenStyle: this.options.hiddenStyle,
5870
isFitWidth: this.options.is["fit-width"],

0 commit comments

Comments
 (0)