mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Add support for defaultBlockProperties.
Set the defaultBlockProperties property on a squire instance to an object and it will use these properties when it has to create a new default block element.
This commit is contained in:
parent
aa9afdfaf6
commit
f0bd5138e1
3 changed files with 28 additions and 12 deletions
|
@ -1214,6 +1214,8 @@ function Squire ( doc ) {
|
||||||
this._undoStackLength = 0;
|
this._undoStackLength = 0;
|
||||||
this._isInUndoState = false;
|
this._isInUndoState = false;
|
||||||
|
|
||||||
|
this.defaultBlockProperties = undefined;
|
||||||
|
|
||||||
this.addEventListener( 'keyup', this._docWasChanged );
|
this.addEventListener( 'keyup', this._docWasChanged );
|
||||||
|
|
||||||
// IE sometimes fires the beforepaste event twice; make sure it is not run
|
// IE sometimes fires the beforepaste event twice; make sure it is not run
|
||||||
|
@ -1269,6 +1271,12 @@ proto.createElement = function ( tag, props, children ) {
|
||||||
return createElement( this._doc, tag, props, children );
|
return createElement( this._doc, tag, props, children );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
proto.createDefaultBlock = function ( children ) {
|
||||||
|
return fixCursor(
|
||||||
|
this.createElement( 'DIV', this.defaultBlockProperties, children )
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
proto.didError = function ( error ) {
|
proto.didError = function ( error ) {
|
||||||
console.log( error );
|
console.log( error );
|
||||||
};
|
};
|
||||||
|
@ -2062,7 +2070,7 @@ var decreaseBlockQuoteLevel = function ( frag ) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var removeBlockQuote = function (/* frag */) {
|
var removeBlockQuote = function (/* frag */) {
|
||||||
return fixCursor( this.createElement( 'div', [
|
return this.createDefaultBlock([
|
||||||
this.createElement( 'INPUT', {
|
this.createElement( 'INPUT', {
|
||||||
id: startSelectionId,
|
id: startSelectionId,
|
||||||
type: 'hidden'
|
type: 'hidden'
|
||||||
|
@ -2071,7 +2079,7 @@ var removeBlockQuote = function (/* frag */) {
|
||||||
id: endSelectionId,
|
id: endSelectionId,
|
||||||
type: 'hidden'
|
type: 'hidden'
|
||||||
})
|
})
|
||||||
]) );
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
var makeList = function ( self, frag, type ) {
|
var makeList = function ( self, frag, type ) {
|
||||||
|
@ -2772,9 +2780,9 @@ if ( isIE8 ) {
|
||||||
var firstChild = this._body.firstChild;
|
var firstChild = this._body.firstChild;
|
||||||
if ( firstChild.nodeName === 'P' ) {
|
if ( firstChild.nodeName === 'P' ) {
|
||||||
this._saveRangeToBookmark( this.getSelection() );
|
this._saveRangeToBookmark( this.getSelection() );
|
||||||
replaceWith( firstChild, this.createElement( 'DIV', [
|
replaceWith( firstChild, this.createDefaultBlock([
|
||||||
empty( firstChild )
|
empty( firstChild )
|
||||||
]) );
|
]));
|
||||||
this.setSelection( this._getRangeAndRemoveBookmark() );
|
this.setSelection( this._getRangeAndRemoveBookmark() );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -3274,7 +3282,7 @@ proto.insertElement = function ( el, range ) {
|
||||||
} else {
|
} else {
|
||||||
body.appendChild( el );
|
body.appendChild( el );
|
||||||
// Insert blank line below block.
|
// Insert blank line below block.
|
||||||
body.appendChild( fixCursor( this.createElement( 'div' ) ) );
|
body.appendChild( this.createDefaultBlock() );
|
||||||
range.setStart( el, 0 );
|
range.setStart( el, 0 );
|
||||||
range.setEnd( el, 0 );
|
range.setEnd( el, 0 );
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -101,6 +101,8 @@ function Squire ( doc ) {
|
||||||
this._undoStackLength = 0;
|
this._undoStackLength = 0;
|
||||||
this._isInUndoState = false;
|
this._isInUndoState = false;
|
||||||
|
|
||||||
|
this.defaultBlockProperties = undefined;
|
||||||
|
|
||||||
this.addEventListener( 'keyup', this._docWasChanged );
|
this.addEventListener( 'keyup', this._docWasChanged );
|
||||||
|
|
||||||
// IE sometimes fires the beforepaste event twice; make sure it is not run
|
// IE sometimes fires the beforepaste event twice; make sure it is not run
|
||||||
|
@ -156,6 +158,12 @@ proto.createElement = function ( tag, props, children ) {
|
||||||
return createElement( this._doc, tag, props, children );
|
return createElement( this._doc, tag, props, children );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
proto.createDefaultBlock = function ( children ) {
|
||||||
|
return fixCursor(
|
||||||
|
this.createElement( 'DIV', this.defaultBlockProperties, children )
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
proto.didError = function ( error ) {
|
proto.didError = function ( error ) {
|
||||||
console.log( error );
|
console.log( error );
|
||||||
};
|
};
|
||||||
|
@ -949,7 +957,7 @@ var decreaseBlockQuoteLevel = function ( frag ) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var removeBlockQuote = function (/* frag */) {
|
var removeBlockQuote = function (/* frag */) {
|
||||||
return fixCursor( this.createElement( 'div', [
|
return this.createDefaultBlock([
|
||||||
this.createElement( 'INPUT', {
|
this.createElement( 'INPUT', {
|
||||||
id: startSelectionId,
|
id: startSelectionId,
|
||||||
type: 'hidden'
|
type: 'hidden'
|
||||||
|
@ -958,7 +966,7 @@ var removeBlockQuote = function (/* frag */) {
|
||||||
id: endSelectionId,
|
id: endSelectionId,
|
||||||
type: 'hidden'
|
type: 'hidden'
|
||||||
})
|
})
|
||||||
]) );
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
var makeList = function ( self, frag, type ) {
|
var makeList = function ( self, frag, type ) {
|
||||||
|
@ -1659,9 +1667,9 @@ if ( isIE8 ) {
|
||||||
var firstChild = this._body.firstChild;
|
var firstChild = this._body.firstChild;
|
||||||
if ( firstChild.nodeName === 'P' ) {
|
if ( firstChild.nodeName === 'P' ) {
|
||||||
this._saveRangeToBookmark( this.getSelection() );
|
this._saveRangeToBookmark( this.getSelection() );
|
||||||
replaceWith( firstChild, this.createElement( 'DIV', [
|
replaceWith( firstChild, this.createDefaultBlock([
|
||||||
empty( firstChild )
|
empty( firstChild )
|
||||||
]) );
|
]));
|
||||||
this.setSelection( this._getRangeAndRemoveBookmark() );
|
this.setSelection( this._getRangeAndRemoveBookmark() );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2161,7 +2169,7 @@ proto.insertElement = function ( el, range ) {
|
||||||
} else {
|
} else {
|
||||||
body.appendChild( el );
|
body.appendChild( el );
|
||||||
// Insert blank line below block.
|
// Insert blank line below block.
|
||||||
body.appendChild( fixCursor( this.createElement( 'div' ) ) );
|
body.appendChild( this.createDefaultBlock() );
|
||||||
range.setStart( el, 0 );
|
range.setStart( el, 0 );
|
||||||
range.setEnd( el, 0 );
|
range.setEnd( el, 0 );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue