My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Extensions  
Extending jQTouch with extra functionality
Featured
Updated Dec 22, 2009 by RBoulanouar

Extensions (beta)

Extensions allow any developer to easily extend jQTouch with additional functionality. Including an extension is easy, simply include it in the <head> of your document, after including the base jQTouch script:

    <script src="jqtouch/jqtouch.js" type="application/x-javascript" charset="utf-8"></script>
    <script src="extensions/jqt.location.js" type="application/x-javascript" charset="utf-8"></script>

Included Extensions

  • Location Provides access to geo-location features in iPhone 3.0. See demos/ext_location for usage.
  • Floaty Allows the user to create a "floaty" bar. See demos/ext_floaty for usage.
  • Offline A JS debugger for offline capable apps. See also: OfflineSupport
  • Autotitles Auto set the title in the toolbar from referrer

Creating Extensions

The following shows the typical structure of a jQTouch extension:

(function($) {
    if ($.jQTouch)
    {
        $.jQTouch.addExtension(function Counter(jQTouch){
            
            var mycount = 0;
            
            function addOne() {
                ++mycount;
            }
            
            function getCount() {
                return mycount;
            }

            return {
                addOne: addOne,
                getCount: getCount
            }
        });
    }
})(jQuery);

There are a few things happening here. First we wrap the overall code in an anonymous, self-executing function, so we can cleanly substitute the dollar sign ($) for the jQuery namespace. This is general good practice when working with jQuery.

Specific to jQTouch, we call $.jQTouch.addExtension(), and pass it a function. The function will be run each time a new jQTouch object is created, (var jQT = new $.jQTouch()), and receives a copy of the jQTouch object as a parameter. The function can store local variables (var mycount) and can attach public functions/variables to the jQTouch object, by returning an object. For example, with the above extension, we could do this on our page:

$(document).ready(function(){
    var jQT = new $.jQTouch();
    jQT.addOne();
    jQT.addOne();
    
    console.log(jQT.getCount()); // 2
});

Obviously, this is an simple example, but with the ability to use jQuery $.fn-style plugins, run on instance initialization, and directly extend jQTouch's public functions/attributes, plugins can be quite powerful. This support is extremely new to jQTouch, so I really appreciate any feedback/questions in the comments below.

Comment by sha...@gmail.com, Oct 26, 2009

Has anyone written extensions?

Comment by project member davidcol...@gmail.com, Oct 26, 2009

There are a couple included with jQTouch, and I know of a few in development.

Comment by brickysam26, Nov 2, 2009

Here's a couple extensions that I ported for jQTouch from another code base http://cubiq.org/slideing-div-on-iphone-ipod-touch/5:

Sliding: Sliding

Scrolling: Scrolling

Scaling: Scaling

Comment by YouCount...@gmail.com, Nov 24, 2009

Brickysam26 your code for scrolling does not work for me. Do you have a working example anywhere or can you upload one please?

Comment by brickysam26, Dec 1, 2009

Sorry, for the confusion, my original extension didn't handle a scrolling div on the main page automatically, only on inserted pages, I have updated them to also check the main page nodes. I also have a short demo for vertical scrolling that you can look at, I will try to upload a better example of all of the extensions in the future.

Example: Example

Sliding: Sliding

Scrolling: Scrolling

Scaling: Scaling

Comment by brickysam26, Dec 1, 2009

Additionally, you have to use at least Revision: 118 of jQTouch in order for the extensions to work.

Comment by rexe...@gmail.com, Dec 2, 2009

For me also scrolling example doesn't work. Using jQtouch beta 2. Do I need to use scrolling.css file? I have to download it? From Where? Or there is some other example?

Comment by brickysam26, Dec 3, 2009

I started a project for these extensions http://code.google.com/p/jqextensions/. I haven't had much time yet to document them, but I did upload an example and the previously mentioned scrolling.css (which consists of the css at the top of the extension pages). Feel free to comment or report issues there. Look in the source for the updated versions of each of these files.

Comment by dylan.th...@gmail.com, Dec 3, 2009

Anyone have any ideas for implementing a menu bar at the bottom that is persitance and remains in position even when scrolling? I guess you could place it in a frames and have the top frame contain the actual jqtouch instances. I know a menu bar would be high on my priority list. Any thoughts?

Comment by nimbus.s...@gmail.com, Dec 7, 2009

@dylan.thurston Do you mean like AppleInsider when viewed with an iPhone or in Safari with the iPhone/iPod Touch user agent?

Comment by Abid.Aqu...@gmail.com, Dec 8, 2009

Hi, I have checked the scroll extension with latest revision 121 but its not working. Any help please?

Comment by parcej...@gmail.com, Dec 10, 2009

Can I use extensions to change an option that was initialized from false to true? I initialize the option useFastTouch: false. Later, when I go into a specific DIV, I want to make it true. Is that possible?

Comment by brickysam26, Dec 13, 2009

Abid, Please refer to the example in the project page for the extensions that I wrote. You can find it here http://code.google.com/p/jqextensions/downloads/list

Comment by tonyonhi...@gmail.com, Jan 25, 2010

@brickysam26 I'm using the scroll extension and trying to implement the a contact list (ala cubiq.org/dropbox/abc/) but I'm stuck at getting the scrollto function to work. How can I do this (since I don't have access to the "scroller" object - like cubiq.org does)...

Thanks, Tony

Comment by tudori...@gmail.com, Mar 17, 2010

I've written an extension for gestures for jQTouch. Try it here: http://bit.ly/98T1vt . Feedback is welcome.

Comment by bobriako...@gmail.com, Apr 17, 2010

Does anybody get Scrolling extension to work on Android devices?

Comment by tgo...@gmail.com, May 7, 2010

I wrote an extension that allows you to have dynamic page heights. This means that you can align stuff to the bottom of the window (like a nav bar) and have it work for any browser height (iPad, Android, PC browser, etc.)

http://www.golen.net/blog/2010/05/07/jqtouch-dynamicheight-extension/

Comment by rolandov...@gmail.com, May 11, 2010

Are there any extensions for contact form building?

Comment by brickysam26, Jun 16, 2010
Comment by wbednar...@gmail.com, Jun 17, 2010

Check out scroll plugin based on TouchScroll? - http://code.google.com/p/jqtscroll/

Comment by cricketl...@gmail.com, Jun 24, 2010

How about an extension for building a bottom toolbar? Has this been done?

Comment by cendri...@gmail.com, Jul 21, 2010

I'm confused. Can you access private variables via extensions?

Comment by jimmybro...@gmail.com, Aug 5, 2010

Code works great except for one issue, which I see on the cubiq site unsolved as well. Maybe someone here can help.

If you have a form inside of a scrollable div, changing content in a select option will prevent you from scrolling further up the div. Any ideas?

What I've already tried:

"On input blur trigger reset on vertical-scroll > div."

Comment by jubilee....@gmail.com, Dec 20, 2010

HI everyone I need help help here this is part of the code

$(function(){ jQT.generateGallery("gallery",[

<?for($i=0;$i<$count;$i++){?>
{src:"http://breathecast.com/files/photo/<?=$photo[$i]img??>", caption:"<?=$artistname??> - Photo <? echo $i+1;?>"},
<?}?>
]);
}); I want to have it on my here
<div id="gallery"></div>

but it's not displaying anything

Comment by kbaye...@gmail.com, May 13, 2011

Somehow, the Autotitle extension is not working for me at all. Even in the demo downloaded directly from JQTouch and run without any change, I get Name? as the title.

Anyone has any ideas?

Comment by kbaye...@gmail.com, May 13, 2011

In the previous post, I meant get "Fruit Name" in square brackets, instead of the referrer title.


Sign in to add a comment
Powered by Google Project Hosting