-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modal UI #3605
Modal UI #3605
Changes from 52 commits
7d0f415
a11c3df
2dd3d63
b2c174f
0e882fd
fef08d9
b0aa243
9ba9496
acac37b
acf3710
0135ad2
7fc210d
1283ebb
b51276b
71eb69b
ef87614
e25c9e4
619528c
d5e4ce5
0f4213e
aeffe3b
6481cb5
89eac9e
d6a3ec7
c4fda88
9d44616
bfc1794
c2b3a2b
e228b93
20c436e
5233b21
bdb4c53
cc09699
ad1a6ed
f1ffb2b
0d3e611
0202e66
54b48d9
627a797
538a39b
33dd5d6
ab3a1dd
9448c01
dd345f4
ff51227
b696039
6996d42
3088dda
a8751bb
dca69cb
5b066a2
2259a24
3be8af8
6573c62
ab7fc46
66589e1
a6562f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ var IPython = (function (IPython) { | |
this.placeholder = options.placeholder || ''; | ||
this.read_only = options.cm_config.readOnly; | ||
this.selected = false; | ||
this.rendered = false; | ||
this.mode = 'command'; | ||
this.metadata = {}; | ||
// load this from metadata later ? | ||
this.user_highlight = 'auto'; | ||
|
@@ -60,6 +62,7 @@ var IPython = (function (IPython) { | |
if (this.element !== null) { | ||
this.element.data("cell", this); | ||
this.bind_events(); | ||
this.init_classes(); | ||
} | ||
}; | ||
|
||
|
@@ -97,6 +100,26 @@ var IPython = (function (IPython) { | |
Cell.prototype.create_element = function () { | ||
}; | ||
|
||
Cell.prototype.init_classes = function () { | ||
// Call after this.element exists to initialize the css classes | ||
// related to selected, rendered and mode. | ||
if (this.selected) { | ||
this.element.addClass('selected'); | ||
} else { | ||
this.element.addClass('unselected'); | ||
} | ||
if (this.rendered) { | ||
this.element.addClass('rendered'); | ||
} else { | ||
this.element.addClass('unrendered'); | ||
} | ||
if (this.mode === 'edit') { | ||
this.element.addClass('edit_mode'); | ||
} else { | ||
this.element.addClass('command_mode'); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. semicolon |
||
|
||
|
||
/** | ||
* Subclasses can implement override bind_events. | ||
|
@@ -108,67 +131,167 @@ var IPython = (function (IPython) { | |
var that = this; | ||
// We trigger events so that Cell doesn't have to depend on Notebook. | ||
that.element.click(function (event) { | ||
if (that.selected === false) { | ||
if (!that.selected) { | ||
$([IPython.events]).trigger('select.Cell', {'cell':that}); | ||
} | ||
}; | ||
}); | ||
that.element.focusin(function (event) { | ||
if (that.selected === false) { | ||
if (!that.selected) { | ||
$([IPython.events]).trigger('select.Cell', {'cell':that}); | ||
} | ||
}; | ||
}); | ||
if (this.code_mirror) { | ||
this.code_mirror.on("change", function(cm, change) { | ||
$([IPython.events]).trigger("set_dirty.Notebook", {value: true}); | ||
}); | ||
} | ||
if (this.code_mirror) { | ||
this.code_mirror.on('focus', function(cm, change) { | ||
$([IPython.events]).trigger('edit_mode.Cell', {cell: that}); | ||
}); | ||
} | ||
if (this.code_mirror) { | ||
this.code_mirror.on('blur', function(cm, change) { | ||
if (that.mode === 'edit') { | ||
setTimeout(function () { | ||
var isf = IPython.utils.is_focused; | ||
var trigger = true; | ||
if (isf('div#tooltip') || isf('div.completions')) { | ||
trigger = false; | ||
} | ||
if (trigger) { | ||
$([IPython.events]).trigger('command_mode.Cell', {cell: that}); | ||
} | ||
}, 1); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* Triger typsetting of math by mathjax on current cell element | ||
* @method typeset | ||
*/ | ||
Cell.prototype.typeset = function () { | ||
if (window.MathJax){ | ||
if (window.MathJax) { | ||
var cell_math = this.element.get(0); | ||
MathJax.Hub.Queue(["Typeset", MathJax.Hub, cell_math]); | ||
} | ||
}; | ||
|
||
/** | ||
* should be triggerd when cell is selected | ||
* handle cell level logic when a cell is selected | ||
* @method select | ||
* @return is the action being taken | ||
*/ | ||
Cell.prototype.select = function () { | ||
this.element.addClass('selected'); | ||
this.selected = true; | ||
if (!this.selected) { | ||
this.element.addClass('selected'); | ||
this.element.removeClass('unselected'); | ||
this.selected = true; | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* should be triggerd when cell is unselected | ||
* handle cell level logic when a cell is unselected | ||
* @method unselect | ||
* @return is the action being taken | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this statement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you actually have "@return is the action being taken" in lots of places. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's like an event handler, return true if an action is taken, false if nothing happend |
||
*/ | ||
Cell.prototype.unselect = function () { | ||
this.element.removeClass('selected'); | ||
this.selected = false; | ||
if (this.selected) { | ||
this.element.addClass('unselected'); | ||
this.element.removeClass('selected'); | ||
this.selected = false; | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
/** | ||
* should be overritten by subclass | ||
* @method get_text | ||
* handle cell level logic when a cell is rendered | ||
* @method render | ||
* @return is the action being taken | ||
*/ | ||
Cell.prototype.get_text = function () { | ||
Cell.prototype.render = function () { | ||
if (!this.rendered) { | ||
this.element.addClass('rendered'); | ||
this.element.removeClass('unrendered'); | ||
this.rendered = true; | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
/** | ||
* should be overritten by subclass | ||
* @method set_text | ||
* @param {string} text | ||
* handle cell level logic when a cell is unrendered | ||
* @method unrender | ||
* @return is the action being taken | ||
*/ | ||
Cell.prototype.set_text = function (text) { | ||
Cell.prototype.unrender = function () { | ||
if (this.rendered) { | ||
this.element.addClass('unrendered'); | ||
this.element.removeClass('rendered'); | ||
this.rendered = false; | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
/** | ||
* enter the command mode for the cell | ||
* @method command_mode | ||
* @return is the action being taken | ||
*/ | ||
Cell.prototype.command_mode = function () { | ||
if (this.mode !== 'command') { | ||
this.element.addClass('command_mode'); | ||
this.element.removeClass('edit_mode'); | ||
this.mode = 'command'; | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
/** | ||
* enter the edit mode for the cell | ||
* @method command_mode | ||
* @return is the action being taken | ||
*/ | ||
Cell.prototype.edit_mode = function () { | ||
if (this.mode !== 'edit') { | ||
this.element.addClass('edit_mode'); | ||
this.element.removeClass('command_mode'); | ||
this.mode = 'edit'; | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Focus the cell in the DOM sense | ||
* @method focus_cell | ||
*/ | ||
Cell.prototype.focus_cell = function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the |
||
this.element.focus(); | ||
} | ||
|
||
/** | ||
* Focus the editor area so a user can type | ||
* @method focus_editor | ||
*/ | ||
Cell.prototype.focus_editor = function () { | ||
this.refresh(); | ||
this.code_mirror.focus(); | ||
} | ||
|
||
/** | ||
* Refresh codemirror instance | ||
* @method refresh | ||
|
@@ -177,20 +300,19 @@ var IPython = (function (IPython) { | |
this.code_mirror.refresh(); | ||
}; | ||
|
||
|
||
/** | ||
* should be overritten by subclass | ||
* @method edit | ||
**/ | ||
Cell.prototype.edit = function () { | ||
* @method get_text | ||
*/ | ||
Cell.prototype.get_text = function () { | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty method., but I guess you know that. |
||
|
||
|
||
/** | ||
* should be overritten by subclass | ||
* @method render | ||
**/ | ||
Cell.prototype.render = function () { | ||
* @method set_text | ||
* @param {string} text | ||
*/ | ||
Cell.prototype.set_text = function (text) { | ||
}; | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see indentation with tabs here while trying to resolve conflict to test the branch.