Skip to content

Commit 07de8c6

Browse files
committed
Use jQuery.ready to prevent too early event binding
This prevents binding before the service is initialized
1 parent 305114a commit 07de8c6

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

templateListener.xml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,34 @@
66
<templatename>headInclude</templatename>
77
<eventname>javascriptInit</eventname>
88
<templatecode><![CDATA[{if $__wcf->user->userID}
9-
(function() {
10-
var notification = new WCF.System.Notification('{lang}wcf.user.notification.new{/lang}', 'info');
11-
12-
be.bastelstu.wcf.push.onMessage('be.bastelstu.max.wcf.user.newNotification', function() {
13-
// You have mail!
14-
notification.show(null, 5e3);
9+
(function($, window) {
10+
$(function() {
11+
var notification = new WCF.System.Notification('{lang}wcf.user.notification.new{/lang}', 'info');
1512
16-
// Load WCF notifications and fire the corresponding callback
17-
// See WCF.System.KeepAlive <https://github.com/WoltLab/WCF/blob/3a80c04c92fab9dcc84d520717ed72fd1ef0a4ff/wcfsetup/install/files/js/WCF.js#L8219>
18-
if (typeof WCF.System.PushNotification !== 'undefined') {
19-
new WCF.Action.Proxy({
20-
autoSend: true,
21-
data: {
22-
actionName: 'keepAlive',
23-
className: 'wcf\\data\\session\\SessionAction'
24-
},
25-
failure: function() { },
26-
showLoadingOverlay: false,
27-
success: function(data) {
28-
WCF.System.PushNotification.executeCallbacks(data);
29-
},
30-
suppressErrors: true
31-
});
32-
}
13+
be.bastelstu.wcf.push.onMessage('be.bastelstu.max.wcf.user.newNotification', function() {
14+
// You have mail!
15+
notification.show(null, 5e3);
16+
17+
// Load WCF notifications and fire the corresponding callback
18+
// See WCF.System.KeepAlive <https://github.com/WoltLab/WCF/blob/3a80c04c92fab9dcc84d520717ed72fd1ef0a4ff/wcfsetup/install/files/js/WCF.js#L8219>
19+
if (typeof WCF.System.PushNotification !== 'undefined') {
20+
new WCF.Action.Proxy({
21+
autoSend: true,
22+
data: {
23+
actionName: 'keepAlive',
24+
className: 'wcf\\data\\session\\SessionAction'
25+
},
26+
failure: function() { },
27+
showLoadingOverlay: false,
28+
success: function(data) {
29+
WCF.System.PushNotification.executeCallbacks(data);
30+
},
31+
suppressErrors: true
32+
});
33+
}
34+
});
3335
});
34-
})();{/if}]]></templatecode>
36+
})(jQuery, window);{/if}]]></templatecode>
3537
</templatelistener>
3638
</import>
3739
</data>

0 commit comments

Comments
 (0)