/*! * Aloha Editor * Author & Copyright (c) 2012-2013 Gentics Software GmbH * aloha-sales@gentics.com * Licensed unter the terms of http://www.aloha-editor.com/license.html * * @overview * Utility functions for content handling. */ define(['jquery'], function ($) { 'use strict'; /** * Checks whether the markup describes a paragraph that is propped by * a
tag but is otherwise empty. * * Will return true for: * *


* * as well as: * *


* * @param {string} html Markup * @return {boolean} True if html describes a propped paragraph. */ function isProppedParagraph(html) { var trimmed = $.trim(html); if (!trimmed) { return false; } var node = $('
' + trimmed + '
')[0]; var containsSingleP = node.firstChild === node.lastChild && 'p' === node.firstChild.nodeName.toLowerCase(); if (containsSingleP) { var kids = node.firstChild.children; return (kids && 1 === kids.length && 'br' === kids[0].nodeName.toLowerCase()); } return false; } function wrapContent(content) { if (typeof content === 'string') { return $('
' + content + '
'); } if (content instanceof $) { return $('
').append(content); } return null; } return { wrapContent: wrapContent, isProppedParagraph: isProppedParagraph }; });