-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreactive_block_grid.coffee
81 lines (61 loc) · 2.01 KB
/
reactive_block_grid.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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Template.reactiveBlockGridItem.helpers
partial: ->
Template.parentData(1).template
position: ->
idMap=Template.parentData(1).cursor.fetch().map (i)-> i._id
_.indexOf(idMap, @_id)
Template.reactiveBlockGridItem.rendered = ->
$ul=Template.parentData(1).reactiveBlockGrid
if $ul?.data 'isotope-initialized'
li=$(this.find('li'))
$ul.isotope('insert', li)
setTimeout ->
$ul.isotope('updateSortData').isotope()
, 100
li.imagesLoaded ->
$ul.isotope('layout')
Template.reactiveBlockGrid.helpers
cursor: ->
@cursor
cssClasses: ->
@cssClass
Template.reactiveBlockGrid.destroyed = ()->
if @queryHandle
@queryHandle.stop()
@queryHandle = null
Template.reactiveBlockGrid.rendered = ()->
options={
itemSelector: 'li'
sortBy: 'reactiveBlockPosition'
sortAscending: true
getSortData:
reactiveBlockPosition: '[data-reactive-block-position] parseInt'
}
for opt in ['layoutMode', 'transitionDuration']
options[opt] = @data[opt] if @data[opt]?
masonryOptions = {}
for opt in ['columnWidth', 'gutter', 'isFitWidth']
masonryOptions[opt] = @data[opt] if @data[opt]?
options.masonry = masonryOptions unless _.isEmpty(masonryOptions)
$el=$(@find('ul.reactiveBlockGrid'))
$el.isotope options
for el in $(@find('.reactiveBlockGridElementContainer'))
$el.isotope 'insert', el
$el.attr('data-isotope-initialized', 'true')
@data.reactiveBlockGrid=$el
$el.imagesLoaded ->
$el.isotope 'layout'
if @data.cursor.limit? || @data.cursor.skip?
@queryHandle = @data.cursor.observeChanges
addedBefore: -> null
movedBefore: -> null
removed: (id) ->
selector = "[data-reactive-block-grid-item-id=#{id}]"
item = $el.find(selector)
$el.isotope('remove', item).isotope('layout')
else
@queryHandle = @data.cursor.observe
removed: (doc) ->
selector="[data-reactive-block-grid-item-id=#{doc._id}]"
item=$el.find(selector)
$el.isotope('remove', item).isotope('layout')