Skip to content

Commit 2336227

Browse files
committed
Use hasFocus for IE.
Should fix gsklee#171, gsklee#167 Ref gsklee#47 Not sure if gsklee#47 is fixed yet.
1 parent 7cfa1c0 commit 2336227

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ngStorage.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@
8686
'$window',
8787
'$log',
8888
'$timeout',
89+
'$document',
8990

9091
function(
9192
$rootScope,
9293
$window,
9394
$log,
94-
$timeout
95+
$timeout,
96+
$document
9597
){
9698
function isStorageSupported(storageType) {
9799

@@ -190,7 +192,12 @@
190192

191193
// #6: Use `$window.addEventListener` instead of `angular.element` to avoid the jQuery-specific `event.originalEvent`
192194
$window.addEventListener && $window.addEventListener('storage', function(event) {
193-
if (storageKeyPrefix === event.key.slice(0, prefixLength)) {
195+
// Reference doc.
196+
var doc = $document[0];
197+
// Figure out if hasFocus / hasFocus() exists.
198+
var hasDocFocus = angular.isDefined(doc.hasFocus);
199+
200+
if ( ( hasDocFocus ? (doc.hasFocus || doc.hasFocus()) : true ) && storageKeyPrefix === event.key.slice(0, prefixLength) ) {
194201
event.newValue ? $storage[event.key.slice(prefixLength)] = deserializer(event.newValue) : delete $storage[event.key.slice(prefixLength)];
195202

196203
_last$storage = angular.copy($storage);

0 commit comments

Comments
 (0)