Skip to content

Commit d301a98

Browse files
author
rakeshAlgo
committed
Implement view source icon functionality
1 parent b200290 commit d301a98

File tree

4 files changed

+118
-71
lines changed

4 files changed

+118
-71
lines changed

src/css/clipboard.css

Lines changed: 109 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,89 @@
11
.view-source-button {
2-
position: absolute;
3-
right: 1rem;
4-
top: 12px;
5-
display: none;
62
color: var(--color-brand-gray4);
3+
font-family: "Source Code Pro", sans-serif;
4+
background: url(../img/awesome-github.svg) no-repeat center center;
5+
background-size: cover;
6+
display: inline-block;
7+
width: 16px;
8+
height: 15.5px;
9+
font-size: 0;
10+
margin-left: 0.5rem;
11+
}
12+
13+
.view-source-button:hover::after {
14+
content: attr(data-title);
15+
color: var(--color-brand-gray4);
16+
font-size: var(--font-base);
17+
font-weight: var(--weight-light);
18+
line-height: 1;
19+
text-transform: capitalize;
20+
position: absolute;
21+
bottom: -53px;
22+
right: -30%;
23+
left: auto;
24+
margin: 0;
25+
padding: 5px;
26+
text-align: center;
27+
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.06);
28+
background: var(--color-brand-white);
29+
border: 1px solid var(--color-brand-gray7);
30+
box-sizing: border-box;
31+
border-radius: 3px;
32+
min-width: 90px;
733
font-family: "Source Sans Pro", sans-serif;
8-
z-index: 1;
934
}
1035

11-
.doc .listingblock:hover .view-source-button {
12-
display: block;
36+
.view-source-button:hover::before {
37+
width: 0;
38+
height: 0;
39+
border-left: 7px solid transparent;
40+
border-right: 7px solid transparent;
41+
border-bottom: 10px solid var(--color-brand-white);
42+
position: absolute;
43+
content: "";
44+
box-shadow: inset 0 0 1px #bec0c1;
45+
bottom: -27px;
46+
right: auto;
47+
left: auto;
1348
}
1449

1550
.copy-code-button {
16-
position: absolute;
1751
background: url(../img/copy.png) no-repeat center right/contain;
18-
width: 24px;
19-
height: 14px;
20-
right: 3.2rem;
21-
top: 12px;
22-
display: none;
52+
width: 13px;
53+
height: 16px;
2354
cursor: pointer;
2455
font-family: "Source Sans Pro", sans-serif;
2556
color: var(--color-brand-gray4);
26-
z-index: 1;
57+
margin-left: 0.5rem;
58+
margin-right: 0.5rem;
2759
}
2860

2961
a.copy-code-button:focus,
3062
a.copy-code-button:hover {
3163
color: var(--color-brand-gray4);
3264
}
3365

34-
.doc .listingblock:hover .copy-code-button {
35-
display: block;
36-
}
3766

3867
.copy-code-button:hover::after {
3968
content: attr(data-title);
4069
color: var("--color-brand-gray4");
41-
font-size: 14px;
70+
font-size: var(--font-base);
4271
font-weight: var(--weight-light);
4372
line-height: 1;
4473
text-transform: capitalize;
4574
position: absolute;
4675
bottom: -53px;
47-
right: -100%;
48-
left: -100%;
49-
margin: auto;
76+
right: -30%;
77+
left: auto;
78+
margin: 0;
5079
padding: 5px;
5180
text-align: center;
5281
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.06);
5382
background: var(--color-brand-white);
5483
border: 1px solid var(--color-brand-gray7);
5584
box-sizing: border-box;
5685
border-radius: 3px;
57-
/* min-width: 90px; */
86+
min-width: 80px;
5887
font-family: "Source Sans Pro", sans-serif;
5988
}
6089

@@ -68,5 +97,63 @@ a.copy-code-button:hover {
6897
content: "";
6998
box-shadow: inset 0 0 1px #bec0c1;
7099
bottom: -27px;
100+
right: auto;
101+
left: auto;
102+
}
103+
104+
105+
.doc .listingblock code[data-lang] + .source-type-box {
106+
position: absolute;
107+
top: 0;
108+
right: 0;
109+
display: none;
110+
align-items: center;
111+
z-index: 1;
112+
padding-top: 12px;
113+
}
114+
115+
.doc .listingblock code[data-lang] + .source-type-box .data-source {
116+
content: attr(data-lang);
117+
color: var("--color-brand-gray1");
118+
font-size: 0.75rem;
119+
font-weight: var(--weight-normal);
120+
letter-spacing: 1px;
121+
line-height: 18px;
122+
text-transform: uppercase;
123+
font-family: "Source Code Pro", sans-serif;
124+
padding-right: 0.5rem;
125+
border-right: 1px solid var(--color-brand-gray9);
126+
}
127+
128+
/* .doc .listingblock:hover code[data-lang] + .source-type-box .data-source {
129+
display: block;
130+
} */
131+
132+
.doc .listingblock:hover code[data-lang] + .source-type-box {
133+
display: flex;
134+
}
135+
136+
.doc .listingblock pre .fade-shadow {
137+
content: "";
138+
display: inline-block;
139+
background:
140+
transparent
141+
linear-gradient(
142+
180deg,
143+
#f1f7fe0d 0%,
144+
#f1f7fe40 18%,
145+
#f1f7fe 68%,
146+
#f1f7fe 100%
147+
)
148+
0% 0% no-repeat padding-box;
149+
width: 65px;
150+
height: 80%;
151+
position: absolute;
71152
right: 0;
153+
top: 0;
72154
}
155+
156+
code.language-console.hljs.shell {
157+
white-space: nowrap;
158+
overflow-x: auto;
159+
}

src/css/doc.css

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -575,51 +575,7 @@
575575
576576
*/
577577

578-
.doc .listingblock code[data-lang] + .data-source {
579-
content: attr(data-lang);
580-
color: var("--color-brand-gray1");
581-
display: none;
582-
font-size: 0.75rem;
583-
font-weight: var(--weight-normal);
584-
letter-spacing: 1px;
585-
line-height: 18px;
586-
text-transform: uppercase;
587-
position: absolute;
588-
top: 12px;
589-
right: 4.5rem;
590-
font-family: "Source Sans Pro", sans-serif;
591-
padding-right: 0.5rem;
592-
border-right: 1px solid var(--color-brand-gray9);
593-
}
594-
595-
.doc .listingblock:hover code[data-lang] + .data-source {
596-
display: block;
597-
}
598578

599-
.doc .listingblock pre .fade-shadow {
600-
content: "";
601-
display: inline-block;
602-
background:
603-
transparent
604-
linear-gradient(
605-
180deg,
606-
#f1f7fe0d 0%,
607-
#f1f7fe40 18%,
608-
#f1f7fe 68%,
609-
#f1f7fe 100%
610-
)
611-
0% 0% no-repeat padding-box;
612-
width: 65px;
613-
height: 80%;
614-
position: absolute;
615-
right: 0;
616-
top: 0;
617-
}
618-
619-
code.language-console.hljs.shell {
620-
white-space: nowrap;
621-
overflow-x: auto;
622-
}
623579

624580
.doc .dlist {
625581
margin: 1.5rem 0;

src/img/awesome-github.svg

Lines changed: 1 addition & 0 deletions
Loading

src/js/07-copy-to-clipboard.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
viewSourceLink.href = codeBlock.dataset.sourceUrl
99
viewSourceLink.className = 'view-source-button'
1010
viewSourceLink.target = '_blank'
11-
viewSourceLink.dataset.title = 'View Source'
11+
viewSourceLink.dataset.title = 'View On Github'
1212
viewSourceLink.appendChild(document.createTextNode('View'))
1313
}
14-
14+
// console.log(codeBlock)
15+
var sourceTypeBox = document.createElement('div')
16+
sourceTypeBox.className = 'source-type-box'
1517
var copyButton = document.createElement('a')
1618
copyButton.className = 'copy-code-button'
1719
//copyButton.type = 'button'
@@ -45,9 +47,10 @@
4547
}
4648
})
4749
var pre = codeBlock.parentNode
48-
pre.appendChild(dataSource)
49-
if (viewSourceLink) pre.appendChild(viewSourceLink)
50-
pre.appendChild(copyButton)
50+
pre.appendChild(sourceTypeBox)
51+
sourceTypeBox.appendChild(dataSource)
52+
if (viewSourceLink) sourceTypeBox.appendChild(viewSourceLink)
53+
sourceTypeBox.appendChild(copyButton)
5154
pre.appendChild(fadeShadow)
5255
})
5356
})()

0 commit comments

Comments
 (0)