Recent Posts
Tags
 

jQuery Mobile

jQuery Mobile

22:27 14 May in JavaScript, jQuery, JSON, Thomas' Toolkit
0 Comments

I’ve been on a jQuery Mobile based product for almost a week.  Its a revamp of a project I did 2 years ago.

The original system ran on WordPress just for the HTML shell, and my own custom JS, heavy on the AJAX, then later on jQTouch for mobile.  Its been a solid performer for about 2 years now, and a pretty hot item our clients, so there must be something to it.

But, times change, and I’m feeling that jQuery Mobile is evolved enough now to take a real run at it.

So far its been easy enough to learn, once you get by the whole ‘pageinit’ thing.  I’m only adapting the system, not rewriting it yet.  This job is “old brain in new body”.  For the moment, I’ve found this works to call custom JavaScript for each page:

$( document ).delegate( "#my_page_id",  "pageinit",  function() {
$.ajax(...); 
});

There after, watch your variable scope. 😉

I started writing JavaScript straight out, but these days I use jQuery almost entirely. So far as AJAX and element manipulation are concerned, it doesn’t get much easier, or lighter.

As to interchange, I’m using more JSON. I’m trying to avoid JSON strings in DB fields, but it ends up being viable in a pinch, especially given how tight my schedule is. Although just using it to move data around in code is quite appealing. I’m using JSON objects for several data elements, including various navigational objects, mostly coming out of PHP/MySQL. It’s PHP that makes JSON so inviting. An array in Javascript can’t hold as much data as a PHP array, but an object can hold more ordered segments of data. I toss multidimensional arrays around all the time, usually popping out to XML, but a few plugins I’m using need JSON objects to instanciate them.

var obj = {"arr":[]};

I use that bit a lot. Simple. Efficient. Once created (however you choose), obj.arr is an array that is just waiting for your data, and its really easy to move data from XML into it using jQuery and the lovely each() function, and using a simple ‘for loop’ in JavaScript, to move things out and on to the page. Watch.

//assemble object
var obj = {"arr":[]};
obj.arr[0].addr = 'http://www.google.com';
obj.arr[0].name = 'Google';
obj.arr[1].addr = 'http://www.bing.com';
obj.arr[1].name = 'Bing';

//process object using for loop and jquery
var $menu = $('#my_menu_container ul')
for(x in obj.arr){
$menu.append('
  • '+obj.arr[x].name+'
  • '); }

    With that code, we get:

    I think my week has been more than that however.

    Cy is bopping along. Henrietta (or Coco, or Baby ‘X’, as you like) is coming… soon. We are still working on the house. The renovation upstairs is almost done, and painting and decorating shall soon begin. I hope sincerely that it is all complete by the time the baby comes, but I have a feeling she is going to keep her own schedule.

    Work is going well.  In addition to the a fore mentioned project, I took a chunk of last week and this to try and wrap up someone else’s data project.  That thankfully has gone quickly.  It was a case of ‘too many cooks’.  Nothing a bit of homogenization couldn’t cure  Still, the work was fun. One can’t ask for more than that, I suppose.

    Its been cold the last few days, but should warm up again soon.  I’m mostly about the lawn right now, but still looking forward to more work around the house.  We have a major operation planned for next weekend:  Operation: Dumpster.  A big house clearing effort, in preparation for a rather large yard sale.  That I’ll be posting updates on, I promise.

    Have a good night.

    No Comments

    Post A Comment

    %d bloggers like this: