-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathlayout.js
67 lines (53 loc) · 1.77 KB
/
layout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var $ = require('jquery')
var _ = require('underscore')
var Backbone = require('backbone')
var Header = require('./views/header')
var vizwit = require('./vizwit')
var vent = _.clone(Backbone.Events)
var fieldsCache = {}
module.exports = function (config, options) {
options = options || {}
if (!config.version || config.version !== '2') console.error('Wrong config version')
// Render header
if (config.header) {
var header = new Header(config.header)
$(options.headerSelector).empty().append(header.render().el)
// Update <title> tag
if (config.header.title) {
var originalTitle = $('title').text()
$('title').text(config.header.title + ' - ' + originalTitle)
}
}
var container = $(options.contentSelector)
var heightInterval = 60 // from gridstack.js
var current = {x: null, y: null}
var row
container.empty()
config.cards.forEach(function (config) {
// If y suggests we're on a new row (including the first item), create a new row
if (config.y !== current.y) {
row = $('<div class="row"></div>')
container.append(row)
current.y = config.y
current.x = 0
}
var column = $('<div/>')
// Add width class
column.addClass('col-sm-' + config.width)
// If x is not the same as our current x position, add offset class
if (config.x !== current.x) {
column.addClass('col-sm-offset-' + (config.x - current.x))
}
// Set height of new div
column.css('min-height', config.height * heightInterval)
// Increment current.x to new starting position
current.x += config.width
// Add the div to the current row
row.append(column)
// Initialize vizwit on new div
vizwit.init(column, config.vizwit, {
vent: vent,
fieldsCache: fieldsCache
})
})
}