ng2-encrm-components
Version:
68 lines • 2.74 kB
JavaScript
var core_1 = require('@angular/core');
var ButtonDropdownComponent = (function () {
function ButtonDropdownComponent(_elementRef) {
var _this = this;
this._elementRef = _elementRef;
this.isOpen = false;
/**
* hides dropdown on outside click
* @param target
*/
this.documentClickHandler = function (target) {
if (!_this._elementRef.nativeElement.contains(target)) {
_this.hide();
}
};
}
ButtonDropdownComponent.prototype.toggleShow = function () {
this.isOpen = !this.isOpen;
this.checkPosition();
};
ButtonDropdownComponent.prototype.hide = function () {
this.isOpen = false;
this.checkPosition();
};
/**
* check position of menu and move if it is placed out of view window
*/
ButtonDropdownComponent.prototype.checkPosition = function () {
var _this = this;
setTimeout(function () {
// czy da się pozbyć elementRef?
var el = _this._elementRef.nativeElement.querySelector('[list]');
var triggerRect = _this._elementRef.nativeElement
.querySelector('#wrap')
.getBoundingClientRect();
var arrowContainer = _this._elementRef.nativeElement.querySelector('.arrow-container');
if (!el) {
return;
}
var menuRect = el.getBoundingClientRect();
if (menuRect.right > window.innerWidth) {
var left = +el.style.left.slice(0, -2);
el.style.left = left - (menuRect.right - window.innerWidth) - 20 + 'px';
}
if (menuRect.left < 0) {
var left = +el.style.left.slice(0, -2);
el.style.left = left - menuRect.left + 5 + 'px';
}
arrowContainer.style.left = triggerRect.width / 2 + 'px';
}, 1);
};
__decorate([
core_1.HostListener('document:click', ['$event.target']),
__metadata('design:type', Object)
], ButtonDropdownComponent.prototype, "documentClickHandler", void 0);
ButtonDropdownComponent = __decorate([
core_1.Component({
selector: 'button-dropdown',
template: require('./button-dropdown.component.html'),
styles: [require('./button-dropdown.component.scss')]
}),
__metadata('design:paramtypes', [core_1.ElementRef])
], ButtonDropdownComponent);
return ButtonDropdownComponent;
}());
exports.ButtonDropdownComponent = ButtonDropdownComponent;
//# sourceMappingURL=button-dropdown.component.js.map
;