From 0a2482d18ac41714ec355fed08808399eb230f12 Mon Sep 17 00:00:00 2001 From: zodern Date: Thu, 2 Apr 2015 15:34:17 -0500 Subject: [PATCH] moved text editor to it's own repository --- app.json | 11 +++++ index.js | 48 ++++++++++++++++++++ public/index.html | 23 ++++++++++ public/js/Silk.js | 35 +++++++++++++++ public/js/mousetrap.js | 9 ++++ public/js/textEditor.js | 95 ++++++++++++++++++++++++++++++++++++++++ public/logo.png | Bin 0 -> 9344 bytes public/textEditor.css | 48 ++++++++++++++++++++ 8 files changed, 269 insertions(+) create mode 100644 app.json create mode 100644 index.js create mode 100644 public/index.html create mode 100644 public/js/Silk.js create mode 100644 public/js/mousetrap.js create mode 100644 public/js/textEditor.js create mode 100644 public/logo.png create mode 100644 public/textEditor.css diff --git a/app.json b/app.json new file mode 100644 index 0000000..96b8a6a --- /dev/null +++ b/app.json @@ -0,0 +1,11 @@ +{ + "name": "Text Editor", + "title": "Text Editor", + "url": "/textEditor/index.html", + "icon": "logo.png", + "multipleWindows": true, + "opens": [ + "text/plain", + "*" + ] +} diff --git a/index.js b/index.js new file mode 100644 index 0000000..47e4411 --- /dev/null +++ b/index.js @@ -0,0 +1,48 @@ +var methods = Silk.methods; + +methods.add({ + "te/open": function (file, callObj, send) { + var fs = require("fs"); + var fileName = file; + console.log("fileName"); + fs.exists(fileName, function (exists) { + if (!exists) return send("this file does not exist"); + + fs.stat(fileName, function (err, stats) { + if (err) return send(err); + if (stats.isDirectory()) + return send(new Error("Editing directories in a text editor is not currently supported")); + fs.readFile(fileName, function (err, data) { + if (err) return send(err); + var ret = { + state: "ready", + content: data.toString("utf-8") + } + send(void(0), ret); + }) + }); + }); + return { + state: "loading" + } + } +}); + +methods.add({ + "te/save": function (data, callObj, send) { + var fs = require("fs"); + console.log(data); + path = data.path; + contents = data.contents; + console.log("=========="); + // console.log(contents); + fs.writeFile(path, contents, function (err) { + if (err) return console.log(err); + console.log("saved: " + path); + }); + console.log("finished"); + + // tricks silk into sending return value; + return " "; + } +}) \ No newline at end of file diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..11fca2e --- /dev/null +++ b/public/index.html @@ -0,0 +1,23 @@ + + + + + + + + +
+
+ +
+ + + + + + + + + + + diff --git a/public/js/Silk.js b/public/js/Silk.js new file mode 100644 index 0000000..8f169bb --- /dev/null +++ b/public/js/Silk.js @@ -0,0 +1,35 @@ +/*! Silk.js 2014-11-13 */ +var Silk = {}; + +Silk.events = {}, Silk.events.openFile = function() {}, Silk.event = function(name, func) { + switch (Silk.events[name] = func, name) { + case "openFile": + Silk.fileToOpen(); + } +}; + +var chan = Channel.build({ + window: window.parent, + origin: "*", + scope: "testScope" +}); + +Silk.openFile = function(path, mime) { + chan.notify({ + method: "openFile", + params: { + path: path, + mime: mime + } + }); +}, chan.bind("fileToOpen", function(context, data) { + Silk.events.openFile(data.path); +}), Silk.fileToOpen = function() { + name = "file", name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regexS = "[\\?&]" + name + "=([^&#]*)", regex = new RegExp(regexS), results = regex.exec(window.location.href); + if (null == results) return null; + try { + Silk.events.openFile(decodeURIComponent(results[1])); + } catch (e) {} + return decodeURIComponent(results[1]); +}; diff --git a/public/js/mousetrap.js b/public/js/mousetrap.js new file mode 100644 index 0000000..d5f6af2 --- /dev/null +++ b/public/js/mousetrap.js @@ -0,0 +1,9 @@ +/* mousetrap v1.4.6 craig.is/killing/mice */ +(function(J,r,f){function s(a,b,d){a.addEventListener?a.addEventListener(b,d,!1):a.attachEvent("on"+b,d)}function A(a){if("keypress"==a.type){var b=String.fromCharCode(a.which);a.shiftKey||(b=b.toLowerCase());return b}return h[a.which]?h[a.which]:B[a.which]?B[a.which]:String.fromCharCode(a.which).toLowerCase()}function t(a){a=a||{};var b=!1,d;for(d in n)a[d]?b=!0:n[d]=0;b||(u=!1)}function C(a,b,d,c,e,v){var g,k,f=[],h=d.type;if(!l[a])return[];"keyup"==h&&w(a)&&(b=[a]);for(g=0;gg||h.hasOwnProperty(g)&&(p[h[g]]=g)}e=p[d]?"keydown":"keypress"}"keypress"==e&&f.length&&(e="keydown");return{key:c,modifiers:f,action:e}}function F(a,b,d,c,e){q[a+":"+d]=b;a=a.replace(/\s+/g," ");var f=a.split(" ");1":".","?":"/","|":"\\"},G={option:"alt",command:"meta","return":"enter",escape:"esc",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},p,l={},q={},n={},D,z=!1,I=!1,u=!1;for(f=1;20>f;++f)h[111+f]="f"+f;for(f=0;9>=f;++f)h[f+96]=f;s(r,"keypress",y);s(r,"keydown",y);s(r,"keyup",y);var m={bind:function(a,b,d){a=a instanceof Array?a:[a];for(var c=0;c3k5fMeCcoFo_f(H*8 zt+oEQUi_=5pjN7={Yla`Ce^lSn_o3+`ZLa(oNV%hWd6!#pIThljmndD= zHJwhMvUSsWw6Pi+Jr6ordIbQ00~r^Bgn4mnWSdQg>!;RX?~yoG(t%@SKyNxmP+((Y ztP7H0FGHWq07e8C$9sru`q)U9?KynDK$6t}a&k6GUc^WxJCw-PMg~=Q?EnLi1yp9# z06H>Tqyo`o)B%YX^^DUA=Rt>K(avg&^97R30Z1_bhN$c4kk4t-tVlKsd>_Tb8DKHCO`%Z#H5s@K*BI$Mt^r0TY)ab{ijBNBe7Owe zL~o-;-yErCn?j>qr(|HwSOci!d$zqW6vDayKK3~sxl2lcgzoS7;UpI zg!ACF&V~ZQj$!D4H|YS{08p9ZtX)V4+D2C}b->26+^HOGOB536WSRlVv|-swtyz2u z-6&_>ZLIqefep=bYoS&nHt1Ab3f-t6vEdF~=Tf6y(%-s-Z){fGsi<8j=)S50k2k@- zCM^pV^eZZb{B#GNR6~fH%b$Tx%>fG<6@^0nj(ue4j@kg_y$LddAvJW52IZtrO<{2D77a^r_lJ93j{ut zc-z+MzFP{fx!RlR81b}J>46t06VfSUH}$gYq*Dli@h$|B&yyZ@s3ny`Zs+@R z!zUD_Y$N;@APevkooH|jf>5H99nKm>PL{6Jk;KkpHZEjG+FG}p5XX)h`pY7vu69?= Joy~{N`~}8}V?zJ{ literal 0 HcmV?d00001 diff --git a/public/textEditor.css b/public/textEditor.css new file mode 100644 index 0000000..4d947fc --- /dev/null +++ b/public/textEditor.css @@ -0,0 +1,48 @@ +#text { + width: 100%; + height: 100%; + padding: 20px; + padding-bottom: 50px; + padding-top: 50px; + position: absolute; + top: 0px; + left: 0px; + box-sizing: border-box; + background-color: rgb(237, 237, 237); + color: rgb(69, 69, 69); + -webkit-transition: .2s all; + font-family: monospace; + line-height: 1.5; + font-size: 14px; +} +#text:focus { + background-color: rgb(255, 255, 255); +} +#toolBar { + position: absolute; + top: 0px; + left: 0px; + z-index: 1; + padding: 10px; + width: 100%; + height: 40px; + border-bottom: 3px solid rgba(128, 128, 128, 0.8); + box-sizing: border-box; + background-color: rgba(237, 237, 237, 0.8); +} +#save { +position: absolute; +height: 37px; +width: 60px; +top: 0px; +right: 0px; +background-color: rgba(219, 179, 53, 1); +border: 0px; +color: rgb(71, 71, 71); +font-size: 14px; +cursor: pointer; + -webkit-transition: .2s background-color; +} +#save:hover{ + background-color: rgb(219, 166, 0); +} \ No newline at end of file