Last active
May 12, 2022 21:14
-
-
Save GarySwift/ceca6a4e5b4af484a06caeb6c6104b1a to your computer and use it in GitHub Desktop.
Revisions
-
GarySwift revised this gist
May 12, 2022 . 2 changed files with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ import { cookies } from './lib/cookies'; import modal from './lib/modal'; $(document).ready(function() { modal(cookies); }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ export default function(cookies) { cookies.checkCookie(); } -
GarySwift created this gist
May 12, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ import { cookies } from './lib/cookies'; import modal from './lib/modal'; $(document).ready(function() { modal(cookies, 'Gutenberg'); }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ const cookies = { name: "username", timeInDays: 1, hello: function(name) { return 'Hello ' + name; }, setCookie: function(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); let expires = "expires="+d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + "path=/"; // document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; }, getCookie: function(cname) { let name = cname + "="; let ca = document.cookie.split(';'); for(let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; }, checkCookie: function () { let user = this.getCookie(this.name); if (user != "") { alert("Welcome again " + user); } else { user = prompt("Please enter your name:", ""); if (user != "" && user != null) { this.setCookie("username", user, this.timeInDays); } } } } export { cookies } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ export default function(cookies, name) { console.log('// modal code here'); console.log(cookies.hello(name)); cookies.checkCookie(); }