generated from phucbm/gulp-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
97 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import md from "../md/cookie.md"; | ||
import mdView from "../md/view-cookie-popup.md"; | ||
|
||
export function testCookie(root){ | ||
root.insertAdjacentHTML('beforeend', md); | ||
|
||
const isViewingPopup = new URL(window.location.href).search === '?view-cookie-popup'; | ||
|
||
if(isViewingPopup){ | ||
root.insertAdjacentHTML('beforeend', mdView); | ||
} | ||
const popup = EasyPopup.get('popup-cookie'); | ||
|
||
|
||
const isClearCookie = new URL(window.location.href).search === '?clear-all-cookie'; | ||
if(isClearCookie){ | ||
console.log('clear cookie') | ||
Pia.remove(popup.cookie.key) // todo: finish clear cookie | ||
} | ||
|
||
|
||
EasyPopup.init(); | ||
|
||
popup.on('open', () => { | ||
console.log(Pia.test(popup.cookie.key)) | ||
}); | ||
} |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
## `cookie` | ||
|
||
Requires [PiaJs](https://github.com/phucbm/pia) v0.0.4 or later. | ||
|
||
Show popup **once** and not showing again after a period of time. | ||
|
||
- Popup re-appears after 7 days: `{autoShow:true, cookie: 7}` | ||
- Popup re-appears after 30 days: `{autoShow:true, cookie: "30 days"}` | ||
- Popup re-appears after 8 hours: `{autoShow:true, cookie: "8 hours"}` | ||
|
||
Show popup for **a number of times** and reset after a period of time. | ||
|
||
- Shows 3 times, then re-appears after 7 days: `{autoShow:true, cookie: 7, showingTimes: 3}` | ||
|
||
### Clear cookie | ||
|
||
To clear cookie for all client devices. | ||
|
||
- `{autoShow:false}`: prevent the popup reappears, however, the cookie still exists in the client | ||
devices. | ||
- `{cookie:undefined}`: clear cookie if any. | ||
|
||
### Update cookie | ||
|
||
Set a new cookie name to disconnect with the current cookie. Otherwise, the popup will always look for the cookie with | ||
the | ||
default name. | ||
|
||
- `{cookie:"new_expiration_value", cookieName:"new_name"}` | ||
|
||
### Test cookie | ||
|
||
Using [`Pia.test()`](https://github.com/phucbm/pia#test-record). | ||
|
||
```js | ||
const popup = EasyPopup.get('popup-cookie'); | ||
|
||
console.log(Pia.test(popup.cookie.key)); | ||
``` | ||
|
||
> [Click here to reload and view demo cookie popups](?view-cookie-popup) |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
> You're viewing page with cookie popups. Click [❌ clear all demo cookies](?clear-all-cookie) to remove cookie and test | ||
> again. | ||
<div data-easy-popup='{"id": "popup-cookie","autoShow": "true", "cookie": "1 day"}'> | ||
<!-- Popup content --> | ||
<h2>1 day popup</h2> | ||
<h3>This popup auto open once, and off for 1 day.</h3> | ||
</div> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 characters