/**
* Toolbar Dialog
*
* @param {Element} link The toolbar link which causes the dialog to show up
* @param {Element} container The dialog container
*
* @example
*
* insert an image
*
*
*
*
*
*
*
*
*/
(function(wysihtml) {
var dom = wysihtml.dom,
CLASS_NAME_OPENED = "wysihtml-command-dialog-opened",
SELECTOR_FORM_ELEMENTS = "input, select, textarea",
SELECTOR_FIELDS = "[data-wysihtml-dialog-field]",
ATTRIBUTE_FIELDS = "data-wysihtml-dialog-field";
wysihtml.toolbar.Dialog = wysihtml.lang.Dispatcher.extend(
/** @scope wysihtml.toolbar.Dialog.prototype */ {
constructor: function(link, container) {
this.link = link;
this.container = container;
},
_observe: function() {
if (this._observed) {
return;
}
var that = this,
callbackWrapper = function(event) {
var attributes = that._serialize();
that.fire("save", attributes);
that.hide();
event.preventDefault();
event.stopPropagation();
};
dom.observe(that.link, "click", function() {
if (dom.hasClass(that.link, CLASS_NAME_OPENED)) {
setTimeout(function() { that.hide(); }, 0);
}
});
dom.observe(this.container, "keydown", function(event) {
var keyCode = event.keyCode;
if (keyCode === wysihtml.ENTER_KEY) {
callbackWrapper(event);
}
if (keyCode === wysihtml.ESCAPE_KEY) {
that.cancel();
}
});
dom.delegate(this.container, "[data-wysihtml-dialog-action=save]", "click", callbackWrapper);
dom.delegate(this.container, "[data-wysihtml-dialog-action=cancel]", "click", function(event) {
that.cancel();
event.preventDefault();
event.stopPropagation();
});
this._observed = true;
},
/**
* Grabs all fields in the dialog and puts them in key=>value style in an object which
* then gets returned
*/
_serialize: function() {
var data = {},
fields = this.container.querySelectorAll(SELECTOR_FIELDS),
length = fields.length,
i = 0;
for (; ifoo
*
* and we have the following dialog:
*
*
*
* after calling _interpolate() the dialog will look like this
*
*
*
* Basically it adopted the attribute values into the corresponding input fields
*
*/
_interpolate: function(avoidHiddenFields) {
var field,
fieldName,
newValue,
focusedElement = document.querySelector(":focus"),
fields = this.container.querySelectorAll(SELECTOR_FIELDS),
length = fields.length,
i = 0;
for (; i= 11
*
* Note that it sends the recorded audio to the google speech recognition api:
* http://stackoverflow.com/questions/4361826/does-chrome-have-buil-in-speech-recognition-for-input-type-text-x-webkit-speec
*
* Current HTML5 draft can be found here
* http://lists.w3.org/Archives/Public/public-xg-htmlspeech/2011Feb/att-0020/api-draft.html
*
* "Accessing Google Speech API Chrome 11"
* http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
*/
(function(wysihtml) {
var dom = wysihtml.dom;
var linkStyles = {
position: "relative"
};
var wrapperStyles = {
left: 0,
margin: 0,
opacity: 0,
overflow: "hidden",
padding: 0,
position: "absolute",
top: 0,
zIndex: 1
};
var inputStyles = {
cursor: "inherit",
fontSize: "50px",
height: "50px",
marginTop: "-25px",
outline: 0,
padding: 0,
position: "absolute",
right: "-4px",
top: "50%"
};
var inputAttributes = {
"x-webkit-speech": "",
"speech": ""
};
wysihtml.toolbar.Speech = function(parent, link) {
var input = document.createElement("input");
if (!wysihtml.browser.supportsSpeechApiOn(input)) {
link.style.display = "none";
return;
}
var lang = parent.editor.textarea.element.getAttribute("lang");
if (lang) {
inputAttributes.lang = lang;
}
var wrapper = document.createElement("div");
wysihtml.lang.object(wrapperStyles).merge({
width: link.offsetWidth + "px",
height: link.offsetHeight + "px"
});
dom.insert(input).into(wrapper);
dom.insert(wrapper).into(link);
dom.setStyles(inputStyles).on(input);
dom.setAttributes(inputAttributes).on(input);
dom.setStyles(wrapperStyles).on(wrapper);
dom.setStyles(linkStyles).on(link);
var eventName = "onwebkitspeechchange" in input ? "webkitspeechchange" : "speechchange";
dom.observe(input, eventName, function() {
parent.execCommand("insertText", input.value);
input.value = "";
});
dom.observe(input, "click", function(event) {
if (dom.hasClass(link, "wysihtml-command-disabled")) {
event.preventDefault();
}
event.stopPropagation();
});
};
})(wysihtml);
/**
* Toolbar
*
* @param {Object} parent Reference to instance of Editor instance
* @param {Element} container Reference to the toolbar container element
*
* @example
*