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