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:
parent
96bdda13ca
commit
8d8798a673
3 changed files with 40 additions and 6 deletions
|
@ -1438,7 +1438,7 @@ function getSquireInstance ( doc ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Squire ( doc ) {
|
function Squire ( doc, config ) {
|
||||||
var win = doc.defaultView;
|
var win = doc.defaultView;
|
||||||
var body = doc.body;
|
var body = doc.body;
|
||||||
var mutation;
|
var mutation;
|
||||||
|
@ -1504,6 +1504,9 @@ function Squire ( doc ) {
|
||||||
// Add key handlers
|
// Add key handlers
|
||||||
this._keyHandlers = Object.create( keyHandlers );
|
this._keyHandlers = Object.create( keyHandlers );
|
||||||
|
|
||||||
|
// Override default properties
|
||||||
|
this.initConfig( config );
|
||||||
|
|
||||||
// Fix IE<10's buggy implementation of Text#splitText.
|
// 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
|
// 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 ''.
|
// node into the document, and sets its value to undefined rather than ''.
|
||||||
|
@ -1534,7 +1537,6 @@ function Squire ( doc ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
body.setAttribute( 'contenteditable', 'true' );
|
body.setAttribute( 'contenteditable', 'true' );
|
||||||
this.setHTML( '' );
|
|
||||||
|
|
||||||
// Remove Firefox's built-in controls
|
// Remove Firefox's built-in controls
|
||||||
try {
|
try {
|
||||||
|
@ -1543,10 +1545,25 @@ function Squire ( doc ) {
|
||||||
} catch ( error ) {}
|
} catch ( error ) {}
|
||||||
|
|
||||||
instances.push( this );
|
instances.push( this );
|
||||||
|
|
||||||
|
// For fixCursor would query instance by doc first,
|
||||||
|
// we initialize HTML after instance saved
|
||||||
|
this.setHTML( '' );
|
||||||
}
|
}
|
||||||
|
|
||||||
var proto = Squire.prototype;
|
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 ) {
|
proto.createElement = function ( tag, props, children ) {
|
||||||
return createElement( this._doc, tag, props, children );
|
return createElement( this._doc, tag, props, children );
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -14,7 +14,7 @@ function getSquireInstance ( doc ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Squire ( doc ) {
|
function Squire ( doc, config ) {
|
||||||
var win = doc.defaultView;
|
var win = doc.defaultView;
|
||||||
var body = doc.body;
|
var body = doc.body;
|
||||||
var mutation;
|
var mutation;
|
||||||
|
@ -80,6 +80,9 @@ function Squire ( doc ) {
|
||||||
// Add key handlers
|
// Add key handlers
|
||||||
this._keyHandlers = Object.create( keyHandlers );
|
this._keyHandlers = Object.create( keyHandlers );
|
||||||
|
|
||||||
|
// Override default properties
|
||||||
|
this.initConfig( config );
|
||||||
|
|
||||||
// Fix IE<10's buggy implementation of Text#splitText.
|
// 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
|
// 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 ''.
|
// node into the document, and sets its value to undefined rather than ''.
|
||||||
|
@ -110,7 +113,6 @@ function Squire ( doc ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
body.setAttribute( 'contenteditable', 'true' );
|
body.setAttribute( 'contenteditable', 'true' );
|
||||||
this.setHTML( '' );
|
|
||||||
|
|
||||||
// Remove Firefox's built-in controls
|
// Remove Firefox's built-in controls
|
||||||
try {
|
try {
|
||||||
|
@ -119,10 +121,25 @@ function Squire ( doc ) {
|
||||||
} catch ( error ) {}
|
} catch ( error ) {}
|
||||||
|
|
||||||
instances.push( this );
|
instances.push( this );
|
||||||
|
|
||||||
|
// For fixCursor would query instance by doc first,
|
||||||
|
// we initialize HTML after instance saved
|
||||||
|
this.setHTML( '' );
|
||||||
}
|
}
|
||||||
|
|
||||||
var proto = Squire.prototype;
|
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 ) {
|
proto.createElement = function ( tag, props, children ) {
|
||||||
return createElement( this._doc, tag, props, children );
|
return createElement( this._doc, tag, props, children );
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue