SwarmOnline Menu Mobile
  • Home
  • About
  • Services
  • Portfolio
  • Blog
  • Contact

Recent Posts

  • Launching Sencha Insights
  • Documenting your Sencha apps with JSDuck
  • Localising Sencha Touch and Ext JS applications with Ux.locale.Manager
  • Announcing SwarmOnline’s New Website!
  • Constructing a complex form layout with Ext JS 4

Recent Comments

  • Stuart on Ext.ux.TouchCalendar – A Sencha Touch Calendar component
  • Stuart on Localising Sencha Touch and Ext JS applications with Ux.locale.Manager
  • Manuel Rodriguez on Localising Sencha Touch and Ext JS applications with Ux.locale.Manager
  • Remi Bloch on Ext.ux.TouchCalendar – A Sencha Touch Calendar component
  • Remi Bloch on Ext.ux.TouchCalendar – A Sencha Touch Calendar component

Archives

  • March 2013
  • February 2013
  • December 2012
  • September 2012
  • August 2012
  • November 2011
  • October 2011
  • May 2011
  • March 2011
  • February 2011
  • January 2011
  • November 2010

Categories

  • Development Tips
  • Ext JS
  • News
  • Sencha Touch
  • Sencha Touch Extensions & Plugins
  • Web Design
  • Web Design & Development Blog

Ext.ux.touch. ListOptions : Add a Twitter style menu to your List Items

8
08 Mar
2011
Ext.ux.touch.ListOptions

Sencha Touch

Sencha Touch Extensions & Plugins

Web Design & Development Blog

Overview

This plugin duplicates the functionality found in Twitter’s mobile apps where an options menu is exposed after swiping over an item in a list. The plugin was created as an ‘I wonder if that’s possible’ type project and serves to prove once again that anything native apps can do Sencha Touch can do too.

Extract the ZIP file into the ‘examples’ directory of the Sencha Touch libary package.

Download - Ext.ux.touch.ListOptions (14kb) (1717)

Demo – Ext.ux.touch.ListOptions

The demo shows the basic List example with the plugin applied and with a few items in the options menu.

The Plugin

The plugin is added to Ext.List components and requires only a few configuration options to get it up and running quickly, however it also offers quite a lot of control over its behaviour.

Configuration Options

optionsSelectorSelector to use to get the dynamically created List Options Ext.Element (where the menu options are held)Once hidden the List Options element will be removedDefaults to ‘x-list-options‘
menuOptionsAn array of objects to be applied to the ‘listOptionsTpl‘ XTemplate to create the List Options menu
menuOptionSelectorSelector to use to get individual List Options within the created Ext.ElementThis is used when attaching event handlers to the menu optionsDefaults to ‘x-menu-option‘
menuOptionsTplExt.XTemplate to use to create the List Options view
menuOptionPressedClassCSS Class that is applied to the tapped Menu Option while it is being touched. Defaults to ‘x-menu-option-pressed‘
menuOptionDataFilterSet to a function that takes in 2 arguments – your initial ‘menuOptions‘ config option and the current item’s Model instance.
The function must return either the original ‘menuOptions’ variable or a revised one
revealAnimationAnimation used to reveal the List Options. Only works properly with ‘slide‘ animation right now.Defaults to:{
reverse: false,
type: ‘slide’,
duration: 500
}
revealDirectionThe direction the List Item will slide to reveal the List Options
Possible values: ‘left’, ‘right’ and ‘both’
Setting to ‘both’ means it will be decided by the direction of the User’s swipe if ‘triggerEvent‘ is set to ‘itemswipe‘
swipeThresholdDistance (in pixels) a User must swipe before triggering the List Options to be displayed.Set to -1 to disable threshold checks
swipeDirectionThe direction the user must swipe to reveal the menuOnly applicable when ‘triggerEvent‘ is set to ‘itemswipe‘.Possible values: ‘left’, ‘right’ or ‘both’. Defaults to ‘both’
triggerEventExt.DataView event used to trigger the menu revealUsual values are ‘itemswipe‘, ‘itemtap‘, ‘itemdoubletap‘Notes:
itemswipe: see configs ‘swipeThreshold‘ & ‘swipeDirection‘
stopScrollOnShowStops the Ext.List from continuing its scrolling when a List Options menu is about to open.Accepts a boolean value. Defaults to true.
hideOnScrollDecides whether the visible List Options menu is hidden when the List is scrolled. Accepts a boolean value
allowMultipleDecides whether multiple List Options can be visible at once. Accepts a boolean value. Defaults to false
enableSoundEffectsDecides whether a sound effect will be played when the List Options menu opens and closes. Accepts a boolean value. Defaults to false
openSoundEffectURLURL for the sound effect to play when the List Options menu opens (see enableSoundEffects). Set to blank string to prevent sound from playing.
closeSoundEffectURLURL for the sound effect to play when the List Options menu closes (see enableSoundEffects). Set to blank string to prevent sound from playing.

Events

The plugin adds 3 events to the parent Ext.List component.

menuoptiontapThis event is fired when the User taps one of the List Options’ Menu Item – what Elements this event fires on is based on the ‘menuItemSelector‘.The event passes 2 parameters to its handler:menuItemData: this is the array item from the ‘menuOptions‘ array to allow you to perform different functionality based on what menu item was tappedactiveListRecord: the record associated with the List item that the List Options menu is showing for
beforelistoptionstapFired when a List Options menu item is tapped. Takes 2 parameters – the first is the object associated with the tapped menu item from the ‘menuOptions’ config. The second is the Model instance associated with the current menu’s List Item.This event must return true or false. A true return value will mean the tap will execute as normally (the pressed state will occur and the ‘menuoptiontap‘ event will fire. If false the tap will stop and no other actions will occur.This is a useful event to tailor menu option behaviour to the individual Model currently being dealt with.
listoptionsopenFired when the List Options menu is opened
listoptionscloseFired when the List Options menu is closed

An Example

I’ll talk through a simple example that is based on the Ext.List demo in the Sencha Touch download package.

First I’ll quickly explain the Model, Store and plain List. I’ll assume you have a base index.html file with all the library files etc linked into it.

Defining the plugin

Ext.regModel('Contact', {
    fields: ['firstName', 'lastName']
});
var store = new Ext.data.JsonStore({
    model: 'Contact',
    getGroupString: function(record){
        return record.get('lastName')[0];
    },
    data: [{
        firstName: 'Tommy',
        lastName: 'Maintz'
    }
    ...
    {
        firstName: 'Jay',
        lastName: 'Robinson'
    }]
});
var list = new Ext.List({
    fullscreen: true,
    itemTpl: '{firstName} {lastName}',
    indexBar: true,
    store: store,
    disableSelection: true
});
list.show();

If you fire this inside your Ext.setup function and load the page you should see a list with some of Sencha’s employees in it.

Now, let’s add the plugin!

Firstly make sure you’ve added the Plugin’s source file and CSS file.

//Inside the Ext.List's config
...
plugins: [new Ext.ux.touch.ListOptions({
    menuOptions: [{
        id: 'Team Icon Tapped',
            img: 'images/team1_small.png'
    }, {
        id: 'Favourite Icon Tapped',
        img: 'images/favorites1_small.png'
    }, {
        id: 'Cart Icon Tapped',
        img: 'images/shop2_small.png'
    }, {
        id: 'Share Icon Tapped',
        img: 'images/share_small.png'
    }]
})]
...

By taking the default values for all the other config options and adding some menuOptions we get the plugin up and running straight away. You can now play around with the various options to get the plugin working how you want!

If you have any problems with using the plugin, have questions about how it works or have suggestions about ways we can make it better then please leave us a comment or drop us an email!

Extract the ZIP file into the ‘examples’ directory of the Sencha Touch libary package.

Download - Ext.ux.touch.ListOptions (14kb) (1717)

Demo – Ext.ux.touch.ListOptions

Tweet

8
  1. aoboturov - Reply

    August 26, 2011 at 9:58 am

    Very nice work.

    But you’ll have to add:
    .x-list-options ul li {
    list-style-type: none;
    }
    to your stylesheet Ext.ux.touch.TwitterStyleListOptions.css

  2. Dale - Reply

    January 15, 2012 at 7:57 pm

    This looks great, however, your demo doesn’t reflect this. Would you be able to update your online demo to demonstrate this?

    I just see a normal disclosure list in your demo.

    Thanks in advance!

    • Stuart - Reply

      January 15, 2012 at 9:57 pm

      Hi Dale,

      If you click and swipe your mouse across the list items it will reveal the options menu.

      Thanks
      Stuart

  3. Rob Squires - Reply

    March 21, 2012 at 10:12 am

    Hey Guys,

    I’ve used this add on number of projects in the past and it’s worked really well…thanks!

    Are you planning to port this to Sencha Touch 2 at all?

    thanks
    rob.

  4. s.t.a.s - Reply

    April 3, 2012 at 4:22 pm

    Has anybody checked it in Sencha Touch 2.0? I placed “Ext.ux.touch.ListOptions.js” in my site directory, copied css files also and added plugin in my list and now I see an error message in Ext.ux.touch.ListOptions.js:
    Ext is not defined

    And another one related with previous:
    Cannot read property ‘touch’ of undefined

    It seems that it can’t find Ext.ux.touch with this code in Ext.ux.touch.ListOptions.js:
    Ext.ns(‘Ext.ux.touch’);

    How to solve it?

    • Andy - Reply

      April 3, 2012 at 4:37 pm

      Hi,

      This plugin won’t work with Sencha Touch 2 at the moment and we’ve not had a chance to upgrade it yet.

      Sorry about that.

  5. s.t.a.s - Reply

    April 3, 2012 at 5:14 pm

    Do you have any plans about that? Can we expect it soon? :)

  6. s.t.a.s - Reply

    April 5, 2012 at 11:12 am

    Guys, I did some work in porting your component to Sencha Touch 2.0 but I need some help in it. Here is the discussion: http://www.sencha.com/forum/showthread.php?193361-Twitter-style-menu-in-List-items-Sencha-Touch-2.0&p=772856#post772856

Leave a Comment - Cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

About SwarmOnline

Based in Glasgow’s West End, SwarmOnline provide web development, cross platform mobile app development and training services for local and international organisations. We have expert knowledge of Sencha technologies and have been Sencha Partners since 2011. We specialise in creating dynamic, innovative and practical solutions.

Meet the Team...

Newsletter

Subscribe to our newsletter and we’ll keep you up-to-date. We don't do spam.

Get in touch!

Email: info@swarmonline.com   
Skype: andrew-swarmonline stuart-swarmonline   
Phone: 0141 438 2231   


© 2013 SwarmOnline Ltd. All Rights Reserved.

SwarmOnline Ltd is a Limited Company registered in Scotland, with company number SC411633. Our Registered Office is 1-2 249 Byres Road, Glasgow G12 8UB.