Raymond Camden's Blog Rss

Context Menu Example with jQuery Mobile

3

Posted in Mobile, Development, jQuery, JavaScript, HTML5 | Posted on 05-23-2012 | 885 views

Yesterday a reader asked me about building context menu support for images within a jQuery Mobile operation. Turns out it's pretty easy. Obviously there is no such thing as a right click menu on a touch device. That being said - the convention that most mobile applications use is a "taphold" listener. You touch the item with your finger and wait. In a second or two, the context menu pops up. The taphold event is trivial to use in jQuery Mobile (with a caveat I'll get to in a second), but what isn't as trivial is decided what UI to use. jQuery Mobile will - soon - have a popup UI item. For now though I decided on the excellent SimpleDialog2 plugin by JTSage. Let's look at an example.

Creating watermarked images in PhoneGap

4

Posted in Mobile, jQuery, JavaScript, HTML5 | Posted on 05-22-2012 | 685 views

A reader asked me if it was possible to watermark images (like those taken with a camera) in PhoneGap. This is rather trivial using Canvas (hey, it does have a use!) so I whipped up the following example to demonstrate it in action.

cfObjective 2012

4

Posted in JavaScript, HTML5, ColdFusion | Posted on 05-20-2012 | 1,342 views

Another year and another cfObjective is behind me. Every year this conference gets better and this year was no exception. The location is great (even with it under heavy remodeling), the food was great (although did they really need to feed me half a chicken on the last day!), and of course, the content continues to be very well done and very interesting. My thanks to the entire team at cfObjective for their hard work and dedication in helping create this year's conference.

While I attended many sessions, here is a short list of what I thought was interesting and my take aways from each:

  • Simeon Bateman presented on "Enterprise JavaScript Applications" and Node.js. His first presentation was a good overview of the tools that can help you build JavaScript applications. He demonstrated multiple things, including Backbone. I've seen that before but I think I'm going to play around with it a bit more. As for Node - I don't think I've been shy about my disappointment around Node. Not so much in the technology but how it is 'marketed' and presented to other developers. Sim did show the classic HTTP server example (the one I complain about), but then moved into much more interesting areas with his discussion of Connect and Express. I found these pretty interesting, but then Sim went on to discuss where he thought Node.js could be most useful - as a complement to other server-side languages (like ColdFusion) by providing highly performant network type services (like websockets) via Socket.io. He focused on the practical use cases for Node and that to me is what really made it seem better.
  • I only caught one presentation by Elliott Sprehn, but it was a good one. He talked about "Production Ready JavaScript" and some of the issues you face when you get past the 1000-line mark in your JavaScript files. I found his discussion of testing and logging of user actions in JavaScript fascinating. I plan on trying to implement, and blog, some of the things he discussed.
  • Charlie Arehart gave a great talk on ColdFusion under Tomcat. I really had no idea how much Tomcat could do.
  • Mark Mandel talked about Closures in ColdFusion 10 and blew my mind. I'm not discussing it here because it was too much. I've got another blog entry just on that for later this week.
  • I had seen Dave Ferguson talk on security before - but it is always a good idea to be reminded of just how much work is involved in creating a secure site. I especially liked his fact versus myth approach.
  • I saw Scott Stroz present on "How to Pimp Out Your Model" and PhoneGap. I've seen the first presentation before, but I really enjoy how he brings the concepts of MVC to a simpler, easier to understand level. I'm still approached by people having trouble wrapping their heads around the concept and if you can see Scott present on it - do so. Obviously I'm already familiar with PhoneGap, but Scott's presentation was very polished and has encouraged me to bring mine up to a higher level.

There were even more great presentations, but as I have to go catch the Super Shuttle I'm going to wrap it up here. I've said it before but I'll say it again. cfObjective is an incredible conference and well worth your money and time. I cannot encourage my readers enough. Whether you want to learn more about ColdFusion or JavaScript, it is a great opportunity to both learn and network.

Some thoughts on organizing a large jQuery Mobile project

7

Posted in Mobile, Development, jQuery, JavaScript, HTML5 | Posted on 05-16-2012 | 1,793 views

Ben Forta pinged me with an interesting question (and when the Forta pings you, you respond) that I thought I'd share here. It's one of those "best practices" questions that really has no best answer, so as always, I'm very eager to hear what my readers have to say. Don't feel afraid to tell me I'm completely off my rocker - that makes for fun conversation. Ok, so the question:

I have a JQ+jQM=PG app. It started off as 2 small pages and 50 lines of code, and is now 10 pages and over 1000 lines of code (excluding lots of .js libraries, some my own and some downloaded, that are all included).

My question simply is how would you go about organizing the code? Each "page" in its own HTML file? Would you put page supporting event handlers with those pages? What about handlers that use JQ to manipulate other pages? Separate all JavaScript in included files? And actually, how the heck do you even use JQ to manipulate controls in another page?

I know there is no right or wrong answer, but I am about to start refactoring this entire mess, so ... any thoughts you'd like to share?

Adding "Filter as you type" support to IndexedDB

Posted in Development, jQuery, JavaScript, HTML5 | Posted on 05-14-2012 | 1,572 views

One truly disappointing aspect of IndexedDB is that there is no (simple) support for search across your data. It is very much based on the idea of knowing your keys and fetching data based on those keys. You can easily retrieve the "Ray" user object, but you can't search for user objects that have an age within a certain range and a skill property of so and so. That's not to imply you can't do some sorting and filtering though.

IndexedDB supports the idea of key range objects. As you can probably guess, these allow you return objects based on a range of values that match with a particular index. Remember that IndexedDB objects can have any number of properties, but you have to specify which are indexed. And now you know a good reason why - it gives you a chance to filter later on.

Ranges can go in either direction and can be inclusive or exclusive. By that I mean, you can say "Anything object with a name 'above' and including Barry" or "Anything object with a name 'below' Zelda but not including that name." You can also combine both and get a single object too.

For my use-case, I wanted to use a range filter so that I could support 'filter as you type'. My data consists of notes that include a title, body, and created property. I'm not going to go through the steps of setting that up as my previous blog entries (linked at the bottom) went over most of the detail there. Instead, let's focus on how I built in the 'filter as you type' metaphor.

To begin with, I had a function that handled "get all" and displaying the data. It worked by opening a cursor and looping while data existed. Here's how that version looked:

In order to support a bound range, you have to change how you open your object store (remember, think of this like a database table). When we just get everything, we run openCursor on the objectStore (line 18 above). When we want a bound list of data, we get an index first (this is the property we said we wanted to be able to filter on), create the range, and then open a cursor on that. So with a small amount of work, we can update our displayNotes function to take an optional filter. (Note that I also switched to a table display. The change in HTML isn't terribly important here so I won't cover it.)

Focus on lines 31 to 40. You can see the different ways to open the cursor. Note specifically we do our binding based on an input string, like "ra" and append "z" to give an end to the range. So typing in "ra" means we want all notes with a title from "raa" to "raz".

Outside of that - the code is identical. I moved the success portion into a new inner function (handleResult), but it works the same no matter how I get the cursor itself.

You can demo this yourself by hitting the demo button below, but as before, this is Firefox only due to - what I believe - is a bad implementation in Chrome. (I think it could be made to work in Chrome, but as I'm building these examples to help me learn more about IndexedDB, I'm fine supporting the most compatible browser.)

You can find the complete source by .... viewing source. ;)

Example of invokeAndPublish with WebSockets and ColdFusion 10

Posted in jQuery, JavaScript, HTML5, ColdFusion | Posted on 05-11-2012 | 1,821 views

While preparing for my presentation earlier this week on WebSockets and ColdFusion 10, I ran into an issue trying to wrap my head around one of the features: invokeAndPublish. The docs describe it like so:

Using CFC data with Handlebars

11

Posted in jQuery, JavaScript, HTML5, ColdFusion | Posted on 05-11-2012 | 2,013 views

Earlier this week Steve wrote to me asking how to use data retrieved in a ColdFusion Component in a Handlebars template. While ColdFusion makes it trivial to serve up query data via JSON, the result format isn't always easy to use in JavaScript utilities. Here's a quick example I wrote that demonstrates how to work around this.

Setting up console debugging for PhoneGap and Android

9

Posted in Mobile, Development, JavaScript | Posted on 05-10-2012 | 2,149 views

In case you haven't figured it out yet, debugging in mobile is "sub-optimal". (Whatever you do - don't do a Google Images search on sub-optimal.) Brian Leroux has an epic presentation on the topic and I highly encourage taking a look through it. I thought I'd share how I'm debugging in PhoneGap and Android right now.

To be clear - this is a sucky way of doing it. "Sub-optimal" is being too nice. Whenever possible I do as much work as I can on the desktop. But when I get desperate and need to test something on a device, I end up resorting to console.log messages. I know this is only one step better than a bunch of alerts, but I thought it might be useful to show how this is done with Android and some tips to make it a bit more palatable.

Recording, slides, and code from my WebSockets presentation

2

Posted in Development, JavaScript, HTML5, ColdFusion | Posted on 05-09-2012 | 2,004 views

Enjoy. I'm going to have some followup blog posts on this coming up this week.

Recording URL: http://experts.adobeconnect.com/p459pvx19cw/

The demo files may be found at the bottom of this blog post.

Transcripts from PhoneGap Session

4

Posted in Mobile, Development, JavaScript, HTML5 | Posted on 05-08-2012 | 2,388 views

First off - a huge thank you to everyone who came to our PhoneGap Open Q and A today. We had more than 50 attendees for most of the two hour block which I think is a great turnout. We even had a troll (for a few minutes), so that means we must be doing something right!

The questions were very interesting. I noticed lots of attention around notifications and push, two areas I've not really dug into yet. I also noticed a few questions on the front-facing camera. (According to Andrew, on devices with two cameras, the native UI should simply prompt you when you request the camera.)

The Q and A transcript, as well as the more random general chat, are attached as zip files below.

As always - if you have any feedback about the session concerning how we could improve it, just let me know in the comments below.

p.s. I had a few requests for plain text versions. Here is a plain text version of the Q and A and here is a plain text version of the chat.