1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    10
    Vote Rating
    6
    jonasba is on a distinguished road

      6  

    Default My image viewer component

    My image viewer component


    Hi!

    I've been looking for an image viewer component, capable of viewing an image and zooming in and out. I could not find any, so I decided to make one for myself. It is my first ExtJS component ever, but I thought I'd share it with you anyway. Feedback is *much* appreciated.

    It can be found on Github.

    I also have a live demo.

    Code:
    Ext.create('Ext.container.Viewport', {
         layout: 'fit',
         items: Ext.create('ImageViewer', {
             renderTo: Ext.getBody(),
             src: 'path/to/your/image.png'
        })
    });
    Localization

    The tooltips are configurable in the following way, enabling the possibility for localization.

    Code:
    Ext.create('Ext.container.Viewport', {
        layout: 'fit',
        items: Ext.create('ImageViewer', {
            renderTo: Ext.getBody(),
            src: 'resources/images/image.png',
            tooltips: {
                stretchHorizontally: 'Strekk vertikalt',
                stretchVertically: 'Strekk horisontalt',
                stretchOptimally: 'Strekk optimalt',
                zoomIn: 'Zoom inn',
                zoomOut: 'Zoom ut',
                rotateClockwise: 'Roter med klokka',
                rotateAntiClockwise: 'Roter mot klokka'
            }
        })
    });
    Multiimage viewing

    I have extended the component to support viewing of multiple images. (This is part of my current work at my job, where I'm doing online browser preview of office documents and etc.)

    It can be found on Github.

    I also have a live demo.

    Code:
    Ext.create('Ext.container.Viewport', {
         layout: 'fit',
         items: Ext.create('MultiImageViewer', {
            renderTo: Ext.getBody(),
            src: [
                'resources/images/001.jpg',
                'resources/images/002.jpg'
            ],
            currentImageTemplate: 'Viewing page {i} of {total}'
        })
    });

  2. #2
    Sencha User loiane's Avatar
    Join Date
    Aug 2009
    Posts
    183
    Vote Rating
    52
    loiane is a jewel in the rough loiane is a jewel in the rough loiane is a jewel in the rough

      0  

    Default


    Really nice!
    Thanks for sharing!
    Sencha/Java evangelist
    Author of ExtJS 4 First Look and Mastering Ext JS books
    English blog: http://loianegroner.com
    Portuguese blog: http://loiane.com
    Sencha Examples: https://github.com/loiane

  3. #3
    Sencha - Community Support Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,962
    Vote Rating
    10
    hendricd will become famous soon enough hendricd will become famous soon enough

      2  

    Cool


    @jonasba -- Nicely done

    Succinct and very clean.

    Thought I'd offer a couple suggestions for Component structure and script performance if you're game.

    These listeners appear a bit 'broad' (and they are never removed) as they would fire your mouse methods any time the mouse moved anywhere in the document
    Code:
    Ext.EventManager.addListener(window, 'mouseup', me.mouseup, me);
    Ext.EventManager.addListener(window, 'mousemove', me.mousemove, me);
    Remember, this cool Component may be nested in a TabPanel or Accordian layout somewhere amoungst hundreds of neighbors

    Consider 'scoping' them to the ImageContainer only.
    You could either add them to your current #ImageContainer listeners block:

    Code:
    listeners: { 
      el: 
         { mousedown: me.mousedown,
           mousemove: me.mousemove,
           mouseup:   me.mouseup,
           scope: me 
     } },
    or implement them here (ideally using mon) using the initEvents template method:

    Code:
    initEvents : function() {
             var me = this;
             me.callParent();
             me.mon( me.getImageContainer().getEl(), {
             
                mousedown: me.mousedown,
                mousemove: me.mousemove,
                mouseup:   me.mouseup,
                scope: me 
            });
     },
    For those following along: either is equivalent but, more importantly, listeners set this way are removed for you during destruction.

    On the performance side, try to reduce the calls to the getters during DOM events. Get the references you need once, and run with them. Should smooth things out a bit:

    Code:
    rotateImage: function () {
    
            var me = this,
                imageEl = me.getImage().getEl(),
                rotation = me.getRotation(),
                rotate =  'rotate(' + rotation + 'deg)',
                tmpOriginalWidth;
    
            tmpOriginalWidth = me.getOriginalWidth();
            me.setOriginalWidth(me.getOriginalHeight());
            me.setOriginalHeight(tmpOriginalWidth);
    
            imageEl.applyStyles( {    //a bit quicker
                 'transform' :  rotate,
                 '-o-transform' :rotate,
                 '-ms-transform' : rotate,
                 '-moz-transform' : rotate,
                 '-webkit-transform' : rotate
             });
    
            me.setMargins(me.getMargins());
        },
    Anyway, you see the pattern, right? (Compiled Java this is not!)

    Great job!

    Now, let's see some more of these!
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  4. #4
    Sencha User
    Join Date
    Jul 2012
    Posts
    10
    Vote Rating
    6
    jonasba is on a distinguished road

      0  

    Default


    Thanks for the feedback! I'll definitely make some changes, now that I know what's best practise around here. By the way, I extended the component to add support for multiple images.

    It can be found on Github.

    I also have a live demo.

  5. #5
    Sencha User loiane's Avatar
    Join Date
    Aug 2009
    Posts
    183
    Vote Rating
    52
    loiane is a jewel in the rough loiane is a jewel in the rough loiane is a jewel in the rough

      0  

    Default Sencha Try

    Sencha Try


    Why don't you submit this example to Sencha Try?
    I'm sure people will enjoy it!

    http://try.sencha.com/
    Sencha/Java evangelist
    Author of ExtJS 4 First Look and Mastering Ext JS books
    English blog: http://loianegroner.com
    Portuguese blog: http://loiane.com
    Sencha Examples: https://github.com/loiane

  6. #6
    Sencha User
    Join Date
    Jul 2012
    Posts
    10
    Vote Rating
    6
    jonasba is on a distinguished road

      0  

    Default


    Quote Originally Posted by hendricd View Post
    These listeners appear a bit 'broad' (and they are never removed) as they would fire your mouse methods any time the mouse moved anywhere in the document
    The problem with scoping the mousemove event to apply only to the actual image container, is that when a user drags an image, moves the mouse outside the image container area and then moves it inside from another side, the image will jump suddenly. Although I as a developer very much understands why and how this happens, it is a very unexpected behaviour for a typical user. Therefore I'd like the image to follow the mouse no matter where it is being moved.

    Do you have a suggestion of how to do this and accomplish the same behaviour?

    Edit: I suppose I could make this a configurable option?

  7. #7
    Sencha User
    Join Date
    Oct 2011
    Location
    Ukraine
    Posts
    154
    Vote Rating
    6
    Romick is on a distinguished road

      0  

    Default IE?

    IE?


    Did you test your component in IE? It seems not working properly... omg.

  8. #8
    Sencha User
    Join Date
    Jul 2012
    Posts
    10
    Vote Rating
    6
    jonasba is on a distinguished road

      0  

    Default


    Quote Originally Posted by hendricd View Post
    Consider 'scoping' them to the ImageContainer only.
    Quote Originally Posted by hendricd View Post
    or implement them here (ideally using mon) using the initEvents template method:
    Quote Originally Posted by hendricd View Post
    On the performance side, try to reduce the calls to the getters during DOM events. Get the references you need once, and run with them. Should smooth things out a bit:
    I have done all of the above now.

    Quote Originally Posted by Romick View Post
    Did you test your component in IE? It seems not working properly... omg.
    No, I did not. However, I have done it now and I fixed a couple of bugs. I don't generally support IE or any Microsoft products, but you seem like a really nice and appreciative guy, so I figured what the heck!

  9. #9
    Sencha User
    Join Date
    Jul 2012
    Posts
    10
    Vote Rating
    6
    jonasba is on a distinguished road

      0  

    Default


    @Vaugheren: Thanks!

    I've updated it and made the tooltips configurable. See first post.

  10. #10
    Sencha User
    Join Date
    Jul 2012
    Posts
    235
    Vote Rating
    0
    chandan.behura is on a distinguished road

      0  

    Default


    thanks a lot

    try to solve miy issue in bellow link


    http://www.sencha.com/forum/showthre...ded#post861101

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi