UNPKG

mframejs

Version:
71 lines 2.64 kB
Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var exported_1 = require("../decorator/exported"); var exported_2 = require("../binding/exported"); var CssAttribute = (function () { function CssAttribute() { this.lastStyles = []; } CssAttribute.prototype.created = function () { var _this = this; this.value = this.$attribute.value; this.$element.removeAttribute(this.$attribute.name); this.subscribeInternal = { name: 'cssAttribute:', value: this.value, call: function (newValue, oldValue) { if (oldValue !== newValue) { _this.splitAndInsert(newValue); } } }; exported_2.BindingEngine.subscribeClassProperty(this.$bindingContext, this.value, this.subscribeInternal); }; CssAttribute.prototype.splitAndInsert = function (value) { var _this = this; try { value = value === undefined || value === null ? '' : value; var x = value .split(';') .map(function (statement) { return statement.split(':'); }).filter(function (value) { if (value.length === 2) { return true; } else { return false; } }) .map(function (result) { return { attribute: result[0], value: result[1].replace(/ /g, '') }; }); var newStyles_1 = []; x.forEach(function (val) { newStyles_1.push(val.attribute.trim()); _this.$element.style[val.attribute.trim()] = val.value.trim(); }); this.lastStyles.forEach(function (val) { if (newStyles_1.indexOf(val) === -1) { _this.$element.style[val] = null; } }); this.lastStyles = newStyles_1; } catch (e) { console.error('could not parse css values'); } }; CssAttribute.prototype.detached = function () { exported_2.BindingEngine.unSubscribeClassProperty(this.$bindingContext, this.subscribeInternal); }; CssAttribute = tslib_1.__decorate([ exported_1.customAttribute('css') ], CssAttribute); return CssAttribute; }()); exports.CssAttribute = CssAttribute; //# sourceMappingURL=cssAttribute.js.map