UNPKG

ng2-materialize

Version:

An Angular 2+ wrap around Materialize library

77 lines (76 loc) 3.38 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var 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 function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var handle_prop_changes_1 = require("../shared/handle-prop-changes"); var MzCheckboxDirective = (function (_super) { __extends(MzCheckboxDirective, _super); function MzCheckboxDirective(elementRef, renderer) { var _this = _super.call(this) || this; _this.elementRef = elementRef; _this.renderer = renderer; return _this; } MzCheckboxDirective.prototype.ngOnInit = function () { this.initHandlers(); this.initElements(); this.handleProperties(); }; MzCheckboxDirective.prototype.initHandlers = function () { var _this = this; this.handlers = { filledIn: function () { return _this.handleFilledIn(); }, label: function () { return _this.handleLabel(); }, }; }; MzCheckboxDirective.prototype.initElements = function () { this.checkboxElement = $(this.elementRef.nativeElement); this.checkboxContainerElement = $(this.elementRef.nativeElement).parent('.checkbox-field'); this.labelElement = this.createLabelElement(); }; MzCheckboxDirective.prototype.createLabelElement = function () { var labelElement = document.createElement('label'); labelElement.setAttribute('for', this.id); this.renderer.invokeElementMethod(this.checkboxElement, 'after', [labelElement]); return $(labelElement); }; MzCheckboxDirective.prototype.handleProperties = function () { if (this.checkboxContainerElement.length === 0) { console.error('Input with mz-checkbox directive must be placed inside a [mz-checkbox-container] tag', this.checkboxElement); return; } _super.prototype.executePropHandlers.call(this); }; MzCheckboxDirective.prototype.handleLabel = function () { this.renderer.invokeElementMethod(this.labelElement, 'text', [this.label]); }; MzCheckboxDirective.prototype.handleFilledIn = function () { this.renderer.setElementClass(this.checkboxElement[0], 'filled-in', this.filledIn); }; return MzCheckboxDirective; }(handle_prop_changes_1.HandlePropChanges)); MzCheckboxDirective.decorators = [ { type: core_1.Directive, args: [{ selector: 'input[mzCheckbox], input[mz-checkbox]', },] }, ]; /** @nocollapse */ MzCheckboxDirective.ctorParameters = function () { return [ { type: core_1.ElementRef, }, { type: core_1.Renderer, }, ]; }; MzCheckboxDirective.propDecorators = { 'id': [{ type: core_1.HostBinding }, { type: core_1.Input },], 'filledIn': [{ type: core_1.Input },], 'label': [{ type: core_1.Input },], }; exports.MzCheckboxDirective = MzCheckboxDirective;