Skip to content

Commit

Permalink
feat(md-modal): add modal for 0.97.8, keep trigger for older versions…
Browse files Browse the repository at this point in the history
…, add ready event
  • Loading branch information
Thanood committed Nov 2, 2016
1 parent 66ebfeb commit 3f01961
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/config-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export class ConfigBuilder {
}

useModal(): ConfigBuilder {
this.globalResources.push('./modal/modal');
this.globalResources.push('./modal/modal-trigger');
return this;
}
Expand Down
1 change: 1 addition & 0 deletions src/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export * from './footer/footer';
export * from './input/input-prefix';
export * from './input/input-update-service';
export * from './input/input';
export * from './modal/modal';
export * from './modal/modal-trigger';
export * from './navbar/navbar';
export * from './pagination/pagination';
Expand Down
47 changes: 47 additions & 0 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { bindable, customAttribute } from 'aurelia-templating';
import { inject } from 'aurelia-dependency-injection';
import { getBooleanFromAttributeValue } from '../common/attributes';
import { AttributeManager } from '../common/attributeManager';
import { fireMaterializeEvent } from '../common/events';

@customAttribute('md-modal')
@inject(Element)
export class MdModal {
@bindable() dismissible = true;

constructor(element) {
this.element = element;
this.attributeManager = new AttributeManager(this.element);
this.onComplete = this.onComplete.bind(this);
this.onReady = this.onReady.bind(this);
}

attached() {
this.attributeManager.addClasses('modal');
$(this.element).modal({
complete: this.onComplete,
dismissible: getBooleanFromAttributeValue(this.dismissible),
ready: this.onReady
});
}

detached() {
this.attributeManager.removeClasses('modal');
}

onComplete() {
fireMaterializeEvent(this.element, 'modal-complete');
}

onReady(modal, trigger) {
fireMaterializeEvent(this.element, 'modal-ready', { modal, trigger });
}

open() {
$(this.element).modal('open');
}

close() {
$(this.element).modal('close');
}
}

0 comments on commit 3f01961

Please sign in to comment.