Skip to content

Commit

Permalink
show confirmation leaving the page
Browse files Browse the repository at this point in the history
  • Loading branch information
hmsk committed Nov 19, 2012
1 parent f733d4c commit 68b2ede
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions public/scripts/app.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();

});
1 change: 1 addition & 0 deletions views/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit 68b2ede

Please sign in to comment.