define("morph",
["./morph/morph","./morph/dom-helper","exports"],
function(__dependency1__, __dependency2__, __exports__) {
"use strict";
var Morph = __dependency1__["default"];
var Morph;
__exports__.Morph = Morph;
var DOMHelper = __dependency2__["default"];
var DOMHelper;
__exports__.DOMHelper = DOMHelper;
});
define("morph/dom-helper",
["../morph/morph","./dom-helper/build-html-dom","exports"],
function(__dependency1__, __dependency2__, __exports__) {
"use strict";
var Morph = __dependency1__["default"];
var buildHTMLDOM = __dependency2__.buildHTMLDOM;
var svgNamespace = __dependency2__.svgNamespace;
var svgHTMLIntegrationPoints = __dependency2__.svgHTMLIntegrationPoints;
var deletesBlankTextNodes = (function(){
var element = document.createElement('div');
element.appendChild( document.createTextNode('') );
var clonedElement = element.cloneNode(true);
return clonedElement.childNodes.length === 0;
})();
var ignoresCheckedAttribute = (function(){
var element = document.createElement('input');
element.setAttribute('checked', 'checked');
var clonedElement = element.cloneNode(false);
return !clonedElement.checked;
})();
function isSVG(ns){
return ns === svgNamespace;
}
// This is not the namespace of the element, but of
// the elements inside that elements.
function interiorNamespace(element){
if (
element &&
element.namespaceURI === svgNamespace &&
!svgHTMLIntegrationPoints[element.tagName]
) {
return svgNamespace;
} else {
return null;
}
}
// The HTML spec allows for "omitted start tags". These tags are optional
// when their intended child is the first thing in the parent tag. For
// example, this is a tbody start tag:
//
//
//
//
//
// The tbody may be omitted, and the browser will accept and render:
//
//
//
//
// However, the omitted start tag will still be added to the DOM. Here
// we test the string and context to see if the browser is about to
// perform this cleanup.
//
// http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#optional-tags
// describes which tags are omittable. The spec for tbody and colgroup
// explains this behavior:
//
// http://www.whatwg.org/specs/web-apps/current-work/multipage/tables.html#the-tbody-element
// http://www.whatwg.org/specs/web-apps/current-work/multipage/tables.html#the-colgroup-element
//
var omittedStartTagChildTest = /<([\w:]+)/;
function detectOmittedStartTag(string, contextualElement){
// Omitted start tags are only inside table tags.
if (contextualElement.tagName === 'TABLE') {
var omittedStartTagChildMatch = omittedStartTagChildTest.exec(string);
if (omittedStartTagChildMatch) {
var omittedStartTagChild = omittedStartTagChildMatch[1];
// It is already asserted that the contextual element is a table
// and not the proper start tag. Just see if a tag was omitted.
return omittedStartTagChild === 'tr' ||
omittedStartTagChild === 'col';
}
}
}
function buildSVGDOM(html, dom){
var div = dom.document.createElement('div');
div.innerHTML = '';
return div.firstChild.childNodes;
}
/*
* A class wrapping DOM functions to address environment compatibility,
* namespaces, contextual elements for morph un-escaped content
* insertion.
*
* When entering a template, a DOMHelper should be passed:
*
* template(context, { hooks: hooks, dom: new DOMHelper() });
*
* TODO: support foreignObject as a passed contextual element. It has
* a namespace (svg) that does not match its internal namespace
* (xhtml).
*
* @class DOMHelper
* @constructor
* @param {HTMLDocument} _document The document DOM methods are proxied to
*/
function DOMHelper(_document){
this.document = _document || window.document;
this.namespace = null;
}
var prototype = DOMHelper.prototype;
prototype.constructor = DOMHelper;
prototype.insertBefore = function(element, childElement, referenceChild) {
return element.insertBefore(childElement, referenceChild);
};
prototype.appendChild = function(element, childElement) {
return element.appendChild(childElement);
};
prototype.appendText = function(element, text) {
return element.appendChild(this.document.createTextNode(text));
};
prototype.setAttribute = function(element, name, value) {
element.setAttribute(name, value);
};
if (document.createElementNS) {
// Only opt into namespace detection if a contextualElement
// is passed.
prototype.createElement = function(tagName, contextualElement) {
var namespace = this.namespace;
if (contextualElement) {
if (tagName === 'svg') {
namespace = svgNamespace;
} else {
namespace = interiorNamespace(contextualElement);
}
}
if (namespace) {
return this.document.createElementNS(namespace, tagName);
} else {
return this.document.createElement(tagName);
}
};
} else {
prototype.createElement = function(tagName) {
return this.document.createElement(tagName);
};
}
prototype.setNamespace = function(ns) {
this.namespace = ns;
};
prototype.detectNamespace = function(element) {
this.namespace = interiorNamespace(element);
};
prototype.createDocumentFragment = function(){
return this.document.createDocumentFragment();
};
prototype.createTextNode = function(text){
return this.document.createTextNode(text);
};
prototype.repairClonedNode = function(element, blankChildTextNodes, isChecked){
if (deletesBlankTextNodes && blankChildTextNodes.length > 0) {
for (var i=0, len=blankChildTextNodes.length;i]*)>", 'i'))[0];
var endTag = ''+tagName+'>';
var wrappedHTML = [startTag, html, endTag];
var i = wrappingTags.length;
var wrappedDepth = 1 + i;
while(i--) {
wrappedHTML.unshift('<'+wrappingTags[i]+'>');
wrappedHTML.push(''+wrappingTags[i]+'>');
}
var wrapper = document.createElement('div');
scriptSafeInnerHTML(wrapper, wrappedHTML.join(''));
var element = wrapper;
while (wrappedDepth--) {
element = element.firstChild;
while (element && element.nodeType !== 1) {
element = element.nextSibling;
}
}
while (element && element.tagName !== tagName) {
element = element.nextSibling;
}
return element ? element.childNodes : [];
}
var buildDOM;
if (needsShy) {
buildDOM = function buildDOM(html, contextualElement, dom){
contextualElement = dom.cloneNode(contextualElement, false);
scriptSafeInnerHTML(contextualElement, html);
return contextualElement.childNodes;
};
} else {
buildDOM = function buildDOM(html, contextualElement, dom){
contextualElement = dom.cloneNode(contextualElement, false);
contextualElement.innerHTML = html;
return contextualElement.childNodes;
};
}
var buildIESafeDOM;
if (tagNamesRequiringInnerHTMLFix.length > 0 || movesWhitespace) {
buildIESafeDOM = function buildIESafeDOM(html, contextualElement, dom) {
// Make a list of the leading text on script nodes. Include
// script tags without any whitespace for easier processing later.
var spacesBefore = [];
var spacesAfter = [];
html = html.replace(/(\s*)(