0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

override default properties by config

This commit is contained in:
crossjs 2015-05-05 18:47:33 +08:00
parent 22408056bb
commit 21326b9fd1

View file

@ -52,19 +52,19 @@
<span id="makeLink" class="prompt">Link</span>
</p>
<p>
<span id="increaseQuoteLevel">Quote</span>
<span id="decreaseQuoteLevel">Dequote</span>
<span id="increaseQuoteLevel">Quote</span>
<span id="decreaseQuoteLevel">Dequote</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span id="makeUnorderedList">List</span>
<span id="removeList">Unlist</span>
<span id="increaseListLevel">Increase list level</span>
<span id="decreaseListLevel">Decrease list level</span>
<span id="makeUnorderedList">List</span>
<span id="removeList">Unlist</span>
<span id="increaseListLevel">Increase list level</span>
<span id="decreaseListLevel">Decrease list level</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span id="undo">Undo</span>
<span id="redo">Redo</span>
<span id="undo">Undo</span>
<span id="redo">Redo</span>
</p>
</header>
<script type="text/template" id="editorStyles">
@ -112,60 +112,38 @@
</script>
<script type="text/javascript" src="build/squire-raw.js"></script>
<script type="text/javascript" charset="utf-8">
var Squire = window.Squire;
var editor;
var iframe = document.createElement( 'iframe' );
iframe.addEventListener( 'load', function () {
// Make sure we're in standards mode.
var doc = iframe.contentDocument;
if ( doc.compatMode !== 'CSS1Compat' ) {
doc.open();
doc.write( '<!DOCTYPE html><title></title>' );
doc.close();
doc.open();
doc.write( '<!DOCTYPE html><title></title>' );
doc.close();
}
// doc.close() can cause a re-entrant load event in some browsers,
// such as IE9.
if ( editor ) {
return;
return;
}
// Create Squire instance
editor = new Squire( doc, {
defaultBlockTag: 'P'
} );
// Add styles to frame
var style = doc.createElement( 'style' );
style.type = 'text/css';
style.textContent = document.getElementById( 'editorStyles' ).textContent;
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 );
document.body.appendChild( iframe );
document.addEventListener( 'click', function ( e ) {
var id = e.target.id,
value;
if ( id && editor && editor[ id ] ) {
if ( e.target.className === 'prompt' ) {
value = prompt( 'Value:', e.target.getAttribute('value') );
value = prompt( 'Value:' );
}
editor[ id ]( value );
}