Skip to content

Commit e044240

Browse files
authored
Update live-view.js
1 parent c1c2228 commit e044240

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

live-view.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,95 @@
11

2+
// setup live view
3+
function setupLiveView() {
4+
5+
const url = new URL(window.location.href);
6+
const urlQuery = url.searchParams.get('q');
7+
8+
window.history.pushState(window.location.origin, 'Codeit', window.location.origin + '/full');
9+
10+
if (urlQuery) {
11+
12+
toggleSidebar(false);
13+
saveSidebarStateLS();
14+
15+
treeLoc = urlQuery.split('+')[0].split(',');
16+
17+
const fileName = urlQuery.split('+')[1].split(',')[0];
18+
const fileSha = urlQuery.split('+')[1].split(',')[1];
19+
20+
// change selected file
21+
changeSelectedFile(treeLoc.join(), fileSha, fileName, '\n\r', getFileLang(fileName),
22+
[0, 0], [0, 0], false);
23+
24+
// if on mobile device
25+
if (isMobile) {
26+
27+
// update bottom float
28+
updateFloat();
29+
30+
// expand bottom float
31+
bottomWrapper.classList.add('expanded');
32+
33+
}
34+
35+
// open live view
36+
toggleLiveView(selectedFile);
37+
38+
// if file is not modified; fetch from Git
39+
if (!modifiedFiles[fileSha]) {
40+
41+
// start loading
42+
startLoading();
43+
44+
// get file from git
45+
const resp = await git.getFile(treeLoc, fileEl.innerText);
46+
47+
// change selected file
48+
changeSelectedFile(treeLoc.join(), fileSha, fileEl.innerText, resp.content, getFileLang(fileEl.innerText),
49+
[0, 0], [0, 0], false);
50+
51+
// stop loading
52+
stopLoading();
53+
54+
} else { // else, load file from modifiedFiles object
55+
56+
const modFile = modifiedFiles[fileSha];
57+
58+
changeSelectedFile(modFile.dir, modFile.sha, modFile.name, modFile.content, modFile.lang,
59+
modFile.caretPos, modFile.scrollPos, false);
60+
61+
}
62+
63+
// show file content in codeit
64+
cd.textContent = decodeUnicode(selectedFile.content);
65+
66+
// change codeit lang
67+
cd.lang = selectedFile.lang;
68+
69+
// set caret pos in codeit
70+
cd.setSelection(selectedFile.caretPos[0], selectedFile.caretPos[1]);
71+
72+
// set scroll pos in codeit
73+
cd.scrollTo(selectedFile.scrollPos[0], selectedFile.scrollPos[1]);
74+
75+
// clear codeit history
76+
cd.history = [];
77+
78+
// update line numbers
79+
updateLineNumbersHTML();
80+
81+
// if on desktop
82+
if (!isMobile) {
83+
84+
// check codeit scrollbar
85+
checkScrollbarArrow();
86+
87+
}
88+
89+
}
90+
91+
}
92+
293
// open live view when swiped up on bottom float
394
function addBottomSwipeListener() {
495

0 commit comments

Comments
 (0)