Rendering of buttons
Browse files- assets/scripts/src/constants.js +1 -0
- assets/scripts/src/popover.js +59 -9
- assets/scripts/src/sholo.js +10 -1
- assets/styles/scss/demo.scss +6 -0
- index.html +1 -1
assets/scripts/src/constants.js
CHANGED
@@ -15,6 +15,7 @@ export const CLASS_POPOVER_FOOTER = 'sholo-popover-footer';
|
|
15 |
export const CLASS_CLOSE_BTN = 'sholo-close-btn';
|
16 |
export const CLASS_NEXT_STEP_BTN = 'sholo-next-btn';
|
17 |
export const CLASS_PREV_STEP_BTN = 'sholo-prev-btn';
|
|
|
18 |
|
19 |
// language=HTML
|
20 |
export const POPOVER_HTML = `
|
|
|
15 |
export const CLASS_CLOSE_BTN = 'sholo-close-btn';
|
16 |
export const CLASS_NEXT_STEP_BTN = 'sholo-next-btn';
|
17 |
export const CLASS_PREV_STEP_BTN = 'sholo-prev-btn';
|
18 |
+
export const CLASS_BTN_DISABLED = 'sholo-disabled';
|
19 |
|
20 |
// language=HTML
|
21 |
export const POPOVER_HTML = `
|
assets/scripts/src/popover.js
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
import Element from './element';
|
2 |
import {
|
3 |
-
|
|
|
|
|
|
|
4 |
CLASS_POPOVER_TIP,
|
5 |
-
CLASS_POPOVER_TITLE,
|
6 |
ID_POPOVER,
|
7 |
-
OVERLAY_PADDING,
|
8 |
POPOVER_HTML,
|
9 |
} from './constants';
|
10 |
|
@@ -12,12 +14,20 @@ import {
|
|
12 |
* Popover that is displayed on top of the highlighted element
|
13 |
*/
|
14 |
export default class Popover extends Element {
|
15 |
-
constructor(options
|
16 |
-
padding: OVERLAY_PADDING,
|
17 |
-
}, window, document) {
|
18 |
super();
|
19 |
|
20 |
-
this.options =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
this.window = window;
|
22 |
this.document = document;
|
23 |
|
@@ -36,6 +46,10 @@ export default class Popover extends Element {
|
|
36 |
this.tipNode = popover.querySelector(`.${CLASS_POPOVER_TIP}`);
|
37 |
this.titleNode = popover.querySelector(`.${CLASS_POPOVER_TITLE}`);
|
38 |
this.descriptionNode = popover.querySelector(`.${CLASS_POPOVER_DESCRIPTION}`);
|
|
|
|
|
|
|
|
|
39 |
}
|
40 |
|
41 |
/**
|
@@ -75,12 +89,16 @@ export default class Popover extends Element {
|
|
75 |
.className = CLASS_POPOVER_TIP;
|
76 |
}
|
77 |
|
|
|
|
|
|
|
|
|
78 |
show(position) {
|
79 |
this.reset();
|
80 |
|
81 |
// Set the title and descriptions
|
82 |
-
this.titleNode.
|
83 |
-
this.descriptionNode.
|
84 |
|
85 |
// Position the popover around the given position
|
86 |
switch (this.options.position) {
|
@@ -101,6 +119,37 @@ export default class Popover extends Element {
|
|
101 |
this.autoPosition(position);
|
102 |
break;
|
103 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
|
106 |
/**
|
@@ -168,6 +217,7 @@ export default class Popover extends Element {
|
|
168 |
/**
|
169 |
* Automatically positions the popover around the given position
|
170 |
* such that the element and popover remain in view
|
|
|
171 |
* @param elementPosition
|
172 |
*/
|
173 |
autoPosition(elementPosition) {
|
|
|
1 |
import Element from './element';
|
2 |
import {
|
3 |
+
CLASS_BTN_DISABLED,
|
4 |
+
CLASS_CLOSE_BTN,
|
5 |
+
CLASS_NEXT_STEP_BTN,
|
6 |
+
CLASS_POPOVER_DESCRIPTION, CLASS_POPOVER_FOOTER,
|
7 |
CLASS_POPOVER_TIP,
|
8 |
+
CLASS_POPOVER_TITLE, CLASS_PREV_STEP_BTN,
|
9 |
ID_POPOVER,
|
|
|
10 |
POPOVER_HTML,
|
11 |
} from './constants';
|
12 |
|
|
|
14 |
* Popover that is displayed on top of the highlighted element
|
15 |
*/
|
16 |
export default class Popover extends Element {
|
17 |
+
constructor(options, window, document) {
|
|
|
|
|
18 |
super();
|
19 |
|
20 |
+
this.options = Object.assign({
|
21 |
+
isFirst: true,
|
22 |
+
isLast: true,
|
23 |
+
totalCount: 1,
|
24 |
+
currentIndex: 0,
|
25 |
+
doneBtnText: 'Done',
|
26 |
+
closeBtnText: 'Close',
|
27 |
+
nextBtnText: 'Next →',
|
28 |
+
prevBtnText: '← Previous',
|
29 |
+
}, options);
|
30 |
+
|
31 |
this.window = window;
|
32 |
this.document = document;
|
33 |
|
|
|
46 |
this.tipNode = popover.querySelector(`.${CLASS_POPOVER_TIP}`);
|
47 |
this.titleNode = popover.querySelector(`.${CLASS_POPOVER_TITLE}`);
|
48 |
this.descriptionNode = popover.querySelector(`.${CLASS_POPOVER_DESCRIPTION}`);
|
49 |
+
this.footerNode = popover.querySelector(`.${CLASS_POPOVER_FOOTER}`);
|
50 |
+
this.nextBtnNode = popover.querySelector(`.${CLASS_NEXT_STEP_BTN}`);
|
51 |
+
this.prevBtnNode = popover.querySelector(`.${CLASS_PREV_STEP_BTN}`);
|
52 |
+
this.closeBtnNode = popover.querySelector(`.${CLASS_CLOSE_BTN}`);
|
53 |
}
|
54 |
|
55 |
/**
|
|
|
89 |
.className = CLASS_POPOVER_TIP;
|
90 |
}
|
91 |
|
92 |
+
/**
|
93 |
+
* Shows the popover at the given position
|
94 |
+
* @param position
|
95 |
+
*/
|
96 |
show(position) {
|
97 |
this.reset();
|
98 |
|
99 |
// Set the title and descriptions
|
100 |
+
this.titleNode.innerHTML = this.options.title;
|
101 |
+
this.descriptionNode.innerHTML = this.options.description;
|
102 |
|
103 |
// Position the popover around the given position
|
104 |
switch (this.options.position) {
|
|
|
119 |
this.autoPosition(position);
|
120 |
break;
|
121 |
}
|
122 |
+
|
123 |
+
this.renderButtons();
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Enables, disables buttons, sets the text and
|
128 |
+
* decides if to show them or not
|
129 |
+
*/
|
130 |
+
renderButtons() {
|
131 |
+
this.nextBtnNode.innerHTML = this.options.nextBtnText;
|
132 |
+
this.prevBtnNode.innerHTML = this.options.prevBtnText;
|
133 |
+
this.closeBtnNode.innerHTML = this.options.closeBtnText;
|
134 |
+
|
135 |
+
// If there was only one item, hide the buttons
|
136 |
+
if (this.options.totalCount === 1) {
|
137 |
+
this.footerNode.style.display = 'none';
|
138 |
+
return;
|
139 |
+
}
|
140 |
+
|
141 |
+
this.footerNode.style.display = 'block';
|
142 |
+
if (this.options.isFirst) {
|
143 |
+
this.prevBtnNode.classList.add(CLASS_BTN_DISABLED);
|
144 |
+
} else {
|
145 |
+
this.prevBtnNode.classList.remove(CLASS_BTN_DISABLED);
|
146 |
+
}
|
147 |
+
|
148 |
+
if (this.options.isLast) {
|
149 |
+
this.nextBtnNode.innerHTML = this.options.doneBtnText;
|
150 |
+
} else {
|
151 |
+
this.nextBtnNode.innerHTML = this.options.nextBtnText;
|
152 |
+
}
|
153 |
}
|
154 |
|
155 |
/**
|
|
|
217 |
/**
|
218 |
* Automatically positions the popover around the given position
|
219 |
* such that the element and popover remain in view
|
220 |
+
* @todo add the left and right positioning decisions
|
221 |
* @param elementPosition
|
222 |
*/
|
223 |
autoPosition(elementPosition) {
|
assets/scripts/src/sholo.js
CHANGED
@@ -183,8 +183,17 @@ export default class Sholo {
|
|
183 |
}
|
184 |
|
185 |
let popover = null;
|
186 |
-
const popoverOptions = Object.assign({}, this.options, elementOptions.popover || {});
|
187 |
if (elementOptions.popover && elementOptions.popover.description) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
popover = new Popover(popoverOptions, this.window, this.document);
|
189 |
}
|
190 |
|
|
|
183 |
}
|
184 |
|
185 |
let popover = null;
|
|
|
186 |
if (elementOptions.popover && elementOptions.popover.description) {
|
187 |
+
const popoverOptions = Object.assign(
|
188 |
+
{},
|
189 |
+
this.options,
|
190 |
+
elementOptions.popover, {
|
191 |
+
totalCount: steps.length,
|
192 |
+
currentIndex: index,
|
193 |
+
isFirst: index === 0,
|
194 |
+
isLast: index === steps.length - 1,
|
195 |
+
},
|
196 |
+
);
|
197 |
popover = new Popover(popoverOptions, this.window, this.document);
|
198 |
}
|
199 |
|
assets/styles/scss/demo.scss
CHANGED
@@ -119,6 +119,12 @@ div#sholo-popover-item {
|
|
119 |
margin: 10px 0 0;
|
120 |
}
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
.sholo-close-btn {
|
123 |
float: left;
|
124 |
}
|
|
|
119 |
margin: 10px 0 0;
|
120 |
}
|
121 |
|
122 |
+
a.sholo-disabled {
|
123 |
+
color: #808080;
|
124 |
+
cursor: default;
|
125 |
+
pointer-events: none;
|
126 |
+
}
|
127 |
+
|
128 |
.sholo-close-btn {
|
129 |
float: left;
|
130 |
}
|
index.html
CHANGED
@@ -69,7 +69,7 @@
|
|
69 |
popover: {
|
70 |
title: 'Adding Introductions',
|
71 |
description: 'You can use it to add popovers on top of the website',
|
72 |
-
position: 'left'
|
73 |
},
|
74 |
},
|
75 |
{
|
|
|
69 |
popover: {
|
70 |
title: 'Adding Introductions',
|
71 |
description: 'You can use it to add popovers on top of the website',
|
72 |
+
position: 'left',
|
73 |
},
|
74 |
},
|
75 |
{
|