Skip to content

Commit fe2c5cd

Browse files
author
Roberto Alsina
committedMay 19, 2017
Responsive mode not very broken anymore
1 parent 2964c60 commit fe2c5cd

File tree

1 file changed

+41
-42
lines changed
  • nikola/data/themes/base/assets/js

1 file changed

+41
-42
lines changed
 

‎nikola/data/themes/base/assets/js/flowr.js

+41-42
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,26 @@
1111

1212

1313
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+
1434
var data = (function() {
1535
var lastId = 0,
1636
store = {};
@@ -21,8 +41,8 @@
2141
if (element.myCustomDataTag === undefined) {
2242
id = lastId++;
2343
element.myCustomDataTag = id;
24-
}
25-
store[id] = info;
44+
} else { id = element.myCustomDataTag; }
45+
store[id] = extend(store[id], info);
2646
},
2747

2848
get: function(element) {
@@ -31,7 +51,21 @@
3151
};
3252
}());
3353

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+
3569
var ROW_CLASS_NAME = 'flowr-row'; // Class name for the row of flowy
3670
var MAX_LAST_ROW_GAP = 25; // If the width of last row is lesser than max-width, recalculation is needed
3771
var NO_COPY_FIELDS = ['complete', 'data', 'responsive']; // these attributes will not be carried forward for append related calls
@@ -52,22 +86,6 @@
5286
'rows': -1, // Maximum number of rows to render. -1 for no limit.
5387
'responsive': true // make content responsive
5488
};
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-
7189

7290
var settings = extend(DEFAULTS, options);
7391

@@ -122,10 +140,7 @@
122140
}
123141
}
124142

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) {
129144
var itemIndex = 0;
130145
var itemsLength = data.length;
131146
var lineItems = [];
@@ -199,24 +214,8 @@
199214
data: lineItems,
200215
width: testWidth + requiredPadding()
201216
};
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-
}
218217
}
219-
} //utils
218+
220219

221220
// If the responsive var is set to true then listen for resize method
222221
// and prevent resizing from happening twice if responsive is set again during append phase!
@@ -232,7 +231,7 @@
232231
task_id = clearTimeout(task_id);
233232
task_id = null;
234233
}
235-
task_id = setTimeout(utils.reorderContent, 80);
234+
task_id = setTimeout(function() {reorderContent(data);}, 80);
236235
data.set($this, {task_id: task_id});
237236
}
238237
});
@@ -254,7 +253,7 @@
254253
data.set($this, {data: allData});
255254

256255
// 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) {
258257
if (settings.rows > 0 && currentRow >= settings.rows)
259258
break;
260259
// remove the number of elements in the new row from the top of data stack

0 commit comments

Comments
 (0)
Please sign in to comment.