|
5 | 5 | <style>
|
6 | 6 | *{margin:0;padding:0;border:0;box-sizing:border-box;vertical-align:middle}
|
7 | 7 | html,body{height:100%;font:12px arial}
|
8 |
| -.CodeMirror,#iframe{width:50%;height:100%;float:left;transition:.5s} |
9 |
| -#iframe{border-left:1px solid} |
10 |
| -#toggle{position:fixed;bottom:0;left:50%;transform:translateX(-50%);z-index:50;transition:.5s} |
| 8 | +#code,.CodeMirror,#iframe{height:100%;float:left;transition:.5s} |
| 9 | +#code,.CodeMirror{width:40%} |
| 10 | +#iframe{border-left:1px solid;width:60%} |
| 11 | +#toggle{position:fixed;bottom:0;left:40%;transform:translateX(-50%);z-index:50;transition:.5s} |
11 | 12 | #toggle:checked{bottom:170px;transform:translateX(-50%) translateY(50%)}
|
12 | 13 | #menu{position:fixed;bottom:-170px;height:170px;width:100%;border-top:1px solid;z-index:2;transition:.5s}
|
13 | 14 | #toggle:checked~#menu{bottom:0}
|
|
68 | 69 | console.old_clear();
|
69 | 70 | }
|
70 | 71 |
|
| 72 | +// Count chars |
| 73 | +count_chars=function(b,a,c,d){a=[];for(c=0;c<b.length;c++)54==(b[d="charCodeAt"](c)>>10)?(a.push(1024*(b[d](c)-55296)+b[d](c+1)+9216),c++):a.push(b[d](c));return a.length} |
| 74 | + |
| 75 | +// Count UTF-8 bytes |
| 76 | +count_bytes=function(b,a,c,d,n){a=[];for(c=0;c<b.length;c++)128>b[d="charCodeAt"](c)?a.push(b[d](c)):(n=b[c],55296==(b[d](c)&64512)&&(n=b.substr(c,2),c++),encodeURI(n).replace(/\w+/g,function(b){a.push(parseInt(b,16))}));return a.length} |
| 77 | + |
| 78 | + |
71 | 79 | // Read hash
|
72 | 80 | if(location.hash){
|
73 | 81 | code.value=decodeURIComponent(location.hash.slice(1));
|
|
85 | 93 | download.href="data:text/html,"+encodeURIComponent(editor.getValue());
|
86 | 94 |
|
87 | 95 | // Update count
|
88 |
| -document.title=input.length+" chars - Codegolf IDE"; |
| 96 | +document.title=count_chars(input)+" chars / "+count_bytes(input)+" bytes - Codegolf IDE"; |
89 | 97 |
|
90 | 98 | // After typing code, clear console and update iframe and export link
|
91 | 99 | editor.on("keyup",function(){
|
92 | 100 | console.clear();
|
93 | 101 | input=editor.getValue();
|
94 | 102 | iframe.srcdoc=custom_console+editor.getValue();
|
95 | 103 | download.href="data:text/html,"+encodeURIComponent(input);
|
96 |
| - document.title=input.length+" chars - Codegolf IDE"; |
| 104 | + document.title=count_chars(input)+" chars / "+count_bytes(input)+" bytes - Codegolf IDE"; |
97 | 105 | });
|
98 | 106 |
|
99 | 107 | // Save
|
|
0 commit comments