diff --git a/playground/css/fiddle.css b/playground/css/fiddle.css index 952edd1..203bd21 100644 --- a/playground/css/fiddle.css +++ b/playground/css/fiddle.css @@ -37,16 +37,35 @@ body { #header-title { color: #00d8ff; font-size: 24px; - line-height: 50px; - height: 50px; + line-height: 48px; + /*height: 50px;*/ + padding-left: 10px; + vertical-align: middle; display: inline-block; } +.title-link, .title-link:hover, .title-link:visited { + text-decoration: none; + color: #00d8ff; +} + #buttons-bar { padding-left: 40px; display: inline-block; } +#buttons-bar button, #buttons-bar div { + margin-right: 10px; +} + +.toolbar-dropdown { + display: inline-block; +} + +.button-icon { + margin-right: 5px; +} + .fiddle { height: 100%; } @@ -63,6 +82,7 @@ body { width: 50%; display: table-cell; vertical-align: top; + padding: 5px; } .sample-view { diff --git a/playground/fiddle-main.js b/playground/fiddle-main.js index ff1218a..d2f180d 100644 --- a/playground/fiddle-main.js +++ b/playground/fiddle-main.js @@ -6,7 +6,9 @@ requirejs.config({ firebase: 'https://cdn.firebase.com/js/client/2.0.5/firebase', react: 'http://fb.me/react-with-addons-0.12.1', //ace: '../ace-builds-1.1.8/src-min/ace', - fiddle: './fiddle' + fiddle: './fiddle', + text: 'libs/requirejs-plugins/text', + json: 'libs/requirejs-plugins/json' //'react/addons': 'http://fb.me/react-with-addons-0.12.1' }, shim: { @@ -41,8 +43,8 @@ requirejs(['jquery', 'react', 'fiddle'], function ($, React, fiddle) { //}); - var h = (contentHeight / 2) - 10; - var w = ($(document).width() / 2) - 10; + //var h = (contentHeight / 2) - 10; + //var w = ($(document).width() / 2) - 10; //var size = getWindowSize(); //$('#editor-rt').css({ // top: 50, left: 0, bottom: h, right: w, position: 'absolute' @@ -70,17 +72,8 @@ requirejs(['jquery', 'react', 'fiddle'], function ($, React, fiddle) { //var h = (contentHeight / 2) - 10; //var w = ($(document).width() / 2) - 10; var $this = $(this); - //$this.parent().width(); - //$this.parent().width(); - console.log('' + $this.parent().height() + ',' + $this.parent().width() ); - //$(this).css({); - $this.height($this.parent().height() - 2).width($this.parent().width() - 2); - //$(this).css({ - // top: 50 + h, left: w, bottom: 0, right: 0, position: 'absolute' - //}); }); - //.large-text-area } }); diff --git a/playground/fiddle.js b/playground/fiddle.js index b5dfcb0..1233ed1 100644 --- a/playground/fiddle.js +++ b/playground/fiddle.js @@ -3,7 +3,7 @@ */ /*eslint global-strict:0, no-alert:0*/ /*global Firebase:true,alert:true*/ -define(['react', 'firebase', 'lodash', './fiddle.rt'], function (React, Firebase, _, fiddleTemplate) { +define(['react', 'firebase', 'lodash', './fiddle.rt', 'jquery'], function (React, Firebase, _, fiddleTemplate, $) { 'use strict'; function generateRandomId() { @@ -40,7 +40,35 @@ define(['react', 'firebase', 'lodash', './fiddle.rt'], function (React, Firebase Firebase.goOffline(); alert('saved the fiddle, you can share your url'); }.bind(this)); + }, + clear: function () { + this.refs.playground.clear(); + }, + + loadSample: function (name) { + //require(['text!./samples/' + name + '.rt', 'text!./samples/' + name + '.code'], function (rt, code) { + // var currentState = { + // templateHTML: rt, + // templateProps: code + // }; + // //this.updateSample(currentState); + // this.refs.playground.setState(currentState); + //}); + + var playground = this.refs.playground; + $.get('playground/samples/' + name + '.rt', null, function (data, textStatus, jqXHR) { + var rt = data; + $.get('playground/samples/' + name + '.code', null, function (data2, textStatus2, jqXHR2) { + var currentState = { + templateHTML: rt, + templateProps: data2 + }; + //this.updateSample(currentState); + playground.setState(currentState); + }); + }); + //this.refs.playground.clear(); }, render: function () { diff --git a/playground/fiddle.rt b/playground/fiddle.rt index 77a605e..397d74d 100644 --- a/playground/fiddle.rt +++ b/playground/fiddle.rt @@ -2,13 +2,34 @@
diff --git a/playground/fiddle.rt.js b/playground/fiddle.rt.js index 6b4b459..2d823dc 100644 --- a/playground/fiddle.rt.js +++ b/playground/fiddle.rt.js @@ -9,20 +9,93 @@ define([ evt.preventDefault(); this.save(); } + function onClick2(evt) { + evt.preventDefault(); + this.clear(); + } + function onClick3(evt) { + evt.preventDefault(); + this.loadSample('rt-if'); + } + function onClick4(evt) { + evt.preventDefault(); + this.loadSample('rt-repeat'); + } + function onClick5(evt) { + evt.preventDefault(); + this.loadSample('rt-props'); + } + function onClick6(evt) { + evt.preventDefault(); + this.loadSample('todo'); + } + function onClick7(evt) { + evt.preventDefault(); + this.loadSample('weather'); + } return function () { - return React.createElement('div', { 'className': 'fiddle' }, React.createElement('div', { 'id': 'header' }, React.createElement('div', { 'id': 'header-title' }, React.createElement('span', {}, '<'), React.createElement('img', { + return React.createElement('div', { 'className': 'fiddle' }, React.createElement('div', { 'id': 'header' }, React.createElement('div', { 'id': 'header-title' }, React.createElement('a', { + 'href': 'index.html', + 'className': 'title-link' + }, React.createElement('span', {}, '<'), React.createElement('img', { 'className': 'nav-logo', 'src': 'https://facebook.github.io/react/img/logo.svg', 'width': '32', 'height': '32' - }), React.createElement('span', {}, '/>'), '\n RTFiddle\n '), React.createElement('div', { 'id': 'buttons-bar' }, React.createElement('button', { - 'className': 'btn', + }), React.createElement('span', {}, '/>')), '\n RTFiddle\n '), React.createElement('div', { 'id': 'buttons-bar' }, React.createElement('button', { + 'type': 'button', + 'className': 'btn btn-default', 'onClick': onClick1.bind(this) - }, 'Save fiddle'))) /*
*/ - /*

React Templates fiddle

*/ - /*

Play with react templates and save/share your results

*/ - /* */ - /*
*/, React.createElement('div', { 'className': 'playground-container' }, React.createElement(playground, { + }, React.createElement('span', { + 'className': 'glyphicon glyphicon-star button-icon', + 'aria-hidden': 'true' + }), 'Save fiddle\n '), React.createElement('button', { + 'type': 'button', + 'className': 'btn btn-default', + 'onClick': onClick2.bind(this) + }, React.createElement('span', { + 'className': 'glyphicon glyphicon-trash button-icon', + 'aria-hidden': 'true' + }), 'Clear\n '), React.createElement('div', { 'className': 'dropdown toolbar-dropdown' }, React.createElement('button', { + 'className': 'btn btn-default dropdown-toggle', + 'type': 'button', + 'id': 'dropdownMenu1', + 'data-toggle': 'dropdown', + 'aria-expanded': 'true' + }, '\n Load Sample\n ', React.createElement('span', { 'className': 'caret' })), React.createElement('ul', { + 'className': 'dropdown-menu', + 'role': 'menu', + 'aria-labelledby': 'dropdownMenu1' + }, React.createElement('li', { 'role': 'presentation' }, React.createElement('a', { + 'role': 'menuitem', + 'tabIndex': '-1', + 'href': '#', + 'onClick': onClick3.bind(this) + }, 'rt-if')), React.createElement('li', { 'role': 'presentation' }, React.createElement('a', { + 'role': 'menuitem', + 'tabIndex': '-1', + 'href': '#', + 'onClick': onClick4.bind(this) + }, 'rt-repeat')), React.createElement('li', { 'role': 'presentation' }, React.createElement('a', { + 'role': 'menuitem', + 'tabIndex': '-1', + 'href': '#', + 'onClick': onClick5.bind(this) + }, 'rt-props')), React.createElement('li', { 'role': 'presentation' }, React.createElement('a', { + 'role': 'menuitem', + 'tabIndex': '-1', + 'href': '#', + 'onClick': onClick6.bind(this) + }, 'Todo')), React.createElement('li', { 'role': 'presentation' }, React.createElement('a', { + 'role': 'menuitem', + 'tabIndex': '-1', + 'href': '#', + 'onClick': onClick7.bind(this) + }, 'Weather')))))) /*
*/ + /*

React Templates fiddle

*/ + /*

Play with react templates and save/share your results

*/ + /* */ + /*
*/, React.createElement('div', { 'className': 'playground-container' }, React.createElement(playground, { 'ref': 'playground', 'direction': 'vertical', 'fiddle': true diff --git a/playground/playground-fiddle.rt b/playground/playground-fiddle.rt index 5c02656..4532c1f 100644 --- a/playground/playground-fiddle.rt +++ b/playground/playground-fiddle.rt @@ -22,12 +22,14 @@ mode="javascript" readOnly="{true}" />
-
-

Preview:

-
- - -
+
+
+

Preview:

+
+ + +
+
diff --git a/playground/playground-fiddle.rt.js b/playground/playground-fiddle.rt.js index d2adc89..2e67349 100644 --- a/playground/playground-fiddle.rt.js +++ b/playground/playground-fiddle.rt.js @@ -36,13 +36,13 @@ define([ 'value': this.templateSource, 'mode': 'javascript', 'readOnly': true - })), React.createElement('div', { + })), React.createElement('div', { 'className': 'result-area' }, React.createElement('div', { 'id': 'result-area', 'key': 'result-area', - 'className': 'result-area well' + 'className': 'well' }, React.createElement('h2', {}, 'Preview:'), React.createElement('form', { 'className': 'sample-view', 'onSubmit': onSubmit3.bind(this) - }, React.createElement(this.sample, { 'key': 'sample' })))) /*
*/); + }, React.createElement(this.sample, { 'key': 'sample' }))))) /*
*/); }; }); \ No newline at end of file diff --git a/playground/playground.js b/playground/playground.js index b04f960..978a698 100644 --- a/playground/playground.js +++ b/playground/playground.js @@ -100,6 +100,15 @@ define(['react', 'lodash', './playground-fiddle.rt', './playground.rt'], functio classBase.render = this.sampleRender; this.sample = React.createFactory(React.createClass(classBase)); }, + clear: function () { + //console.log('clear'); + var currentState = { + templateHTML: templateHTML, + templateProps: templateProps + }; + //this.updateSample(currentState); + this.setState(currentState); + }, getInitialState: function () { var currentState = { templateHTML: this.props.templateHTML || templateHTML,