|
1 | | -/*! |
2 | | - * angular-masonry <%= pkg.version %> |
3 | | - * Pascal Hartig, https://passy.me/ |
4 | | - * License: MIT |
| 1 | +/** |
| 2 | + * angular-masonry |
| 3 | + * |
| 4 | + * @external 'angular.module' |
| 5 | + * @version <%= pkg.version %> |
| 6 | + * @author {@link https://passy.me/|Pascal Hartig} |
| 7 | + * @license: MIT |
5 | 8 | */ |
6 | 9 | (function () { |
7 | 10 | 'use strict'; |
|
15 | 18 | var timeout = null; |
16 | 19 |
|
17 | 20 | this.preserveOrder = false; |
18 | | - this.loadImages = true; |
| 21 | + this.loadImages = false; |
19 | 22 |
|
20 | 23 | this.scheduleMasonryOnce = function scheduleMasonryOnce() { |
21 | 24 | var args = arguments; |
|
42 | 45 | return; |
43 | 46 | } |
44 | 47 | schedule.forEach(function scheduleForEach(args) { |
45 | | - $element.masonry.apply($element, args); |
| 48 | + var method = args[0]; |
| 49 | + args = args.slice(1); |
| 50 | + |
| 51 | + self.masonry[method].apply(self.masonry, args); |
46 | 52 | }); |
47 | 53 | schedule = []; |
48 | 54 | }, 30); |
|
59 | 65 |
|
60 | 66 | function _add() { |
61 | 67 | if (Object.keys(bricks).length === 0) { |
62 | | - $element.masonry('resize'); |
| 68 | + self.masonry.resize(); |
63 | 69 | } |
64 | 70 | if (bricks[id] === undefined) { |
65 | 71 | // Keep track of added elements. |
66 | 72 | bricks[id] = true; |
67 | 73 | defaultLoaded(element); |
68 | | - $element.masonry(method, element, true); |
| 74 | + self.masonry[method](element, true); |
69 | 75 | } |
70 | 76 | } |
71 | 77 |
|
|
97 | 103 | } |
98 | 104 |
|
99 | 105 | delete bricks[id]; |
100 | | - $element.masonry('remove', element); |
| 106 | + self.masonry.remove(element); |
101 | 107 | this.scheduleMasonryOnce('layout'); |
102 | 108 | }; |
103 | 109 |
|
|
106 | 112 |
|
107 | 113 | if ($element.data('masonry')) { |
108 | 114 | // Gently uninitialize if still present |
109 | | - $element.masonry('destroy'); |
| 115 | + self.masonry.destroy(); |
110 | 116 | } |
111 | 117 | $scope.$emit('masonry.destroyed'); |
112 | 118 |
|
113 | 119 | bricks = {}; |
114 | 120 | }; |
115 | 121 |
|
116 | 122 | this.reload = function reload() { |
117 | | - $element.masonry(); |
| 123 | + self.masonry.reload(); |
118 | 124 | $scope.$emit('masonry.reloaded'); |
119 | 125 | }; |
120 | 126 |
|
|
123 | 129 | return { |
124 | 130 | restrict: 'AE', |
125 | 131 | controller: 'MasonryCtrl', |
| 132 | + controllerAs: 'msnry', |
126 | 133 | link: { |
127 | 134 | pre: function preLink(scope, element, attrs, ctrl) { |
128 | 135 | var attrOptions = scope.$eval(attrs.masonry || attrs.masonryOptions); |
129 | 136 | var options = angular.extend({ |
130 | 137 | itemSelector: attrs.itemSelector || '.masonry-brick', |
131 | 138 | columnWidth: parseInt(attrs.columnWidth, 10) || attrs.columnWidth |
132 | 139 | }, attrOptions || {}); |
133 | | - element.masonry(options); |
| 140 | + |
134 | 141 | scope.masonryContainer = element[0]; |
| 142 | + ctrl.masonry = new Masonry(scope.masonryContainer, options); |
| 143 | + |
135 | 144 | var loadImages = scope.$eval(attrs.loadImages); |
136 | | - ctrl.loadImages = loadImages !== false; |
| 145 | + ctrl.loadImages = !!loadImages; |
| 146 | + |
137 | 147 | var preserveOrder = scope.$eval(attrs.preserveOrder); |
138 | | - ctrl.preserveOrder = (preserveOrder !== false && attrs.preserveOrder !== undefined); |
| 148 | + ctrl.preserveOrder = (preserveOrder !== false && attrs.preserveOrder !== undefined); |
| 149 | + |
139 | 150 | var reloadOnShow = scope.$eval(attrs.reloadOnShow); |
| 151 | + |
140 | 152 | if (reloadOnShow !== false && attrs.reloadOnShow !== undefined) { |
141 | 153 | scope.$watch(function () { |
142 | 154 | return element.prop('offsetParent'); |
|
146 | 158 | } |
147 | 159 | }); |
148 | 160 | } |
| 161 | + |
149 | 162 | var reloadOnResize = scope.$eval(attrs.reloadOnResize); |
150 | 163 | if (reloadOnResize !== false && attrs.reloadOnResize !== undefined) { |
151 | 164 | scope.$watch('masonryContainer.offsetWidth', function (newWidth, oldWidth) { |
152 | | - if (newWidth != oldWidth) { |
| 165 | + if (newWidth !== oldWidth) { |
153 | 166 | ctrl.reload(); |
154 | 167 | } |
155 | 168 | }); |
|
0 commit comments