From 7795a6dfbc87f708089630dbd4d538f0b15f02ac Mon Sep 17 00:00:00 2001 From: Daniel X Moore Date: Sun, 21 May 2017 09:58:55 -0700 Subject: [PATCH 1/9] This commit intentionally left blank From 9cf31c5285079180edad5ad81ccf4984ac8b7c18 Mon Sep 17 00:00:00 2001 From: Daniel X Moore Date: Sun, 21 May 2017 09:59:03 -0700 Subject: [PATCH 2/9] :crown::purple_heart: Updated at https://danielx.net/editor/ --- dirty.coffee | 29 +++ dirty.coffee.md | 34 --- download.md | 2 +- editor.coffee | 523 ++++++++++++++++++++++++++++++++++++++++++++ editor.coffee.md | 527 --------------------------------------------- main.coffee | 43 ++++ main.coffee.md | 50 ----- pixie.cson | 3 +- test/editor.coffee | 2 +- 9 files changed, 598 insertions(+), 615 deletions(-) create mode 100644 dirty.coffee delete mode 100644 dirty.coffee.md create mode 100644 editor.coffee delete mode 100644 editor.coffee.md create mode 100644 main.coffee delete mode 100644 main.coffee.md diff --git a/dirty.coffee b/dirty.coffee new file mode 100644 index 0000000..fa9de96 --- /dev/null +++ b/dirty.coffee @@ -0,0 +1,29 @@ +module.exports = (I, self) -> + # TODO: May want to not stash this on I, possibly have a volatileAccessor? + self.attrAccessor "savedCommand" + + self.extend + dirty: -> + self.savedCommand() != self.lastCommand() + lastCommand: -> + self.history().last() + markClean: -> + self.savedCommand self.lastCommand() + + self.markClean() + + # HACK: This assumes we're the only app in the page + # NOTE: Track `prompted` so in an iframe it's less likely to trigger twice + prompted = false + window.addEventListener "beforeunload", (e) -> + unless prompted + if self.dirty() + e.returnValue = "Your changes haven't yet been saved. If you leave now you will lose your work." + prompted = true + + setTimeout -> + prompted = false + + return e.returnValue + + return self diff --git a/dirty.coffee.md b/dirty.coffee.md deleted file mode 100644 index b19eeda..0000000 --- a/dirty.coffee.md +++ /dev/null @@ -1,34 +0,0 @@ -Dirty -===== - -Handle dirty tracking and onbeforeunload event for editors. - - module.exports = (I, self) -> - # TODO: May want to not stash this on I, possibly have a volatileAccessor? - self.attrAccessor "savedCommand" - - self.extend - dirty: -> - self.savedCommand() != self.lastCommand() - lastCommand: -> - self.history().last() - markClean: -> - self.savedCommand self.lastCommand() - - self.markClean() - - # HACK: This assumes we're the only app in the page - # NOTE: Track `prompted` so in an iframe it won't trigger twice - prompted = false - window.addEventListener "beforeunload", (e) -> - unless prompted - if self.dirty() - e.returnValue = "Your changes haven't yet been saved. If you leave now you will lose your work." - prompted = true - - setTimeout -> - prompted = false - - return e.returnValue - - return self diff --git a/download.md b/download.md index 0b56ec0..73eb595 100644 --- a/download.md +++ b/download.md @@ -50,4 +50,4 @@ Pixi Paint is [open source software](https://github.com/STRd6/pixel-editor). > $(".content").eq(0).empty() > .append($ "

", text: "Live Demo") > $(".content").eq(1).empty() -> .append($ "