Skip to content

Commit

Permalink
Few keyboard shortcuts and tweak to language
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Mar 27, 2012
1 parent b3ddc04 commit 98bf3f5
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 19 deletions.
13 changes: 10 additions & 3 deletions css/style.css
Expand Up @@ -2009,17 +2009,24 @@ div.CodeMirror-selected { background: #d9d9d9; }

.label {
/*overflow: hidden;*/
/*min-height: 34px;*/
/*line-height: 34px;*/
padding: 10px;
}

.label label {
margin: 0;
}

.label .options {
float: right;
display: block;
height: 35px;
margin-right: 10px;
/*height: 35px;*/
/*margin-right: 10px;*/
}

.label .options label {
height: 35px;
/*height: 35px;*/
display: inline-block;
cursor: pointer;
}
Expand Down
4 changes: 2 additions & 2 deletions index.php
Expand Up @@ -129,8 +129,8 @@
<div class="label">
<strong>Live Preview</strong>
<span class="options">
<button id="runwithalerts">Run with alerts</button>
<label>Disable JS<input type="checkbox" id="disablejs" checked></label>
<button id="runwithalerts">Run JS with alerts</button>
<label>Include JS<input type="checkbox" id="enablejs"></label>
</span>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion js/chrome/app.js
Expand Up @@ -61,7 +61,6 @@ $document.one('jsbinReady', function () {

// $sp1.filter(':visible').trigger('init', (splitterSettings[0] || {x:null}).x);
// $sp2.filter(':visible').trigger('init', (splitterSettings[1] || {x:null}).x);
console.log('>>>>>>>> ready');
$bin.removeAttr('style').addClass('ready');
});

Expand Down
6 changes: 3 additions & 3 deletions js/chrome/navigation.js
Expand Up @@ -181,7 +181,7 @@ $('#runwithalerts').click(function () {

// TODO memorise
editors.live.disablejs = jsbin.settings.disablejs;
$('#disablejs').change(function () {
jsbin.settings.disablejs = editors.live.disablejs = this.checked;
$('#enablejs').change(function () {
jsbin.settings.disablejs = editors.live.disablejs = !this.checked;
editors.live.render();
}).attr('checked', jsbin.settings.disablejs ? true : false);
}).attr('checked', jsbin.settings.disablejs ? false : true);
9 changes: 9 additions & 0 deletions js/editors/editors.js
Expand Up @@ -120,6 +120,15 @@ panels.distribute = function () {
}
};

panels.show = function (panelId) {
this.panels[panelId].show();
if (this.panels[panelId].editor) {
this.panels[panelId].editor.focus();
}
}

panels.focused = null;

// dirty, but simple
Panel.prototype.distribute = function () {
panels.distribute();
Expand Down
29 changes: 28 additions & 1 deletion js/editors/keycontrol.js
Expand Up @@ -3,9 +3,21 @@

var keyboardHelpVisible = false;

function keycontrol(panel, event) {
$body.keydown(keycontrol);

var panelShortcuts = {
49: 'javascript',
50: 'css',
51: 'html',
52: 'console',
53: 'live'
};

function keycontrol(event) {
event = normalise(event);

var panel = jsbin.panels.focused ? jsbin.panels.focused.editor : {};

// these should fire when the key goes down
if (event.type == 'keydown') {
if (panel.id == 'javascript') {
Expand All @@ -15,6 +27,21 @@ function keycontrol(panel, event) {
}
}

// shortcut for showing a panel
if (panelShortcuts[event.which] !== undefined && event.altKey && event.metaKey) {
jsbin.panels.show(panelShortcuts[event.which]);
event.stop();
} else if (event.which === 27 && event.altKey) {
jsbin.panels.focused.hide();
var visible = jsbin.panels.getVisible();
if (visible.length) {
jsbin.panels.focused = visible[0];
if (visible[0].editor) {
visible[0].editor.focus();
}
}
}

if (event.which == 191 && event.shiftKey && event.metaKey) {
// show help
$body.toggleClass('keyboardHelp');
Expand Down
7 changes: 4 additions & 3 deletions js/editors/libraries.js
Expand Up @@ -59,10 +59,11 @@ Libraries.prototype.init = function () {
jquerymobile : {
text: 'jQuery Mobile',
requires: 'http://code.jquery.com/jquery-1.6.4.min.js',
style: 'http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0.min.css',
style: 'http://code.jquery.com/mobile/latest/jquery.mobile.css',
scripts: [
{ text: 'jQuery Mobile 1.0', url: 'http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js' },
{ text: 'jQuery Mobile 1.0b3', url: 'http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js' }
{ text: 'jQuery Mobile Latest', url: 'http://code.jquery.com/mobile/latest/jquery.mobile.js' },
{ text: 'jQuery Mobile 1.0.1', url: 'http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.1.min.js' },
{ text: 'jQuery Mobile 1.1.0rc1', url: 'http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.js' }
]
},
others: {
Expand Down
14 changes: 8 additions & 6 deletions js/editors/panel.js
Expand Up @@ -9,7 +9,7 @@ var editorModes = {
var Panel = function (name, settings) {
var panel = this;
panel.settings = settings = settings || {};
panel.name = name;
panel.id = panel.name = name;
panel.$el = $('.panel.' + name);
panel.el = document.getElementById(name);
panel.order = Panel.order++;
Expand Down Expand Up @@ -66,9 +66,9 @@ var Panel = function (name, settings) {
});
this.controlButton.appendTo('#panels');

this.$el.find('.label').prepend('<a href="#close" class="close"></a>').find('.close').click(function () {
panel.hide();
});
// this.$el.find('.label').prepend('<a href="#close" class="close"></a>').find('.close').click(function () {
// panel.hide();
// });

panel.hide();
}
Expand Down Expand Up @@ -162,8 +162,10 @@ Panel.prototype = {
return pos.line;
};

editor.setOption('onKeyEvent', keycontrol);
this.settings.focus && editor.setOption('onFocus', $.proxy(this.settings.focus, this));
// editor.setOption('onKeyEvent', keycontrol);
editor.setOption('onFocus', function () {
jsbin.panels.focused = panel;
});

editor.id = panel.name;

Expand Down

0 comments on commit 98bf3f5

Please sign in to comment.