Permalink
Browse files

show confirmation leaving the page

  • Loading branch information...
1 parent f733d4c commit 68b2ede4399118f2192ef8e3f8f6f82645f1d969 @hmsk hmsk committed Nov 19, 2012
Showing with 22 additions and 0 deletions.
  1. +21 −0 public/scripts/app.js
  2. +1 −0 views/index.haml
View
@@ -1,4 +1,6 @@
$(function(){
+ if (typeof GithubPreview === 'undefined') GithubPreview = {};
+
// keep text and preview at 100% height
function resize() {
var height = $(window).height() - $("#header").outerHeight() - 20;
@@ -85,4 +87,23 @@ $(function(){
showHelp();
}
});
+
+ // confirmation
+ function setupConfirmation() {
+ GithubPreview.changedForm = false;
+ $(window).bind('beforeunload', function(e) {
+ if (GithubPreview.changedForm) {
+ console.log(e.clipboardData);
+ return 'You have uncopied changes.';
+ }
+ });
+
+ $('#text').bind('input', function() {
+ GithubPreview.changedForm = true;
+ }).bind('copy cut', function() {
+ GithubPreview.changedForm = false;
+ });
+ }
+ setupConfirmation();
+
});
View
@@ -21,6 +21,7 @@
%a#showhelp{:href => "#"} Show Formatting Help
:javascript
function getText() {
+ GithubPreview.changedForm = false;
return $('#text').val();
}
%object#clippy{classid: "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", width: "110", height: "14"}

0 comments on commit 68b2ede

Please sign in to comment.