Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions dom-renderers/DOMRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ DOMRenderer.prototype.insertEl = function insertEl (tagName) {
this._assertParentLoaded();
this._assertChildrenLoaded();

if (this._parent.void)
throw new Error(
this._parent.path + ' is a void element. ' +
'Void elements are not allowed to have children.'
);

if (this._target) this._parent.element.removeChild(this._target.element);

this._target = new ElementCache(document.createElement(tagName), this._path);
Expand Down Expand Up @@ -558,15 +564,21 @@ DOMRenderer.prototype.setContent = function setContent(content) {
this._assertTargetLoaded();
this.findChildren();

if (!this._target.content) {
this._target.content = document.createElement('div');
this._target.content.classList.add('famous-dom-element-content');
this._target.element.insertBefore(
this._target.content,
this._target.element.firstChild
);
if (this._target.formElement) {
this._target.element.value = content;
}
this._target.content.innerHTML = content;
else {
if (!this._target.content) {
this._target.content = document.createElement('div');
this._target.content.classList.add('famous-dom-element-content');
this._target.element.insertBefore(
this._target.content,
this._target.element.firstChild
);
}
this._target.content.innerHTML = content;
}


this.setSize(
this._target.explicitWidth ? false : this._target.size[0],
Expand Down
30 changes: 21 additions & 9 deletions dom-renderers/ElementCache.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/**
* The MIT License (MIT)
*
*
* Copyright (c) 2015 Famous Industries Inc.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -24,7 +24,9 @@

'use strict';

// Transform identity matrix.
var VoidElements = require('./VoidElements');

// Transform identity matrix.
var ident = [
1, 0, 0, 0,
0, 1, 0, 0,
Expand All @@ -37,13 +39,23 @@ var ident = [
* path, world transform, inverted parent, final transform (as being used for
* setting the actual `transform`-property) and post render size (final size as
* being rendered to the DOM).
*
*
* @class ElementCache
*
*
* @param {Element} element DOMElement
* @param {String} path Path used for uniquely identifying the location in the scene graph.
*/
* @param {String} path Path used for uniquely identifying the location in the
* scene graph.
*/
function ElementCache (element, path) {
this.tagName = element.tagName.toLowerCase();
this.void = VoidElements[this.tagName];

var constructor = element.constructor;

this.formElement = constructor === HTMLInputElement ||
constructor === HTMLTextAreaElement ||
constructor === HTMLSelectElement;

this.element = element;
this.path = path;
this.content = null;
Expand Down
51 changes: 51 additions & 0 deletions dom-renderers/VoidElements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Famous Industries Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

'use strict';

/**
* Map of void elements as defined by the
* [HTML5 spec](http://www.w3.org/TR/html5/syntax.html#elements-0).
*
* @type {Object}
*/
var VoidElements = {
area : true,
base : true,
br : true,
col : true,
embed : true,
hr : true,
img : true,
input : true,
keygen: true,
link : true,
meta : true,
param : true,
source: true,
track : true,
wbr : true
};

module.exports = VoidElements;
11 changes: 6 additions & 5 deletions dom-renderers/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/**
* The MIT License (MIT)
*
*
* Copyright (c) 2015 Famous Industries Inc.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -28,5 +28,6 @@ module.exports = {
DOMRenderer: require('./DOMRenderer'),
ElementCache: require('./ElementCache'),
Events: require('./events'),
Math: require('./Math')
Math: require('./Math'),
VoidElements: require('./VoidElements')
};