##// END OF EJS Templates
Moved util functions into util.js
Jonathan Frederic -
Show More
@@ -280,8 +280,6 b' casper.notebook_test(function () {'
280 this.trigger_keydown('shift+m'); // Merge
280 this.trigger_keydown('shift+m'); // Merge
281 this.validate_state('merge', 'command', 0);
281 this.validate_state('merge', 'command', 0);
282 this.test.assertEquals(this.get_cell_text(0), 'ab\ncd', 'merge; Verify that cell 0 has the merged contents.');
282 this.test.assertEquals(this.get_cell_text(0), 'ab\ncd', 'merge; Verify that cell 0 has the merged contents.');
283
284
285 });
283 });
286
284
287 // Utility functions.
285 // Utility functions.
@@ -342,106 +340,4 b' casper.notebook_test(function () {'
342 }
340 }
343 return true;
341 return true;
344 };
342 };
345
346
347 /* TODO: MOVE EVERYTHING BELOW THIS LINE INTO THE BASE (utils.js) */
348
349
350 this.select_cell = function (index) {
351 this.evaluate(function (i) {
352 IPython.notebook.select(i);
353 }, {i: index});
354 };
355
356 this.click_cell_editor = function(index) {
357 // Code Mirror does not play nicely with emulated brower events.
358 // Instead of trying to emulate a click, here we run code similar to
359 // the code used in Code Mirror that handles the mousedown event on a
360 // region of codemirror that the user can focus.
361 this.evaluate(function (i) {
362 cm = IPython.notebook.get_cell(i).code_mirror;
363 if (cm.options.readOnly != "nocursor" && (document.activeElement != cm.display.input))
364 cm.display.input.focus();
365 }, {i: index});
366 };
367
368 this.focus_notebook = function() {
369 this.evaluate(function (){
370 $('#notebook').focus();
371 }, {});
372 };
373
374 this.trigger_keydown = function() {
375 for (var i = 0; i < arguments.length; i++) {
376 this.evaluate(function (k) {
377 IPython.keyboard.trigger_keydown(k);
378 }, {k: arguments[i]});
379 }
380 };
381
382 this.get_keyboard_mode = function() {
383 return this.evaluate(function() {
384 return IPython.keyboard_manager.mode;
385 }, {});
386 };
387
388 this.get_notebook_mode = function() {
389 return this.evaluate(function() {
390 return IPython.notebook.mode;
391 }, {});
392 };
393
394 this.get_cell = function(index) {
395 return this.evaluate(function(i) {
396 var cell = IPython.notebook.get_cell(i);
397 if (cell) {
398 return cell;
399 }
400 return null;
401 }, {i : index});
402 };
403
404 this.is_cell_editor_focused = function(index) {
405 return this.evaluate(function(i) {
406 var cell = IPython.notebook.get_cell(i);
407 if (cell) {
408 return $(cell.code_mirror.getInputField()).is('.CodeMirror-focused *');
409 }
410 return false;
411 }, {i : index});
412 };
413
414 this.is_only_cell_selected = function(index) {
415 return this.is_only_cell_on(index, 'selected', 'unselected');
416 };
417
418 this.is_only_cell_edit = function(index) {
419 return this.is_only_cell_on(index, 'edit_mode', 'command_mode');
420 };
421
422 this.is_only_cell_on = function(i, on_class, off_class) {
423 var cells_length = this.get_cells_length();
424 for (var j = 0; j < cells_length; j++) {
425 if (j === i) {
426 if (this.cell_has_class(j, off_class) || !this.cell_has_class(j, on_class)) {
427 return false;
428 }
429 } else {
430 if (!this.cell_has_class(j, off_class) || this.cell_has_class(j, on_class)) {
431 return false;
432 }
433 }
434 }
435 return true;
436 };
437
438 this.cell_has_class = function(index, classes) {
439 return this.evaluate(function(i, c) {
440 var cell = IPython.notebook.get_cell(i);
441 if (cell) {
442 return cell.element.hasClass(c);
443 }
444 return false;
445 }, {i : index, c: classes});
446 };
447 });
343 });
@@ -233,6 +233,105 b' casper.cell_element_function = function(index, selector, function_name, function'
233 }, index, selector, function_name, function_args);
233 }, index, selector, function_name, function_args);
234 };
234 };
235
235
236
237 casper.select_cell = function(index) {
238 this.evaluate(function (i) {
239 IPython.notebook.select(i);
240 }, {i: index});
241 };
242
243 casper.click_cell_editor = function(index) {
244 // Code Mirror does not play nicely with emulated brower events.
245 // Instead of trying to emulate a click, here we run code similar to
246 // the code used in Code Mirror that handles the mousedown event on a
247 // region of codemirror that the user can focus.
248 this.evaluate(function (i) {
249 cm = IPython.notebook.get_cell(i).code_mirror;
250 if (cm.options.readOnly != "nocursor" && (document.activeElement != cm.display.input))
251 cm.display.input.focus();
252 }, {i: index});
253 };
254
255 casper.focus_notebook = function() {
256 this.evaluate(function (){
257 $('#notebook').focus();
258 }, {});
259 };
260
261 casper.trigger_keydown = function() {
262 for (var i = 0; i < arguments.length; i++) {
263 this.evaluate(function (k) {
264 IPython.keyboard.trigger_keydown(k);
265 }, {k: arguments[i]});
266 }
267 };
268
269 casper.get_keyboard_mode = function() {
270 return this.evaluate(function() {
271 return IPython.keyboard_manager.mode;
272 }, {});
273 };
274
275 casper.get_notebook_mode = function() {
276 return this.evaluate(function() {
277 return IPython.notebook.mode;
278 }, {});
279 };
280
281 casper.get_cell = function(index) {
282 return this.evaluate(function(i) {
283 var cell = IPython.notebook.get_cell(i);
284 if (cell) {
285 return cell;
286 }
287 return null;
288 }, {i : index});
289 };
290
291 casper.is_cell_editor_focused = function(index) {
292 return this.evaluate(function(i) {
293 var cell = IPython.notebook.get_cell(i);
294 if (cell) {
295 return $(cell.code_mirror.getInputField()).is('.CodeMirror-focused *');
296 }
297 return false;
298 }, {i : index});
299 };
300
301 casper.is_only_cell_selected = function(index) {
302 return this.is_only_cell_on(index, 'selected', 'unselected');
303 };
304
305 casper.is_only_cell_edit = function(index) {
306 return this.is_only_cell_on(index, 'edit_mode', 'command_mode');
307 };
308
309 casper.is_only_cell_on = function(i, on_class, off_class) {
310 var cells_length = this.get_cells_length();
311 for (var j = 0; j < cells_length; j++) {
312 if (j === i) {
313 if (this.cell_has_class(j, off_class) || !this.cell_has_class(j, on_class)) {
314 return false;
315 }
316 } else {
317 if (!this.cell_has_class(j, off_class) || this.cell_has_class(j, on_class)) {
318 return false;
319 }
320 }
321 }
322 return true;
323 };
324
325 casper.cell_has_class = function(index, classes) {
326 return this.evaluate(function(i, c) {
327 var cell = IPython.notebook.get_cell(i);
328 if (cell) {
329 return cell.element.hasClass(c);
330 }
331 return false;
332 }, {i : index, c: classes});
333 };
334
236 // Wrap a notebook test to reduce boilerplate.
335 // Wrap a notebook test to reduce boilerplate.
237 casper.notebook_test = function(test) {
336 casper.notebook_test = function(test) {
238 this.open_new_notebook();
337 this.open_new_notebook();
General Comments 0
You need to be logged in to leave comments. Login now