-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmasonrify.coffee
66 lines (51 loc) · 1.97 KB
/
masonrify.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
class Masonrify
@instances= {}
constructor: (container, options) ->
options = _.extend({itemSelector: ".masonry_element", stamp: ".stamped", masonry: options}, options)
@_ms = new Isotope(container, options)
@_container = container
addItems: (items) -> @_ms.addItems(items)
appended: (div) -> @_ms.appended(div)
refreshSize: (item) -> @_ms.fit(item)
debouncedRelayout: _.debounce( ()->
#console.log("masonry debounced")
if (@_ms)
#if (true)
#console.log("masonry reloading and sorting original order")
#$(@_container).isotope( 'reloadItems' ).isotope({ sortBy: 'original-order' }).isotope('reLayout');
#@_ms.reloadItems()
@_ms.layout()
,200)
remove: (item) -> @_ms.remove(item[0])
unStamp: (element,callback) ->
@_ms.unstamp(element)
callback() if callback?
@debouncedRelayout(false)
reStamp: (element, callback) ->
@_ms.stamp(element)
callback() if callback?
@debouncedRelayout(false)
on: (event, callback) ->
@_ms.on(event, callback)
off: (event, callback) ->
@_ms.off(event, callback)
#Meteor.startup ->
getContainerId = (data) -> data.container ? data
Template.masonryContainer.rendered = ->
#console.log(this.data)
Masonrify.instances[this.data.id] = new Masonrify(this.firstNode, this.data)
Template.masonryContainer.masonryContainerId = ->
#console.log("got masonry cont id", this.id)
this.id
Template.masonryElement.setContainerId = (arg1,arg2) ->
#console.log("setContainerId", this, arg1,arg2)
return null
Template.masonryElement.rendered = (arg1, arg2) ->
#console.log("masonryElement rendered", this)
contId = getContainerId(this.data)
element = this.firstNode
Masonrify.instances[contId]?.appended(element)
#Masonrify.instances[contId]?.debouncedRelayout()
imagesLoaded(this.firstNode, -> Masonrify.instances[contId]?.debouncedRelayout())
Template.masonryElement.destroyed = ->
Masonrify.instances[getContainerId(this.data)]?.debouncedRelayout(true)