glass-platform
Version:
Glass platform
68 lines (59 loc) • 2.37 kB
JavaScript
(function(){require.register('glass/ui/html/Control',function(module,exports,require){// Generated by CoffeeScript 1.6.2
(function() {
var Control, UiControl, assert, createElement, dispose, exports, initialize, isElement, isNode, _ref;
UiControl = require('../Control');
_ref = require('./index'), isElement = _ref.isElement, isNode = _ref.isNode, createElement = _ref.createElement;
module.exports = exports = Control = UiControl.extend({
id: 'glass.ui.html.Control',
properties: {
initialize: initialize = function() {
var parentNode, _ref1;
if (Object.isString(this.element)) {
this.element = createElement(this.element);
}
if (!isNode(this.element)) {
throw new Error("element property is required");
}
if ((_ref1 = this.container) == null) {
this.container = this.element;
}
parentNode = isElement(this.parent.container) ? this.parent.container : isElement(this.parent) ? this.parent : global.window != null ? global.window.document.body : void 0;
parentNode.appendChild(this.element);
return this.inner(initialize);
},
dispose: dispose = function() {
this.element.parentNode.removeChild(this.element);
return this.inner(dispose);
},
element: {
description: 'The actual DOM node or element.\nThis can also be set to a tag name or html element declaration.\nIf a string it will be converted to an element at construction.',
value: 'span'
},
container: {
description: 'The element to add children to. Usually same as this.element.'
}
}
});
if (typeof describe === 'function') {
assert = require('assert');
describe('glass.ui.html.Control', function() {
if (global.window) {
return it('should be able to add to window', function() {
var control;
control = new Control({
parent: global,
element: createElement('<span>Test</span>')
});
assert.equal(window.document.body, control.element.parentNode);
assert.equal(window.document.body.lastChild, control.element);
control.dispose();
return assert(control.element.parentNode == null);
});
}
});
}
}).call(this);
/*
//@ sourceMappingURL=Control.map
*/
})})()