diff --git a/polymer-quill.html b/polymer-quill.html index 3918b67..fdf2a16 100644 --- a/polymer-quill.html +++ b/polymer-quill.html @@ -1,4 +1,3 @@ - @@ -86,22 +85,21 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e --calculated-polymer-quill-editor-overflow: var(--polymer-quill-editor-overflow, scroll); display: block; @apply(--polymer-quill); - } + }; #editor { max-height: var(--calculated-polymer-quill-editor-max-height); min-height: var(--calculated-polymer-quill-editor-min-height); overflow: var(--calculated-polymer-quill-editor-overflow); border: var(--calculated-polymer-quill-editor-border); - } + }; .results { padding: 20px 10px; overflow-x: scroll; - } + }; .disabled { border: 1px solid #ccc !important; opacity: 0.85; - } - + };
@@ -220,7 +218,6 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e storeAs: { type: String, value: 'delta', - notify: true, }, /** * Save Interval in milliseconds. @@ -229,7 +226,6 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e saveInterval: { type: Number, value: 2000, - notify: true, }, /** * Delay load of content in milliseconds. @@ -239,7 +235,6 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e delay: { type: Number, value: 10, - notify: true, }, /** * Show Results below editor of saves in Delta or HMTL format. @@ -248,7 +243,6 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e showResults: { type: Boolean, value: false, - notify: true, }, /** * Show Results below editor of saves in HMTL format. @@ -257,7 +251,6 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e showHtml: { type: Boolean, value: false, - notify: true, }, /** * Editor toolbar type. @@ -266,7 +259,6 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e toolbarType: { type: String, value: 'standard', - notify: true, }, /** * Standard Tool @@ -275,7 +267,6 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e standardToolbar: { type: Boolean, value: true, - notify: true, }, /** * Enable tracks if editing is enabled. @@ -284,7 +275,6 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e enable: { type: String, value: 'true', - notify: true, }, /** * Whether to instantiate the editor to read-only mode. @@ -293,7 +283,6 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e readOnly: { type: Boolean, value: false, - notify: true, }, /** * Disable Class title. @@ -310,7 +299,6 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e useContentReset: { type: Boolean, value: false, - notify: true, }, /** * Placeholder for empty editor. @@ -319,7 +307,6 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e placeholder: { type: String, value: 'Compose an epic...', - notify: true, } }, @@ -400,10 +387,12 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e } } change = change.compose(delta); - }.bind(this)); - - // Save periodically - setInterval(function() { + }.bind(this)) + + var typingTimer + var saveInterval = this.saveInterval + var source = "api" + var savePeriodically = function() { if (change.length() > 0) { if (this.showResults) { console.log('Saving changes', change); @@ -416,11 +405,23 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e this.html = this.quill.root.innerHTML; // Fire custom event change - this.fire('change', {delta: change, change: JSON.stringify(change), content: this.content, html: this.html, entireDelta: this.quill.getContents()}); - change = new Delta(); + if (source == "user") { + this.fire('change', {delta: change, change: JSON.stringify(change), content: this.content, html: this.html, entireDelta: this.quill.getContents()}) + } else { + this.fire('update', {delta: change, change: JSON.stringify(change), content: this.content, html: this.html, entireDelta: this.quill.getContents()}) + } + change = new Delta() + } else if (this.content !== JSON.stringify(this.quill.getContents()) && this.content !== this.quill.getContents()) { // Allow changes from the Two-way data binding system + this.resetContent(this.content) } - }.bind(this), this.saveInterval); - + clearTimeout(typingTimer) + typingTimer = setTimeout(savePeriodically, saveInterval) + }.bind(this) + this.quill.on('text-change', function(delta, oldDelta, theSource) { + source = theSource + clearTimeout(typingTimer) + typingTimer = setTimeout(savePeriodically, saveInterval) + }) // Check for unsaved data window.onbeforeunload = function() { if (change.length() > 0) { @@ -463,7 +464,11 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e var notset = true; if (this.content && this.content.length > 1 && this.content != undefined && this.content !="

undefined

" ) { if (this.storeAs === 'delta') { - this.quill.setContents(JSON.parse(this.content),'api'); + if (Array.isArray(this.content)) { + this.quill.setContents(this.content,'api'); + } else { + this.quill.setContents(JSON.parse(this.content),'api'); + } } else { // HTML this.quill.root.innerHTML = this.content; } @@ -510,14 +515,20 @@

Standard Toolbar, Hide Results, Default height (100px), Save as HTML, Save e resetContent: function(content){ // Set content this.async(function() { + var range = this.quill.getSelection() if (this.storeAs === 'delta') { - if (this.content.length > 1) { + if (Array.isArray(this.content)) { + this.quill.setContents(this.content,'api') + } else if (this.content.length > 1) { this.quill.setContents(JSON.parse(this.content),'api'); } } else { // HTML this.quill.root.innerHTML = this.content; } - this.html = this.quill.root.innerHTML; + this.html = this.quill.root.innerHTML + if (range !== null ) { + this.quill.setSelection(range) + } },this.delay); },