Archive for the ‘Javascript’ Category

Notes from the RJS Peepcode Screencast

Saturday, February 3rd, 2007

I recently finished watching the RJS Peepcode Screencast and boy does it kick butt. Here’s my notes from watching it:

  • simply helpful plugin generates dom ids based on object’s: @thing.dom_id – more info

  • use link_to_function + rjs in the view to generate js without an ajax call. example: link_to_function "Click Me", update_page {|page| page.alert "No postback!" }

  • call custom js functions with page.call page.call "my_func_name", param, anotherparam, etc

  • consider putting custom js functions that should be globally available in public/javascripts/application.js (this is included by javascript_include_tag :defaults)

  • page.select will fetch things by id or class page.select('#tasks div a').each do |item| page.hide item end

  • use a method name in a string var as a function call page.send 'method_name', param

  • replace/replace_html for outside/inside an element with page.replace_html page.replace_html 'task_totals', @task_totals

  • insert your own custom js into the page with < < page < < "my_js_method()"

    • or - page < < %( my_js_method(); function some_other_func() { ... } )
    • or - page < < render :partial => "update_totals"
  • assign js vars with values from ruby with page.assign page.assign 'task_totals', @task_totals

  • keep users informed of ajax calls during link_to_remote calls with :loading and :complete callbacks link_to_remote "Click Me", :url => tasks_url(:action => 'hello'), :loading => "Element.show('loading_div')", :complete => "Element.hide('loading_div')"

  • use rjs directly in the controller with render :update render :update do |page| page.alert('whatever') end

  • test rjs with ARTS

ETech 2006 Notes

Tuesday, March 7th, 2006

I’m posting all of the notes that I take, as well as any I can find shared by others via SubEthaEdit over at http://avantbard.com/docs/etech2006/.

So far, pretty fun.

Google Maps + Geocaching Improvements

Thursday, June 30th, 2005

So, it looks like Google Maps recently changed a bit of their interface that breaks my previous GMapsShowCenter bookmarklet. Luckily, we don’t even need that bookmarklet anymore.

A friendly fellow geocacher made a slight tweak to my GoogleMapIt bookmarklet that takes care of adding the point to the map (basically you just need to pass in the point coordinates in the query string with the ‘q’ variable).

Here’s the updated version, which works great. Thanks to geocacher Sugarcrum for the tweak!

GoogleMapIt <- drag this to your bookmark bar.

GoogleMaps Geocaching Bookmarklets

Monday, June 6th, 2005

This weekend, I spent a few hours learning a little bit about hacking Google Maps and making my own bookmarklets to help with Geocaching. Here’s what I came up with…

GoogleMapIt – a bookmarklet that finds the first instance of Latitude/Longitude coordinates (written in degrees and minutes) on a web page, converts them to decimal degrees, and opens a new window showing that location using Google Maps (Google Maps wants decimal degrees for loading lat/lon maps).

GMapsShowCenter – a bookmarklet that creates a location marker in the center of the Google Map you’re currently viewing. Helpful for when you’ve just loaded some latitude/longitude coordinates into Google Maps and need to see the marker for where they point to (by default, Google Maps doesn’t show a location marker when you load lat/lon maps).

Example usage:

  1. Add GoogleMapIt and GMapsShowCenter to your browser’s bookmarks bar by dragging these links there (or add to Favorites in IE).
  2. Load the page for any geocache, like The White Duck (my cache).
  3. Click on the GoogleMapIt bookmarkelt in your browser’s bookmark bar.
  4. Click on the ShowCenterMarker bookmarklet.
  5. Admire the location of the cache.

Safari Backslash Replacement Bug

Sunday, June 5th, 2005

Been working on some javascript bookmarklet code and found this bug in Safari (I’m using version 2.0 (214)).

In the href value of any anchor tag (link), all backslash characters appearing BEFORE a question mark character get replaced with forwardslash characters

this behavior manifests when: - you drag the link to the bookmark bar to make a bookmarklet - you copy the link to clipboard - you look at the link href in the in status bar

this behavior does not seem to manifest when: - you click on the link

Example: The href of <a href=”http://foo\bar\?baz\quux”>TestLink</a> goes from “foo\bar\?baz\quux” to “foo/bar/?baz\quux” – Try It: TestLink

Why does this suck? If you’re writing some javascript code that you’d like users to use as a bookmarklet, and that javascript code includes some regular expression with some backslash characters in it, your regex will get messed up when the user drags your bookmarklet link to their bookmark bar.

Javascript RPC Links

Monday, November 15th, 2004

Linkdump of some current JS RPC related stuff I’ve been reading:

Youngpup

Thursday, October 28th, 2004

Congratulations to Aaron Boodman, who joins the ranks of UI team at Google. (via massless)

Some of his javascript code examples are very cool. I especially like the transparent menus.

UPDATE: The transparent menus dont work in Safari. =~(

Library Lookup

Thursday, September 16th, 2004

Man, Library Lookup (via 43Folders) is a really fucking cool application of bookmarklets working for you. Basically, you add a bookmarklet to your browser’s bookmark bar for your local library. Then you browse a book title at Amazon and click the bookmarklet. New window pops up with that book in your library’s catalog, so you can place a hold on it.

Super. Fucking. Cool.

Mozilla/Firefox: Javascript Console In Sidebar

Tuesday, September 7th, 2004

Want to load the Javascript Console in the sidebar instead of using it in a seperate window (I sure did). Thanks to a tip from Jesse Ruderman (via Leonard) at squarefree.com for the info. Here’s how:

  1. Make a bookmark with this address: chrome://global/content/console.xul
  2. Go to Bookmarks->Manage Bookmarks, right-click the new bookmark, select Properties
  3. Check the ‘Load this bookmark in the sidebar’ box

That’s it; you’re done. Now go enjoy viewing your page and the js console in the same window!

Javascript Styling

Wednesday, June 16th, 2004

For anyone else who might be trying something similar:

I was working on a little project with Javascript, and I needed to be able to change a DOM element’s style by changing its class attribute. So, I tried to use:

element.setAttribute('class', 'className')

but that didn’t work in all browsers; it worked fine in Safari and Mozilla, but IE6 wasn’t happy with it. IE6 didn’t throw any errors, mind you, and if I tried:

alert(element.getAttribute('class'))

it appeared that the class did get changed properly, but IE just wasn’t re-rendering the element with the new class applied to it.

“Boo-urns!” I thought, but then I stumbled upon another way to do it:

element.className='className'

did the trick! So, now my code works in Safari, Mozilla, and IE6. w00t!

Oh, and if you’re curious about what I was up to, I’ll tell you. Basically, I was trying to create a function that would filter a table’s rows in realtime (as you typed) based on the contents of a text search box. If you’re not sure what I mean, think about how iTunes filters your Library when you type in the search box. That’s what I was trying to do.

Want to see a demo? Click here to see it in action.