Skip to content

Commit 1038692

Browse files
author
humancopy
committed
add two events: forkit-hover & forkit-out
1 parent 82f8dc1 commit 1038692

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

js/forkit.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
// The current state of the ribbon
3333
state = STATE_CLOSED,
3434

35+
// The last event sent so we don't dispatch multiple times
36+
last_event = '',
37+
3538
// Ribbon text, correlates to states
3639
closedText = '',
3740
detachedText = '',
@@ -187,6 +190,7 @@
187190
function detach() {
188191
state = STATE_DETACHED;
189192
dom.ribbonTag.innerHTML = detachedText;
193+
dispatchEvent( 'forkit-hover' );
190194
}
191195

192196
function animate() {
@@ -275,6 +279,7 @@
275279
anchorB.y += ( anchorA.y - anchorB.y ) * 0.2;
276280

277281
rotation += ( 45 - rotation ) * 0.2;
282+
dispatchEvent( 'forkit-out' );
278283
}
279284
}
280285

@@ -322,9 +327,11 @@
322327
}
323328

324329
function dispatchEvent( type ) {
325-
var event = document.createEvent( 'HTMLEvents', 1, 2 );
326-
event.initEvent( type, true, true );
327-
dom.ribbon.dispatchEvent( event );
330+
if ( last_event != type ) {
331+
var event = document.createEvent( 'HTMLEvents', 1, 2 );
332+
event.initEvent( type, true, true );
333+
dom.ribbon.dispatchEvent( event );
334+
}
328335
}
329336

330337
/**

0 commit comments

Comments
 (0)