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

Require <html data-squireinit="true"> to auto-instantiate.

Explicit opt-in to autoinstantiation (included in the default document.html)
means Squire may be loaded in sites that themselves are loaded in iframes,
without unexpected consequences.

Resolves #104.
This commit is contained in:
Neil Jenkins 2015-07-06 12:19:21 +07:00
parent 32d56823ce
commit 522a481dd3
6 changed files with 15 additions and 11 deletions

View file

@ -39,7 +39,9 @@ Installation and usage
Advanced usage Advanced usage
-------------- --------------
If you load the library into a top-level document (rather than an iframe), it will not turn the page into an editable document, but will instead add a function named `Squire` to the global scope. Call `new Squire( document )`, with the `document` from an iframe to instantiate multiple rich text areas on the same page efficiently. Note, for compatibility with all browsers (particularly Firefox), you MUST wait for the iframe's `onload` event to fire before instantiating Squire. If you load the library into a top-level document (rather than an iframe), or load it in an iframe without the `data-squireinit="true"` attribute on its `<html>` element, it will not turn the page into an editable document, but will instead add a constructor named `Squire` to the global scope.
Call `new Squire( document )`, with the `document` from an iframe to instantiate multiple rich text areas on the same page efficiently. Note, for compatibility with all browsers (particularly Firefox), you MUST wait for the iframe's `onload` event to fire before instantiating Squire.
### Setting the default block style ### Setting the default block style

View file

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en" data-squireinit="true">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

View file

@ -3854,14 +3854,15 @@ proto.decreaseListLevel = command( 'modifyBlocks', decreaseListLevel );
if ( typeof exports === 'object' ) { if ( typeof exports === 'object' ) {
module.exports = Squire; module.exports = Squire;
} else { } else {
if ( top !== win ) { win.Squire = Squire;
if ( top !== win &&
doc.documentElement.getAttribute( 'data-squireinit' ) === 'true' ) {
win.editor = new Squire( doc ); win.editor = new Squire( doc );
if ( win.onEditorLoad ) { if ( win.onEditorLoad ) {
win.onEditorLoad( win.editor ); win.onEditorLoad( win.editor );
win.onEditorLoad = null; win.onEditorLoad = null;
} }
} else {
win.Squire = Squire;
} }
} }

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en" data-squireinit="true">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

View file

@ -3,14 +3,15 @@
if ( typeof exports === 'object' ) { if ( typeof exports === 'object' ) {
module.exports = Squire; module.exports = Squire;
} else { } else {
if ( top !== win ) { win.Squire = Squire;
if ( top !== win &&
doc.documentElement.getAttribute( 'data-squireinit' ) === 'true' ) {
win.editor = new Squire( doc ); win.editor = new Squire( doc );
if ( win.onEditorLoad ) { if ( win.onEditorLoad ) {
win.onEditorLoad( win.editor ); win.onEditorLoad( win.editor );
win.onEditorLoad = null; win.onEditorLoad = null;
} }
} else {
win.Squire = Squire;
} }
} }