ipython/ipython — pull request #6354 by Carreau (2014-08-24 10:46:08+00:00)
Title: load the per kernel custom.js

Work in progress.

Try to load the custom.js from kernel spec when switching kernels in the notebook.
Does not do it at load time as IIUC, @takluyver implementation load the kernelspec directly from metadata.
which would need a bit more refactor.

from a design point of view the per kernel custom.js **may** define 2 methods `patch` and `unpatch` that are respectively called when switching to/away from the kernel.

The arguments the `patch` function takes is still to be defined.
I'm leaning toward having the first argument of `unpatch` being something returned by `patch`.
Indeed as module are dynamically loaded by require it is hard to have a stateful object returned by require.

I would them propose something along the following.

`patch` get as arguments the current version of IPython as well as a handle to instances of (.. notebook? IPython? to complete ..).
Handles to IPython javascript modules could be accessed by defining them as dependencies of your `custom.js`. The `patch` get called when the user decide to switch to your kernel, and can return an object that will be passed to `unpatch` method

`custom.js` should also define an `unpatch`method that takes as first argument the object returned by `patch` and is responsible to restore any modification done by `patch`.

this would lead to custom.js looking like :
```
define(['base/js/tooltip'],{
patch: function(){
console.log('patch from bash');
var param = {tooltip_orig_foo:Tooltip.foo}
Tooltip.foo = 'xzt'
return param
},
unpatch: function(orig){
console.log('unpatch from bash')
Tooltip.foo = orig.tooltip_orig_foo
}
});
```