Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
95c5f9d4
Commit
95c5f9d4
authored
Jun 16, 2016
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better support for checking whether the page is visible or not.
parent
ee6d7ebd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
7 deletions
+48
-7
src/converse-core.js
src/converse-core.js
+47
-6
src/converse-notification.js
src/converse-notification.js
+1
-1
No files found.
src/converse-core.js
View file @
95c5f9d4
...
@@ -570,13 +570,54 @@
...
@@ -570,13 +570,54 @@
}
}
};
};
var
saveWindowState
=
function
(
ev
,
hidden
)
{
var
state
;
var
v
=
"
visible
"
,
h
=
"
hidden
"
,
event_map
=
{
'
focus
'
:
v
,
'
focusin
'
:
v
,
'
pageshow
'
:
v
,
'
blur
'
:
h
,
'
focusout
'
:
h
,
'
pagehide
'
:
h
};
ev
=
ev
||
window
.
event
;
if
(
ev
.
type
in
event_map
)
{
state
=
event_map
[
ev
.
type
];
}
else
{
state
=
document
[
hidden
]
?
"
hidden
"
:
"
visible
"
;
}
if
(
state
===
'
visible
'
)
{
converse
.
clearMsgCounter
();
}
converse
.
windowState
=
state
;
};
this
.
registerGlobalEventHandlers
=
function
()
{
this
.
registerGlobalEventHandlers
=
function
()
{
$
(
window
).
on
(
"
blur focus
"
,
function
(
ev
)
{
// Taken from:
if
((
converse
.
windowState
!==
ev
.
type
)
&&
(
ev
.
type
===
'
focus
'
))
{
// http://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active
converse
.
clearMsgCounter
();
var
hidden
=
"
hidden
"
;
}
// Standards:
converse
.
windowState
=
ev
.
type
;
if
(
hidden
in
document
)
{
});
document
.
addEventListener
(
"
visibilitychange
"
,
_
.
partial
(
saveWindowState
,
_
,
hidden
));
}
else
if
((
hidden
=
"
mozHidden
"
)
in
document
)
{
document
.
addEventListener
(
"
mozvisibilitychange
"
,
_
.
partial
(
saveWindowState
,
_
,
hidden
));
}
else
if
((
hidden
=
"
webkitHidden
"
)
in
document
)
{
document
.
addEventListener
(
"
webkitvisibilitychange
"
,
_
.
partial
(
saveWindowState
,
_
,
hidden
));
}
else
if
((
hidden
=
"
msHidden
"
)
in
document
)
{
document
.
addEventListener
(
"
msvisibilitychange
"
,
_
.
partial
(
saveWindowState
,
_
,
hidden
));
}
else
if
(
"
onfocusin
"
in
document
)
{
// IE 9 and lower:
document
.
onfocusin
=
document
.
onfocusout
=
_
.
partial
(
saveWindowState
,
_
,
hidden
);
}
else
{
// All others:
window
.
onpageshow
=
window
.
onpagehide
=
window
.
onfocus
=
window
.
onblur
=
_
.
partial
(
saveWindowState
,
_
,
hidden
);
}
// set the initial state (but only if browser supports the Page Visibility API)
if
(
document
[
hidden
]
!==
undefined
)
{
_
.
partial
(
saveWindowState
,
_
,
hidden
)({
type
:
document
[
hidden
]
?
"
blur
"
:
"
focus
"
});
}
};
};
this
.
afterReconnected
=
function
()
{
this
.
afterReconnected
=
function
()
{
...
...
src/converse-notification.js
View file @
95c5f9d4
...
@@ -117,7 +117,7 @@
...
@@ -117,7 +117,7 @@
if
(
ignore_blur
)
{
if
(
ignore_blur
)
{
return
enabled
;
return
enabled
;
}
else
{
}
else
{
return
enabled
&&
converse
.
windowState
===
'
blur
'
;
return
enabled
&&
converse
.
windowState
===
'
hidden
'
;
}
}
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment