Skip to content

Instantly share code, notes, and snippets.

@exhuma
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exhuma/37fc60ecece83adab3e3 to your computer and use it in GitHub Desktop.
Save exhuma/37fc60ecece83adab3e3 to your computer and use it in GitHub Desktop.
Closure RTE as part of a larger Component.

README

This example shows the use of a richtext-editor component as part of another, larger component.

The Problem

While the component shows up properly, the rendered IFRAME does not take up the full width of the editor. A wild guess is that the IFRAME is rendered before the width is available.

Any idea how to fix this?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip="">
<head>
<meta charset="UTF-8" />
<title>Test</title>
<style type="text/css" media="screen">
@import "/static/css/goog.css";
@import "/static/css/goog/common.css";
@import "/static/css/goog/button.css";
@import "/static/css/goog/dialog.css";
@import "/static/css/goog/linkbutton.css";
@import "/static/css/goog/menu.css";
@import "/static/css/goog/menuitem.css";
@import "/static/css/goog/menuseparator.css";
@import "/static/css/goog/tab.css";
@import "/static/css/goog/tabbar.css";
@import "/static/css/goog/toolbar.css";
@import "/static/css/goog/colormenubutton.css";
@import "/static/css/goog/palette.css";
@import "/static/css/goog/colorpalette.css";
@import "/static/css/goog/editor/bubble.css";
@import "/static/css/goog/editor/dialog.css";
@import "/static/css/goog/editor/linkdialog.css";
@import "/static/css/goog/editortoolbar.css";
@import "/static/css/style.css";
BODY, HTML {
margin: 2em;
background: #ffffff;
}
#editor {
width: 600px;
height: 300px;
background-color: white;
border: 1px solid grey;
}
</style>
<script type="text/javascript" src="http://localhost:9810/compile?id=prod"></script>
</head>
<body>
Test Page<br />
<div id="editor"></div>
<div id="output"></div>
<script type="text/javascript" charset="utf-8">
var obj = new eurinfo.widgets.RichText();
obj.render(goog.dom.getElement('editor'));
</script>
</body>
</html>
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 :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment