PPK in the BK on Mobile JavaScript
2011 April 16
- Comments
- Topics
-
I recently had the pleasure of seeing a true Web pioneer give a talk on mobile JavaScript. A Touching Look Into The Future Known As Today
brings Peter-Paul Koch (@ppk, creator of quirksmode.org) to Brooklyn to give an updated talk about his experience in the trenches testing JavaScript touch event support on various mobile devices. I'll attempt to distill it down to some key points.
Mouse events and touch events are blended on mobile
The three interaction modes, in the order of the most to least we know about them:
- Mouse
- Keyboard
- Touch
Event handling on the desktop is easy because the mouse and keyboard events rarely fire simultaneously. But with the advent of touch-screen devices, both touch and mouse events fire, a conscious decision to allow mobile users to browse the countless existing sites relying on mouse events for interaction.
If you want to make a distinction:
// desktop
element.onmousedown = dostuff;
// touch
element.ontouchstart = function() {
dostuff();
element.onmousedown = null;
};
Continue reading PPK in the BK on Mobile JavaScript
RequireJS: What Not To Do
2011 March 26
- Comments
- Topics
-
As with most things, using RequireJS wrong can be worse than not using it at all.
RequireJS is a modular script loader that lets you pull in multiple JavaScript files in an optimized way that cheats a few rules we've been used to when downloading resources in the traditional way on the Web. Not only does RequireJS have great API documentation, its Why page is a great read, and explains how they've arrived at their approach of using head.appendChild(script) to load JavaScript asynchronously.
After building The Shoshin Project (a simple single-page web app) which used Google Closure to bundle multiple JavaScript files/modules into a single request, the concept evolved into a more interactive, multiple-page site. As a team we decided to try out RequireJS on the new site, hoping to carry on the modular approach used in the original site without being forced to include all possible combinations of JavaScript modules on every page load.
In our first dive into things, we put our page enhancements like overlays, autocomplete, and so on into the RequireJS modular system. Shortly into it we noticed some strange behavior where it looked like some of our slower external scripts were blocking even the most simple page interactions from livening up.
Continue reading RequireJS: What Not To Do
jQuery Effect Sequencer
2010 November 01
- Comments
- Topics
-
I've got the opportunity to build a client-heavy web experience with a big emphasis on transitions and effects. This is probably something that would have been built using Flash just a short time ago, but today we're using everyone's favorite JavaScript library, jQuery.
Just before diving in, I attended jQuery Boston and got totally inspired by a few key talks on JavaScript architecture, mobile web apps, and one gnome-filled piece from Karl Swedberg titled jQuery Effects: Beyond the Basics. This was a really jam-packed presentation that had something for all levels of jQuery ninja. My favorite part was a little recursive function called sequencer that calls animations, one after the other, on a collection of elements. If you try to do something like this directly (without the sequencer):
$('#Gnomes').children().animate({height: '100px'}, 'fast');
jQuery is going to perform the animations simultaneously, which may or may not be desired. I grabbed the sequencer because I wanted to create a tiling-in effect for a list of items of a dynamic length. In the process, I generalized the sequencer a bit, so it works with not only animate, but the shortcuts we've all come to love such as hide/show, slideIn/slideOut, and so on, and packaged it as part of a small transitions framework that's hopefully going to allow me to do some rapid prototyping on the transitions in my site. Read on for the demo and github link!
Continue reading jQuery Effect Sequencer
Spellcheck Rich Text with GoogieSpell
2010 August 29
- Comments
- Topics
-
In an earlier post, I explained how to modify the GoogieSpell JavaScript spellchecker to work with text in HTML tags. For an introduction to Orangoo Labs' GoogieSpell, refer to that post. Based on feedback I received, it appeared worthwhile to show how to spellcheck rich text on demand. I'll explain how that's done with a popular editor, FCKEditor.
In retrospect, I shouldn't be surprised as this is a much more useful application of GoogieSpell. In fact, SCAYT, a similar tool to GoogieSpell (but requiring a license), has found its way into CKEditor, the successor to FCKEditor. As a bonus, I've included JavaScript that will integrate GoogieSpell with CKEditor, but I'll limit the detail here to the FCKEditor implementation.
Continue reading Spellcheck Rich Text with GoogieSpell
Sorting jQuery DOM Elements
2010 March 28
- Comments
- Topics
-
While updating the jQuery version referenced by a website I was working on, I found an interesting trick you can do with collections of DOM elements as of jQuery 1.3.2 (February 2009). Prior to this release, selecting a collection of DOM elements would return a plain old JavaScript object. Now, you get an array.
This may not jump out at you as exciting in and of itself, but for me the
ability to use array methods on these collections was really helpful. By writing a simple array sort method, I was able to grab one giant alphabetically ordered list of items from any number of smaller, categorized lists on my page, and then display that list in different ways on the fly.
Continue reading Sorting jQuery DOM Elements
1 2 Next>