From c5ab5dfe26ffe2ab886e56e6a39f29678bde2b5e Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 12 Feb 2016 11:45:40 +0100 Subject: [PATCH] realtime style editor with lorum ipsum --- www/style/index.html | 73 ++++++++++++++++++++++++++++++++++++++++++++ www/style/main.js | 61 ++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 www/style/index.html create mode 100644 www/style/main.js diff --git a/www/style/index.html b/www/style/index.html new file mode 100644 index 000000000..7f06e78f1 --- /dev/null +++ b/www/style/index.html @@ -0,0 +1,73 @@ + + + + + + + + + + + Edit this document's style + +

HTML Ipsum Presents

+ +

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.

+ +

Header Level 2

+ +
    +
  1. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  2. +
  3. Aliquam tincidunt mauris eu risus.
  4. +
+ +

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.

+ +

Header Level 3

+ + + +

+#header h1 a { 
+    display: block; 
+    width: 300px; 
+    height: 80px; 
+}
+
+ + + + + + + + + + + + + + + + + + + +
th 1th 2
onetwo
threefour
+ + + + diff --git a/www/style/main.js b/www/style/main.js new file mode 100644 index 000000000..e8b621cc1 --- /dev/null +++ b/www/style/main.js @@ -0,0 +1,61 @@ +define([ + '/api/config?cb=' + Math.random().toString(16).substring(2), + '/common/realtime-input.js', + '/common/messages.js', + '/common/crypto.js', + '/bower_components/jquery/dist/jquery.min.js', + '/customize/pad.js' +], function (Config, Realtime, Messages, Crypto) { + var $ = jQuery; + $(window).on('hashchange', function() { + window.location.reload(); + }); + + var userName = Crypto.rand64(8); + + if (window.location.href.indexOf('#') === -1) { + window.location.href = window.location.href + '#' + Crypto.genKey(); + return; + } + + var key = Crypto.parseKey(window.location.hash.slice(1)); + + var $style = $('style').eq(1), + $css = $('#css'), + $edit = $('#edit'); + + $edit.attr('href', '/text/'+ window.location.hash); + + var lazyDraw = (function () { + var to, + delay = 500; + return function (content) { + to && clearTimeout(to); + to = setTimeout(function () { + $style.text(content); + },delay); + }; + }()); + + var draw = function () { + lazyDraw($css.val()); + }; + + $css // set the initial value + .val($style.text()) + .on('change', draw); + + var rts = $('textarea').toArray().map(function (e, i) { + var rt = Realtime.start(e, // window + Config.websocketURL, // websocketUrl + userName, // userName + key.channel, // channel + key.cryptKey, // cryptKey + { + onRemote: draw, + onInit: draw, + onReady: draw + }); + return rt; + }); +});