[fix] element argument should support HTML and SVG element
This commit is contained in:
parent
a7e61db72f
commit
49e6880252
@ -184,7 +184,7 @@ export default class Bar {
|
|||||||
if (e.type === 'click') {
|
if (e.type === 'click') {
|
||||||
this.gantt.trigger_event('click', [this.task]);
|
this.gantt.trigger_event('click', [this.task]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.gantt.unselect_all();
|
this.gantt.unselect_all();
|
||||||
this.group.classList.toggle('active');
|
this.group.classList.toggle('active');
|
||||||
|
|
||||||
|
|||||||
54
src/index.js
54
src/index.js
@ -17,29 +17,50 @@ export default class Gantt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup_wrapper(element) {
|
setup_wrapper(element) {
|
||||||
|
let svg_element, wrapper_element;
|
||||||
|
|
||||||
|
// CSS Selector is passed
|
||||||
if (typeof element === 'string') {
|
if (typeof element === 'string') {
|
||||||
element = document.querySelector(element);
|
element = document.querySelector(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(element instanceof HTMLElement)) {
|
// get the SVGElement
|
||||||
throw new Error('Invalid argument passed for element');
|
if (element instanceof HTMLElement) {
|
||||||
|
wrapper_element = element;
|
||||||
|
svg_element = element.querySelector('svg');
|
||||||
|
} else if (element instanceof SVGElement) {
|
||||||
|
svg_element = element;
|
||||||
|
} else {
|
||||||
|
throw new TypeError(
|
||||||
|
'Frappé Gantt only supports usage of a string CSS selector,' +
|
||||||
|
" HTML DOM element or SVG DOM element for the 'element' parameter"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// parent div element
|
// svg element
|
||||||
|
if (!svg_element) {
|
||||||
|
// create it
|
||||||
|
this.$svg = createSVG('svg', {
|
||||||
|
append_to: wrapper_element,
|
||||||
|
class: 'gantt'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.$svg = svg_element;
|
||||||
|
this.$svg.classList.add('gantt');
|
||||||
|
}
|
||||||
|
|
||||||
|
// wrapper element
|
||||||
this.$container = document.createElement('div');
|
this.$container = document.createElement('div');
|
||||||
this.$container.classList.add('gantt-container');
|
this.$container.classList.add('gantt-container');
|
||||||
element.appendChild(this.$container);
|
|
||||||
|
|
||||||
// parent svg element
|
const parent_element = this.$svg.parentElement;
|
||||||
this.$svg = createSVG('svg', {
|
parent_element.appendChild(this.$container);
|
||||||
append_to: this.$container,
|
this.$container.appendChild(this.$svg);
|
||||||
class: 'gantt'
|
|
||||||
});
|
|
||||||
|
|
||||||
// popup wrapper
|
// popup wrapper
|
||||||
this.popup_wrapper = document.createElement('div');
|
this.popup_wrapper = document.createElement('div');
|
||||||
this.popup_wrapper.classList.add('popup-wrapper');
|
this.popup_wrapper.classList.add('popup-wrapper');
|
||||||
this.$svg.parentElement.appendChild(this.popup_wrapper);
|
this.$container.appendChild(this.popup_wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_options(options) {
|
setup_options(options) {
|
||||||
@ -572,10 +593,15 @@ export default class Gantt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bind_grid_click() {
|
bind_grid_click() {
|
||||||
$.on(this.$svg, this.options.popup_trigger, '.grid-row, .grid-header', () => {
|
$.on(
|
||||||
this.unselect_all();
|
this.$svg,
|
||||||
this.hide_popup();
|
this.options.popup_trigger,
|
||||||
});
|
'.grid-row, .grid-header',
|
||||||
|
() => {
|
||||||
|
this.unselect_all();
|
||||||
|
this.hide_popup();
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bind_bar_events() {
|
bind_bar_events() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user