Posts Tagged ‘JavaScript’

Changing URL parameters with jQuery

September 20th, 2011

You can find plenty of resources about this topic just by googling the web, most of which will point to jQuery plugins.
But the fact is that it’s so easy to achieve this by simply using jQuery that you do not need a plugin.

The code is pretty much self explanatory:

/*
 * queryParameters -> handles the query string parameters
 * queryString -> the query string without the fist '?' character
 * re -> the regular expression
 * m -> holds the string matching the regular expression
 */
var queryParameters = {}, queryString = location.search.substring(1),
    re = /([^&=]+)=([^&]*)/g, m;

// Creates a map with the query string parameters
while (m = re.exec(queryString)) {
    queryParameters[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}

// Add new parameters or update existing ones
queryParameters['newParameter'] = 'new parameter';
queryParameters['existingParameter'] = 'new value';

/*
 * Replace the query portion of the URL.
 * Query.param() -> create a serialized representation of an array or
 *     object, suitable for use in a URL query string or Ajax request.
 */
location.search = $.param(queryParameters);

You can clearly improve the regular expression, but the one above meet my needs.

samaxesJS JavaScript library updates

April 5th, 2010

Both the TOC (Table of Contents) components from samaxesJS JavaScript library have been updated.

Changes include:

  • Reduced file size by removing duplicated code using a for loop when defining and processing indexes (1.8KB for the minified jQuery TOC plugin).
  • Added a new option: context, allowing the TOC to list headings from only a portion of the page.

Please report any bug you may find in the project Issue Tracking.

Stripes framework and jQuery Autocomplete

December 16th, 2008

I really enjoy jQuery. But finding the right UI widget can be a daunting task.
Autocomplete is one of those widgets.

I decided to share an asynchronous example on how to use the jQuery Autocomplete plugin with Stripes.

Here’s an example output:
Stripes and jQuery Autocomplete example
» Read more: Stripes framework and jQuery Autocomplete

Stripes framework and jQuery: AJAX forms and HTTP Session Validation

October 23rd, 2008

This example was greatly inspired by the Stripes and jQuery AJAX Forms article from Freddy Daoud, but with some nice improvements

Last week I was working on a new Stripes/AJAX example. It involves having a table listing entities, being the last row of the table a form for adding new ones.
The form gets submitted via AJAX, using jQuery, and the response is validated in order to check if the HTTP session is still valid.

If everything is OK, the list is refreshed and a success message appears. On the other hand, if validation errors occur, the list is refreshed and an error message appears.
Also, if the user’s session has expired on the server, an alert is shown to inform the user that his session is invalid, and the page is reloaded so the user can login once more.
» Read more: Stripes framework and jQuery: AJAX forms and HTTP Session Validation

samaxesJS JavaScript Controls

July 23rd, 2008

samaxesJS is a set of utilities and controls, written in JavaScript, for building rich interactive web applications.

The first extension is a dynamic Table of Contents script.

The TOC control dynamically builds a table of contents from the headings in a document and prepends legal-style section numbers to each of the headings:

  • adds numeration in front of all headings,
  • generates an HTML table of contents,
  • degrades gracefully if JavaScript is not available/enabled.

More information available in the project home page at Google Code Hosting.

IE7 JavaScript library

August 17th, 2006

Today I stumbled on an article from 5ThirtyOne about an IE7 JavaScript library simply called IE7.

IE7 is a JavaScript library to make IE behave like a standards-compliant browser. It fixes many CSS issues and makes transparent PNG work correctly under IE5 and IE6

Impressive…

JavaScript 2 and the Future of the Web

May 14th, 2006

Brendan Eich, creator of JavaScript, give a keynote at The Ajax Experience.

Ajaxian have placed the presentation online so everyone can read up on some of the thoughts and discussion on JavaScript 2 and more.

Here we got to hear from the mouth of someone deep into the ECMA process about what we are going to see in JavaScript 2 and importantly why:

Motivation for JS2

  • Fix problems in JS1 that bug people daily
  • A type system to enforce invariants
    • instead of writing/debugging lots of value-checking code
    • optional annotations, an extension to JS1
  • Programming in the large
    • Package system
    • Visibility qualifiers (namespaces, private internal public)
    • Optional static type checking
  • Support bootstrapping and metaprogramming
    • Self-host most of the standard objects
    • Self-host compiler front end and type checker
    • Reduce need for future ECMA Editions

As Brendan flicked through these slides, I couldn’t help buy realise how important the decisions are. These changes are probably going to profoundly effect all of our lives in the near future.

Brendan Eich Keynote from The Ajax Experience