salix/client/core/src/icon-menu/icon-menu.js

69 lines
1.6 KiB
JavaScript
Raw Normal View History

import {module} from '../module';
export default class IconMenu {
constructor($element, $http, $timeout) {
this.$element = $element;
this.$http = $http;
this.$timeout = $timeout;
this._showDropDown = false;
this._pos = undefined;
}
get showDropDown() {
return this._showDropDown;
}
set showDropDown(value) {
this._showDropDown = value;
}
get pos() {
return this._pos;
}
set pos(value) {
this._pos = value;
}
getItems() {
this.$http.get(this.url).then(
json => {
this.items = json.data;
}
);
}
$onInit() {
if (!this.items && this.url) {
this.getItems();
}
this.$element.bind('mouseover', e => {
this.$timeout(() => {
this.showDropDown = true;
2017-06-15 06:26:03 +00:00
if (e.target.nodeName === 'BUTTON')
this.pos = e.target.getBoundingClientRect();
});
});
this.$element.bind('mouseout', () => {
this.$timeout(() => {
this.showDropDown = false;
});
});
}
$onDestroy() {
this.$element.unbind('mouseover');
this.$element.unbind('mouseout');
}
}
IconMenu.$inject = ['$element', '$http', '$timeout'];
module.component('vnIconMenu', {
template: require('./icon-menu.html'),
bindings: {
url: '@?',
items: '=?',
icon: '@',
selected: '='
},
controller: IconMenu,
controllerAs: 'im'
});