-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclusterize.coffee
42 lines (35 loc) · 1.19 KB
/
clusterize.coffee
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
import { Mongo } from 'meteor/mongo'
import { Template } from 'meteor/templating'
import Clusterize from './clusterize-blaze.js'
import './clusterize.tpl.jade'
Template.clusterize.onRendered ->
@autorun =>
data = Template.currentData()
if data.data instanceof Mongo.Collection.Cursor
list = data.data.fetch()
cacheTemplate = true
else
list = data.data
cacheTemplate = false
return unless (@clusterize || list?.length > 0)
template = Template[data.template]
rowsInBlock = data.rowsInBlock
blocksInCluster = data.blocksInCluster
otherArgs = _.omit(data, ['template', 'data', 'rowsInBlock', 'blocksInCluster'])
if @clusterize
@clusterize.update(list)
else
@clusterize = new Clusterize
rows: list,
template: template,
otherArgs: otherArgs,
scrollId: 'scrollArea',
contentId: 'contentArea',
tag: 'div',
rows_in_block: rowsInBlock,
blocks_in_cluster: blocksInCluster,
no_data_text: ''
initialScrollPosition: @data.initialScrollPosition || 0
cacheTemplate: cacheTemplate
Template.clusterize.onDestroyed ->
@clusterize.destroy(true) if @clusterize