ferngully-aurelia-tools
Version:
Ferngully Tools for Aurelia
135 lines • 5.64 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { customAttribute, inject, bindable, bindingMode, TemplatingEngine } from "aurelia-framework";
import { AureliaHelperService } from "../../../services/aurelia-helper-service";
import { I18N } from 'aurelia-i18n';
let Popover = class Popover {
constructor(element, templatingEngine, aureliaHelperService, i18n) {
this.templatingEngine = templatingEngine;
this.aureliaHelperService = aureliaHelperService;
this.i18n = i18n;
this.element = element;
}
bind(bindingContext) {
this.bindingContext = bindingContext;
this.title = this.i18n.tr(this.title);
this.content = this.i18n.tr(this.content);
if (this.enable) {
this.configurePopover();
}
if (this.template) {
$(this.element).on("shown.bs.popover.myTooltip", () => this.enhance());
}
if (this.trigger === "hover-modal") {
let $element = $(this.element);
let fnHandleMouseOver = () => $element.one('mouseover.myTooltip', () => {
$element.focus();
});
fnHandleMouseOver();
$element.on("hide.bs.popover.myTooltip", () => fnHandleMouseOver());
}
}
unbind() {
if (this.template) {
$(this.element).off('shown.bs.popover.myTooltip');
}
}
titleChanged(newValue, oldValue) {
this.title = newValue;
}
contentChanged(newValue) {
this.content = newValue;
}
templateChanged(newValue, oldValue) {
this.template = newValue;
}
enableChanged(newValue, oldValue) {
this.enable = newValue;
if (newValue) {
this.configurePopover();
}
else {
$(this.element).popover("destroy");
}
}
configurePopover() {
$(this.element)
.popover({
title: () => { return this.title; },
placement: this.placement,
trigger: this.trigger === "hover-modal" ? "focus" : this.trigger,
container: this.container,
html: this.html,
animation: this.animation,
viewport: this.viewport,
delay: this.template ? 100 : 0,
content: () => {
return this.template ? this.template.content : this.content;
}
});
}
enhance() {
this.aureliaHelperService.enhance(this.template.selectionPath, this.template.bindingContext || this.bindingContext);
}
};
__decorate([
bindable({ defaultValue: 0, defaultBindingMode: bindingMode.oneWay }),
__metadata("design:type", Object)
], Popover.prototype, "delay", void 0);
__decorate([
bindable({ defaultValue: "top", defaultBindingMode: bindingMode.oneWay }),
__metadata("design:type", Object)
], Popover.prototype, "placement", void 0);
__decorate([
bindable({ defaultValue: null, defaultBindingMode: bindingMode.oneWay }),
__metadata("design:type", String)
], Popover.prototype, "title", void 0);
__decorate([
bindable({ defaultValue: null, defaultBindingMode: bindingMode.oneWay, primaryProperty: true }),
__metadata("design:type", String)
], Popover.prototype, "content", void 0);
__decorate([
bindable({ defaultValue: null, defaultBindingMode: bindingMode.oneWay }),
__metadata("design:type", Object)
], Popover.prototype, "template", void 0);
__decorate([
bindable({ defaultValue: "body", defaultBindingMode: bindingMode.oneWay }),
__metadata("design:type", Object)
], Popover.prototype, "container", void 0);
__decorate([
bindable({ defaultValue: "hover", defaultBindingMode: bindingMode.oneWay }),
__metadata("design:type", String)
], Popover.prototype, "trigger", void 0);
__decorate([
bindable({ defaultValue: true, defaultBindingMode: bindingMode.oneWay }),
__metadata("design:type", Boolean)
], Popover.prototype, "enable", void 0);
__decorate([
bindable({ defaultValue: true, defaultBindingMode: bindingMode.oneWay }),
__metadata("design:type", Boolean)
], Popover.prototype, "animation", void 0);
__decorate([
bindable({ defaultValue: false, defaultBindingMode: bindingMode.oneWay }),
__metadata("design:type", Boolean)
], Popover.prototype, "html", void 0);
__decorate([
bindable({ defaultValue: { selector: 'body', padding: 0 }, defaultBindingMode: bindingMode.oneWay }),
__metadata("design:type", Object)
], Popover.prototype, "viewport", void 0);
Popover = __decorate([
customAttribute('popover'),
inject(Element, TemplatingEngine, AureliaHelperService, I18N),
__metadata("design:paramtypes", [HTMLElement,
TemplatingEngine,
AureliaHelperService,
I18N])
], Popover);
export { Popover };
//# sourceMappingURL=popover.js.map