Archive for August, 2009

Scrolling to an element when outside of the viewport with prototypejs

Often times you’ll have be playing, say, videos with a list of videos down the page. If the list gets too long the video player becomes out of sight as the user scrolls down. This can be a big confuser to users: they click on a link to see a video and they don’t see anything happen because the video player is out of sight. Here’s what you can do: scroll to the video player if it is out of sight like so:

if ($("videoplayer").viewportOffset()[1] < 0) {
 Effect.ScrollTo('videoplayer', {duration: 0.2});
}

Requires both prototype and effects.js in scriptaculous.

  • Share/Bookmark

No Comments

Grab last item in XSLT for-each

This is simple and fun!

Here’s an example of doing something in all instances EXCEPT the last one. Reversing this is obvious:

 

Often times you want a horizontal rule in all instances except the last item. You can also use this method for adding a class name to the last item:

  • last
    • Share/Bookmark

    No Comments

    Best Way to Get Gmail in Ruby on Rails

    Gmail is not as easy as sendmail, unless you have this tutorial. This gem/tutorial is by far the best solution.

    action_mailer_tls

    There are a lot of solutions out there so it can be hard to know which to choose. I have tried many and found this to be dead simple. Takes 5 minutes to setup.

    • Share/Bookmark

    No Comments

    Ruby on Rails Time Saver – delete development.log

    When uploading your local build to a server delete your development.log file because they tend to get long and thus heavy on kilobytes.

    • Share/Bookmark

    No Comments

    Firefox 3.5 Supports Word-Break Break-Word

    Ever had a situation where you are dealing with long unbroken strings? For example, say you have to display user-entered web URLs. Sometimes the user will paste in a really long URL, and it keeps overflowing the container. You can make the parent container overflow: hidden but then it will crop the URL. A potentially better solution is to force the browser to introduce line-breaks mid-word.

    This has always been difficult to achieve cross-browser until now. Unlike most cross-browser quirks, this was one where Interenet Explorer actually had it right. Since IE 5.5, you have been able to use word-wrap: break-word to cause this behavior. Now, finally, Firefox has caught on. As of version 3.5, Firefox now supports this CSS property as well.

    Here is the recommended code to cause this behavior:

    white-space: pre-wrap; /* css-3 */
    white-space: -pre-wrap; /* Opera 4-6 */
    white-space: -o-pre-wrap; /* Opera 7 */
    word-wrap: break-word; /* Internet Explorer 5.5+ and Firefox 3.5+ */

    Source: UnBlog

    • Share/Bookmark

    , ,

    1 Comment