jQuery – lazy load (or effect) when an element is scrolled into the viewport

1. Implement a test to determine if the element is within the viewport. This one works. 2. Find a throttle or debounce function. Here’s my take, and underscore’s. 3. Create a function that uses the method in #1 to test if the element is visible, then perform your action (load an image, animate, add more […]

JavaScript – how to remove array elements while in a loop

This is actually a bit more simple than it seems. The key points are: 1. Decrement the iteration count when you splice out an element 2. Remember to test .length during the loop’s conditional test (contrary to normal best-practice).

POC: http://jsfiddle.net/moagrius/983N2/

JavaScript – detect support for background-size: cover

Most of the other solutions worked generally, but gave false negatives (e.g., IE9 does support it, but most test would indicate it did not). Here’s what seems to work so far, for me:

If you just use the second test (in the if block), old IE will report true – the first test is […]

Android – Accordion Widget

I’ve published a new Android widget, for API’s later than 3 (although we could swap out the animator to support older versions if necessary). The widget manages the layout and display state of arbitrary Views so is completely customizable. As always, it’s available on github.

PHP – RegexRouter

PHP Routing class that translates any valid PCRE into a closure, in 14 lines of wholesome goodness For the impatient:

Android – draw single or separate borders on Views

Just subclass the View type you’re using, and override on Draw with a quick call to canvas.drawLine. Remember to call super.onDraw first, so that the text or image or standard contents is rendered beneath your border. Also, ViewGroups will need to have setWillNotDraw( false );

Android – dynamic Fragment not filling parent

If, during onCreateView, you’re using the ‘new’ operator to instantiate a View instance (rather than inflating from XML, and/or using the attachToRoot parameter), your fragment’s View will be given default layout parameters of WRAP_CONTENT. If your content is smaller than the screen, this can look odd. Since you’re not directly adding the view to the […]

Android – event dispatching with LocalBroadcastReceiver

If your background is with ECMA languages (JavaScript, ActionScript), passing data around the Android environment can get a little confusing. Fortunately, there’s a class that makes things a little more familiar – LocalBroadcastReceiver. Strangely, this is only available in the support library, but that’s pretty much a requirement for most apps, and is in fact […]

Android – custom addView behavior

In many widgets, one particular ViewGroup should contain all the “content”, while other Views might serve as containers, controllers, navigation elements, or decoration. For example, for short, scrolling ListView-like widgets, it can be easier to wrap a LinearLayout in a ScrollView, rather than worrying about adapters and header views… This technique allows you to create […]

Create a Virtual Host on Windows

While you can often stick a project in a subdirectory of your htdocs and access from localhost/project, that can be inconvenient (e.g., assume leading slashes from absolute-from-root pathing, like /path/to/file.ext). It’s simple enough to create a virtual host like http://project.local or http://project.dev. 1. Open httpd-vhosts.conf (usually in your Apache install directory, under conf/extra… note that […]