to a ) and keeps its childs
*
- * @param {Object} parent Instance of main wysihtml5.Editor class
- * @param {Element} view Instance of wysihtml5.views.* class
- * @param {String} placeholderText
+ * @author Christopher Blum
+ * @param {Element} element The list element which should be renamed
+ * @param {Element} newNodeName The desired tag name
*
* @example
- * wysihtml.utils.simulatePlaceholder(this, composer, "Foobar");
- */
-wysihtml5.utils.simulatePlaceholder = function(parent, view, placeholderText) {
- var unset = function() {
- if (view.hasPlaceholderSet()) {
- view.clear();
- }
- Element.removeClassName(view.element, "placeholder");
- },
- set = function() {
- if (view.isEmpty()) {
- view.setValue(placeholderText);
- Element.addClassName(view.element, "placeholder");
- }
- };
-
- parent
- .observe("set_placeholder", set)
- .observe("unset_placeholder", unset)
- .observe("focus:composer", unset)
- .observe("paste:composer", unset)
- .observe("blur:composer", set);
-
- set();
-};/**
- * Class that takes care that the value of the composer and the textarea is always in sync
+ *
+ *
+ * - eminem
+ * - dr. dre
+ * - 50 Cent
+ *
+ *
+ *
+ *
+ *
+ *
+ * - eminem
+ * - dr. dre
+ * - 50 Cent
+ *
*/
-wysihtml5.utils.Synchronizer = Class.create(
- /** @scope wysihtml5.utils.Synchronizer.prototype */ {
- INTERVAL: 400,
-
- initialize: function(parent, textarea, composer) {
- this.parent = parent;
- this.textarea = textarea;
- this.composer = composer;
-
- this._observe();
- },
-
- /**
- * Sync html from composer to textarea
- * Takes care of placeholders
- * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the textarea
- */
- fromComposerToTextarea: function(shouldParseHtml) {
- this.textarea.setValue(this._trim(this.composer.getValue()), shouldParseHtml);
- },
-
- /**
- * Sync value of textarea to composer
- * Takes care of placeholders
- * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer
- */
- fromTextareaToComposer: function(shouldParseHtml) {
- var textareaValue = this.textarea.getValue();
- if (textareaValue) {
- this.composer.setValue(textareaValue, shouldParseHtml);
- } else {
- this.composer.clear();
- this.parent.fire("set_placeholder");
- }
- },
-
- /**
- * Invoke syncing based on view state
- * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer/textarea
- */
- sync: function(shouldParseHtml) {
- if (this.parent.currentView.name == "textarea") {
- this.fromTextareaToComposer(shouldParseHtml);
- } else {
- this.fromComposerToTextarea(shouldParseHtml);
- }
- },
-
- /**
- * Initializes interval-based syncing
- * also makes sure that on-submit the composer's content is synced with the textarea
- * immediately when the form gets submitted
- */
- _observe: function() {
- var interval,
- form = this.textarea.element.up("form"),
- startInterval = function() {
- interval = setInterval(function() { this.fromComposerToTextarea(); }.bind(this), this.INTERVAL);
- }.bind(this),
- stopInterval = function() {
- clearInterval(interval);
- interval = null;
- };
-
- startInterval();
-
- if (form) {
- // If the textarea is in a form make sure that after onreset and onsubmit the composer
- // has the correct state
- form.observe("submit", function() { this.sync(true); }.bind(this));
- form.observe("reset", function() { this.fromTextareaToComposer.bind(this).defer(); }.bind(this));
- }
-
- this.parent.observe("change_view", function(event) {
- var view = event.memo;
- if (view == "composer" && !interval) {
- this.fromTextareaToComposer(true);
- startInterval();
- } else if (view == "textarea") {
- this.fromComposerToTextarea(true);
- stopInterval();
- }
- }.bind(this));
-
- this.parent.observe("destroy:composer", stopInterval);
- },
-
- /**
- * Normalizes white space in the beginning and end
- * This: " foo " will become: " foo "
- */
- _trim: (function() {
- var WHITE_SPACE_START = /^\s+/,
- WHITE_SPACE_END = /\s+$/;
- return function(str) {
- return str.replace(WHITE_SPACE_START, " ").replace(WHITE_SPACE_END, " ");
- };
- })()
-});if ("textContent" in document.documentElement) {
- wysihtml5.utils.setTextContent = function(element, text) {
- element.textContent = text;
- };
-
- wysihtml5.utils.getTextContent = function(element) {
- return element.textContent;
- };
-} else if ("innerText" in document.documentElement) {
- wysihtml5.utils.setTextContent = function(element, text) {
- element.innerText = text;
- };
-
- wysihtml5.utils.getTextContent = function(element) {
- return element.innerText;
- };
-} else {
- wysihtml5.utils.setTextContent = function(element, text) {
- element.nodeValue = text;
- };
-
- wysihtml5.utils.getTextContent = function(element) {
- return element.nodeValue;
- };
-}
-/**
+wysihtml5.dom.renameElement = function(element, newNodeName) {
+ var newElement = element.ownerDocument.createElement(newNodeName),
+ firstChild;
+ while (firstChild = element.firstChild) {
+ newElement.appendChild(firstChild);
+ }
+ wysihtml5.dom.copyAttributes(["align", "className"]).from(element).to(newElement);
+ element.parentNode.replaceChild(newElement, element);
+ return newElement;
+};/**
* Takes an element, removes it and replaces it with it's childs
*
* @author Christopher Blum
@@ -5842,10 +4895,10 @@ wysihtml5.utils.Synchronizer = Class.create(
*