$(function(){
+function setEndOfContenteditable(contentEditableElement)
+{
+ var range,selection;
+ if(document.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
+ {
+ range = document.createRange();//Create a range (a range is a like the selection but invisible)
+ range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
+ range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
+ selection = window.getSelection();//get the selection object (allows you to change selection)
+ selection.removeAllRanges();//remove any selections already made
+ selection.addRange(range);//make the range you have just created the visible selection
+ }
+ else if(document.selection)//IE 8 and lower
+ {
+ range = document.body.createTextRange();//Create a range (a range is a like the selection but invisible)
+ range.moveToElementText(contentEditableElement);//Select the entire contents of the element with the range
+ range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
+ range.select();//Select the range (make it the visible selection
+ }
+}
+
+/**
+ * @depend ../library/cursorToEnd.js
+ */
+
+
var TodoView = Backbone.View.extend({
tagName: 'div',
className: 'todo',
if (!options.atEnd) {
this.$el.find("> .text").focus();
} else {
- this.$el.find("> .text").focus();
- this.$el.find("> .text").val(this.$el.find("> .text"));
+ setEndOfContenteditable(this.$el.find("> .text")[0]);
}
return this;
},
if (this.model.hasChildren()) {
return;
}
- // TODO: Focus end of previous node
var previousNode = this.model.previousNode(this.model.collection);
if (!previousNode) {
return;
// - If there are children, make the new node the first child. Focus the second node.
// NOTE: Copy-paste is overridden so there can't be more than one line break.
// NOTE: Shift-enter is overridden and handled seperately, to allow "notes" spanning multiple lines.
+ // NOTE: Line break on empty bullet should shift it up the tree for perfect imitation; this is stupid so I ignored it.
} else if ((lines.length === 2 && lines[1].length === 0) || (lines.length === 3 && lines[1].length === 0 && lines[2].length === 0)) { // Line break at end
this.model.setText(this.decodeText(lines[0]));
+function setEndOfContenteditable(contentEditableElement)
+{
+ var range,selection;
+ if(document.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
+ {
+ range = document.createRange();//Create a range (a range is a like the selection but invisible)
+ range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
+ range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
+ selection = window.getSelection();//get the selection object (allows you to change selection)
+ selection.removeAllRanges();//remove any selections already made
+ selection.addRange(range);//make the range you have just created the visible selection
+ }
+ else if(document.selection)//IE 8 and lower
+ {
+ range = document.body.createTextRange();//Create a range (a range is a like the selection but invisible)
+ range.moveToElementText(contentEditableElement);//Select the entire contents of the element with the range
+ range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
+ range.select();//Select the range (make it the visible selection
+ }
+}
+
+/**
+ * @depend ../library/cursorToEnd.js
+ */
+
+
var TodoView = Backbone.View.extend({
tagName: 'div',
className: 'todo',
if (!options.atEnd) {
this.$el.find("> .text").focus();
} else {
- this.$el.find("> .text").focus();
- this.$el.find("> .text").val(this.$el.find("> .text"));
+ setEndOfContenteditable(this.$el.find("> .text")[0]);
}
return this;
},
if (this.model.hasChildren()) {
return;
}
- // TODO: Focus end of previous node
var previousNode = this.model.previousNode(this.model.collection);
if (!previousNode) {
return;
// - If there are children, make the new node the first child. Focus the second node.
// NOTE: Copy-paste is overridden so there can't be more than one line break.
// NOTE: Shift-enter is overridden and handled seperately, to allow "notes" spanning multiple lines.
+ // NOTE: Line break on empty bullet should shift it up the tree for perfect imitation; this is stupid so I ignored it.
} else if ((lines.length === 2 && lines[1].length === 0) || (lines.length === 3 && lines[1].length === 0 && lines[2].length === 0)) { // Line break at end
this.model.setText(this.decodeText(lines[0]));
--- /dev/null
+function setEndOfContenteditable(contentEditableElement)
+{
+ var range,selection;
+ if(document.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
+ {
+ range = document.createRange();//Create a range (a range is a like the selection but invisible)
+ range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
+ range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
+ selection = window.getSelection();//get the selection object (allows you to change selection)
+ selection.removeAllRanges();//remove any selections already made
+ selection.addRange(range);//make the range you have just created the visible selection
+ }
+ else if(document.selection)//IE 8 and lower
+ {
+ range = document.body.createTextRange();//Create a range (a range is a like the selection but invisible)
+ range.moveToElementText(contentEditableElement);//Select the entire contents of the element with the range
+ range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
+ range.select();//Select the range (make it the visible selection
+ }
+}
+/**
+ * @depend ../library/cursorToEnd.js
+ */
+
+
var TodoView = Backbone.View.extend({
tagName: 'div',
className: 'todo',
if (!options.atEnd) {
this.$el.find("> .text").focus();
} else {
- this.$el.find("> .text").focus();
- this.$el.find("> .text").val(this.$el.find("> .text"));
+ setEndOfContenteditable(this.$el.find("> .text")[0]);
}
return this;
},
if (this.model.hasChildren()) {
return;
}
- // TODO: Focus end of previous node
var previousNode = this.model.previousNode(this.model.collection);
if (!previousNode) {
return;
// - If there are children, make the new node the first child. Focus the second node.
// NOTE: Copy-paste is overridden so there can't be more than one line break.
// NOTE: Shift-enter is overridden and handled seperately, to allow "notes" spanning multiple lines.
+ // NOTE: Line break on empty bullet should shift it up the tree for perfect imitation; this is stupid so I ignored it.
} else if ((lines.length === 2 && lines[1].length === 0) || (lines.length === 3 && lines[1].length === 0 && lines[2].length === 0)) { // Line break at end
this.model.setText(this.decodeText(lines[0]));