Permalink
Browse files

Panels can be reordered in code, ready for dynamic reordering

  • Loading branch information...
1 parent 3bde822 commit d9e179d80ef540bf313ad68c13f1f097f1934c5b @remy remy committed Apr 12, 2012
Showing with 67 additions and 20 deletions.
  1. +47 −10 js/editors/editors.js
  2. +8 −7 js/editors/keycontrol.js
  3. +12 −3 js/editors/panel.js
View
@@ -5,10 +5,10 @@
//= require "panel"
//= require "../render/live"
//= require "../render/console"
+//= require "keycontrol"
var panels = {};
-
panels.getVisible = function () {
var panels = this.panels,
visible = [];
@@ -182,10 +182,12 @@ Panel.prototype.distribute = function () {
jsbin.panels = panels;
var editors = panels.panels = {
- javascript: new Panel('javascript', { editor: true, label: 'JavaScript', nosplitter: true }),
- css: new Panel('css', { editor: true, label: 'CSS' }),
html: new Panel('html', { editor: true, label: 'HTML' }),
- console: new Panel('console', { label: 'Console', init: function () { this.render(); } }),
+ css: new Panel('css', { editor: true, label: 'CSS' }),
+ javascript: new Panel('javascript', { editor: true, label: 'JavaScript', init: function () {
+ // checkForErrors();
+ } }),
+ console: new Panel('console', { label: 'Console' }),
live: new Panel('live', { label: 'Output', show: function () {
// contained in live.js
$(document).bind('codeChange.live', function (event, data) {
@@ -198,7 +200,7 @@ var editors = panels.panels = {
}
});
renderLivePreview();
- }})
+ } })
};
@@ -245,12 +247,49 @@ Panel.prototype.hide = function () {
panels.restore();
panels.focus(panels.getVisible()[0] || null);
+// allow panels to be reordered
+(function () {
+ var panelsEl = document.getElementById('panels'),
+ moving = null;
+
+ panelsEl.ondragstart = function (e) {
+ if (e.target.nodeName == 'A') {
+ moving = e.target;
+ } else {
+ return false;
+ }
+ };
+
+ panelsEl.ondragover = function (e) {
+ console.log(e)
+ return false;
+ };
+
+ panelsEl.ondragend = function () {
+ moving = false;
+ return false;
+ };
+
+ panelsEl.ondrop = function (e) {
+ console.log(e.dataTransfer);
+ if (moving) {
+
+ }
+ return false;
+ };
+
+}());
+
var editorsReady = setInterval(function () {
var ready = true,
- resizeTimer = null;
- for (var panel in panels.panels) {
- if (!panels.panels[panel].ready) ready = false;
+ resizeTimer = null,
+ panel,
+ panelId;
+
+ for (panelId in panels.panels) {
+ panel = panels.panels[panelId];
+ if (panel.visible && !panel.ready) ready = false;
}
panels.ready = ready;
@@ -272,5 +311,3 @@ var editorsReady = setInterval(function () {
$document.trigger('jsbinReady');
}
}, 100);
-
-//= require "keycontrol"
View
@@ -5,13 +5,14 @@ var keyboardHelpVisible = false;
$body.keydown(keycontrol);
-var panelShortcuts = {
- 49: 'javascript', // 1
- 50: 'css', // 2
- 51: 'html', // 3
- 52: 'console', // 4
- 53: 'live' // 5
-};
+var panelShortcuts = {}
+// 49: 'javascript', // 1
+// 50: 'css', // 2
+// 51: 'html', // 3
+// 52: 'console', // 4
+// 53: 'live' // 5
+// };
+panelShortcuts.start = 48;
// work out the browser platform
var ua = navigator.userAgent;
View
@@ -1,4 +1,5 @@
-var $document = $(document);
+var $document = $(document),
+ $source = $('#source');
var editorModes = {
html: 'htmlmixed',
@@ -10,9 +11,17 @@ var Panel = function (name, settings) {
var panel = this;
panel.settings = settings = settings || {};
panel.id = panel.name = name;
- panel.$el = $('.panel.' + name);
+ panel.$el = $('.panel.' + name).remove();
+ panel.$el.appendTo($source);
panel.el = document.getElementById(name);
- panel.order = Panel.order++;
+ panel.order = ++Panel.order;
+
+ // keyboard shortcut (set in keyboardcontrol.js)
+ panelShortcuts[panelShortcuts.start + panel.order] = panel.id;
+
+ if (panel.order === 1) {
+ settings.nosplitter = true;
+ }
var splitterSettings = {};

0 comments on commit d9e179d

Please sign in to comment.