playable
Version:
Video player based on HTML5Video
60 lines • 2.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var templates_1 = require("./templates");
var htmlToElement_1 = (0, tslib_1.__importDefault)(require("../htmlToElement"));
var stylable_1 = (0, tslib_1.__importDefault)(require("../stylable"));
var types_1 = require("./types");
var tooltip_container_scss_1 = (0, tslib_1.__importDefault)(require("./tooltip-container.scss"));
var TooltipContainer = /** @class */ (function (_super) {
(0, tslib_1.__extends)(TooltipContainer, _super);
function TooltipContainer(tooltip) {
var _this = _super.call(this) || this;
_this._tooltip = tooltip;
_this._initDOM();
return _this;
}
TooltipContainer.prototype.getElement = function () {
return this._$rootElement;
};
TooltipContainer.prototype._initDOM = function () {
this._$rootElement = (0, htmlToElement_1.default)((0, templates_1.tooltipContainerTemplate)({
styles: this.styleNames,
}));
this._$rootElement.appendChild(this._tooltip.getElement());
};
TooltipContainer.prototype.getTooltipPositionStyles = function (position) {
if (typeof position === 'function') {
position = position(this._$rootElement);
}
if (position.placement === types_1.TooltipPositionPlacement.TOP) {
return {
left: "".concat(this._getTooltipLeftX(position.x), "px"),
top: 0,
bottom: 'initial',
};
}
return {
left: "".concat(this._getTooltipLeftX(position.x), "px"),
top: 'initial',
bottom: 0,
};
};
TooltipContainer.prototype.destroy = function () {
this._tooltip = null;
this._$rootElement = null;
};
TooltipContainer.prototype._getTooltipLeftX = function (tooltipCenterX) {
var tooltipRect = this._tooltip.getElement().getBoundingClientRect();
var tooltipContainerRect = this._$rootElement.getBoundingClientRect();
var tooltipLeftX = tooltipCenterX - tooltipRect.width / 2;
// ensure `x` is in range of placeholder rect
tooltipLeftX = Math.max(tooltipLeftX, 0);
tooltipLeftX = Math.min(tooltipLeftX, tooltipContainerRect.width - tooltipRect.width);
return tooltipLeftX;
};
return TooltipContainer;
}(stylable_1.default));
TooltipContainer.extendStyleNames(tooltip_container_scss_1.default);
exports.default = TooltipContainer;
//# sourceMappingURL=tooltip-container.js.map