123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- goog.provide('goog.editor.Plugin');
- goog.require('goog.events.EventTarget');
- goog.require('goog.functions');
- goog.require('goog.log');
- goog.require('goog.object');
- goog.require('goog.reflect');
- goog.require('goog.userAgent');
- goog.editor.Plugin = function() {
- goog.events.EventTarget.call(this);
-
- this.enabled_ = this.activeOnUneditableFields();
-
- this.fieldObject = null;
-
- this.autoDispose_ = true;
-
- this.logger = goog.log.getLogger('goog.editor.Plugin');
- };
- goog.inherits(goog.editor.Plugin, goog.events.EventTarget);
- goog.editor.Plugin.prototype.getFieldDomHelper = function() {
- return this.getFieldObject() && this.getFieldObject().getEditableDomHelper();
- };
- goog.editor.Plugin.prototype.getFieldObject = function() {
- return this.fieldObject;
- };
- goog.editor.Plugin.prototype.setFieldObject = function(fieldObject) {
- this.fieldObject = fieldObject;
- };
- goog.editor.Plugin.prototype.registerFieldObject = function(fieldObject) {
- this.setFieldObject(fieldObject);
- };
- goog.editor.Plugin.prototype.unregisterFieldObject = function(fieldObj) {
- if (this.getFieldObject()) {
- this.disable(this.getFieldObject());
- this.setFieldObject(null);
- }
- };
- goog.editor.Plugin.prototype.enable = function(fieldObject) {
- if (this.getFieldObject() == fieldObject) {
- this.enabled_ = true;
- } else {
- goog.log.error(
- this.logger, 'Trying to enable an unregistered field with ' +
- 'this plugin.');
- }
- };
- goog.editor.Plugin.prototype.disable = function(fieldObject) {
- if (this.getFieldObject() == fieldObject) {
- this.enabled_ = false;
- } else {
- goog.log.error(
- this.logger, 'Trying to disable an unregistered field ' +
- 'with this plugin.');
- }
- };
- goog.editor.Plugin.prototype.isEnabled = function(fieldObject) {
- return this.getFieldObject() == fieldObject ? this.enabled_ : false;
- };
- goog.editor.Plugin.prototype.setAutoDispose = function(autoDispose) {
- this.autoDispose_ = autoDispose;
- };
- goog.editor.Plugin.prototype.isAutoDispose = function() {
- return this.autoDispose_;
- };
- goog.editor.Plugin.prototype.activeOnUneditableFields = goog.functions.FALSE;
- goog.editor.Plugin.prototype.isSilentCommand = goog.functions.FALSE;
- goog.editor.Plugin.prototype.disposeInternal = function() {
- if (this.getFieldObject()) {
- this.unregisterFieldObject(this.getFieldObject());
- }
- goog.editor.Plugin.superClass_.disposeInternal.call(this);
- };
- goog.editor.Plugin.prototype.getTrogClassId;
- goog.editor.Plugin.Op = {
- KEYDOWN: 1,
- KEYPRESS: 2,
- KEYUP: 3,
- SELECTION: 4,
- SHORTCUT: 5,
- EXEC_COMMAND: 6,
- QUERY_COMMAND: 7,
- PREPARE_CONTENTS_HTML: 8,
- CLEAN_CONTENTS_HTML: 10,
- CLEAN_CONTENTS_DOM: 11
- };
- goog.editor.Plugin.OPCODE =
- goog.object.transpose(goog.reflect.object(goog.editor.Plugin, {
- handleKeyDown: goog.editor.Plugin.Op.KEYDOWN,
- handleKeyPress: goog.editor.Plugin.Op.KEYPRESS,
- handleKeyUp: goog.editor.Plugin.Op.KEYUP,
- handleSelectionChange: goog.editor.Plugin.Op.SELECTION,
- handleKeyboardShortcut: goog.editor.Plugin.Op.SHORTCUT,
- execCommand: goog.editor.Plugin.Op.EXEC_COMMAND,
- queryCommandValue: goog.editor.Plugin.Op.QUERY_COMMAND,
- prepareContentsHtml: goog.editor.Plugin.Op.PREPARE_CONTENTS_HTML,
- cleanContentsHtml: goog.editor.Plugin.Op.CLEAN_CONTENTS_HTML,
- cleanContentsDom: goog.editor.Plugin.Op.CLEAN_CONTENTS_DOM
- }));
- goog.editor.Plugin.IRREPRESSIBLE_OPS = goog.object.createSet(
- goog.editor.Plugin.Op.PREPARE_CONTENTS_HTML,
- goog.editor.Plugin.Op.CLEAN_CONTENTS_HTML,
- goog.editor.Plugin.Op.CLEAN_CONTENTS_DOM);
- goog.editor.Plugin.prototype.handleKeyDown;
- goog.editor.Plugin.prototype.handleKeyPress;
- goog.editor.Plugin.prototype.handleKeyUp;
- goog.editor.Plugin.prototype.handleSelectionChange;
- goog.editor.Plugin.prototype.handleKeyboardShortcut;
- goog.editor.Plugin.prototype.execCommand = function(command, var_args) {
-
-
- var silent = this.isSilentCommand(command);
- if (!silent) {
-
-
-
-
-
-
- if (goog.userAgent.GECKO) {
- this.getFieldObject().stopChangeEvents(true, true);
- }
- this.getFieldObject().dispatchBeforeChange();
- }
- try {
- var result = this.execCommandInternal.apply(this, arguments);
- } finally {
-
-
-
-
-
- if (!silent) {
-
-
- this.getFieldObject().dispatchChange();
- this.getFieldObject().dispatchSelectionChangeEvent();
- }
- }
- return result;
- };
- goog.editor.Plugin.prototype.execCommandInternal;
- goog.editor.Plugin.prototype.queryCommandValue;
- goog.editor.Plugin.prototype.prepareContentsHtml;
- goog.editor.Plugin.prototype.cleanContentsDom;
- goog.editor.Plugin.prototype.cleanContentsHtml;
- goog.editor.Plugin.prototype.isSupportedCommand = function(command) {
- return false;
- };
- goog.editor.Plugin.prototype.saveScrollPosition = function() {
- if (this.getFieldObject() && goog.userAgent.EDGE) {
- var win = this.getFieldObject().getEditableDomHelper().getWindow();
- return win.scrollTo.bind(win, win.scrollX, win.scrollY);
- }
- return function() {};
- };
|