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
003af0c4
Commit
003af0c4
authored
Dec 15, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`visibilitychange` is supported by all browsers we support
So simplify the code that saves the window state
parent
935ca52b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
52 deletions
+12
-52
dist/converse.js
dist/converse.js
+6
-27
src/headless/converse-core.js
src/headless/converse-core.js
+6
-25
No files found.
dist/converse.js
View file @
003af0c4
...
...
@@ -63394,7 +63394,7 @@ _converse.initialize = function (settings, callback) {
_converse.emit('logout');
};
this.saveWindowState = function (ev
, hidden
) {
this.saveWindowState = function (ev) {
// XXX: eventually we should be able to just use
// document.visibilityState (when we drop support for older
// browsers).
...
...
@@ -63412,7 +63412,7 @@ _converse.initialize = function (settings, callback) {
if (ev.type in event_map) {
state = event_map[ev.type];
} else {
state = document
[hidden]
? "hidden" : "visible";
state = document
.hidden
? "hidden" : "visible";
}
if (state === 'visible') {
...
...
@@ -63427,32 +63427,11 @@ _converse.initialize = function (settings, callback) {
};
this.registerGlobalEventHandlers = function () {
// Taken from:
// http://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active
let hidden = "hidden"; // Standards:
document.addEventListener("visibilitychange", _converse.saveWindowState); // set the initial state
if (hidden in document) {
document.addEventListener("visibilitychange", _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.partial(_converse.saveWindowState, _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a, hidden));
} else if ((hidden = "mozHidden") in document) {
document.addEventListener("mozvisibilitychange", _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.partial(_converse.saveWindowState, _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a, hidden));
} else if ((hidden = "webkitHidden") in document) {
document.addEventListener("webkitvisibilitychange", _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.partial(_converse.saveWindowState, _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a, hidden));
} else if ((hidden = "msHidden") in document) {
document.addEventListener("msvisibilitychange", _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.partial(_converse.saveWindowState, _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a, hidden));
} else if ("onfocusin" in document) {
// IE 9 and lower:
document.onfocusin = document.onfocusout = _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.partial(_converse.saveWindowState, _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a, hidden);
} else {
// All others:
window.onpageshow = window.onpagehide = window.onfocus = window.onblur = _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.partial(_converse.saveWindowState, _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a, hidden);
} // set the initial state (but only if browser supports the Page Visibility API)
if (document[hidden] !== undefined) {
_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.partial(_converse.saveWindowState, _lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a, hidden)({
type: document[hidden] ? "blur" : "focus"
_converse.saveWindowState({
'type': document.hidden ? "blur" : "focus"
});
}
_converse.emit('registeredGlobalEventHandlers');
};
src/headless/converse-core.js
View file @
003af0c4
...
...
@@ -817,7 +817,7 @@ _converse.initialize = function (settings, callback) {
_converse
.
emit
(
'
logout
'
);
};
this
.
saveWindowState
=
function
(
ev
,
hidden
)
{
this
.
saveWindowState
=
function
(
ev
)
{
// XXX: eventually we should be able to just use
// document.visibilityState (when we drop support for older
// browsers).
...
...
@@ -834,7 +834,7 @@ _converse.initialize = function (settings, callback) {
if
(
ev
.
type
in
event_map
)
{
state
=
event_map
[
ev
.
type
];
}
else
{
state
=
document
[
hidden
]
?
"
hidden
"
:
"
visible
"
;
state
=
document
.
hidden
?
"
hidden
"
:
"
visible
"
;
}
if
(
state
===
'
visible
'
)
{
_converse
.
clearMsgCounter
();
...
...
@@ -844,29 +844,10 @@ _converse.initialize = function (settings, callback) {
};
this
.
registerGlobalEventHandlers
=
function
()
{
// Taken from:
// http://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active
let
hidden
=
"
hidden
"
;
// Standards:
if
(
hidden
in
document
)
{
document
.
addEventListener
(
"
visibilitychange
"
,
_
.
partial
(
_converse
.
saveWindowState
,
_
,
hidden
));
}
else
if
((
hidden
=
"
mozHidden
"
)
in
document
)
{
document
.
addEventListener
(
"
mozvisibilitychange
"
,
_
.
partial
(
_converse
.
saveWindowState
,
_
,
hidden
));
}
else
if
((
hidden
=
"
webkitHidden
"
)
in
document
)
{
document
.
addEventListener
(
"
webkitvisibilitychange
"
,
_
.
partial
(
_converse
.
saveWindowState
,
_
,
hidden
));
}
else
if
((
hidden
=
"
msHidden
"
)
in
document
)
{
document
.
addEventListener
(
"
msvisibilitychange
"
,
_
.
partial
(
_converse
.
saveWindowState
,
_
,
hidden
));
}
else
if
(
"
onfocusin
"
in
document
)
{
// IE 9 and lower:
document
.
onfocusin
=
document
.
onfocusout
=
_
.
partial
(
_converse
.
saveWindowState
,
_
,
hidden
);
}
else
{
// All others:
window
.
onpageshow
=
window
.
onpagehide
=
window
.
onfocus
=
window
.
onblur
=
_
.
partial
(
_converse
.
saveWindowState
,
_
,
hidden
);
}
// set the initial state (but only if browser supports the Page Visibility API)
if
(
document
[
hidden
]
!==
undefined
)
{
_
.
partial
(
_converse
.
saveWindowState
,
_
,
hidden
)({
type
:
document
[
hidden
]
?
"
blur
"
:
"
focus
"
});
}
document
.
addEventListener
(
"
visibilitychange
"
,
_converse
.
saveWindowState
);
// set the initial state
_converse
.
saveWindowState
({
'
type
'
:
document
.
hidden
?
"
blur
"
:
"
focus
"
});
_converse
.
emit
(
'
registeredGlobalEventHandlers
'
);
};
...
...
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