Skip to content

Commit c9f05f5

Browse files
committed
[feature] adding tip
1 parent 0a4aad2 commit c9f05f5

File tree

8 files changed

+245
-12
lines changed

8 files changed

+245
-12
lines changed

‎css/base.css‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@
4343
--breakpoint-xxl:1600px;
4444
--z-index-link:1000;
4545
--z-index-header:2000;
46-
--z-index-shade:3000;
47-
--z-index-modal:4000;
48-
--z-index-menu:5000;
46+
--z-index-tip:3000;
47+
--z-index-shade:4000;
48+
--z-index-modal:5000;
49+
--z-index-menu:6000;
4950
}
5051

5152
:root.is-link-block{

‎css/button.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ button[disabled]:active,
6969
cursor: default;
7070
}
7171

72+
.button-text{
73+
pointer-events: none;
74+
}
75+
7276
button [class^="icon-"],
7377
button [class*=" icon-"],
7478
.button [class^="icon-"],

‎css/form.css‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ input[type="color"]::-webkit-color-swatch{
155155
border:0;
156156
}
157157

158-
input[type="color"]+.label-button-color{
158+
input[type="color"]+.input-label-button{
159159
padding-right:2.25em;
160160
justify-content: center;
161161
align-items: center;
162162
}
163163

164-
input[type="color"]+.label-button-color:before{
164+
input[type="color"]+.input-label-button:before{
165165
background-color:rgb(var(--accent));
166166
content:"";
167167
border-radius:50%;
@@ -208,6 +208,7 @@ input[type="radio"]{
208208
font-size:1em;
209209
line-height:1;
210210
cursor: pointer;
211+
pointer-events: none;
211212
box-sizing: border-box;
212213
-webkit-tap-highlight-color:rgba(0,0,0,0);
213214
}
@@ -285,14 +286,28 @@ input[type="radio"]:checked:focus+label .label-icon{
285286
transform:scale(1.2);
286287
}
287288

288-
input[type="checkbox"]+.button-checkbox,
289-
input[type="radio"]+.button-checkbox{
289+
input[type="color"]+.input-label-button,
290+
input[type="checkbox"]+.input-label-button,
291+
input[type="radio"]+.input-label-button{
290292
justify-content: center;
291293
align-items: center;
292294
}
293295

294-
input[type="checkbox"]:checked+.button-checkbox,
295-
input[type="radio"]:checked+.button-checkbox{
296+
input[type="color"]:hover+.input-label-button,
297+
input[type="color"]:focus+.input-label-button,
298+
input[type="checkbox"]:hover+.input-label-button,
299+
input[type="checkbox"]:focus+.input-label-button,
300+
input[type="radio"]:hover+.input-label-button,
301+
input[type="radio"]:focus+.input-label-button{
302+
background-color:var(--gray-03);
303+
border-bottom-color:rgb(var(--accent));
304+
color:var(--white);
305+
outline:0;
306+
}
307+
308+
input[type="color"]:checked+.input-label-button,
309+
input[type="checkbox"]:checked+.input-label-button,
310+
input[type="radio"]:checked+.input-label-button{
296311
border-bottom-color:rgb(var(--accent));
297312
}
298313

‎css/tip.css‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.tip{
2+
position: absolute;
3+
max-width:20em;
4+
margin:1em1em;
5+
left:0;
6+
top:0;
7+
opacity:1;
8+
z-index:var(--z-index-tip);
9+
transition: opacity var(--animation-speed-fast) ease-in-out;
10+
transform-origin: bottom center;
11+
pointer-events: none;
12+
}
13+
14+
@keyframes grow{
15+
0%{
16+
transform:translate(0,0.2em) scale(0.95);
17+
clip-path:circle(0 at 50%100%);
18+
}
19+
20+
100%{
21+
transform:translate(0,0) scale(1);
22+
clip-path:circle(100% at 50%100%);
23+
}
24+
}
25+
26+
@keyframes shirnk{
27+
0%{
28+
transform:translate(0,0) scale(1);
29+
clip-path:circle(100% at 50%100%);
30+
}
31+
32+
100%{
33+
transform:translate(0,0.2em) scale(0.95);
34+
clip-path:circle(0 at 50%100%);
35+
}
36+
}
37+
38+
.tip-intro{
39+
animation: grow var(--animation-speed-slow) 1;
40+
}
41+
42+
.tip-outro{
43+
animation: shirnk var(--animation-speed-slow) 1;
44+
}
45+
46+
.tip-message{
47+
padding:0.5em1em;
48+
background-color:var(--gray-04);
49+
border:0;
50+
border-radius:calc(var(--radius) *2);
51+
color:var(--gray-18);
52+
font-size:0.8em;
53+
font-family:var(--font-regular);
54+
text-align: center;
55+
position: relative;
56+
display: block;
57+
z-index:1;
58+
}
59+
60+
.tip-arrow{
61+
border:0.5em solid transparent;
62+
border-top-color:var(--gray-04);
63+
position: absolute;
64+
width:0;
65+
height:0;
66+
top:100%;
67+
left:50%;
68+
display: block;
69+
z-index:2;
70+
transform:translate(-50%,0);
71+
}

‎index.html‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<linkrel="stylesheet" href="css/form.css">
2020
<linkrel="stylesheet" href="css/shade.css">
2121
<linkrel="stylesheet" href="css/modal.css">
22+
<linkrel="stylesheet" href="css/tip.css">
2223
<linkrel="stylesheet" href="css/menu.css">
2324
<linkrel="stylesheet" href="css/header.css">
2425
<linkrel="stylesheet" href="css/date.css">
@@ -52,7 +53,7 @@
5253
<divclass="button-group nested-button mb-0">
5354
<divclass="checkbox-wrap">
5455
<inputid="control-edit" class="control-edit" type="checkbox" tabindex="1">
55-
<labelfor="control-edit" class="button button-checkbox">
56+
<labelfor="control-edit" class="button input-label-button">
5657
<divclass="button-text">Edit</div>
5758
</label>
5859
</div>
@@ -64,7 +65,7 @@
6465
<divclass="header-item header-accent">
6566
<divclass="input-wrap">
6667
<inputid="control-layout-theme" type="color" class="control-layout-theme" value="#00ff00" tabindex="1">
67-
<labelfor="control-layout-theme" class="button label-button-color mb-0">
68+
<labelfor="control-layout-theme" class="button input-label-button mb-0">
6869
<spanclass="button-text">Accent</span>
6970
</label>
7071
</div>
@@ -291,6 +292,7 @@ <h1 class="menu-header">Page</h1>
291292
<scriptsrc="js/menu.js"></script>
292293
<scriptsrc="js/header.js"></script>
293294
<scriptsrc="js/modal.js"></script>
295+
<scriptsrc="js/tip.js"></script>
294296
<scriptsrc="js/shade.js"></script>
295297
<scriptsrc="js/theme.js"></script>
296298
<scriptsrc="js/date.js"></script>

‎js/helper.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ var helper = (function(){
233233

234234
functionmakeObject(string){
235235
var_stringOrBooleanOrNumber=function(stringToTest){
236-
console.log(stringToTest);
237236
if(stringToTest=="true"){
238237
returntrue;
239238
}elseif(stringToTest=="false"){

‎js/init.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@ clock.init();
3838
// bind keyboard keys
3939
keyboard.init();
4040

41+
// bind tips
42+
tip.init();
43+
4144
// render header height padding
4245
header.init();

‎js/tip.js‎

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
vartip=(function(){
2+
3+
vardestroyTimer=null;
4+
5+
varintervalId;
6+
7+
var_bind=function(){
8+
varallTip=helper.eA("[data-tip-options]");
9+
for(vari=0;i<allTip.length;i++){
10+
varoptions=helper.makeObject(allTip[i].dataset.tipOptions);
11+
_bind_tip(allTip[i]);
12+
};
13+
};
14+
15+
var_bind_tip=function(tip){
16+
varoptions=helper.makeObject(tip.dataset.tipOptions);
17+
varaction={
18+
focus: function(){
19+
tip.addEventListener("focus",function(){
20+
if(options.delay){
21+
intervalId=setInterval(function(){
22+
render(tip);
23+
},options.delay);
24+
}else{
25+
render(tip);
26+
};
27+
},false);
28+
tip.addEventListener("blur",function(){
29+
destroy();
30+
clearInterval(intervalId);
31+
},false);
32+
},
33+
hover: function(){
34+
tip.addEventListener("mouseover",function(){
35+
if(options.delay){
36+
intervalId=setInterval(function(){
37+
render(tip);
38+
},options.delay);
39+
}else{
40+
render(tip);
41+
};
42+
},false);
43+
tip.addEventListener("mouseout",function(){
44+
destroy();
45+
clearInterval(intervalId);
46+
},false);
47+
}
48+
};
49+
action[options.state]();
50+
};
51+
52+
vardelayDestroy=function(){
53+
varallTipBox=helper.eA(".tip-box");
54+
for(vari=0;i<allTipBox.length;i++){
55+
if(!allTipBox[i].classList.contains("is-opaque")){
56+
allTipBox[i].parentElement.removeChild(allTipBox[i]);
57+
};
58+
};
59+
};
60+
61+
vardestroy=function(){
62+
varallTipBox=helper.eA(".tip-box");
63+
if(allTipBox[0]){
64+
for(vari=0;i<allTipBox.length;i++){
65+
allTipBox[i].destroy();
66+
};
67+
};
68+
};
69+
70+
varrender=function(tip){
71+
// console.log(tip.getBoundingClientRect());
72+
varoptions=helper.makeObject(tip.dataset.tipOptions);
73+
varbody=helper.e("body");
74+
vartipWrapper=document.createElement("div");
75+
tipWrapper.setAttribute("class","tip tip-box is-transparent");
76+
vartipArrow=document.createElement("span");
77+
tipArrow.setAttribute("class","tip-arrow");
78+
vartipMessage=document.createElement("p");
79+
tipMessage.setAttribute("class","tip-message");
80+
tipMessage.textContent=options.message;
81+
tipWrapper.destroy=function(){
82+
if(tipWrapper.classList.contains("is-opaque")){
83+
helper.removeClass(tipWrapper,"is-opaque");
84+
helper.addClass(tipWrapper,"is-transparent");
85+
helper.removeClass(tipWrapper,"tip-intro");
86+
helper.addClass(tipWrapper,"tip-outro");
87+
}else{
88+
tipWrapper.remove();
89+
};
90+
};
91+
tipWrapper.addEventListener("transitionend",function(event,elapsed){
92+
if(event.propertyName==="opacity"&&getComputedStyle(this).opacity==0){
93+
this.parentElement.removeChild(this);
94+
};
95+
}.bind(tipWrapper),false);
96+
97+
tipWrapper.appendChild(tipMessage);
98+
tipWrapper.appendChild(tipArrow);
99+
body.appendChild(tipWrapper);
100+
tipWrapper.setAttribute("style","width: "+(parseInt(tipWrapper.getBoundingClientRect().width,10)+2)+"px;");
101+
102+
varwidth=parseInt(tipWrapper.getBoundingClientRect().width);
103+
vartop=parseInt(tip.getBoundingClientRect().top,10)+parseInt(pageYOffset,10)-parseInt(tipWrapper.getBoundingClientRect().height,10)-parseInt(getComputedStyle(tipWrapper).marginTop,10)-parseInt(getComputedStyle(tipWrapper).marginBottom,10);
104+
varleft=parseInt(tip.getBoundingClientRect().left,10)+parseInt((tip.getBoundingClientRect().width/2),10)-parseInt(((width+parseInt(getComputedStyle(tipWrapper).marginLeft,10)+parseInt(getComputedStyle(tipWrapper).marginRight,10))/2),10);
105+
106+
tipWrapper.setAttribute("style","width: "+width+"px; top: "+top+"px; left: "+left+"px");
107+
varstyle={
108+
top: tipWrapper.style.top,
109+
width: tipWrapper.style.width
110+
};
111+
112+
if(tipWrapper.getBoundingClientRect().left<parseInt(getComputedStyle(tipWrapper).marginLeft,10)){
113+
// console.log("too far left");
114+
tipWrapper.setAttribute("style","width: "+style.width+" top: "+style.top+" left: "+0+"px;");
115+
tipArrow.setAttribute("style","left: "+(parseInt(tip.getBoundingClientRect().left,10)+parseInt((tip.getBoundingClientRect().width/2),10)-parseInt(getComputedStyle(tipWrapper).marginLeft,10))+"px;");
116+
}elseif(tipWrapper.getBoundingClientRect().right>(document.documentElement.clientWidth-parseInt(getComputedStyle(tipWrapper).marginLeft,10))){
117+
// console.log("too far right");
118+
tipWrapper.setAttribute("style","width: "+style.width+" top: "+style.top+" left: initial; right: "+0+"px;");
119+
tipArrow.setAttribute("style","left: "+(-parseInt(tipWrapper.getBoundingClientRect().left,10)+parseInt(tip.getBoundingClientRect().left,10)+(parseInt((tip.getBoundingClientRect().width),10)/2))+"px;");
120+
};
121+
122+
getComputedStyle(tipWrapper).opacity;
123+
helper.removeClass(tipWrapper,"is-transparent");
124+
helper.addClass(tipWrapper,"is-opaque");
125+
helper.addClass(tipWrapper,"tip-intro");
126+
};
127+
128+
varinit=function(){
129+
_bind();
130+
};
131+
132+
// exposed methods
133+
return{
134+
destroy: destroy,
135+
init: init
136+
};
137+
138+
})();

0 commit comments

Comments
(0)