|
goog.provide('eurinfo.widgets.RichText'); |
|
|
|
goog.require('goog.editor.Command'); |
|
goog.require('goog.editor.Field'); |
|
goog.require('goog.editor.plugins.BasicTextFormatter'); |
|
goog.require('goog.ui.Component'); |
|
goog.require('goog.ui.editor.DefaultToolbar'); |
|
goog.require('goog.ui.editor.ToolbarController'); |
|
|
|
/** |
|
* @constructor |
|
* @extends {goog.ui.Component} |
|
*/ |
|
eurinfo.widgets.RichText = function() { |
|
goog.base(this); |
|
|
|
/** @private */ |
|
this.editorId_ = 'rte-editor'; |
|
|
|
/** @private */ |
|
this.toolBarEl_ = this.dom_.createDom('div'); |
|
|
|
/** @private */ |
|
this.editorEl_ = this.dom_.createDom('div', {'id' : this.editorId_}); |
|
|
|
/** |
|
* @type {goog.editor.Field?} |
|
* @private |
|
*/ |
|
this.field_ = null; |
|
|
|
}; |
|
goog.inherits(eurinfo.widgets.RichText, goog.ui.Component); |
|
|
|
|
|
/** |
|
* @public |
|
* @return {string} |
|
*/ |
|
eurinfo.widgets.RichText.prototype.getContent = function() { |
|
return this.field_.getCleanContents(); |
|
}; |
|
|
|
|
|
/** |
|
* @inheritDoc |
|
*/ |
|
eurinfo.widgets.RichText.prototype.createDom = function() { |
|
this.decorateInternal(this.dom_.createElement('div')); |
|
}; |
|
|
|
|
|
/** |
|
* @inheritDoc |
|
*/ |
|
eurinfo.widgets.RichText.prototype.decorateInternal = function(element) { |
|
element.appendChild(this.toolBarEl_); |
|
element.appendChild(this.editorEl_); |
|
this.setElementInternal(element); |
|
}; |
|
|
|
/** @inheritDoc */ |
|
eurinfo.widgets.RichText.prototype.enterDocument = function() { |
|
goog.base(this, 'enterDocument'); |
|
|
|
this.field_ = new goog.editor.Field(this.editorId_); |
|
|
|
// Register a plugin |
|
this.field_.registerPlugin(new goog.editor.plugins.BasicTextFormatter()); |
|
|
|
// Add some buttons to the tool bar |
|
var buttons = [ |
|
goog.editor.Command.BOLD, |
|
goog.editor.Command.ITALIC, |
|
goog.editor.Command.UNDERLINE, |
|
]; |
|
|
|
var myToolbar = goog.ui.editor.DefaultToolbar.makeToolbar(buttons, |
|
this.toolBarEl_); |
|
|
|
// Handle events from toolbar |
|
new goog.ui.editor.ToolbarController(this.field_, myToolbar); |
|
|
|
// Make the editor usable |
|
this.field_.makeEditable(); |
|
}; |
|
|
|
// vim: set ft=closure.javascript : |