Last active
December 16, 2015 04:05
-
-
Save mikebranski/3babbe35e66c1fc87289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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