ng2-encrm-components
Version:
190 lines • 7.86 kB
JavaScript
"use strict";
var core_1 = require("@angular/core");
var popover_content_component_1 = require("./popover-content.component");
var Popover = (function () {
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
function Popover(viewContainerRef, resolver) {
this.viewContainerRef = viewContainerRef;
this.resolver = resolver;
this.popoverOnHover = false;
this.popoverDismissTimeout = 0;
this.flavor = 'default';
}
// -------------------------------------------------------------------------
// Event listeners
// -------------------------------------------------------------------------
Popover.prototype.showOrHideOnClick = function () {
if (this.popoverOnHover)
return;
if (this.popoverDisabled)
return;
this.toggle();
};
Popover.prototype.showOnHover = function () {
if (!this.popoverOnHover)
return;
if (this.popoverDisabled)
return;
this.show();
};
Popover.prototype.hideOnHover = function () {
if (this.popoverCloseOnMouseOutside)
return; // don't do anything since not we control this
if (!this.popoverOnHover)
return;
if (this.popoverDisabled)
return;
this.hide();
};
Popover.prototype.ngOnChanges = function (changes) {
if (changes['popoverDisabled']) {
if (changes['popoverDisabled'].currentValue) {
this.hide();
}
}
};
// -------------------------------------------------------------------------
// Public Methods
// -------------------------------------------------------------------------
Popover.prototype.toggle = function () {
if (!this.visible) {
this.show();
}
else {
this.hide();
}
};
Popover.prototype.show = function () {
var _this = this;
if (this.visible)
return;
this.visible = true;
if (typeof this.content === "string") {
var factory = this.resolver.resolveComponentFactory(popover_content_component_1.PopoverContent);
if (!this.visible)
return;
this.popover = this.viewContainerRef.createComponent(factory);
var popover = this.popover.instance;
popover.popover = this;
popover.content = this.content;
if (this.popoverPlacement !== undefined)
popover.placement = this.popoverPlacement;
if (this.popoverAnimation !== undefined)
popover.animation = this.popoverAnimation;
if (this.popoverTitle !== undefined)
popover.title = this.popoverTitle;
if (this.popoverCloseOnClickOutside !== undefined)
popover.closeOnClickOutside = this.popoverCloseOnClickOutside;
if (this.popoverCloseOnMouseOutside !== undefined)
popover.closeOnMouseOutside = this.popoverCloseOnMouseOutside;
popover.flavor = this.flavor;
popover.onCloseFromOutside.subscribe(function () { return _this.hide(); });
// if dismissTimeout option is set, then this popover will be dismissed in dismissTimeout time
if (this.popoverDismissTimeout > 0)
setTimeout(function () { return _this.hide(); }, this.popoverDismissTimeout);
}
else {
var popover = this.content;
popover.popover = this;
if (this.popoverPlacement !== undefined)
popover.placement = this.popoverPlacement;
if (this.popoverAnimation !== undefined)
popover.animation = this.popoverAnimation;
if (this.popoverTitle !== undefined)
popover.title = this.popoverTitle;
if (this.popoverCloseOnClickOutside !== undefined)
popover.closeOnClickOutside = this.popoverCloseOnClickOutside;
if (this.popoverCloseOnMouseOutside !== undefined)
popover.closeOnMouseOutside = this.popoverCloseOnMouseOutside;
popover.onCloseFromOutside.subscribe(function () { return _this.hide(); });
// if dismissTimeout option is set, then this popover will be dismissed in dismissTimeout time
if (this.popoverDismissTimeout > 0)
setTimeout(function () { return _this.hide(); }, this.popoverDismissTimeout);
popover.show();
}
};
Popover.prototype.hide = function () {
if (!this.visible)
return;
this.visible = false;
if (this.popover)
this.popover.destroy();
if (this.content instanceof popover_content_component_1.PopoverContent)
this.content.hideFromPopover();
};
Popover.prototype.getElement = function () {
return this.viewContainerRef.element.nativeElement;
};
__decorate([
core_1.Input("popover"),
__metadata('design:type', Object)
], Popover.prototype, "content", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Boolean)
], Popover.prototype, "popoverDisabled", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Boolean)
], Popover.prototype, "popoverAnimation", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Object)
], Popover.prototype, "popoverPlacement", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', String)
], Popover.prototype, "popoverTitle", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Boolean)
], Popover.prototype, "popoverOnHover", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Boolean)
], Popover.prototype, "popoverCloseOnClickOutside", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Boolean)
], Popover.prototype, "popoverCloseOnMouseOutside", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Number)
], Popover.prototype, "popoverDismissTimeout", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Object)
], Popover.prototype, "flavor", void 0);
__decorate([
core_1.HostListener("click"),
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', void 0)
], Popover.prototype, "showOrHideOnClick", null);
__decorate([
core_1.HostListener("focusin"),
core_1.HostListener("mouseenter"),
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', void 0)
], Popover.prototype, "showOnHover", null);
__decorate([
core_1.HostListener("focusout"),
core_1.HostListener("mouseleave"),
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', void 0)
], Popover.prototype, "hideOnHover", null);
Popover = __decorate([
core_1.Directive({
selector: "[popover]",
exportAs: "popover"
}),
__metadata('design:paramtypes', [core_1.ViewContainerRef, core_1.ComponentFactoryResolver])
], Popover);
return Popover;
}());
exports.Popover = Popover;
//# sourceMappingURL=popover.directive.js.map