@dzeio/form-manager
Version:
A powerfull Form Manager
61 lines (60 loc) • 2.43 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var Functions_1 = require("../Functions");
var AttributeListeners_1 = __importDefault(require("./AttributeListeners"));
var AttributeAbstract_1 = __importDefault(require("./AttributeAbstract"));
var AutosetAttribute = (function (_super) {
__extends(AutosetAttribute, _super);
function AutosetAttribute() {
return _super !== null && _super.apply(this, arguments) || this;
}
AutosetAttribute.prototype.trigger = function () {
var _this = this;
var str = this.input.element.getAttribute("data-autoset") || "";
if (Functions_1.evalF(str, function (ster) { _this.input.setValue(ster); }))
return;
this.normal(str);
};
AutosetAttribute.prototype.normal = function (str) {
var regexp = new RegExp("{([a-zA-Z0-9]+)}");
var loopMax = 0;
while (regexp.test(str) && loopMax++ < 10) {
var el = regexp.exec(str || "");
if (el === null) {
break;
}
str = str.replace(new RegExp(el[0], "g"), this.input.form.getJSON()[el[1]]);
}
this.input.setValue(str);
if (loopMax >= 10) {
throw new Error("Error, too many differents variables");
}
};
AutosetAttribute.listeners = [
AttributeListeners_1.default.CHANGE,
AttributeListeners_1.default.FORM_FILL,
AttributeListeners_1.default.MODE_SWITCH
];
AutosetAttribute.identity = {
attribute: AutosetAttribute,
dataElement: "data-autoset"
};
return AutosetAttribute;
}(AttributeAbstract_1.default));
exports.default = AutosetAttribute;