1 // Copyright (C) 2010-2017 Yozons, Inc. 2 // CKEditor for Vaadin - Widget linkage for using CKEditor within a Vaadin application. 3 // 4 // This software is released under the Apache License 2.0 <http://www.apache.org/licenses/LICENSE-2.0.html> 5 // 6 package org.vaadin.openesignforms.ckeditor.widgetset.client.ui; 7 8 import com.google.gwt.core.client.JavaScriptObject; 9 10 /** 11 * Wrapper around CKEDITOR.editor js object 12 */ 13 public class CKEditor extends JavaScriptObject { 14 15 protected CKEditor() { 16 } 17 18 public final native boolean checkDirty() 19 /*-{ 20 return this.checkDirty(); 21 }-*/; 22 23 public final native void resetDirty() 24 /*-{ 25 this.resetDirty(); 26 }-*/; 27 28 public final native String getData() 29 /*-{ 30 return this.getData(); 31 }-*/; 32 33 public final native void setData(String htmlData) 34 /*-{ 35 return this.setData(htmlData); 36 }-*/; 37 38 public final native boolean isReadOnly() 39 /*-{ 40 return this.readOnly; 41 }-*/; 42 43 public final native void setReadOnly(boolean isReadOnly) 44 /*-{ 45 this.setReadOnly(isReadOnly); 46 }-*/; 47 48 public final native void setWriterRules(String tagName, String jsRule) 49 /*-{ 50 var rule = @org.vaadin.openesignforms.ckeditor.widgetset.client.ui.CKEditorService::convertJavaScriptStringToObject(Ljava/lang/String;)(jsRule); 51 this.dataProcessor.writer.setRules(tagName, rule); 52 }-*/; 53 54 public final native void setKeystroke(int keystroke, String command) 55 /*-{ 56 this.setKeystroke(keystroke, command); 57 }-*/; 58 59 public final native void pushProtectedSource(String regexString) 60 /*-{ 61 var regex = @org.vaadin.openesignforms.ckeditor.widgetset.client.ui.CKEditorService::convertJavaScriptStringToObject(Ljava/lang/String;)(regexString); 62 this.config.protectedSource.push( regex ); 63 }-*/; 64 65 public final native void setWriterIndentationChars(String indentationChars) 66 /*-{ 67 this.dataProcessor.writer.indentationChars = indentationChars; 68 }-*/; 69 70 public final native void instanceReady(CKEditorService.CKEditorListener listener) 71 /*-{ 72 // The 'listener' passed to us is used as 'listenerData' for the callback. 73 this.on( 'blur', function( ev ) { 74 ev.listenerData.@org.vaadin.openesignforms.ckeditor.widgetset.client.ui.CKEditorService.CKEditorListener::onBlur()(); 75 }, null, listener); 76 77 this.on( 'focus', function( ev ) { 78 ev.listenerData.@org.vaadin.openesignforms.ckeditor.widgetset.client.ui.CKEditorService.CKEditorListener::onFocus()(); 79 }, null, listener); 80 81 this.on( 'vaadinsave', function( ev ) { 82 ev.listenerData.@org.vaadin.openesignforms.ckeditor.widgetset.client.ui.CKEditorService.CKEditorListener::onSave()(); 83 }, null, listener); 84 85 // hook into the change events for ckEditor 86 this.on('change', function(ev) { 87 ev.listenerData.@org.vaadin.openesignforms.ckeditor.widgetset.client.ui.CKEditorService.CKEditorListener::onChange()(); 88 }, null, listener); 89 90 this.on('selectionChange', function(ev) { 91 ev.listenerData.@org.vaadin.openesignforms.ckeditor.widgetset.client.ui.CKEditorService.CKEditorListener::onSelectionChange()(); 92 }, null, listener); 93 this.on('contentDom', function(ev) { 94 this.document.on('keyup', function(ev2) { 95 ev2.listenerData.@org.vaadin.openesignforms.ckeditor.widgetset.client.ui.CKEditorService.CKEditorListener::onSelectionChange()(); 96 }, null, ev.listenerData); 97 this.document.on('mouseup', function(ev2) { 98 ev2.listenerData.@org.vaadin.openesignforms.ckeditor.widgetset.client.ui.CKEditorService.CKEditorListener::onSelectionChange()(); 99 }, null, ev.listenerData); 100 }, null, listener); 101 102 this.on('mode', function(ev) { 103 ev.listenerData.@org.vaadin.openesignforms.ckeditor.widgetset.client.ui.CKEditorService.CKEditorListener::onModeChange(Ljava/lang/String;)(ev.editor.mode); 104 }, null, listener); 105 this.on('dataReady', function(ev) { 106 ev.listenerData.@org.vaadin.openesignforms.ckeditor.widgetset.client.ui.CKEditorService.CKEditorListener::onDataReady()(); 107 }, null, listener); 108 109 }-*/; 110 111 public final native void execCommand(String cmd) 112 /*-{ 113 this.execCommand(cmd); 114 }-*/; 115 116 public final native void updateElement() 117 /*-{ 118 this.updateElement(); 119 }-*/; 120 121 public final native void destroy(boolean noUpdate) 122 /*-{ 123 this.destroy(noUpdate); 124 }-*/; 125 126 public final native void destroy() 127 /*-{ 128 this.destroy(); 129 }-*/; 130 131 public final native void resize(int width, int height) 132 /*-{ 133 this.resize(width, height); 134 }-*/; 135 136 public final native String getId() 137 /*-{ 138 return this.id; 139 }-*/; 140 141 public final native void focus() 142 /*-{ 143 this.focus(); 144 }-*/; 145 146 public final native int getTabIndex() 147 /*-{ 148 return this.tabIndex; 149 }-*/; 150 151 public final native void setTabIndex(int tabIndex) 152 /*-{ 153 this.tabIndex = tabIndex; 154 }-*/; 155 156 public final native void insertHtml(String data) 157 /*-{ 158 this.insertHtml(data); 159 }-*/; 160 161 public final native void insertText(String data) 162 /*-{ 163 this.insertText(data); 164 }-*/; 165 166 public final native void protectBody(boolean protectBody) 167 /*-{ 168 if (this.document) { 169 if (this.document.getBody()) { 170 this.document.getBody().$.contentEditable = !this.readOnly && !protectBody; 171 } 172 } 173 }-*/; 174 175 public final native String getSelectedHtml() 176 /*-{ 177 return this.getSelectedHtml(true); 178 }-*/; 179 180 }