/** * 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