Skip to content

Commit 6ab7943

Browse files
committed
bug fixes, issues
1 parent 772329d commit 6ab7943

13 files changed

Lines changed: 145 additions & 34 deletions

File tree

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ This is only the **FRONTEND**. There is also a backend component which is not op
1414
If you want to see the places where all of the _magic_ happens, take a look at `js/drive.js`, `js/sky.js`, and `js/tabs.js`. Enjoy!
1515

1616
### Recent Updates
17+
+ Fix encoding bug to allow for non-latin characters (é, ï, etc.)
18+
+ Switch between OneDrive and Google Drive
19+
+ New color picker
1720
+ Better publish function
1821
+ Tree contents loaded asyncronously
1922
+ Modes dynamically loaded, instead of all at once
@@ -32,16 +35,16 @@ If you want to see the places where all of the _magic_ happens, take a look at `
3235
+ Copy files
3336
+ Context menu in sidebar
3437
+ Minimize and beautify
35-
+ ~~Warning when closing without saving changes~~ **DONE!**
36-
+ ~~Snippets (coming soon)~~ **DONE!**
38+
+ ~~Warning when closing without saving changes~~
39+
+ ~~Snippets~~
3740
+ Fix running Javascript + Coffeescript
38-
+ ~~Import and export snippets~~ **DONE!**
39-
+ ~~Store open tabs and reload on open~~ **DONE!**
40-
+ ~~Dynamically load modes~~ **DONE!**
41-
+ Custom-made color picker (WIP)
41+
+ ~~Import and export snippets~~
42+
+ ~~Store open tabs and reload on open~~
43+
+ ~~Dynamically load modes~~
44+
+ ~~New color picker~~
4245
+ Chat and collaboration using our backend, so that Onedrive users can chat and collaborate as well
43-
+ ~~Better publishing~~ **DONE!**
44-
+ ~~Remove Roboto font, use websafe font~~ **KEEP IT, LOADED VIA GOOGLE FONTS**
46+
+ ~~Better publishing~~
47+
+ ~~Roboto Font loaded faster~~
4548

4649
### Long-Term Goals
4750
+ Improve user onboarding and visual interface

index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ <h6>
312312
</a>
313313
</span>
314314
<span class="side-run" onclick="run()"><i class="zmdi zmdi-play"></i>Run</span>
315+
<span>
316+
<a href=="https://codeyourcloud.com?sky=true" style="text-decoration: none" id="swap">
317+
<i class="zmdi zmdi-swap"></i>Switch To OneDrive
318+
</a>
319+
</span>
315320
<span>
316321
<a href="https://accounts.google.com/logout" style="text-decoration: none;" id="log-out">
317322
<i class="zmdi zmdi-square-right"></i>Log Out
@@ -514,6 +519,8 @@ <h5>Ctrl + F, &#8984; + F <span>Find</span></h5>
514519
<i class="md zmdi zmdi-close" onclick="broadcast.close()"></i>
515520
</div>
516521

522+
<iframe id="repl" style="display:none"></iframe>
523+
517524
<!--context menu-->
518525
<div id="context" class="popup context-menu">
519526
<span onclick="" class="context-menu__item">
@@ -657,6 +664,7 @@ <h5>Ctrl + F, &#8984; + F <span>Find</span></h5>
657664
<script src="js/tree.js"></script>
658665
<script src="js/tabs.js"></script>
659666
<script src="js/snippets.js"></script>
667+
<script src="js/repl.js"></script>
660668
<script src="js/ready.js"></script>
661669

662670

js/editor.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ manager.setFileTitle = function(id, title){
6060
}
6161
manager.save = function(id){
6262
if(id !== "welcome"){
63-
var content = getEditor(id).getValue()
63+
var content = charToCode(getEditor(id).getValue());
6464
if(typeof content !== "undefined"){ //if nothing is "null"
6565
if(cloud_use === "drive"){
6666
var contentArray = new Array(content.length);
@@ -453,6 +453,14 @@ settings.init = function(){
453453
//
454454
//
455455
settings.state = prefs;
456+
457+
settings.state.tabs = [];
458+
for(var i = 0; i < prefs.tabs.length; i++){
459+
if(prefs.tabs[i].indexOf(cloud_use + "_") === 0){
460+
settings.state.tabs.push(prefs.tabs[i].replace(cloud_use + "_"));
461+
}
462+
}
463+
456464
for(var i = 0; i < settings.state.tabs.length; i++){
457465
if(manager.isOpen(settings.state.tabs[i]) === false){
458466
addTab(settings.state.tabs[i], false);
@@ -462,9 +470,13 @@ settings.init = function(){
462470
}
463471

464472
settings.change = function(){
473+
var info = settings.state;
474+
for(var i = 0; i < info.tabs.length; i++){
475+
info.tabs[i] = cloud_use + "_" + info.tabs[i];
476+
}
465477
$.ajax("https://codeyourcloud.com/prefs/change",{
466478
method: "POST",
467-
data: settings.state,
479+
data: info,
468480
success: function(data, textStatus, jqXHR){
469481
},
470482
error: function(jqXHR, textStatus, errorThrown){

js/frontend.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,14 @@ connect.publish = function(content, mode, fileId){
8686
if(mode === "text/x-markdown" || mode === "gfm"){
8787
content = converter.makeHtml(content);
8888
}
89-
9089
var userId = null;
9190
fileId = fileId.replace(/-/g, '');
92-
9391
if(cloud_use === "drive"){
9492
userId = drive.id;
9593
}
9694
else if(cloud_use === "sky"){
9795
userId = sky.id;
9896
}
99-
10097
var info = {
10198
mode: mode,
10299
content: content,

js/global.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,75 @@ function getParameterByName(name) {
200200
function esc(text){
201201
return $("#escape").text(text).html()
202202
}
203+
204+
String.prototype.toUnicode = function(){
205+
var result = "";
206+
for(var i = 0; i < this.length; i++){
207+
result += "\\u" + ("000" + this[i].charCodeAt(0).toString(16)).substr(-4);
208+
}
209+
return result;
210+
};
211+
212+
function knownCharCodeAt(str, idx) {
213+
str += '';
214+
var code,
215+
end = str.length;
216+
var surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
217+
while ((surrogatePairs.exec(str)) != null) {
218+
var li = surrogatePairs.lastIndex;
219+
if (li - 2 < idx) {
220+
idx++;
221+
}
222+
else {
223+
break;
224+
}
225+
}
226+
if (idx >= end || idx < 0) {
227+
return NaN;
228+
}
229+
code = str.charCodeAt(idx);
230+
var hi, low;
231+
if (0xD800 <= code && code <= 0xDBFF) {
232+
hi = code;
233+
low = str.charCodeAt(idx + 1);
234+
// Go one further, since one of the "characters" is part of a surrogate pair
235+
return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
236+
}
237+
return code;
238+
}
239+
240+
function encode_utf8(s) {
241+
return unescape(encodeURIComponent(s));
242+
}
243+
244+
function decode_utf8(s) {
245+
return decodeURIComponent(escape(s));
246+
}
247+
248+
function codeToChar(text){
249+
var newText = text.replace(/\\u[0-9a-z][0-9a-z][0-9a-z][0-9a-z]/g,
250+
function($0, $1) {
251+
return String.fromCharCode(knownCharCodeAt("" + $1), 0);
252+
}
253+
);
254+
return newText;
255+
}
256+
257+
function charToCode(text){
258+
text = text.split("");
259+
for(var i = 0; i < text.length; i++){
260+
if(/[^\u0000-\u007F]+/g.test(text[i]) === true){
261+
var item = text[i];
262+
text[i] = "";
263+
if(i < (text.length - 1)){
264+
text[i + 1] = item.toUnicode() + text[i +1];
265+
}
266+
else{
267+
text = text.reverse();
268+
text.push(item.toUnicode());
269+
text = text.reverse();
270+
}
271+
}
272+
}
273+
return text.join("");
274+
}

js/logic/com.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ window.addEventListener("message", receiveMessage, false);
22

33
var _change = 0;
44

5+
function encode_utf8(s) {
6+
return unescape(encodeURIComponent(s));
7+
}
8+
9+
function decode_utf8(s) {
10+
return decodeURIComponent(escape(s));
11+
}
12+
513
function receiveMessage(event){
614
if(event.data !== "!_{h:''}"){
715
var json = JSON.parse(event.data);
@@ -18,11 +26,12 @@ function receiveMessage(event){
1826
makeChat(json.message, json.name, json.id, json.photo);
1927
}
2028
else if(json.type === "text"){
29+
console.log(json.text);
2130
try{
22-
text.setText(json.text);
23-
}
24-
catch(e){
25-
}
31+
text.setText(decode_utf8(json.text));
32+
}
33+
catch(e){
34+
}
2635
}
2736
}
2837
}
@@ -39,9 +48,10 @@ function sendData(data){
3948
}
4049

4150
function setValue(value){
51+
console.log(value);
4252
sendData({
4353
type: "text",
44-
value: value,
54+
value: encode_utf8(value),
4555
currentfile: current_file
4656
});
4757
}
@@ -67,7 +77,7 @@ function removeUser(the_id){
6777
}
6878

6979
function setText(value){
70-
text.setText(value);
80+
text.setText(decode_utf8(value));
7181
}
7282

7383
function insertChat(the_message, the_name, is_you, the_photo, is_new){
@@ -86,7 +96,7 @@ function insert_text(point, text){
8696
sendData({
8797
type: "insert_text",
8898
point: point,
89-
text: text,
99+
text: encode_utf8(text),
90100
currentfile: current_file
91101
});
92102
}

js/ready.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ $(document).ready(function(){
4040
broadcast.init();
4141
connect.init();
4242
context.init();
43-
snippets.init(); //<----later
43+
snippets.init();
44+
repl.init();
4445

4546
//===========
4647
//SAVE DIALOG
4748
//===========
48-
window.onmessage = repl.onmessage;
4949
window.onbeforeunload = function(){
5050
if(manager.allSaved() === false){
5151
return "You have unsaved work. Do you really want to quit?"

js/realtime.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function loadSky(){
1919
function init(){
2020
if(_init === false){
2121
_init = true;
22-
//decide wether to load sky or drive
2322
drive.checkAppLogin(function(_logged_in, _acct_data){
2423
true_id = _acct_data.user._id;
2524
$("#loading-bar").css("width","10%");
@@ -46,7 +45,6 @@ function init(){
4645
}
4746
}
4847
else if(window.location.href.indexOf("?drive=true") !== -1 || window.location.href.indexOf("%22action%22:%22") !== -1 || window.location.href.indexOf("#state=/profile&access_token=") !== -1){
49-
//indication of drive
5048
if(drive.logged_in === true){
5149
//all good!
5250
$("#loading-bar").css("width","30%");
@@ -61,15 +59,13 @@ function init(){
6159
else{
6260
//no indication
6361
if(drive.logged_in === true && sky.logged_in === false){
64-
//all good!
6562
$("#loading-bar").css("width","30%");
6663
}
6764
else if(drive.logged_in === false && sky.logged_in === true){
6865
cloud_use = "sky";
6966
$("#loading-bar").css("width","30%");
7067
}
7168
else if(drive.logged_in === true && sky.logged_in === true){
72-
//all good! -> prioritize drive
7369
$("#loading-bar").css("width","30%");
7470
}
7571
else{
@@ -79,8 +75,6 @@ function init(){
7975
}
8076
}
8177
}
82-
83-
8478
if(cloud_use === "drive"){
8579
drive.loadClient();
8680
}

js/repl.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var repl = {};
2+
repl.send = function(send){
3+
repl.elem.contentWindow.postMessage(JSON.stringify(send), '*');
4+
}
5+
repl.onmessage = function(e){
6+
//console.log(JSON.parse(e.data));
7+
}
8+
repl.init = function(){
9+
window.onmessage = repl.onmessage;
10+
repl.elem = document.getElementById("repl");
11+
}

js/sky.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ sky.loadClient = function(){
4242
$("#help_button").remove();
4343
$(".share-button").remove();
4444
$("#log-out").attr("href", sky.logout_url);
45+
$("#swap").attr("href", "https://codeyourcloud.com?drive=true");
46+
$("#swap").html( $("#swap").html().replace("Switch To OneDrive", "Switch To Google Drive") );
4547
sky.getInfo();
4648
}
4749

0 commit comments

Comments
 (0)