Skip to content

Instantly share code, notes, and snippets.

@mikebranski
Last active December 16, 2015 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikebranski/3babbe35e66c1fc87289 to your computer and use it in GitHub Desktop.
Save mikebranski/3babbe35e66c1fc87289 to your computer and use it in GitHub Desktop.
// Super swanky pseudo-code that prevents customers like me from losing their support message
// when they fat finger the wrong button and navigate away before they're done.
// Making some assumptions about Simple's code. :D
var Simple = Simple || {};
Simple.confirmLeavingSupportMessage = "Hold up! You'll lose what you started typing if you leave.";
// Checks if the customer has started typing a message to support.
Simple.hasDirtySupportMessageField = function() {
return !!document.querySelector('#ChatView #chat-body').value.trim();
};
// This _is_ what it's called, right?
Simple.awesomeNavigationFunction = function() {
// Before navigating away, make sure the customer hasn't started a support message that would be lost.
if (this.hasDirtySupportMessageField() && prompt(confirmLeavingSupportMessage)) {
return false;
} else {
// Continue with whatever navigation logic needs to happen.
}
};
// <3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment