0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-03 05:00:13 -05:00

add parameter for override default properties; initialize editor document now run after instance saved.

This commit is contained in:
crossjs 2015-05-05 20:28:30 +08:00
parent 96bdda13ca
commit 8d8798a673
3 changed files with 40 additions and 6 deletions

View file

@ -1438,7 +1438,7 @@ function getSquireInstance ( doc ) {
return null;
}
function Squire ( doc ) {
function Squire ( doc, config ) {
var win = doc.defaultView;
var body = doc.body;
var mutation;
@ -1504,6 +1504,9 @@ function Squire ( doc ) {
// Add key handlers
this._keyHandlers = Object.create( keyHandlers );
// Override default properties
this.initConfig( config );
// Fix IE<10's buggy implementation of Text#splitText.
// If the split is at the end of the node, it doesn't insert the newly split
// node into the document, and sets its value to undefined rather than ''.
@ -1534,7 +1537,6 @@ function Squire ( doc ) {
}
body.setAttribute( 'contenteditable', 'true' );
this.setHTML( '' );
// Remove Firefox's built-in controls
try {
@ -1543,10 +1545,25 @@ function Squire ( doc ) {
} catch ( error ) {}
instances.push( this );
// For fixCursor would query instance by doc first,
// we initialize HTML after instance saved
this.setHTML( '' );
}
var proto = Squire.prototype;
proto.initConfig = function ( config ) {
var prop;
if (config) {
for ( prop in config ) {
if ( config.hasOwnProperty(prop) ) {
this[prop] = config[prop];
}
}
}
};
proto.createElement = function ( tag, props, children ) {
return createElement( this._doc, tag, props, children );
};

File diff suppressed because one or more lines are too long

View file

@ -14,7 +14,7 @@ function getSquireInstance ( doc ) {
return null;
}
function Squire ( doc ) {
function Squire ( doc, config ) {
var win = doc.defaultView;
var body = doc.body;
var mutation;
@ -80,6 +80,9 @@ function Squire ( doc ) {
// Add key handlers
this._keyHandlers = Object.create( keyHandlers );
// Override default properties
this.initConfig( config );
// Fix IE<10's buggy implementation of Text#splitText.
// If the split is at the end of the node, it doesn't insert the newly split
// node into the document, and sets its value to undefined rather than ''.
@ -110,7 +113,6 @@ function Squire ( doc ) {
}
body.setAttribute( 'contenteditable', 'true' );
this.setHTML( '' );
// Remove Firefox's built-in controls
try {
@ -119,10 +121,25 @@ function Squire ( doc ) {
} catch ( error ) {}
instances.push( this );
// For fixCursor would query instance by doc first,
// we initialize HTML after instance saved
this.setHTML( '' );
}
var proto = Squire.prototype;
proto.initConfig = function ( config ) {
var prop;
if (config) {
for ( prop in config ) {
if ( config.hasOwnProperty(prop) ) {
this[prop] = config[prop];
}
}
}
};
proto.createElement = function ( tag, props, children ) {
return createElement( this._doc, tag, props, children );
};