Ext


Go Back   Ext JS Forums > Ext JS Community Forums (3.0) > Ext: Core

Reply
 
Thread Tools
  #1  
Old 06-13-2009, 10:48 AM
mankz's Avatar
mankz mankz is offline
Ext User
 
Join Date: Nov 2007
Location: Lund, Sweden
Posts: 720
mankz is on a distinguished road
Send a message via MSN to mankz Send a message via Skype™ to mankz
Default [Ext Core] Ext.ux.FingerMenu

New menu UX for Ext Core. Not sure what the usability department will say on this one... .

  • Tested in FF3, IE6-8, Chrome 2, Opera 10, Safari 4
  • CSS is optimized for 32x32 icons. See example or source code documentation for usage.
  • MIT License
  • Live Example


Version history
  • 2009-07-02 v1.1 Code cleaning and refactoring. setSelectedIndex added






Suggestions/bugs/feedback welcome!

Example usage:

Ext.onReady(function(){
           var menu = new Ext.ux.FingerMenu({
                cls : 'menuExample',
                selectedIndex : 0,
                items : [
                    {
                        text : 'Lightbox',
                        iconCls : 'icon-lightbox'
                    }, {
                        text : 'Carousel',
                        iconCls : 'icon-carousel'
                    }, {
                        text : 'JSONP Flickr',
                        iconCls : 'icon-flickr'
                    }, {
                        text : 'Tabs',
                        iconCls : 'icon-tab'
                    }
                ]
           });
           
           menu.on('change', function(obj, index) {
                switch(index) {
                    case 0:
                        // Do your thing here...
                    break;
                    
                    case 1:
                        // Do your thing here...
                    break;
           
                    case 2:
                       // Do your thing here...
                    break;
                    
                    case 3:
                       // Do your thing here...
                    break;
                }
           });
});

Source:
/*
The MIT License

Copyright (c) 2009 Mats Bryntse

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/**
 * Ext.ux.FingerMenu
 *
 * @author    Mats Bryntse 
 * @version   1.1
 * 
 * This menu fires a 'change' event when an item is activated
 * 
 */
 
Ext.ns('Ext.ux');

Ext.ux.FingerMenu = Ext.extend(Ext.util.Observable, {
    /*
     * @cfg (array) array of menu config objects 
     *              The menu is built for 32x32 icons, if you need different size icons
     *              you'll have to modify the CSS.
     * 
     *              Example object : 
     *              {
     *                  text : 'Menu item 1',
     *                  iconCls : 'myIconClass',    
     *                  tooltip : 'This option is optional'
     *              }
     *
     */
    items : [],
    
     /*
     * @cfg (string) id of dom element to render the menu into
     */
    renderTo : null,
    
    /*
     * @cfg (int) selected menu index,  -1 for no selection
     */
    selectedIndex : -1,
    
    /*
     * @cfg (int) the width of a collapsed menu item
     */
    collapsedWidth : 40,
    
    /*
     * @cfg (int) the width of a menu item on hover
     */
    hoverWidth : 43,
    
     /*
     * @cfg (int) the full width of a selected menu item
     */
    itemWidth : 190,
    
     /*
     * @cfg (int) the height of a menu item
     */
    itemHeight  : 40,
    
     /*
     * @cfg (int) the amount of space between two menu items
     */
    verticalPadding  : 2,
    
    /*
     * @public (int) returns the currently selected item index
     */
    getSelectedIndex : function() {
        return this.selectedIndex;
    },
    
    /*
     * @public selects the passed index
     */
    setSelectedIndex : function(index) {
        this.onItemClick(null, 'menuitem-' + index);
    },
    
    /*
     * @private
     */
    onItemClick : function(notUsed, t) {
        var target = Ext.get(t);
        
        if (!target.hasClass('fingermenu-show')){
            var current = this.el.child('.fingermenu-show');
            target.radioClass('fingermenu-show');
            
            if (current) {
                current.setX(this.collapsedWidth - this.itemWidth, {
                    duration : 0.3
                });
            }
            
            target.setX(0, {
                duration : 0.3,
                callback : function() {
                    this.selectedIndex = parseInt(target.id.substring('menuitem-'.length), 10);
                    this.fireEvent.defer(10, this, ['change', this, this.selectedIndex]);
                },
                scope : this
            });
        }
   },
   
   /*
     * @private
     */
   onHover : function(e, t) {
       var target = Ext.get(t);
       target = target.is('div') ? target : target.up('div');
       if (target.getX() === (this.collapsedWidth - this.itemWidth)){
           target.setX(this.hoverWidth - this.itemWidth, {
                duration : 0.1
           });
       }
   },
   
   /*
    * @private
    */
   onHoverLeave : function(e, t) {
       var target = Ext.get(t);
       target = target.is('div') ? target : target.up('div');
       
       if (!target.hasClass('fingermenu-show')){
           target.setX(this.collapsedWidth - this.itemWidth,{
                duration : 0.2
           });
       }
   },
    
   /*
    * @private
    */
   constructor : function(config) {
        if (!config || !config.items) throw 'Invalid arguments, see documentation';
        
        Ext.apply(this, config);
        
        var menuCfg = {
                tag: 'div',
                cls: 'fingermenu-panel ' + (config.cls || ''),
                children : []
            },
            items = config.items,
            item,
            selected,
            i;
        
        this.addEvents('change');
        
        for (i = 0; i < items.length; i++) {
            item = items[i];
            selected = (i === this.selectedIndex);
            
            menuCfg.children.push({
                id : 'menuitem-' + i,
                cls : selected ? 'fingermenu-show' : '',
                style : {
                    width : this.itemWidth + 'px',
                    position : 'absolute',
                    left : (selected ? 0 : (this.collapsedWidth - this.itemWidth)) + 'px',
                    top : (i*(this.itemHeight + this.verticalPadding)) + 'px'
                },
                tag: 'div', 
                title : item.tooltip || item.text,
                children : [{
                        tag : 'span',
                        cls : item.iconCls ? ('fingermenu-icon ' + item.iconCls) : '',
                        html : item.text
                    }
                ]
            });
        }
        
        this.el = Ext.DomHelper.append(this.renderTo || Ext.getBody(), menuCfg, true);
        
        this.el.on('click', this.onItemClick, this, { delegate: 'div' });
        
        var divs = this.el.select('div');
        divs.on('mouseenter', this.onHover, this);
        divs.on('mouseleave', this.onHoverLeave, this);
        
        Ext.ux.FingerMenu.superclass.constructor.call(this);
    }
});
Attached Files
File Type: zip FingerMenu.zip (48.4 KB, 90 views)
__________________
Why bother with subroutines when you can type fast?

Last edited by mankz; 07-02-2009 at 12:07 PM.. Reason: Added hover effect
Reply With Quote
  #2  
Old 06-13-2009, 02:10 PM
syscobra's Avatar
syscobra syscobra is offline
Ext User
 
Join Date: Nov 2007
Location: Venezuela
Posts: 128
syscobra is on a distinguished road
Send a message via MSN to syscobra Send a message via Skype™ to syscobra
Default

Nice thanks for sharing...
How about a show on hover?
maybe not as far as when you click, i mean imagine just show the full menu on hover but the active one beeing with more width. Maybe you can change too the active item css as when you have a <a> html tag.
Just suggestions.

Edit: Forgot to say i tryed on IE8 and it works well so maybe it works good in IE6 too cause it doesn't have strange things on the code i thing.
__________________
Javier Rincón aka SysCobra

Last edited by syscobra; 06-13-2009 at 02:12 PM.. Reason: Forgot to say
Reply With Quote
  #3  
Old 06-13-2009, 03:08 PM
mankz's Avatar
mankz mankz is offline
Ext User
 
Join Date: Nov 2007
Location: Lund, Sweden
Posts: 720
mankz is on a distinguished road
Send a message via MSN to mankz Send a message via Skype™ to mankz
Default

Good idea, original post & example page updated!
__________________
Why bother with subroutines when you can type fast?
Reply With Quote
  #4  
Old 06-13-2009, 04:34 PM
galdaka's Avatar
galdaka galdaka is online now
Ext User
 
Join Date: Mar 2007
Location: Spain
Posts: 1,095
galdaka is on a distinguished road
Default

Not work in IE6, IE7 & IE8.

Greeting,
Reply With Quote
  #5  
Old 06-14-2009, 02:15 AM
demongloom's Avatar
demongloom demongloom is offline
Ext User
 
Join Date: Apr 2008
Location: Israel
Posts: 22
demongloom is on a distinguished road
Send a message via ICQ to demongloom
Default

Nice thing!
Can it been backported to 2.x version?
__________________
I'm a three times a hero the galaxy, with a right to wear the atomic weapons. </irony>
Reply With Quote
  #6  
Old 06-14-2009, 03:53 AM
Animal's Avatar
Animal Animal is online now
Ext JS - Community Support Team
 
Join Date: Mar 2007
Location: East Midlands, UK
Posts: 24,299
Animal will become famous soon enough
Default

There is no 2.0 Core.
__________________
ExtJs forum volunteer. No official connection to the Ext Company. I do not speak for them.
ExtJs consultancy offered. £ 50/hour. Evenings+weekends. the_bagbournes@btinternet.com

Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
See Saki's samples: http://examples.extjs.eu/
Build your own Ext: http://extjs.com/products/extjs/build/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
Reply With Quote
  #7  
Old 06-14-2009, 05:16 AM
mankz's Avatar
mankz mankz is offline
Ext User
 
Join Date: Nov 2007
Location: Lund, Sweden
Posts: 720
mankz is on a distinguished road
Send a message via MSN to mankz Send a message via Skype™ to mankz
Default

Quote:
Originally Posted by galdaka View Post
Not work in IE6, IE7 & IE8.

Greeting,
Thanks for the heads up, should be working in IE7/8 now (tried it in IE8 with and without compatibility mode), still haven't tested it in IE6. Would rather bite my tongue really bad than try getting it working in IE6...

Original post and example page updated.
__________________
Why bother with subroutines when you can type fast?
Reply With Quote
  #8  
Old 06-14-2009, 06:49 AM
koko2589 koko2589 is offline
Ext User
 
Join Date: Mar 2009
Posts: 267
koko2589 is on a distinguished road
Default

work very good on ext 2.2 to
__________________
my ext js site

http://itoto1.myroomy.com
Reply With Quote
  #9  
Old 06-14-2009, 09:17 AM
mjlecomte mjlecomte is offline
Ext JS - Quality Assurance Team
 
Join Date: Jul 2007
Location: Florida
Posts: 10,008
mjlecomte is on a distinguished road
Default

Looks good.
Reply With Quote
  #10  
Old 06-14-2009, 03:01 PM
Joe's Avatar
Joe Joe is offline
Ext JS Premium Member
 
Join Date: Apr 2007
Posts: 242
Joe is on a distinguished road
Default Thanks for posting that control

Great to see it working in IE now - cool.

I tested it in IE6 and it worked perfect, so you'll need another good reason to bite your tounge.

Nice to see a ExtJS Core based ux control geared towards content sites. Is this MIT open source - like ExtJS Core? If so, would you mind if I posted this in a SVN dedicated to ExtJS Core components for content sites? Are you interested in being part of such a project?

Thanks again for your active posts in regards to ExtJS Core.
__________________
Joseph Francis,
CoreLan / Meeting Consultants
Reply With Quote
Reply

Thread Tools

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

All times are GMT -5. The time now is 09:41 AM.

© 2006-2009 Ext, LLC
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.