Skip to content

Commit a35604c

Browse files
committed
fix bookmark error on mobile && enable it on PC
1 parent de402b1 commit a35604c

File tree

3 files changed

+116
-30
lines changed

3 files changed

+116
-30
lines changed

static/css/main.css

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,70 @@ li .fa-jk {
547547

548548
code.language-ascii {
549549
font-family: monospace !important;
550+
}
551+
552+
/* The Modal (background) */
553+
.modal {
554+
display: none; /* Hidden by default */
555+
position: fixed; /* Stay in place */
556+
z-index: 1; /* Sit on top */
557+
padding-top: 100px; /* Location of the box */
558+
left: 0;
559+
top: 0;
560+
width: 100%; /* Full width */
561+
height: 100%; /* Full height */
562+
overflow: auto; /* Enable scroll if needed */
563+
background-color: rgb(0,0,0); /* Fallback color */
564+
background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
565+
}
566+
567+
/* Modal Content (image) */
568+
.modal-content {
569+
margin: auto;
570+
display: block;
571+
width: 80%;
572+
max-width: 700px;
573+
}
574+
575+
/* Add Animation */
576+
.modal-content {
577+
-webkit-animation-name: zoom;
578+
-webkit-animation-duration: 0.6s;
579+
animation-name: zoom;
580+
animation-duration: 0.6s;
581+
}
582+
583+
@-webkit-keyframes zoom {
584+
from {-webkit-transform:scale(0)}
585+
to {-webkit-transform:scale(1)}
586+
}
587+
588+
@keyframes zoom {
589+
from {transform:scale(0)}
590+
to {transform:scale(1)}
591+
}
592+
593+
/* The Close Button */
594+
.the-modal-close {
595+
position: absolute;
596+
top: 15px;
597+
right: 35px;
598+
color: #f1f1f1;
599+
font-size: 40px;
600+
font-weight: bold;
601+
transition: 0.3s;
602+
}
603+
604+
.the-modal-close:hover,
605+
.the-modal-close:focus {
606+
color: #bbb;
607+
text-decoration: none;
608+
cursor: pointer;
609+
}
610+
611+
/* 100% Image Width on Smaller Screens */
612+
@media only screen and (max-width: 700px){
613+
.modal-content {
614+
width: 100%;
615+
}
550616
}

static/js/custom.js

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// common functions
2+
window.mobileCheck = function() {
3+
let check = false;
4+
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
5+
return check;
6+
};
7+
18
// load sw.js
29
if("serviceWorker" in navigator) {
310
window.addEventListener("load", () => {
@@ -138,28 +145,37 @@ function addQRPart(html) {
138145
async function html2Img(html) {
139146
let div = document.createElement('div');
140147
div.id = 'capture';
141-
div.setAttribute('style', 'padding: 30px 20px;background: #000;color: #f7f4cb;font-family: "LXGW WenKai";');
148+
div.setAttribute('style', 'padding: 30px 20px;background: #000;color: #f7f4cb;font-family: "LXGW WenKai";max-width: 768px;margin: auto;');
142149
div.innerHTML = html;
143150
addDatePart(div);
144151
let footer = document.createElement('div');
145152
footer.setAttribute('style', 'display: flex;flex-direction: row;justify-content: space-between;align-items: center;margin-top: 20px;padding-top: -20px;padding-top: -20px;border-top-style: dashed;border-top-width: 1px;padding-top: 10px;');
146153
addAuthorPart(footer);
147154
addQRPart(footer);
148155
div.appendChild(footer);
156+
let bodyBackup = document.body;
157+
if (window.mobileCheck()) {
158+
document.body = document.createElement("body");
159+
}
149160
document.body.appendChild(div);
150161
let canvas = await html2canvas(div, {allowTaint: true, useCORS: true});
162+
if (window.mobileCheck()) {
163+
document.body = bodyBackup;
164+
} else {
165+
document.body.removeChild(div);
166+
}
151167
let dataURL = canvas.toDataURL("image/png");
152-
const blob = dataURItoBlob(dataURL);
153-
const data = {
154-
files: [
155-
new File([blob], document.querySelector('.title').textContent + '.png', {
156-
type: blob.type,
157-
}),
158-
],
159-
// title: document.title,
160-
// text: text,
161-
};
162168
if (navigator.canShare && navigator.canShare(data)) {
169+
const blob = dataURItoBlob(dataURL);
170+
const data = {
171+
files: [
172+
new File([blob], document.querySelector('.title').textContent + '.png', {
173+
type: blob.type,
174+
}),
175+
],
176+
// title: document.title,
177+
// text: text,
178+
};
163179
try {
164180
await navigator.share(data);
165181
ga('gtag_UA_154678195_1.send', {
@@ -183,10 +199,17 @@ async function html2Img(html) {
183199
umami.trackEvent('bookmark_fail', 'bookmark');
184200
}
185201
} else {
186-
launch_toast("浏览器不支持此功能");
187-
console.log(`Your system doesn't support sharing files.`);
202+
let modal = document.getElementById("the-modal");
203+
var modalImg = document.getElementById("the-modal-img01");
204+
modal.style.display = "block";
205+
modalImg.src = dataURL;
206+
// Get the <span> element that closes the modal
207+
var span = document.getElementsByClassName("the-modal-close")[0];
208+
// When the user clicks on <span> (x), close the modal
209+
span.onclick = function() {
210+
modal.style.display = "none";
211+
}
188212
}
189-
document.body.removeChild(div);
190213
}
191214

192215
async function oncontroldown(event) {
@@ -216,16 +239,14 @@ function webShare() {
216239

217240
elements.forEach(i => {
218241
i.onpointerup = ()=>{
219-
if (navigator.canShare) {
220-
let selection = document.getSelection(), text = selection.toString();
221-
if (text !== "") {
222-
let rect = selection.getRangeAt(0).getBoundingClientRect();
223-
let articleY = document.body.getBoundingClientRect().top;
224-
control.style.top = `calc(${rect.bottom}px - ${articleY}px + 20px)`;
225-
control.style.left = `calc(${rect.left}px + calc(${rect.width}px / 2) - 30px)`;
226-
control['html']= getSelectionHtml();
227-
document.body.appendChild(control);
228-
}
242+
let selection = document.getSelection(), text = selection.toString();
243+
if (text !== "") {
244+
let rect = selection.getRangeAt(0).getBoundingClientRect();
245+
let articleY = document.body.getBoundingClientRect().top;
246+
control.style.top = `calc(${rect.bottom}px - ${articleY}px + 20px)`;
247+
control.style.left = `calc(${rect.left}px + calc(${rect.width}px / 2) - 30px)`;
248+
control['html']= getSelectionHtml();
249+
document.body.appendChild(control);
229250
}
230251
}
231252
});
@@ -252,12 +273,6 @@ if( document.readyState !== 'loading' ) {
252273

253274
// remove dashboard iframe on mobile
254275

255-
// window.mobileCheck = function() {
256-
// let check = false;
257-
// (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
258-
// return check;
259-
// };
260-
261276
// var dashboard = document.getElementById("dashboard_iframe");
262277

263278
// if (window.mobileCheck()) {

themes/hugo-coder/layouts/_default/baseof.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@
172172

173173
{{ partial "footer.html" . }}
174174
</main>
175+
<!-- The Modal -->
176+
<div id="the-modal" class="modal">
177+
<span class="the-modal-close">&times;</span>
178+
<img class="modal-content" id="the-modal-img01">
179+
</div>
175180

176181
<!-- Global site tag (gtag.js) - Google Analytics -->
177182
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-154678195-1"></script>

0 commit comments

Comments
 (0)