mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 13:16:31 -05:00
override default properties by config
This commit is contained in:
parent
22408056bb
commit
21326b9fd1
1 changed files with 14 additions and 36 deletions
26
Demo.html
26
Demo.html
|
@ -60,7 +60,7 @@
|
||||||
<span id="increaseListLevel">Increase list level</span>
|
<span id="increaseListLevel">Increase list level</span>
|
||||||
<span id="decreaseListLevel">Decrease list level</span>
|
<span id="decreaseListLevel">Decrease list level</span>
|
||||||
|
|
||||||
<span id="insertImage" class="prompt" value="https://pbs.twimg.com/profile_images/508277159681478656/hC9WIBpC_normal.jpeg">Insert image</span>
|
<span id="insertImage" class="prompt">Insert image</span>
|
||||||
<span id="setHTML" class="prompt">Set HTML</span>
|
<span id="setHTML" class="prompt">Set HTML</span>
|
||||||
|
|
||||||
<span id="undo">Undo</span>
|
<span id="undo">Undo</span>
|
||||||
|
@ -112,60 +112,38 @@
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="build/squire-raw.js"></script>
|
<script type="text/javascript" src="build/squire-raw.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
var Squire = window.Squire;
|
|
||||||
var editor;
|
var editor;
|
||||||
var iframe = document.createElement( 'iframe' );
|
var iframe = document.createElement( 'iframe' );
|
||||||
iframe.addEventListener( 'load', function () {
|
iframe.addEventListener( 'load', function () {
|
||||||
// Make sure we're in standards mode.
|
// Make sure we're in standards mode.
|
||||||
var doc = iframe.contentDocument;
|
var doc = iframe.contentDocument;
|
||||||
|
|
||||||
if ( doc.compatMode !== 'CSS1Compat' ) {
|
if ( doc.compatMode !== 'CSS1Compat' ) {
|
||||||
doc.open();
|
doc.open();
|
||||||
doc.write( '<!DOCTYPE html><title></title>' );
|
doc.write( '<!DOCTYPE html><title></title>' );
|
||||||
doc.close();
|
doc.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// doc.close() can cause a re-entrant load event in some browsers,
|
// doc.close() can cause a re-entrant load event in some browsers,
|
||||||
// such as IE9.
|
// such as IE9.
|
||||||
if ( editor ) {
|
if ( editor ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Squire instance
|
// Create Squire instance
|
||||||
editor = new Squire( doc, {
|
editor = new Squire( doc, {
|
||||||
defaultBlockTag: 'P'
|
defaultBlockTag: 'P'
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Add styles to frame
|
// Add styles to frame
|
||||||
var style = doc.createElement( 'style' );
|
var style = doc.createElement( 'style' );
|
||||||
style.type = 'text/css';
|
style.type = 'text/css';
|
||||||
style.textContent = document.getElementById( 'editorStyles' ).textContent;
|
style.textContent = document.getElementById( 'editorStyles' ).textContent;
|
||||||
doc.querySelector( 'head' ).appendChild( style );
|
doc.querySelector( 'head' ).appendChild( style );
|
||||||
|
|
||||||
// plugins
|
|
||||||
editor.addEventListener('mousedown', function(e) {
|
|
||||||
if (e.target.nodeName === 'IMG') {
|
|
||||||
this.selectNode(e.target);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
editor.addEventListener('select', function(e) {
|
|
||||||
console.log(this.getSelectedNode() || this.getSelectedText());
|
|
||||||
});
|
|
||||||
editor.addEventListener('mouseup', function(e) {
|
|
||||||
console.log(this.getPath(),
|
|
||||||
this.getSelectedNode(),
|
|
||||||
this.getSelectedText());
|
|
||||||
});
|
|
||||||
}, false );
|
}, false );
|
||||||
|
|
||||||
document.body.appendChild( iframe );
|
document.body.appendChild( iframe );
|
||||||
|
|
||||||
document.addEventListener( 'click', function ( e ) {
|
document.addEventListener( 'click', function ( e ) {
|
||||||
var id = e.target.id,
|
var id = e.target.id,
|
||||||
value;
|
value;
|
||||||
if ( id && editor && editor[ id ] ) {
|
if ( id && editor && editor[ id ] ) {
|
||||||
if ( e.target.className === 'prompt' ) {
|
if ( e.target.className === 'prompt' ) {
|
||||||
value = prompt( 'Value:', e.target.getAttribute('value') );
|
value = prompt( 'Value:' );
|
||||||
}
|
}
|
||||||
editor[ id ]( value );
|
editor[ id ]( value );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue