Skip to content

Commit

Permalink
Upgrade to Dart 2
Browse files Browse the repository at this point in the history
+ update .gitignore
+ format code
  • Loading branch information
dvorapa committed Oct 3, 2018
1 parent 7317478 commit 6f95d5b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 38 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
# Files and directories created by pub
.dart_tool/
.packages
.pub/
build/
# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock

# Directory created by dartdoc
# If you don't generate documentation locally you can remove this line.
doc/api/

# Avoid committing generated Javascript files:
*.dart.js
*.info.json # Produced by the --dump-info flag.
*.js # When generated by dart2js. Don't specify *.js if your
# project includes source files written in JavaScript.
*.js_
*.js.deps
*.js.map
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.0

* Dart 2 support

## 0.5.0

* Resolved issues with Bootstrap
Expand Down Expand Up @@ -26,4 +30,4 @@

* **New** alert dialog
* **New** confirm dialog
* **New** prompt dialog
* **New** prompt dialog
4 changes: 2 additions & 2 deletions lib/dialogs/alert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import "dart:html";
import "../src/dialog_class.dart";

void alert([String message = ""]) {
Dialog alertDialog = new Dialog([new Text(message)], "Alert");
Dialog alertDialog = Dialog([Text(message)], "Alert");

alertDialog
..showDialog()
..okButton.focus()
..dialogBackdrop.onClick.first.then((_) => alertDialog.closeDialog());

querySelectorAll(".modal button").forEach((ButtonElement buttons) {
querySelectorAll(".modal button").forEach((Element buttons) {
buttons.onClick.first.then((e) => alertDialog.closeDialog());
buttons.onKeyDown.listen((e) {
if (e.keyCode == KeyCode.ESC) {
Expand Down
6 changes: 3 additions & 3 deletions lib/dialogs/confirm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import "dart:html";
import "../src/dialog_class.dart";

Future<bool> confirm([String message = ""]) async {
Completer c = new Completer();
Dialog confirmDialog = new Dialog([new Text(message)], "Confirm", true);
Completer c = Completer();
Dialog confirmDialog = Dialog([Text(message)], "Confirm", true);

confirmDialog
..showDialog()
Expand All @@ -16,7 +16,7 @@ Future<bool> confirm([String message = ""]) async {
confirmDialog.closeDialog();
});

querySelectorAll(".modal button").forEach((ButtonElement buttons) {
querySelectorAll(".modal button").forEach((Element buttons) {
buttons.onClick.first.then((e) {
if (e.target == confirmDialog.okButton) {
c.complete(true);
Expand Down
12 changes: 6 additions & 6 deletions lib/dialogs/prompt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import "dart:html";
import "../src/dialog_class.dart";

Future<String> prompt([String message = "", String value = ""]) async {
Completer c = new Completer();
Completer c = Completer();

LabelElement label = new LabelElement()
LabelElement label = LabelElement()
..classes.add("control-label")
..htmlFor = "dialogInput"
..text = message;
BRElement br = new BRElement();
InputElement input = new InputElement(type: "text")
BRElement br = BRElement();
InputElement input = InputElement(type: "text")
..classes.add("form-control")
..id = "dialogInput"
..value = value;

Dialog promptDialog = new Dialog([label, br, input], "Prompt", true);
Dialog promptDialog = Dialog([label, br, input], "Prompt", true);

promptDialog.showDialog();
input.focus();
Expand All @@ -27,7 +27,7 @@ Future<String> prompt([String message = "", String value = ""]) async {
promptDialog.closeDialog();
});

querySelectorAll(".modal button").forEach((ButtonElement buttons) {
querySelectorAll(".modal button").forEach((Element buttons) {
buttons.onClick.first.then((e) {
if (e.target == promptDialog.okButton) {
c.complete(input.value);
Expand Down
37 changes: 20 additions & 17 deletions lib/src/dialog_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ class Dialog {
bool cancelable;
String cancelName;
String okName;
DivElement dialog = new DivElement();
DivElement dialogBackdrop = new DivElement();
ButtonElement xButton = new ButtonElement();
ButtonElement cancelButton = new ButtonElement();
ButtonElement okButton = new ButtonElement();
DivElement dialog = DivElement();
DivElement dialogBackdrop = DivElement();
ButtonElement xButton = ButtonElement();
ButtonElement cancelButton = ButtonElement();
ButtonElement okButton = ButtonElement();

Dialog(this.content, this.title, [this.cancelable = false,
this.cancelName = "Cancel", this.okName = "OK"]) {
Dialog(this.content, this.title,
[this.cancelable = false,
this.cancelName = "Cancel",
this.okName = "OK"]) {
if (querySelectorAll(
"[href*='//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css']").isEmpty) {
LinkElement link = new LinkElement()
"[href*='//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css']")
.isEmpty) {
LinkElement link = LinkElement()
..href =
"//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"
"//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"
..rel = "stylesheet"
..type = "text/css";
document.querySelector("head").insertAdjacentElement("beforeEnd", link);
Expand All @@ -33,33 +36,33 @@ class Dialog {
..classes.addAll(["modal-backdrop", "fade"])
..style.zIndex = "auto";
dialog.children.add(dialogBackdrop);
DivElement dialogModal = new DivElement()
DivElement dialogModal = DivElement()
..classes.addAll(["modal-dialog", "modal-sm"]);
dialog.children.add(dialogModal);
DivElement dialogContent = new DivElement()..classes.add("modal-content");
DivElement dialogContent = DivElement()..classes.add("modal-content");
dialogModal.children.add(dialogContent);

DivElement dialogHeader = new DivElement()
DivElement dialogHeader = DivElement()
..classes.add("modal-header")
..style.border = "0";
xButton
..classes.add("close")
..text = new String.fromCharCode(215);
..text = String.fromCharCode(215);
dialogHeader.children.add(xButton);
HeadingElement dialogTitle = new HeadingElement.h4()
HeadingElement dialogTitle = HeadingElement.h4()
..classes.add("modal-title")
..text = title;
dialogHeader.children.add(dialogTitle);
dialogContent.children.add(dialogHeader);

DivElement dialogBody = new DivElement()
DivElement dialogBody = DivElement()
..classes.add("modal-body")
..nodes.addAll(content)
..style.paddingBottom = "0"
..style.paddingTop = "0";
dialogContent.children.add(dialogBody);

DivElement dialogFooter = new DivElement()
DivElement dialogFooter = DivElement()
..classes.add("modal-footer")
..style.border = "0";
if (cancelable == true) {
Expand Down
9 changes: 5 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: dialog
version: 0.5.0
version: 0.6.0
description: Modern alert, confirm and prompt dialog implementation
author: Pavel Dvořák <[email protected]>
homepage: https://github.com/dvorapa/dialog-dart
documentation:
environment:
sdk: ">=1.11.1 <2.0.0"
dependencies:
browser: ">=0.10.0 <0.11.0"
sdk: ">=1.11.1 <3.0.0"
dev_dependencies:
build_runner: ^0.10.0
build_web_compilers: ^0.4.0
7 changes: 3 additions & 4 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Meta Name="author" Content="Pavel Dvořák">
<Meta Name="description" Content="Modern alert, confirm and prompt dialog implementation">
<Meta Name="keywords" Content="dialog,dart,alert,confirm,prompt,package,dvorapa">
<Meta Name="version" Content="0.5.0">
<Meta Name="version" Content="0.6.0">
<Link Type="text/css" Rel="stylesheet" Href="style.css">
<Title>Dialog.dart</Title>
</Head>
Expand Down Expand Up @@ -78,7 +78,6 @@ <H2>License</H2>

<a href="https://github.com/dvorapa/dialog-dart/blob/master/LICENSE">The BSD 2-Clause License</a>

<Script Type="application/dart" Src="index.dart"></Script>
<Script Src="packages/browser/dart.js"></Script>
<Script Defer Src="index.dart.js"></Script>
</Body>
</Html>
</Html>

0 comments on commit 6f95d5b

Please sign in to comment.