Rock, Paper, Scissors, Lizard, Spock in JavaScript

Simplify result function with math. http://jsfiddle.net/afrievalt/qBbJn/ . this function will also work with options = [“cockroach”, “nuke”, “shoe”], (from that 70s show) or any odd length array like options = [“water”, “fire”, “paper”, “rock”, “tree”, “metal”, “mud”] //todo: throw error if any index = -1

how to use addHTML function in jsPDF

First, you have to include jsPDF library, and also html2canvas or rasterizeHTML. Then, just create a jsPDF object and save to pdf the entire ‘body’ tag (or whatever): You can find more examples on the jsPDF website: http://mrrio.github.io/jsPDF/

ngular is automatically adding ‘ng-invalid’ class on ‘required’ fields

Since the inputs are empty and therefore invalid when instantiated, Angular correctly adds the ng-invalid class. A CSS rule you might try: Which basically states when the field has had something entered into it at some point since the page loaded and wasn’t reset to pristine by $scope.formName.setPristine(true) and something wasn’t yet entered and it’s invalid then the text … Read more

Why onbeforeunload event is not firing

The onbeforeunload event is not cancel-able, because of security reasons, but if an event handler function for the onbeforeunload event returns a string value, this text will be shown in a confirmation dialog box, where the user can confirm whether he wants to stay or leave the current page. Note that event listeners cannot be registered for the onbeforeunload event with the addEventListener and attachEvent methods (only … Read more

Detecting a mobile browser

Using Regex (from detectmobilebrowsers.com): Here’s a function that uses an insanely long and comprehensive regex which returns a true or false value depending on whether or not the user is browsing with a mobile. For those wishing to include tablets in this test (though arguably, you shouldn’t), you can use the following function: Using navigator.userAgentData … Read more