Skip to content

Commit

Permalink
[fix] element argument should support HTML and SVG element
Browse files Browse the repository at this point in the history
  • Loading branch information
netchampfaris committed Jul 8, 2018
1 parent a7e61db commit 49e6880
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export default class Bar {
if (e.type === 'click') {
this.gantt.trigger_event('click', [this.task]);
}

this.gantt.unselect_all();
this.group.classList.toggle('active');

Expand Down
54 changes: 40 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,50 @@ export default class Gantt {
}

setup_wrapper(element) {
let svg_element, wrapper_element;

// CSS Selector is passed
if (typeof element === 'string') {
element = document.querySelector(element);
}

if (!(element instanceof HTMLElement)) {
throw new Error('Invalid argument passed for element');
// get the SVGElement
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"
);
}

// 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');
}

// parent div element
// wrapper element
this.$container = document.createElement('div');
this.$container.classList.add('gantt-container');
element.appendChild(this.$container);

// parent svg element
this.$svg = createSVG('svg', {
append_to: this.$container,
class: 'gantt'
});
const parent_element = this.$svg.parentElement;
parent_element.appendChild(this.$container);
this.$container.appendChild(this.$svg);

// popup wrapper
this.popup_wrapper = document.createElement('div');
this.popup_wrapper.classList.add('popup-wrapper');
this.$svg.parentElement.appendChild(this.popup_wrapper);
this.$container.appendChild(this.popup_wrapper);
}

setup_options(options) {
Expand Down Expand Up @@ -572,10 +593,15 @@ export default class Gantt {
}

bind_grid_click() {
$.on(this.$svg, this.options.popup_trigger, '.grid-row, .grid-header', () => {
this.unselect_all();
this.hide_popup();
});
$.on(
this.$svg,
this.options.popup_trigger,
'.grid-row, .grid-header',
() => {
this.unselect_all();
this.hide_popup();
}
);
}

bind_bar_events() {
Expand Down

0 comments on commit 49e6880

Please sign in to comment.