|
11 | 11 |
|
12 | 12 |
|
13 | 13 | flowr = function(elem, options) {
|
| 14 | + |
| 15 | + $this = elem; |
| 16 | + |
| 17 | + var extend = function(out) { |
| 18 | + out = out || {}; |
| 19 | + |
| 20 | + for (var i = 1; i < arguments.length; i++) { |
| 21 | + if (!arguments[i]) |
| 22 | + continue; |
| 23 | + |
| 24 | + for (var key in arguments[i]) { |
| 25 | + if (arguments[i].hasOwnProperty(key)) |
| 26 | + out[key] = arguments[i][key]; |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + return out; |
| 31 | + }; |
| 32 | + |
| 33 | + |
14 | 34 | var data = (function() {
|
15 | 35 | var lastId = 0,
|
16 | 36 | store = {};
|
|
21 | 41 | if (element.myCustomDataTag === undefined) {
|
22 | 42 | id = lastId++;
|
23 | 43 | element.myCustomDataTag = id;
|
24 |
| - } |
25 |
| - store[id] = info; |
| 44 | + } else { id = element.myCustomDataTag; } |
| 45 | + store[id] = extend(store[id], info); |
26 | 46 | },
|
27 | 47 |
|
28 | 48 | get: function(element) {
|
|
31 | 51 | };
|
32 | 52 | }());
|
33 | 53 |
|
34 |
| - $this = elem; |
| 54 | + function reorderContent() { |
| 55 | + var _initialWidth = data.get($this).width; |
| 56 | + var _newWidth = $this.offsetWidth; |
| 57 | + var _change = _initialWidth - _newWidth; |
| 58 | + |
| 59 | + if (_initialWidth != _newWidth) { |
| 60 | + $this.innerHTML = ""; |
| 61 | + var _settings = data.get($this).lastSettings || {}; |
| 62 | + _settings.data = data.get($this).data || {}; |
| 63 | + _settings.maxWidth = $this.offsetWidth - 1; |
| 64 | + flowr($this, _settings); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + |
35 | 69 | var ROW_CLASS_NAME = 'flowr-row'; // Class name for the row of flowy
|
36 | 70 | var MAX_LAST_ROW_GAP = 25; // If the width of last row is lesser than max-width, recalculation is needed
|
37 | 71 | var NO_COPY_FIELDS = ['complete', 'data', 'responsive']; // these attributes will not be carried forward for append related calls
|
|
52 | 86 | 'rows': -1, // Maximum number of rows to render. -1 for no limit.
|
53 | 87 | 'responsive': true // make content responsive
|
54 | 88 | };
|
55 |
| - var extend = function(out) { |
56 |
| - out = out || {}; |
57 |
| - |
58 |
| - for (var i = 1; i < arguments.length; i++) { |
59 |
| - if (!arguments[i]) |
60 |
| - continue; |
61 |
| - |
62 |
| - for (var key in arguments[i]) { |
63 |
| - if (arguments[i].hasOwnProperty(key)) |
64 |
| - out[key] = arguments[i][key]; |
65 |
| - } |
66 |
| - } |
67 |
| - |
68 |
| - return out; |
69 |
| - }; |
70 |
| - |
71 | 89 |
|
72 | 90 | var settings = extend(DEFAULTS, options);
|
73 | 91 |
|
|
122 | 140 | }
|
123 | 141 | }
|
124 | 142 |
|
125 |
| - // A standalone utility to calculate the item widths for a particular row |
126 |
| - // Returns rowWidth: width occupied & data : the items in the new row |
127 |
| - var utils = { |
128 |
| - getNextRow: function(data, settings) { |
| 143 | + function getNextRow(data, settings) { |
129 | 144 | var itemIndex = 0;
|
130 | 145 | var itemsLength = data.length;
|
131 | 146 | var lineItems = [];
|
|
199 | 214 | data: lineItems,
|
200 | 215 | width: testWidth + requiredPadding()
|
201 | 216 | };
|
202 |
| - }, //getNextRow |
203 |
| - reorderContent: function() { |
204 |
| - /* |
205 |
| - TODO: optimize for faster resizing by reusing dom objects instead of killing the dom |
206 |
| - */ |
207 |
| - var _initialWidth = data.get($this).width; |
208 |
| - var _newWidth = $this.offsetWidth; |
209 |
| - var _change = _initialWidth - _newWidth; |
210 |
| - |
211 |
| - if (_initialWidth != _newWidth) { |
212 |
| - $this.innerHtml = ''; |
213 |
| - var _settings = data.get($this).lastSettings; |
214 |
| - _settings.data = data.get($this).lastSettings.data; |
215 |
| - _settings.maxWidth = $this.offsetWidth - 1; |
216 |
| - flowr($this, _settings); |
217 |
| - } |
218 | 217 | }
|
219 |
| - } //utils |
| 218 | + |
220 | 219 |
|
221 | 220 | // If the responsive var is set to true then listen for resize method
|
222 | 221 | // and prevent resizing from happening twice if responsive is set again during append phase!
|
|
232 | 231 | task_id = clearTimeout(task_id);
|
233 | 232 | task_id = null;
|
234 | 233 | }
|
235 |
| - task_id = setTimeout(utils.reorderContent, 80); |
| 234 | + task_id = setTimeout(function() {reorderContent(data);}, 80); |
236 | 235 | data.set($this, {task_id: task_id});
|
237 | 236 | }
|
238 | 237 | });
|
|
254 | 253 | data.set($this, {data: allData});
|
255 | 254 |
|
256 | 255 | // While we have a new row
|
257 |
| - while ((rowData = utils.getNextRow(_data, settings)) != null && rowData.data.length > 0) { |
| 256 | + while ((rowData = getNextRow(_data, settings)) != null && rowData.data.length > 0) { |
258 | 257 | if (settings.rows > 0 && currentRow >= settings.rows)
|
259 | 258 | break;
|
260 | 259 | // remove the number of elements in the new row from the top of data stack
|
|
0 commit comments