Skip to content

Commit db6ce73

Browse files
committed
Moved hasSessionStorage and hasLocalStorage into detectors.js (snowplow#91)
1 parent 88a3d5e commit db6ce73

4 files changed

Lines changed: 30 additions & 29 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Renamed SnowPlow everywhere to Snowplow (#69) (TODO)
1616
Prepended window. or SnowPlow.windowAlias. onto _snaq everywhere (#39)
1717
Removed legacy Piwik plugin framework (#56)
1818
Rebased with 0.14.0 (#87)
19+
Moved hasSessionStorage and hasLocalStorage into detectors.js (#91)
1920

2021
Version 0.14.0 (2014-02-12)
2122
---------------------------

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ module.exports = function(grunt) {
121121
},
122122
files: [
123123
{
124-
src: 'dist/bundle.js',
124+
src: 'dist/snowplow.js',
125125
dest: 'dist/sp.js'
126126
}
127127
]

src/js/lib/detectors.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,32 @@
4040
var helpers = require('helpers');
4141
var murmurhash3_32_gc = require('murmurhash').v3;
4242

43+
/*
44+
* Checks whether sessionStorage is available, in a way that
45+
* does not throw a SecurityError in Firefox if "always ask"
46+
* is enabled for cookies (https://github.com/snowplow/snowplow/issues/163).
47+
*/
48+
object.hasSessionStorage = function () {
49+
try {
50+
return !!window.sessionStorage;
51+
} catch (e) {
52+
return true; // SecurityError when referencing it means it exists
53+
}
54+
}
55+
56+
/*
57+
* Checks whether localStorage is available, in a way that
58+
* does not throw a SecurityError in Firefox if "always ask"
59+
* is enabled for cookies (https://github.com/snowplow/snowplow/issues/163).
60+
*/
61+
object.hasLocalStorage = function () {
62+
try {
63+
return !!window.localStorage;
64+
} catch (e) {
65+
return true; // SecurityError when referencing it means it exists
66+
}
67+
}
68+
4369
/*
4470
* Does browser have cookies enabled (for this site)?
4571
*/
@@ -66,8 +92,8 @@
6692
navigator.userAgent,
6793
[ screen.height, screen.width, screen.colorDepth ].join("x"),
6894
( new Date() ).getTimezoneOffset(),
69-
helpers.hasSessionStorage(),
70-
helpers.hasLocalStorage(),
95+
object.hasSessionStorage(),
96+
object.hasLocalStorage(),
7197
];
7298

7399
var plugins = [];

src/js/lib/helpers.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,6 @@
7070
return matches ? matches[1] : url;
7171
}
7272

73-
/*
74-
* Checks whether sessionStorage is available, in a way that
75-
* does not throw a SecurityError in Firefox if "always ask"
76-
* is enabled for cookies (https://github.com/snowplow/snowplow/issues/163).
77-
*/
78-
object.hasSessionStorage = function () {
79-
try {
80-
return !!window.sessionStorage;
81-
} catch (e) {
82-
return true; // SecurityError when referencing it means it exists
83-
}
84-
}
85-
86-
/*
87-
* Checks whether localStorage is available, in a way that
88-
* does not throw a SecurityError in Firefox if "always ask"
89-
* is enabled for cookies (https://github.com/snowplow/snowplow/issues/163).
90-
*/
91-
object.hasLocalStorage = function () {
92-
try {
93-
return !!window.localStorage;
94-
} catch (e) {
95-
return true; // SecurityError when referencing it means it exists
96-
}
97-
}
98-
9973
/*
10074
* Fix-up URL when page rendered from search engine cache or translated page.
10175
* TODO: it would be nice to generalise this and/or move into the ETL phase.

0 commit comments

Comments
 (0)