Skip to content

Commit 592987a

Browse files
committed
support smol screens
1 parent 8dca832 commit 592987a

File tree

4 files changed

+64
-11
lines changed

4 files changed

+64
-11
lines changed

copyparty/httpsrv.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import socket
77
import threading
88

9-
from .__init__ import E
9+
from .__init__ import E, MACOS
1010
from .httpconn import HttpConn
1111
from .authsrv import AuthSrv
1212

@@ -75,9 +75,11 @@ def thr_client(self, sck, addr):
7575
sck.shutdown(socket.SHUT_RDWR)
7676
sck.close()
7777
except (OSError, socket.error) as ex:
78-
self.log(
79-
"%s %s" % addr, "shut_rdwr err:\n {}\n {}".format(repr(sck), ex),
80-
)
78+
if not MACOS:
79+
self.log(
80+
"%s %s" % addr,
81+
"shut_rdwr err:\n {}\n {}".format(repr(sck), ex),
82+
)
8183
if ex.errno not in [10038, 107, 57, 9]:
8284
# 10038 No longer considered a socket
8385
# 107 Transport endpoint not connected

copyparty/web/md.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<a id="navtoggle" href="#">hide nav</a>
1616
{%- if edit %}
1717
<a id="save" href="?edit">save</a>
18+
<a id="sbs" href="#">sbs</a>
19+
<a id="nsbs" href="#">editor</a>
1820
<a id="help" href="#">help</a>
1921
{%- else %}
2022
<a href="?edit">edit (basic)</a>
@@ -46,6 +48,16 @@
4648
* `Ctrl-H` / `Ctrl-Shift-H` to create a header
4749
* `TAB` / `Shift-TAB` to indent/dedent a selection
4850

51+
### toolbar
52+
1. toggle dark mode
53+
2. show/hide navigation bar
54+
3. save changes on server
55+
4. side-by-side editing
56+
5. toggle editor/preview
57+
6. this thing :^)
58+
59+
.
60+
4961
</textarea>
5062
</div>
5163
{%- endif %}
@@ -70,12 +82,10 @@
7082
toggle();
7183
})();
7284

73-
// TODO babel or es5 shims (fix Object.defineProperty too)
74-
// https://stackoverflow.com/questions/48803257/
7585
if (!String.startsWith) {
76-
String.prototype.startsWith = function(search, rawPos) {
77-
var pos = rawPos > 0 ? rawPos|0 : 0;
78-
return this.substring(pos, pos + search.length) === search;
86+
String.prototype.startsWith = function(s, i) {
87+
i = i>0 ? i|0 : 0;
88+
return this.substring(i, i + s.length) === s;
7989
};
8090
}
8191

copyparty/web/md2.css

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,34 @@
1111
#mw {
1212
left: calc(100% - 57em);
1313
}
14+
15+
16+
/* single-screen */
17+
#mtw.preview,
18+
#mw.editor {
19+
opacity: 0;
20+
z-index: 1;
21+
}
22+
#mw.preview,
23+
#mtw.editor {
24+
z-index: 3;
25+
}
26+
#mtw.single,
27+
#mw.single {
28+
left: calc((100% - 58em) / 2);
29+
margin: 0;
30+
}
31+
#mtw.single {
32+
width: 57em;
33+
}
34+
35+
1436
#mp {
1537
position: relative;
1638
}
1739
#mt, #mtr {
1840
width: 100%;
19-
height: 100%;
41+
height: calc(100% - 5px);
2042
color: #444;
2143
background: #f7f7f7;
2244
border: 1px solid #999;
@@ -56,6 +78,8 @@ html.dark #mt {
5678
border-radius: .4em;
5779
padding: 2em;
5880
top: 4em;
81+
overflow-y: auto;
82+
height: calc(100% - 12em);
5983
left: calc(50% - 15em);
6084
right: 0;
6185
width: 30em;

copyparty/web/md2.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var server_md = dom_src.value;
44

55
// dom nodes
66
var dom_swrap = document.getElementById('mtw');
7+
var dom_sbs = document.getElementById('sbs');
8+
var dom_nsbs = document.getElementById('nsbs');
79
var dom_ref = (function () {
810
var d = document.createElement('div');
911
d.setAttribute('id', 'mtr');
@@ -98,11 +100,26 @@ redraw = (function () {
98100
map_src = genmap(dom_ref);
99101
map_pre = genmap(dom_pre);
100102
dbg(document.body.clientWidth + 'x' + document.body.clientHeight);
101-
};
103+
}
104+
function setsbs() {
105+
dom_wrap.setAttribute('class', '');
106+
dom_swrap.setAttribute('class', '');
107+
onresize();
108+
}
109+
function modetoggle() {
110+
mode = dom_nsbs.innerHTML;
111+
dom_nsbs.innerHTML = mode == 'editor' ? 'preview' : 'editor';
112+
mode += ' single';
113+
dom_wrap.setAttribute('class', mode);
114+
dom_swrap.setAttribute('class', mode);
115+
onresize();
116+
}
102117

103118
window.onresize = onresize;
104119
window.onscroll = null;
105120
dom_wrap.onscroll = null;
121+
dom_sbs.onclick = setsbs;
122+
dom_nsbs.onclick = modetoggle;
106123

107124
onresize();
108125
return onresize;

0 commit comments

Comments
 (0)