@@ -17,23 +17,24 @@ class Util
1717 / Android| webOS| iPhone| iPad| iPod| BlackBerry| IEMobile| Opera Mini/ i .test (agent)
1818
1919# Minimalistic WeakMap shim, just in case.
20- WeakMap = @WeakMap or class WeakMap
21- constructor : ->
22- @keys = []
23- @values = []
24-
25- get : (key ) ->
26- for item, i in @keys
27- if item is key
28- return @values [i]
29-
30- set : (key , value ) ->
31- for item, i in @keys
32- if item is key
33- @values [i] = value
34- return
35- @keys .push (key)
36- @values .push (value)
20+ WeakMap = @WeakMap or @MozWeakMap or \
21+ class WeakMap
22+ constructor : ->
23+ @keys = []
24+ @values = []
25+
26+ get : (key ) ->
27+ for item, i in @keys
28+ if item is key
29+ return @values [i]
30+
31+ set : (key , value ) ->
32+ for item, i in @keys
33+ if item is key
34+ @values [i] = value
35+ return
36+ @keys .push (key)
37+ @values .push (value)
3738
3839# Dummy Mutation Observer, to avoid raising exceptions.
3940MutationObserver = @MutationObserver or @WebkitMutationObserver or @MozMutationObserver or \
@@ -42,8 +43,9 @@ MutationObserver = @MutationObserver or @WebkitMutationObserver or @MozMutationO
4243 console .warn ' MutationObserver is not supported by your browser. ' + \
4344 ' WOW.js cannot animate asynchronously loaded content.'
4445
45- observe : ->
46+ @notSupported : true
4647
48+ observe : ->
4749
4850class @WOW
4951 defaults :
@@ -65,10 +67,12 @@ class @WOW
6567 @ start ()
6668 else
6769 document .addEventListener ' DOMContentLoaded' , @start
70+ @finished = []
6871
6972 start : =>
7073 @stopped = false
7174 @boxes = @element .getElementsByClassName (@config .boxClass )
75+ @all = (box for box in @boxes )
7276 if @boxes .length
7377 if @ disabled ()
7478 @ resetStyle ()
@@ -79,15 +83,8 @@ class @WOW
7983 @interval = setInterval @scrollCallback , 50
8084 if @config .live
8185 new MutationObserver (records ) =>
82- unless @stopped
83- newElements = []
84- for record in records
85- for node in record .addedNodes or []
86- # Not every browser supports `classList`,
87- # but those that support `MutationObserver` all do.
88- newElements .push (node) if node .classList .contains (@config .boxClass )
89- @ applyStyle (box, true ) for box in newElements
90- @boxes .push newElements...
86+ for record in records
87+ @ doSync (node) for node in record .addedNodes or []
9188 .observe document .body ,
9289 childList : true
9390 subtree : true
@@ -99,6 +96,18 @@ class @WOW
9996 window .removeEventListener (' resize' , @scrollHandler , false )
10097 clearInterval @interval if @interval ?
10198
99+ sync : (element ) ->
100+ @ doSync (@element ) if MutationObserver .notSupported
101+
102+ doSync : (element ) ->
103+ unless @stopped
104+ for box in (element or @element ).getElementsByClassName (@config .boxClass )
105+ unless box in @all
106+ @ applyStyle (box, true )
107+ @boxes .push box
108+ @all .push box
109+ @scrolled = true
110+
102111 # show box element
103112 show : (box ) ->
104113 @ applyStyle (box)
0 commit comments