0
Fork 0
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:
Neil Jenkins 2014-06-02 10:22:52 +10:00
parent aa9afdfaf6
commit f0bd5138e1
3 changed files with 28 additions and 12 deletions

View file

@ -1214,6 +1214,8 @@ function Squire ( doc ) {
this._undoStackLength = 0;
this._isInUndoState = false;
this.defaultBlockProperties = undefined;
this.addEventListener( 'keyup', this._docWasChanged );
// 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 );
};
proto.createDefaultBlock = function ( children ) {
return fixCursor(
this.createElement( 'DIV', this.defaultBlockProperties, children )
);
};
proto.didError = function ( error ) {
console.log( error );
};
@ -2062,7 +2070,7 @@ var decreaseBlockQuoteLevel = function ( frag ) {
};
var removeBlockQuote = function (/* frag */) {
return fixCursor( this.createElement( 'div', [
return this.createDefaultBlock([
this.createElement( 'INPUT', {
id: startSelectionId,
type: 'hidden'
@ -2071,7 +2079,7 @@ var removeBlockQuote = function (/* frag */) {
id: endSelectionId,
type: 'hidden'
})
]) );
]);
};
var makeList = function ( self, frag, type ) {
@ -2772,7 +2780,7 @@ if ( isIE8 ) {
var firstChild = this._body.firstChild;
if ( firstChild.nodeName === 'P' ) {
this._saveRangeToBookmark( this.getSelection() );
replaceWith( firstChild, this.createElement( 'DIV', [
replaceWith( firstChild, this.createDefaultBlock([
empty( firstChild )
]));
this.setSelection( this._getRangeAndRemoveBookmark() );
@ -3274,7 +3282,7 @@ proto.insertElement = function ( el, range ) {
} else {
body.appendChild( el );
// Insert blank line below block.
body.appendChild( fixCursor( this.createElement( 'div' ) ) );
body.appendChild( this.createDefaultBlock() );
range.setStart( el, 0 );
range.setEnd( el, 0 );
}

File diff suppressed because one or more lines are too long

View file

@ -101,6 +101,8 @@ function Squire ( doc ) {
this._undoStackLength = 0;
this._isInUndoState = false;
this.defaultBlockProperties = undefined;
this.addEventListener( 'keyup', this._docWasChanged );
// 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 );
};
proto.createDefaultBlock = function ( children ) {
return fixCursor(
this.createElement( 'DIV', this.defaultBlockProperties, children )
);
};
proto.didError = function ( error ) {
console.log( error );
};
@ -949,7 +957,7 @@ var decreaseBlockQuoteLevel = function ( frag ) {
};
var removeBlockQuote = function (/* frag */) {
return fixCursor( this.createElement( 'div', [
return this.createDefaultBlock([
this.createElement( 'INPUT', {
id: startSelectionId,
type: 'hidden'
@ -958,7 +966,7 @@ var removeBlockQuote = function (/* frag */) {
id: endSelectionId,
type: 'hidden'
})
]) );
]);
};
var makeList = function ( self, frag, type ) {
@ -1659,7 +1667,7 @@ if ( isIE8 ) {
var firstChild = this._body.firstChild;
if ( firstChild.nodeName === 'P' ) {
this._saveRangeToBookmark( this.getSelection() );
replaceWith( firstChild, this.createElement( 'DIV', [
replaceWith( firstChild, this.createDefaultBlock([
empty( firstChild )
]));
this.setSelection( this._getRangeAndRemoveBookmark() );
@ -2161,7 +2169,7 @@ proto.insertElement = function ( el, range ) {
} else {
body.appendChild( el );
// Insert blank line below block.
body.appendChild( fixCursor( this.createElement( 'div' ) ) );
body.appendChild( this.createDefaultBlock() );
range.setStart( el, 0 );
range.setEnd( el, 0 );
}