/* dom2.js is part of Aloha Editor project http://aloha-editor.org * * Aloha Editor is a WYSIWYG HTML5 inline editing library and editor. * Copyright (c) 2010-2012 Gentics Software GmbH, Vienna, Austria. * Contributors http://aloha-editor.org/contribution.php * * Aloha Editor is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * Aloha Editor is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * As an additional permission to the GNU GPL version 2, you may distribute * non-source (e.g., minimized or compacted) forms of the Aloha-Editor * source code without the copy of the GNU GPL normally required, * provided you include this license notice and a URL through which * recipients can access the Corresponding Source. */ define([ 'aloha/core', 'jquery', 'util/functions', 'util/maps', 'util/arrays', 'util/strings', 'util/browser', 'util/dom', 'util/range' ], function ( Aloha, $, Fn, Maps, Arrays, Strings, Browser, Dom1, RangeObject ) { 'use strict'; var spacesRx = /\s+/; var attrRegex = /\s([^\/<>\s=]+)(?:=(?:"[^"]*"|'[^']*'|[^>\/\s]+))?/g; /** * Like insertBefore, inserts firstChild into parent before * refChild, except also inserts all the following siblings of * firstChild. */ function moveNextAll(parent, firstChild, refChild) { while (firstChild) { var nextChild = firstChild.nextSibling; parent.insertBefore(firstChild, refChild); firstChild = nextChild; } } /** * Used to serialize outerHTML of DOM elements in older (pre-HTML5) Gecko, * Safari, and Opera browsers. * * Beware that XMLSerializer generates an XHTML string (
* instead of
). It is noted here: * http://stackoverflow.com/questions/1700870/how-do-i-do-outerhtml-in-firefox * that some browsers (like older versions of Firefox) have problems with * XMLSerializer, and an alternative, albeit more expensive option, is * described. * * @type {XMLSerializer|null} */ var Serializer = window.XMLSerializer && new window.XMLSerializer(); /** * Gets the serialized HTML that describes the given DOM element and its * innerHTML. * * Polyfill for older versions of Gecko, Safari, and Opera browsers. * @see https://bugzilla.mozilla.org/show_bug.cgi?id=92264 for background. * * @param {HTMLElement} node DOM Element. * @return {String} */ function outerHtml(node) { var html = node.outerHTML; if (typeof html !== 'undefined') { return html; } try { return Serializer ? Serializer.serializeToString(node) : node.xml; } catch (e) { return node.xml; } } /** * Retrieves the names of all attributes from the given elmenet. * * Correctly handles the case that IE7 and IE8 have approx 70-90 * default attributes on each and every element. * * This implementation does not iterate over the elem.attributes * property since that is much slower on IE7 (even when * checking the attrNode.specified property). Instead it parses the * HTML of the element. For elements with few attributes the * performance on IE7 is improved by an order of magnitued. * * On IE7, when you clone a