-
Notifications
You must be signed in to change notification settings - Fork 27
/
mf-notification.js
84 lines (69 loc) · 1.94 KB
/
mf-notification.js
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
82
83
84
( function( M, $ ) {
var m = ( function() {
var calculatePosition = function() {},
canCancel = true,
inBeta = mw.config.get( 'wgMFMode' ) === 'beta';
function isVisible() {
return $( '#mf-notification' ).is( ':visible' );
}
function show( html, classes ) {
canCancel = false;
window.setTimeout( function() {
canCancel = true;
}, 1000 );
$( '#mf-notification div' ).html( html );
calculatePosition();
return $( '#mf-notification' ).
removeAttr( 'class' ).
addClass( classes ).
addClass( 'position-fixed visible' );
}
function close( forceClose ) {
var $notification = $( '#mf-notification' );
if ( !$notification.hasClass( 'visible' ) || !canCancel ) {
return;
} else if ( !$notification.hasClass( 'locked' ) || forceClose ) {
$( '#mf-notification' ).removeClass( 'visible' );
}
}
function notifyAuthenticatedUser() {
var msg = mw.msg( 'mobile-frontend-logged-in-toast-notification',
mw.config.get( 'wgUserName' ) );
if ( window.location.search.indexOf( 'welcome=yes' ) > -1 ) {
show( msg, 'toast' );
}
}
function init( firstRun ) {
// FIXME: turn into view with template
var el = $( '<div id="mf-notification" class="position-fixed"><div></div></div>' ).
appendTo( '#notifications' )[ 0 ];
if ( inBeta ) {
notifyAuthenticatedUser();
}
firstRun = firstRun === undefined ? true : firstRun;
function cancelBubble( ev ) {
ev.stopPropagation();
}
el.ontouchstart = cancelBubble;
$( '<button>' ).click( function( ev ) {
ev.stopPropagation();
close( true );
} ).appendTo( '#mf-notification' );
if ( firstRun ) {
$( window ).scroll( function() {
close();
} );
$( document.body ).bind( 'click touchstart', function() {
close();
} );
}
}
$( init );
return {
close: close,
isVisible: isVisible,
show: show
};
}() );
M.define( 'notifications', m );
}( mw.mobileFrontend, jQuery ) );