Skip to content

Instantly share code, notes, and snippets.

@timfish
Created November 22, 2017 12:57
Show Gist options
  • Save timfish/f18fc53150740c24ef5c19bcaa67d4cc to your computer and use it in GitHub Desktop.
Save timfish/f18fc53150740c24ef5c19bcaa67d4cc to your computer and use it in GitHub Desktop.
ai-dialog-open blur
body.ai-dialog-open #main-content {
filter: blur(3px);
}
ai-dialog-overlay {
background-color: rgba(0,0,0,.2);
}
<template>
<require from="./app.css"></require>
<div id="main-content">
<h1>Dialog Repro</h1>
<button click.delegate="submit()">Open Dialog</button>
</div>
</template>
import {DialogService} from 'aurelia-dialog';
import {Prompt} from './prompt';
export class App {
person = { name: 'Test' };
static inject = [DialogService];
constructor(dialogService) {
this.dialogService = dialogService;
}
submit(){
this.dialogService.open({ viewModel: Prompt, model: this.person}).then(response => {
if (!response.wasCancelled) {
console.log('good');
} else {
console.log('bad');
}
console.log(response.output);
});
}
}
import { customAttribute, inject, TaskQueue } from 'aurelia-framework';
@customAttribute('draggable')
@inject(Element)
export class Draggable {
constructor(element){
this.element = element;
}
attached(){
console.log('attached draggable')
console.log(document.Hammer)
const manager = new Hammer.Manager(this.element.querySelector('ai-dialog-header'));
manager.add(new Hammer.Pan({ direction: Hammer.DIRECTION_ALL, threshold: 0 }));
manager.on('pan', e => this.pan(e));
}
pan(e){
// if there is no top set, dialog is still positioned relative
if(!this.element.style.top){
const {x,y} = this.element.getBoundingClientRect();
this.element.style.top = y +'px'
this.element.style.left = x +'px'
this.element.style.marginTop = '0';
this.element.style.position = 'absolute';
} else {
const top = parseFloat(this.element.style.top.replace(/px/, ''))
const left = parseFloat(this.element.style.left.replace(/px/, ''))
this.element.style.top = (top + e.srcEvent.movementY) +'px';
this.element.style.left = (left + e.srcEvent.movementX) +'px';
}
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app="main">
<h1>Loading...</h1>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script src="https://hammerjs.github.io/dist/hammer.min.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging()
.plugin('aurelia-dialog');
aurelia.start().then(a => a.setRoot());
}
<template>
<require from="./draggable"></require>
<ai-dialog draggable>
<ai-dialog-header>
<h2 style="margin:0;">Edit name</h2>
</ai-dialog-header>
<ai-dialog-body>
<input value.bind="person.name" />
</ai-dialog-body>
<ai-dialog-footer>
<button click.trigger="controller.cancel()">Cancel</button>
<button click.trigger="controller.ok(person)">Ok</button>
</ai-dialog-footer>
</ai-dialog>
</template>
import {DialogController} from 'aurelia-dialog';
export class Prompt {
static inject = [DialogController];
constructor(controller){
this.controller = controller;
}
activate(person){
this.person = person;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment