2
0
mirror of https://github.com/jupyter/notebook.git synced 2025-01-30 12:11:32 +08:00

semicolon fixes buttress half of my js commits

This commit is contained in:
Paul Ivanov 2014-03-18 10:31:51 -07:00
parent 4dd009f198
commit b9ef37ac26
2 changed files with 40 additions and 40 deletions
IPython/html/static
base/js
notebook/js

View File

@ -44,12 +44,12 @@ IPython.keyboard = (function (IPython) {
// These apply to Firefox and Opera
var _mozilla_keycodes = {
'; :': 59, '= +': 61, '- _': 173, 'meta': 224
}
};
// This apply to Webkit and IE
var _ie_keycodes = {
'; :': 186, '= +': 187, '- _': 189,
}
};
var browser = IPython.utils.browser[0];
var platform = IPython.utils.platform;
@ -65,21 +65,21 @@ IPython.keyboard = (function (IPython) {
for (var name in _keycodes) {
var names = name.split(' ');
if (names.length === 1) {
var n = names[0]
keycodes[n] = _keycodes[n]
inv_keycodes[_keycodes[n]] = n
var n = names[0];
keycodes[n] = _keycodes[n];
inv_keycodes[_keycodes[n]] = n;
} else {
var primary = names[0];
var secondary = names[1];
keycodes[primary] = _keycodes[name]
keycodes[secondary] = _keycodes[name]
inv_keycodes[_keycodes[name]] = primary
keycodes[primary] = _keycodes[name];
keycodes[secondary] = _keycodes[name];
inv_keycodes[_keycodes[name]] = primary;
}
}
var normalize_key = function (key) {
return inv_keycodes[keycodes[key]];
}
};
var normalize_shortcut = function (shortcut) {
// Put a shortcut into normalized form:
@ -90,14 +90,14 @@ IPython.keyboard = (function (IPython) {
shortcut = shortcut.toLowerCase().replace('cmd', 'meta');
var values = shortcut.split("+");
if (values.length === 1) {
return normalize_key(values[0])
return normalize_key(values[0]);
} else {
var modifiers = values.slice(0,-1);
var key = normalize_key(values[values.length-1]);
modifiers.sort();
return modifiers.join('+') + '+' + key;
}
}
};
var shortcut_to_event = function (shortcut, type) {
// Convert a shortcut (shift+r) to a jQuery Event object
@ -112,19 +112,19 @@ IPython.keyboard = (function (IPython) {
if (modifiers.indexOf('meta') !== -1) {opts.metaKey = true;}
if (modifiers.indexOf('shift') !== -1) {opts.shiftKey = true;}
return $.Event(type, opts);
}
};
var event_to_shortcut = function (event) {
// Convert a jQuery Event object to a shortcut (shift+r)
var shortcut = '';
var key = inv_keycodes[event.which]
var key = inv_keycodes[event.which];
if (event.altKey && key !== 'alt') {shortcut += 'alt+';}
if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl+';}
if (event.metaKey && key !== 'meta') {shortcut += 'meta+';}
if (event.shiftKey && key !== 'shift') {shortcut += 'shift+';}
shortcut += key;
return shortcut
}
return shortcut;
};
var trigger_keydown = function (shortcut, element) {
// Trigger shortcut keydown on an element
@ -132,17 +132,17 @@ IPython.keyboard = (function (IPython) {
element = $(element);
var event = shortcut_to_event(shortcut, 'keydown');
element.trigger(event);
}
};
// Shortcut manager class
var ShortcutManager = function (delay) {
this._shortcuts = {}
this._counts = {}
this._timers = {}
this._shortcuts = {};
this._counts = {};
this._timers = {};
this.delay = delay || 800; // delay in milliseconds
}
};
ShortcutManager.prototype.help = function () {
var help = [];
@ -168,15 +168,15 @@ IPython.keyboard = (function (IPython) {
return 0;
});
return help;
}
};
ShortcutManager.prototype.clear_shortcuts = function () {
this._shortcuts = {};
}
};
ShortcutManager.prototype.add_shortcut = function (shortcut, data, suppress_help_update) {
if (typeof(data) === 'function') {
data = {help: '', help_index: '', handler: data}
data = {help: '', help_index: '', handler: data};
}
data.help_index = data.help_index || '';
data.help = data.help || '';
@ -189,9 +189,9 @@ IPython.keyboard = (function (IPython) {
this._shortcuts[shortcut] = data;
if (!suppress_help_update) {
// update the keyboard shortcuts notebook help
$([IPython.events]).trigger('rebuild.QuickHelp')
$([IPython.events]).trigger('rebuild.QuickHelp');
}
}
};
ShortcutManager.prototype.add_shortcuts = function (data) {
for (var shortcut in data) {
@ -199,7 +199,7 @@ IPython.keyboard = (function (IPython) {
}
// update the keyboard shortcuts notebook help
$([IPython.events]).trigger('rebuild.QuickHelp');
}
};
ShortcutManager.prototype.remove_shortcut = function (shortcut, suppress_help_update) {
shortcut = normalize_shortcut(shortcut);
@ -209,7 +209,7 @@ IPython.keyboard = (function (IPython) {
// update the keyboard shortcuts notebook help
$([IPython.events]).trigger('rebuild.QuickHelp');
}
}
};
ShortcutManager.prototype.count_handler = function (shortcut, event, data) {
var that = this;
@ -229,7 +229,7 @@ IPython.keyboard = (function (IPython) {
t[shortcut] = timer;
}
return false;
}
};
ShortcutManager.prototype.call_handler = function (event) {
var shortcut = event_to_shortcut(event);
@ -245,7 +245,7 @@ IPython.keyboard = (function (IPython) {
}
}
return true;
}
};
return {
keycodes : keycodes,
@ -256,6 +256,6 @@ IPython.keyboard = (function (IPython) {
shortcut_to_event : shortcut_to_event,
event_to_shortcut : event_to_shortcut,
trigger_keydown : trigger_keydown
}
};
}(IPython));

View File

@ -42,7 +42,7 @@ var IPython = (function (IPython) {
'allows you to type code/text into a cell and is indicated by a green cell '+
'border. <b>Command mode</b> binds the keyboard to notebook level actions '+
'and is indicated by a grey cell border.'
)
);
element.append(doc);
// Command mode
@ -68,7 +68,7 @@ var IPython = (function (IPython) {
QuickHelp.prototype.build_command_help = function () {
var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
return build_div('<h4>Command Mode (press <code>Esc</code> to enable)</h4>', command_shortcuts);
}
};
var special_case = { pageup: "PageUp", pagedown: "Page Down" };
var prettify = function (s) {
@ -92,16 +92,16 @@ var IPython = (function (IPython) {
var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
// Edit mode
return build_div('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>', edit_shortcuts);
}
};
var build_one = function (s) {
var help = s['help'];
var shortcut = prettify(s['shortcut']);
var help = s.help;
var shortcut = prettify(s.shortcut);
return $('<div>').addClass('quickhelp').
append($('<span/>').addClass('shortcut_key').append($(shortcut))).
append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
append($('<span/>').addClass('shortcut_descr').text(' : ' + help));
}
};
var build_div = function (title, shortcuts) {
var i, half, n;
@ -111,12 +111,12 @@ var IPython = (function (IPython) {
var col2 = $('<div/>').addClass('box-flex0');
n = shortcuts.length;
half = ~~(n/2); // Truncate :)
for (i=0; i<half; i++) { col1.append( build_one(shortcuts[i]) ); };
for (i=half; i<n; i++) { col2.append( build_one(shortcuts[i]) ); };
for (i=0; i<half; i++) { col1.append( build_one(shortcuts[i]) ); }
for (i=half; i<n; i++) { col2.append( build_one(shortcuts[i]) ); }
sub_div.append(col1).append(col2);
div.append(sub_div);
return div;
}
};
// Set module variables
IPython.QuickHelp = QuickHelp;