Skip to content

Commit

Permalink
Add new version with id support
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Apr 8, 2019
1 parent 9d1072f commit c184b6b
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 14 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ These are all the options you can use in the constructor:

```js
new HelloBar({
id: "", // A unique ID for this hello bar content (required for targeting)
text: "", // Text you want the banner to display
hideClose: false, // Set to `true` to hide close button
position: "top", // Set to "bottom" to have the bar in the bottom instead of top
fixed: false, // Set to `true` to set the position as fixed (on scroll)
move: null, // Element(s) to force add margin-top to, in case you have any absolutely positioned elements
duration: 500, // Animation duration in miliseconds
delay: 1, // Delay in miliseconds
duration: 500, // Animation duration in ms
delay: 1, // Delay in ms
align: "center", // Text alignment in CSS ("left", "right", or "center")
background: "#eee", // Background color
textColor: null, // Black or white text is automagically determined; you can specify a color if you like
Expand Down
2 changes: 1 addition & 1 deletion build/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/index.css.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hello-bar",
"version": "1.2.0",
"version": "1.3.0",
"main": "build/index.js",
"scripts": {
"start": "node scripts/start.js",
Expand Down
7 changes: 7 additions & 0 deletions src/docs/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const multiLineText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.
class App {
constructor() {
this.libInstance = new Lib({
id: "github",
text: checkOutText,
background: "#5352ed",
size: "large",
Expand All @@ -27,6 +28,7 @@ class App {
case "cookie-law-1":
setTimeout(() => {
this.libInstance = new Lib({
id: "eu",
text: euText,
position: "bottom",
fixed: true
Expand All @@ -37,6 +39,7 @@ class App {
case "cookie-law-2":
setTimeout(() => {
this.libInstance = new Lib({
id: "eu-2",
text: euText,
targeting: {
location: {
Expand All @@ -50,6 +53,7 @@ class App {
case "multiline":
setTimeout(() => {
this.libInstance = new Lib({
id: "multiline",
text: multiLineText,
multiline: true
});
Expand All @@ -59,6 +63,7 @@ class App {
case "evening":
setTimeout(() => {
this.libInstance = new Lib({
id: "evening",
text: eveningText,
background: "#000",
targeting: {
Expand All @@ -75,6 +80,7 @@ class App {
case "random":
setTimeout(() => {
this.libInstance = new Lib({
id: "a-b-test",
text: randomText,
background: "#e24331",
size: "large"
Expand All @@ -85,6 +91,7 @@ class App {
default:
setTimeout(() => {
this.libInstance = new Lib({
id: "github",
text: checkOutText,
background: "#5352ed",
size: "large"
Expand Down
9 changes: 5 additions & 4 deletions src/lib/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class App {
Math.random()
.toString(36)
.substr(2);
if (this.settings.id) this.id = this.settings.id;
this.bar = document.createElement("div");
this.bar.setAttribute("id", this.id);
if (typeof this.settings.text === "object") {
Expand Down Expand Up @@ -96,11 +97,11 @@ class App {
return new Promise((resolve, reject) => {
const finishConfirmation = () => {
if (this.settings.targeting.once) {
if (sessionStorage.getItem("hello-bar--session-showed"))
if (sessionStorage.getItem(`hello-bar-${this.id}--session-showed`))
return reject();
}
if (this.settings.targeting.onceUser) {
if (localStorage.getItem("hello-bar--user-showed")) return reject();
if (localStorage.getItem(`hello-bar-${this.id}--user-showed`)) return reject();
}
if (Object.keys(this.settings.targeting.time).length) {
const timeMatches = {
Expand Down Expand Up @@ -197,8 +198,8 @@ class App {
hideBar() {
if (!document.querySelector(`#${this.id}`)) return;
this.bar.classList.remove("hello-bar--is-visible");
sessionStorage.setItem("hello-bar--session-showed", true);
localStorage.setItem("hello-bar--user-showed", true);
sessionStorage.setItem(`hello-bar-${this.id}--session-showed`, true);
localStorage.setItem(`hello-bar-${this.id}--user-showed`, true);
this.unMove();
setTimeout(() => {
this.bar.parentNode.removeChild(this.bar);
Expand Down

0 comments on commit c184b6b

Please sign in to comment.