On a recent project, I had to trigger a certain behavior when a native HTML5 video had completed playing (i.e. reached the end of the video, manually stopping it should not trigger the behavior).
JavaScript
JavaScript Idle Detection
Recently, I needed to determine when a website visitor was idle for a certain amount of time. I thought this was an interesting problem and wanted to spend a little more time with JavaScript so I wrote some code for it.
JavaScript Distance Between Two Locations
When working with locations in JavaScript, you often have two sets of latitude/longitude coordinates and you need the distance between theme. This function will give you an approximate distance between theme (in miles by default).
WordPress Development Overlay
When doing WordPress theme development I find it helpful to overlay an image of the approved design on top of the code I’m working on. I use a reduced opacity on the image so I can see the code I’m working on. This helps me match things like font size and spacing. I’ve been doing […]
WordPress sanitize_title() in JavaScript
Update While this article details my exploration in recreating the WordPress sanitize_title() behavior in JavaScript, since it was originally written WordPress core has added cleanForSlug(), which is part of the npm package @wordpress/url. I recommend using cleanForSlug() over this code. I was working on a project where I needed the functionality provided by the WordPress […]
wp_localize_script Explanation
Despite the name, the wp_localize_script() function is a great way to pass a PHP value to your JavaScript code.
How to Disable JavaScript in Chrome
2014-08-29 UPDATE: Current version of Chrome has issue I’m seeing an issue where the Disable JavaScript checkbox is becoming unchecked on refresh (thus undoing the point of this post). More info at https://code.google.com/p/chromium/issues/detail?id=369844 Current fix seems to be “click Disable JavaScript a bunch of times” (yes, I realize this is a ridiculous fix) How to […]
jQuery filter Array Method
I really enjoyed Josh Clanton’s article Filtering Arrays with Array.filter on using the JavaScript filter method(). As he points out, Because the filter method is part of the ECMAScript 5 specification, it isn’t available in older browsers like IE8. Josh then lists a couple of options to bring this functionality into older browsers (i.e. IE < 9) […]