Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

Commit

Permalink
feat: charist-events attibute to attach to events fired by chartist o…
Browse files Browse the repository at this point in the history
…r plugins
  • Loading branch information
erik-lieben committed Sep 11, 2016
1 parent d445050 commit ababb0f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/chartist-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { customAttribute, dynamicOptions, inject } from "aurelia-framework";
import { ChartistElement } from "./chartist";

@dynamicOptions()
@inject(Element)
@customAttribute("chartist-events")
export class ChartistEventsAttribute {

private isCustomElement = false;
private elementVM: ChartistElement;

constructor (private element) {
this.isCustomElement = typeof(element.au.controller) === "object" && typeof(element.au.controller.viewModel) === "object";
if (this.isCustomElement) {
this.elementVM = element.au.controller.viewModel;
}
}

public propertyChanged(name, value) {

if (!this.isCustomElement) {
return;
}

if (this.elementVM.chart) {
this.elementVM.chart.on(name, data => value({ sdata: data }));
} else {
this.elementVM.eventsToAttachOnAttached.push( { name: name, value: data => value({ data: data }) });
}
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function configure(config) {
config.globalResources("./chartistElement");
config.globalResources(["./charlist", "./charlist-events"]);
}

0 comments on commit ababb0f

Please sign in to comment.