'use strict'; var jqLite = require('../js/lib/jqLite'), muiTextfield = require('../js/textfield'), textfieldClass = 'mui-textfield', floatingMod = '--float-label', textfieldTagName = textfieldClass; var TextfieldProto = Object.create(HTMLElement.prototype); TextfieldProto.createdCallback = function (){ var root = this.createShadowRoot(), innerEl = _AN_Call_createelement('createElement', document, 'div'), cls; var attrs = { type: _AN_Call_getattribute('getAttribute', this, 'type') || 'text', value: _AN_Call_getattribute('getAttribute', this, 'value'), placeholder: _AN_Call_getattribute('getAttribute', this, 'placeholder'), label: _AN_Call_getattribute('getAttribute', this, 'label'), floating: _AN_Call_getattribute('getAttribute', this, 'floating')} ; cls = textfieldClass; if (attrs.floating !== null ) cls += ' ' + textfieldClass + floatingMod; _AN_Call_setattribute('setAttribute', innerEl, 'class', cls); _AN_Call_appendchild('appendChild', innerEl, _createInputEl(attrs)); if (attrs.label) { var labelEl = _createLabelEl(attrs); _AN_Call_appendchild('appendChild', innerEl, labelEl); } _AN_Call_appendchild('appendChild', root, _getStyleEl().cloneNode(true )); _AN_Call_appendchild('appendChild', root, innerEl); } ; var styleEl; function _getStyleEl(){ if (styleEl === undefined) { styleEl = _AN_Call_createelement('createElement', document, 'style'); _AN_Write_innerhtml('innerHTML', styleEl, false , require('mui.min.css')); } return styleEl; } function _createInputEl(attrs){ var inputEl; if (attrs.type === 'textarea') { inputEl = _AN_Call_createelement('createElement', document, 'textarea'); if (attrs.value) _AN_Call_appendchild('appendChild', inputEl, document.createTextNode(attrs.value)); } else { inputEl = _AN_Call_createelement('createElement', document, 'input'); _AN_Call_setattribute('setAttribute', inputEl, 'type', attrs.type); if (attrs.value) _AN_Call_setattribute('setAttribute', inputEl, 'value', attrs.value); } if (attrs.placeholder) { _AN_Call_setattribute('setAttribute', inputEl, 'placeholder', attrs.placeholder); } muiTextfield.initialize(inputEl); return inputEl; } function _createLabelEl(attrs){ var labelEl = _AN_Call_createelement('createElement', document, 'label'); _AN_Call_appendchild('appendChild', labelEl, document.createTextNode(attrs.label)); return labelEl; } module.exports = { registerElements: function (){ var TextfieldElement = document.registerElement(textfieldTagName, { prototype: TextfieldProto} ); return { TextfieldElement: TextfieldElement} ; } } ;