unobtrusive-javascript

How important do you think Progressive Enhancement is?

Progressive Enhancement is a web development methodology that not only allows greater portability and accessibility but in my opinion, makes the development process easier. What I want is to know what the rest of the community think of this approach. In particular: What do you believe is the minimum set of technologies that a web appli...

Unobtrusive javascript with jquery - good 10 minute tutorial?

I'm looking for a good 10 minute introduction to Unobtrusive Javascript using JQuery. I'm completely new to the concept, and I'd like to see how the event binding and such works. As some background, I'm looking to do a "remove this tag" system similar to what we have here on SO. Looking at the source, I didn't see any js, just an img ...

Associating data to a DOM element for jQuery

In a previous life, I might have done something like this: <a href="#" onclick="f(311);return false;">Click</a><br/> <a href="#" onclick="f(412);return false;">Click</a><br/> <a href="#" onclick="f(583);return false;">Click</a><br/> <a href="#" onclick="f(624);return false;">Click</a><br/> Now with jQuery, I might do something like th...

Does Low Pro Prototype DOM Builder work in IE?

Dan Webb's Low Pro UJS extension to Prototype offers the following elegant DOM Builder: var listItem = $li({ id : 'item-1' }, $strong("Some text") ); // returns a node equivalent to: <li id="item-1"><strong>Some text</strong></li> $('a_list').appendChild(listItem); While this works like a dream for u...

Correct way to pass a variable from the server backend to javascript?

I need to pass a variable that php is aware of to my javascript code and I'm wondering what the correct way to do this is. I already know that I could add this to the page generation: <script type="text/javascript"> var someJSVariable = <?php echo $somePHPVariable ?> </script> But I find this method to be more obtrusive than I'd like...

JQuery toggle VAT switching

Hi , I want to implement a VAT switcher as you can see on http://aria.co.uk top right corner although I want to do it on the client side only. Below is something I came up with, although I need to: switch VAT back and forth (my example goes just one way) save and read the toggled state from a cookie for persistency have it unobtrusiv...

Best way to signal my JS script is loaded

I have a JS script that will be hosted on my server and that others will embed in their html, i.e. ...<code for http://yoursite.com /> <script type="text/javascript" src="http://mysite.com/awesome.js" /> ...<code for http://yoursite.com /> My script surfaces an object with a bunch of properties accessible for use as a javascript Objec...

Delivering a javascript library for web developers

This is a broad-based question around delivering a javascript library that other web developers will use on their site. Here's the scope of my library: I'm providing a data service that's delivered in the form of a JS file. A similar implementation would be Google Analytics. Will always be hosted by me. Developers will simply use the ...

JQuery: Why Unobtrusive JavaScript / Document Ready function rather than OnClick event?

I've just started looking at JQuery. I don't have any AJAX in my web application at present. My existing JavaScript in my HTML looks like: <form ...> <p>Find what? <input ...></p> <div class="ButtonArray"> <a href="AddRecord.ASP&amp;Action=ADD">ADD</a> <a href="#" onClick="return MyFormSubmit();">FIND</a> </div> </form> This disp...

jQuery plug-in to hookup AJAX form - MUST provide error callback

Whats the best way to hookup AJAX functionality to an existing Form using jQuery and allow for an error handling callback. The jQuery.ajax(...) built in function has the following (useful) callback functions: beforeSend complete dataFilter error success I thought I'd found my answer with the jQuery.Form plugin...

Unobtrusive jQuery autocomplete in Rails

I'm using rails, but doing all my Javascript unobtrusively using jQuery in application.js. Unfortunately, this makes it quite difficult to reference URLs. For example, if I want to give a field autocomplete behavior, I have to hard-code the autocomplete URL in application.js since the rails url_for isn't available. Is it possible to ma...

Learning JavaScript for a total non-programmer

I code CSS/XHTML like it should be my mother language, and I do write valid, semantic code following guidelines of accessibility and such. But I want to learn Unobtrusive JavaScripting, but with a total non-programmer brain I need some motivation / tips / etc., like what's the best way to learn it, and how long does it take/did it take...

Best practices for using AJAX without Rails' built-in helpers?

In my blog application, some posts appear as excerpts -- i.e., the user sees the first (say) 500 characters, and can click a link to view the entire post. Here is the relevant partial: <% href = url_for post_path(:id => post) %> <h1 class="title"><%= post.title %></h1> <h2 class="published_on"><%= post.author %> wrote this <%= time_ago...

How do I implement google maps yelp.com style?

I have multiple locations (20+ per page) that need to be mapped on a single map. I would like to click on a link for the location that is not dynamically generated (for SEO purposes) that would open the info window for the respective marker on the map. Behavior should mimic http://maptheburg.com/ - but this map has the sidebar links dy...

Update two different parts of the page using unobtrusive JS (in Rails w/jQuery)

When the user clicks a sorting link on my blog, I want to use AJAX to both pull in new posts and update the sorting link section. This would be easy using RJS, but I want to keep my JS unobtrusive and respond to AJAX requests with only data (and no code). Here's what I'm doing now: $('a.order_by').livequery('click', function() { ...

Where to insert script blocks

The dillema is like this: If I try to fit all the scripts blocks on the masterpage (include page in some frameworks), every page gets a copy of every script (including the ones they don't need) and these quickly adds up and bloats the page size. If I include/insert script blocks where needed, javascript will be spread all over the proj...

How to unobtrusively update the page title with JS (in Rails)

Whenever I load a blog post onto the page with Ajax, I set the page <title> to "My Blog - BLOGPOST_TITLE". Of course "My Blog - " appears in my application layout as well. The question is, how do I tell my Javascript about the string "My Blog - " without duplicating it in my code? ...

So what if custom HTML attributes aren't valid XHTML?

I know that is the reason some people don't approve of them, but does it really matter? I think that the power that they provide, in interacting with JavaScript and storing and sending information from and to the server, outweighs the validation concern. Am I missing something? What are the ramifications of "invalid" HTML? And wouldn'...

How do I get a Rails link_to_remote tag to make a DELETE request when JavaScript is disabled?

I'm using the following code as a link to delete a todo in a simple todo list application I'm making: <%= link_to_remote 'delete', {:url => complete_todo, :confirm => 'Are you sure?', :method => :delete}, { :href => url_for(complete_todo), :method => :delete } %> It works fine when JavaScript is enabled, but when it's disabled it make...

Why does it say xxx is not a function

Hi All, why is this not ok? aContract = function(){}; aContract.prototype = { someFunction: function() { alert('yo'); }, someOtherFunction: some$Other$Function }; var some$Other$Function = function() { alert('Yo yo yo'); }; var c = new aContract(); c.someFunction(); c.someOtherFunction(); Firebug says c.some...