Created
May 10, 2018 03:27
-
-
Save MaximBalaganskiy/86f938400fede9d99aad1cdc6538d39d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | |
</head> | |
<body> | |
<div aurelia-app="src/configure"> | |
Loading... | |
</div> | |
<script src="https://rawgit.com/aurelia-ui-toolkits/demo-materialize/gh-pages/jspm_packages/system.js"></script> | |
<script src="https://rawgit.com/aurelia-ui-toolkits/demo-materialize/gh-pages/jspm.config.js"></script> | |
<script> | |
System.import("aurelia-bootstrapper"); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<require from="./md-wait-cursor"></require> | |
<div> | |
Thanks to @MaximBalaganskiy! | |
</div> | |
<p> | |
<button md-button md-waves="color: light;" md-wait-cursor.bind="loading">wait</button> | |
<md-input md-wait-cursor.bind="loading" label="text field"></md-input> | |
</p> | |
<table style="position: relative"> | |
<thead> | |
<th>H1</th> | |
<th>H2</th> | |
</thead> | |
<tbody> | |
<tr> | |
<td>c1</td> | |
<td>c2</td> | |
</tr> | |
<tr md-wait-cursor.bind="loading"> | |
<td>c3</td> | |
<td>c4</td> | |
</tr> | |
</tbody> | |
</table> | |
<button md-button md-waves="color: light;" click.delegate="toggleLoading()">toggle loading</button> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class App { | |
loading = false; | |
toggleLoading() { | |
this.loading = !this.loading; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function configure(aurelia) { | |
await aurelia.loader.loadModule("materialize-css"); | |
aurelia.use | |
.standardConfiguration() | |
.developmentLogging() | |
.plugin("aurelia-materialize-bridge", bridge => bridge.useAll()) | |
.plugin("aurelia-validation") | |
.globalResources("src/shared/logger"); | |
await aurelia.start(); | |
aurelia.setRoot("src/app"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { customAttribute, autoinject, TemplatingEngine } from "aurelia-framework"; | |
@customAttribute("md-wait-cursor") | |
@autoinject | |
export class MdWaitCursorCustomAttribute { | |
constructor(private element: Element, private templatingEngine: TemplatingEngine) { } | |
value = false; | |
valueChanged(newVal: boolean) { | |
if (newVal && this.trResizeDelegate) { | |
this.trResizeDelegate(); | |
} | |
} | |
trResizeDelegate: () => any; | |
attached() { | |
switch (this.element.tagName) { | |
case "MD-INPUT": this.attachedMdInput(); break; | |
case "BUTTON": this.attachedButton(); break; | |
case "TR": this.attachedTr(); break; | |
} | |
} | |
attachedMdInput() { | |
let inputField = this.element.getElementsByClassName("input-field"); | |
if (!inputField) { | |
return; | |
} | |
let progress: Element = document.createElement("div"); | |
progress.innerHTML = "<md-progress type='circular' size='small' show.bind='value' style='position: absolute; left: 100%; transform: translateX(-100%);'></md-progress>"; | |
progress = progress.children[0]; | |
inputField[0].insertAdjacentElement("afterbegin", progress); | |
let view = this.templatingEngine.enhance(progress); | |
view.bind(this); | |
view.attached(); | |
} | |
attachedButton() { | |
let progress = document.createElement("div"); | |
progress.innerHTML = "<div show.bind='value' style='position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0.7; background: white; z-index: 998;'></div><md-progress type='circular' size='small' show.bind='value' style='position: absolute; left: 50%; transform: translateX(-50%); z-index: 999;'></md-progress>"; | |
progress.style.position = "relative"; | |
progress.style.display = "inline-block"; | |
progress.classList.add("button-wait-cursor-wrapper"); | |
this.element.insertAdjacentElement("beforebegin", progress); | |
let view = this.templatingEngine.enhance(progress); | |
view.bind(this); | |
view.attached(); | |
progress.appendChild(this.element); | |
} | |
attachedTr() { | |
let tr = this.element; | |
let firstTd = this.element.firstElementChild; | |
let progress = $( | |
"<div show.bind='value'>" + | |
"<div style='opacity: 0.7; background: white; width: 100%; height: 100%;'></div>" + | |
"<md-progress type='circular' size='small' style='position: absolute; left: 50%; top: 50%; height: 36px; transform: translateX(-50%) translateY(-50%);'></md-progress>" + | |
"</div>"); | |
this.trResizeDelegate = () => { | |
if (!this.value) { | |
return; | |
} | |
let pos = $(tr).position(); | |
$(progress).css({ | |
position: "absolute", | |
top: pos.top, | |
left: pos.left, | |
width: $(tr).css("width"), | |
height: $(tr).css("height") | |
}); | |
}; | |
this.trResizeDelegate(); | |
let view = this.templatingEngine.enhance(progress[0]); | |
view.bind(this); | |
view.attached(); | |
$(window).resize(this.trResizeDelegate); | |
progress[0].onclick = (ev) => { ev.cancelBubble = true; }; | |
firstTd.appendChild(progress[0]); | |
} | |
detached() { | |
if (this.trResizeDelegate) { | |
$(window).off("resize", this.trResizeDelegate); | |
this.trResizeDelegate = null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment