0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

Add argument to getHTML to include bookmark.

* Selection is then automatically restored when HTML containing a bookmark is
  set.
This commit is contained in:
Neil Jenkins 2012-11-21 12:35:50 +11:00
parent fe6ffb0ed5
commit 8ccc9fad06
2 changed files with 14 additions and 7 deletions

File diff suppressed because one or more lines are too long

View file

@ -301,8 +301,8 @@
var indexOf = Array.prototype.indexOf;
var startSelectionId = 'ss-' + Date.now() + '-' + Math.random();
var endSelectionId = 'es-' + Date.now() + '-' + Math.random();
var startSelectionId = 'squire-selection-start';
var endSelectionId = 'squire-selection-end';
var saveRangeToBookmark = function ( range ) {
var startNode = createElement( 'INPUT', {
@ -374,7 +374,7 @@
range.collapse( true );
}
}
return range;
return range || null;
};
// --- Undo ---
@ -1705,9 +1705,12 @@
return this;
},
getHTML: function () {
getHTML: function ( withBookMark ) {
var brs = [],
node, fixer, html, l;
node, fixer, html, l, range;
if ( withBookMark && ( range = getSelection() ) ) {
saveRangeToBookmark( range );
}
if ( useTextFixer ) {
node = body;
while ( node = node.getNextBlock() ) {
@ -1725,6 +1728,9 @@
brs[l].detach();
}
}
if ( range ) {
getRangeAndRemoveBookmark( range );
}
return html;
},
setHTML: function ( html ) {
@ -1763,7 +1769,8 @@
isInUndoState = false;
// Record undo state
var range = createRange( body.firstChild, 0 );
var range = getRangeAndRemoveBookmark() ||
createRange( body.firstChild, 0 );
recordUndoState( range );
getRangeAndRemoveBookmark( range );
// IE will also set focus when selecting text so don't use