aboutsummaryrefslogtreecommitdiff
path: root/haddock-api/resources/html/js-src/cookies.ts
diff options
context:
space:
mode:
authoralexbiehl <alex.biehl@gmail.com>2017-10-31 21:48:55 +0100
committeralexbiehl <alex.biehl@gmail.com>2017-10-31 21:48:55 +0100
commit08c9e19236770811caf571321f5ece271d1fccff (patch)
treebeb3f6407d14abcab32f9d54811cabd319c356a4 /haddock-api/resources/html/js-src/cookies.ts
parent3896bff411596ef50b5ca2f2be425e89878410aa (diff)
parente5fe98530d9c70f5197494da9de07f42dd7fe334 (diff)
Merge remote-tracking branch 'origin/master' into ghc-head
Diffstat (limited to 'haddock-api/resources/html/js-src/cookies.ts')
-rw-r--r--haddock-api/resources/html/js-src/cookies.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/haddock-api/resources/html/js-src/cookies.ts b/haddock-api/resources/html/js-src/cookies.ts
new file mode 100644
index 00000000..3b68d6d8
--- /dev/null
+++ b/haddock-api/resources/html/js-src/cookies.ts
@@ -0,0 +1,20 @@
+export function setCookie(name: string, value: string) {
+ document.cookie = name + "=" + encodeURIComponent(value) + ";path=/;";
+}
+
+export function clearCookie(name: string) {
+ document.cookie = name + "=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT;";
+}
+
+export function getCookie(name: string) {
+ const nameEQ = name + "=";
+ const ca = document.cookie.split(';');
+ for (let i = 0; i < ca.length; i++) {
+ let c = ca[i];
+ while (c.charAt(0)==' ') c = c.substring(1,c.length);
+ if (c.indexOf(nameEQ) == 0) {
+ return decodeURIComponent(c.substring(nameEQ.length,c.length));
+ }
+ }
+ return null;
+} \ No newline at end of file