Skip to content

Instantly share code, notes, and snippets.

@Thanood
Last active January 29, 2017 15:10
Show Gist options
  • Save Thanood/dae9e6f50033374381b9d991f921b42c to your computer and use it in GitHub Desktop.
Save Thanood/dae9e6f50033374381b9d991f921b42c to your computer and use it in GitHub Desktop.
Aurelia-Materialize bridge collapsible prevent open/close
<template>
<require from="./mdx-no-collapse"></require>
<div>
Thanks to @djensen47!
</div>
<div class="collapsible-basic-use">
<ul md-collapsible>
<li>
<div class="collapsible-header">
First
<div class="secondary-content">
<a click.trigger="editClicked()" mdx-no-collapse class="no-collapse"><i class="left grey-text text-darken-2 material-icons">mode_edit</i></a>
</div>
</div>
<div class="collapsible-body"><p>Lorem ipsum dolor sit amet.</p></div>
</li>
<li>
<div class="collapsible-header">
Second
<div class="secondary-content">
<a click.trigger="editClicked()" mdx-no-collapse class="no-collapse"><i class="left grey-text text-darken-2 material-icons">mode_edit</i></a>
</div>
</div>
<div class="collapsible-body"><p>Lorem ipsum dolor sit amet.</p></div>
</li>
</ul>
</div>
</template>
import {inject} from 'aurelia-framework';
import {MdToastService} from 'aurelia-materialize-bridge';
@inject(MdToastService)
export class App {
constructor(toast) {
this.toast = toast;
}
editClicked() {
this.toast.show('edit button clicked');
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app="main">
<h1>Loading...</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.6/system.js"></script>
<script src="https://rawgit.com/aurelia-ui-toolkits/aurelia-materialize-bundles/0.20.2/config2.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
/*******************************************************************************
* The following two lines enable async/await without using babel's
* "runtime" transformer. Uncomment the lines if you intend to use async/await.
*
* More info here: https://github.com/jdanyow/aurelia-plunker/issues/2
*/
//import regeneratorRuntime from 'babel-runtime/regenerator';
//window.regeneratorRuntime = regeneratorRuntime;
/******************************************************************************/
import 'materialize';
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging()
.plugin('aurelia-materialize-bridge', bridge => bridge.useAll() );
aurelia.start().then(a => a.setRoot());
}
import {customAttribute, inject} from 'aurelia-framework';
/**
* This custom attribute can be used on an element inside of a
* collapsible-header to prevent the element from triggering open/close
* of the collapsible-body.
*
* However, in order for the element to register a click action, you must
* use `click.trigger` and not `click.delegate`.
*/
@customAttribute('mdx-no-collapse')
@inject(Element)
export class MdxNoCollapseCustomAttribute {
constructor(element) {
this.element = element;
}
attached() {
$(this.element).on('click.collapse', (evt) => {
evt.stopPropagation();
});
}
valueChanged(newValue, oldValue) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment