##// END OF EJS Templates
DRY: style in one place, removed code duplication
Paul Ivanov -
Show More
@@ -67,35 +67,7 b' var IPython = (function (IPython) {'
67
67
68 QuickHelp.prototype.build_command_help = function () {
68 QuickHelp.prototype.build_command_help = function () {
69 var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
69 var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
70 var help, shortcut;
70 return build_div('<h4>Command Mode (press <code>Esc</code> to enable)</h4>', command_shortcuts);
71 var i, half, n;
72
73 // Command mode
74 var cmd_div = $('<div/>').append($('<h4>Command Mode (press <code>Esc</code> to enable)</h4>'));
75 var cmd_sub_div = $('<div/>').addClass('hbox');
76 var cmd_col1 = $('<div/>').addClass('box-flex0');
77 var cmd_col2 = $('<div/>').addClass('box-flex0');
78 n = command_shortcuts.length;
79 half = ~~(n/2); // Truncate :)
80 for (i=0; i<half; i++) {
81 help = command_shortcuts[i]['help'];
82 shortcut = prettify(command_shortcuts[i]['shortcut']);
83 cmd_col1.append($('<div>').addClass('quickhelp').
84 append($('<span/>').addClass('shortcut_key').text(shortcut)).
85 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
86 );
87 };
88 for (i=half; i<n; i++) {
89 help = command_shortcuts[i]['help'];
90 shortcut = prettify(command_shortcuts[i]['shortcut']);
91 cmd_col2.append($('<div>').addClass('quickhelp').
92 append($('<span/>').addClass('shortcut_key').text(shortcut)).
93 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
94 );
95 };
96 cmd_sub_div.append(cmd_col1).append(cmd_col2);
97 cmd_div.append(cmd_sub_div);
98 return cmd_div;
99 }
71 }
100
72
101 var special_case = { pageup: "PageUp", pagedown: "Page Down" };
73 var special_case = { pageup: "PageUp", pagedown: "Page Down" };
@@ -104,8 +76,12 b' var IPython = (function (IPython) {'
104 var k, i;
76 var k, i;
105 for (i in keys) {
77 for (i in keys) {
106 k = keys[i];
78 k = keys[i];
107 if ( k.length == 1 ) continue; // leave individual keys lower-cased
79 if ( k.length == 1 ) {
80 keys[i] = "<code><strong>" + k + "</strong></code>";
81 continue; // leave individual keys lower-cased
82 }
108 keys[i] = ( special_case[k] ? special_case[k] : k.charAt(0).toUpperCase() + k.slice(1) );
83 keys[i] = ( special_case[k] ? special_case[k] : k.charAt(0).toUpperCase() + k.slice(1) );
84 keys[i] = "<code><strong>" + keys[i] + "</strong></code>";
109 }
85 }
110 return keys.join('-');
86 return keys.join('-');
111
87
@@ -114,35 +90,32 b' var IPython = (function (IPython) {'
114
90
115 QuickHelp.prototype.build_edit_help = function () {
91 QuickHelp.prototype.build_edit_help = function () {
116 var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
92 var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
117 var help, shortcut;
118 var i, half, n;
119
120 // Edit mode
93 // Edit mode
121 var edit_div = $('<div/>').append($('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>'));
94 return build_div('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>', edit_shortcuts);
122 var edit_sub_div = $('<div/>').addClass('hbox');
95 }
123 var edit_col1 = $('<div/>').addClass('box-flex0');
96
124 var edit_col2 = $('<div/>').addClass('box-flex0');
97 var build_one = function (s) {
125 n = edit_shortcuts.length;
98 var help = s['help'];
99 var shortcut = prettify(s['shortcut']);
100 return $('<div>').addClass('quickhelp').
101 append($('<span/>').addClass('shortcut_key').append($(shortcut))).
102 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
103
104 }
105
106 var build_div = function (title, shortcuts) {
107 var i, half, n;
108 var div = $('<div/>').append($(title));
109 var sub_div = $('<div/>').addClass('hbox');
110 var col1 = $('<div/>').addClass('box-flex0');
111 var col2 = $('<div/>').addClass('box-flex0');
112 n = shortcuts.length;
126 half = ~~(n/2); // Truncate :)
113 half = ~~(n/2); // Truncate :)
127 for (i=0; i<half; i++) {
114 for (i=0; i<half; i++) { col1.append( build_one(shortcuts[i]) ); };
128 help = edit_shortcuts[i]['help'];
115 for (i=half; i<n; i++) { col2.append( build_one(shortcuts[i]) ); };
129 shortcut = prettify(edit_shortcuts[i]['shortcut']);
116 sub_div.append(col1).append(col2);
130 edit_col1.append($('<div>').addClass('quickhelp').
117 div.append(sub_div);
131 append($('<span/>').addClass('shortcut_key').text(shortcut)).
118 return div;
132 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
133 );
134 };
135 for (i=half; i<n; i++) {
136 help = edit_shortcuts[i]['help'];
137 shortcut = prettify(edit_shortcuts[i]['shortcut']);
138 edit_col2.append($('<div>').addClass('quickhelp').
139 append($('<span/>').addClass('shortcut_key').text(shortcut)).
140 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
141 );
142 };
143 edit_sub_div.append(edit_col1).append(edit_col2);
144 edit_div.append(edit_sub_div);
145 return edit_div;
146 }
119 }
147
120
148 // Set module variables
121 // Set module variables
General Comments 0
You need to be logged in to leave comments. Login now