@@ -138,7 +138,7 @@ unBlob.createUserInterface = function() {
138
138
container . className = 'unblob-container--hidden' ;
139
139
140
140
link . className = 'unblob-button'
141
-
141
+ link . target = '_blank' ;
142
142
link . innerHTML = '<svg viewBox="0 0 24 24"><path d="M18 19H6a1 1 0 01-1-1V6c0-.6.5-1 1-1h5c.6 0 1-.5 1-1s-.5-1-1-1H5a2 2 0 00-2 2v14c0 1.1.9 2 2 2h14a2 2 0 002-2v-6c0-.6-.5-1-1-1s-1 .5-1 1v5c0 .6-.5 1-1 1zM14 4c0 .6.5 1 1 1h2.6l-9.1 9.1a1 1 0 101.4 1.4l9.1-9V9c0 .6.5 1 1 1s1-.5 1-1V4c0-.6-.5-1-1-1h-5a1 1 0 00-1 1z"/></svg>' ;
143
143
144
144
container . appendChild ( link ) ;
@@ -155,21 +155,25 @@ unBlob.createUserInterface = function() {
155
155
------------------------------------------------------------------------------*/
156
156
157
157
158
- unBlob . resizeUserInterface = function ( rect ) {
159
- if ( unBlob . ui . offsetLeft !== rect . left ) {
160
- unBlob . ui . style . left = rect . left + 'px' ;
161
- }
158
+ unBlob . resizeUserInterface = function ( ) {
159
+ if ( unBlob . active ) {
160
+ var rect = unBlob . active ;
162
161
163
- if ( unBlob . ui . offsetTop !== rect . top ) {
164
- unBlob . ui . style . top = rect . top + 'px' ;
165
- }
162
+ if ( unBlob . ui . offsetLeft !== rect . left ) {
163
+ unBlob . ui . style . left = rect . left + 'px' ;
164
+ }
166
165
167
- if ( unBlob . ui . offsetWidth !== rect . width ) {
168
- unBlob . ui . style . width = rect . width + 'px' ;
169
- }
166
+ if ( unBlob . ui . offsetTop !== rect . top ) {
167
+ unBlob . ui . style . top = rect . top + 'px' ;
168
+ }
170
169
171
- if ( unBlob . ui . offsetHeight !== rect . height ) {
172
- unBlob . ui . style . height = rect . height + 'px' ;
170
+ if ( unBlob . ui . offsetWidth !== rect . width ) {
171
+ unBlob . ui . style . width = rect . width + 'px' ;
172
+ }
173
+
174
+ if ( unBlob . ui . offsetHeight !== rect . height ) {
175
+ unBlob . ui . style . height = rect . height + 'px' ;
176
+ }
173
177
}
174
178
} ;
175
179
@@ -187,19 +191,28 @@ unBlob.observe = function() {
187
191
data = element . getBoundingClientRect ( ) ;
188
192
189
193
element . classList . add ( 'unblob-media' ) ;
194
+ element . unblob_index = unBlob . rects . length ;
190
195
191
196
unBlob . media . push ( element ) ;
192
197
193
198
unBlob . rects . push ( {
194
199
index : unBlob . rects . length
195
200
} ) ;
196
201
197
- var rect = unBlob . rects [ unBlob . rects . length ] ;
202
+ element . addEventListener ( 'timeupdate' , function ( ) {
203
+ var data = this . getBoundingClientRect ( ) ,
204
+ rect = unBlob . rects [ this . unblob_index ] ;
198
205
199
- rect . left = data . left ;
200
- rect . top = data . top ;
201
- rect . width = data . width ;
202
- rect . height = data . height ;
206
+ if ( data && this . style . display != 'none' ) {
207
+
208
+ rect . left = data . left ;
209
+ rect . top = data . top ;
210
+ rect . width = data . width ;
211
+ rect . height = data . height ;
212
+
213
+ unBlob . resizeUserInterface ( ) ;
214
+ }
215
+ } ) ;
203
216
}
204
217
} , 1000 ) ;
205
218
} ;
@@ -223,6 +236,8 @@ unBlob.updateRects = function() {
223
236
rect . height = data . height ;
224
237
}
225
238
}
239
+
240
+ unBlob . resizeUserInterface ( ) ;
226
241
} ;
227
242
228
243
@@ -231,7 +246,7 @@ unBlob.updateRects = function() {
231
246
------------------------------------------------------------------------------*/
232
247
233
248
unBlob . mouseOver = function ( ) {
234
- var active = false ;
249
+ unBlob . active = false ;
235
250
236
251
for ( var i = 0 , l = unBlob . rects . length ; i < l ; i ++ ) {
237
252
var rect = unBlob . rects [ i ] ;
@@ -242,16 +257,16 @@ unBlob.mouseOver = function() {
242
257
unBlob . mouse . x < rect . left + rect . width &&
243
258
unBlob . mouse . y < rect . top + rect . height
244
259
) {
245
- active = rect ;
260
+ unBlob . active = rect ;
246
261
}
247
262
}
248
263
249
- if ( active ) {
250
- if ( unBlob . ui ) {
264
+ if ( unBlob . active ) {
265
+ if ( unBlob . ui && unBlob . ui . className !== 'unblob-container' ) {
251
266
unBlob . ui . className = 'unblob-container' ;
252
267
}
253
268
254
- var found = unBlob . blobs [ unBlob . media [ active . index ] . src ] ;
269
+ var found = unBlob . blobs [ unBlob . media [ unBlob . active . index ] . src ] ;
255
270
256
271
if (
257
272
found &&
@@ -261,11 +276,11 @@ unBlob.mouseOver = function() {
261
276
) {
262
277
unBlob . ui_link . href = found . activeSourceBuffers [ 0 ] . URL . replace ( / ( \& | \? ) r a n g e \= [ ^ & ] * / , '' ) ;
263
278
} else {
264
- unBlob . ui_link . href = unBlob . media [ active . index ] . src ;
279
+ unBlob . ui_link . href = unBlob . media [ unBlob . active . index ] . src ;
265
280
}
266
281
267
- unBlob . resizeUserInterface ( active ) ;
268
- } else if ( unBlob . ui ) {
282
+ unBlob . resizeUserInterface ( ) ;
283
+ } else if ( unBlob . ui && unBlob . ui . className !== 'unblob-container--hidden' ) {
269
284
unBlob . ui . className = 'unblob-container--hidden' ;
270
285
}
271
286
} ;
@@ -285,20 +300,14 @@ unBlob.init = function() {
285
300
unBlob . createUserInterface ( ) ;
286
301
unBlob . observe ( ) ;
287
302
288
- window . addEventListener ( 'scroll' , unBlob . updateRects ) ;
289
- window . addEventListener ( 'mousewheel' , unBlob . updateRects ) ;
303
+ setInterval ( unBlob . mouseOver ) ;
290
304
291
- window . addEventListener ( 'resize' , function ( ) {
292
- setTimeout ( function ( ) {
293
- unBlob . updateRects ( ) ;
294
- } , 100 ) ;
295
- } ) ;
305
+ window . addEventListener ( 'popstate' , unBlob . updateRects ) ;
306
+ window . addEventListener ( 'scroll' , unBlob . updateRects ) ;
296
307
297
308
window . addEventListener ( 'mousemove' , function ( event ) {
298
309
unBlob . mouse . x = event . clientX ;
299
310
unBlob . mouse . y = event . clientY ;
300
-
301
- unBlob . mouseOver ( ) ;
302
311
} ) ;
303
312
} ) ;
304
313
} ;
0 commit comments