gthmb / jquery-free-transform

provides simple controls that allows you to move/rotate/scale a DOM element. kinda like a simple version of the free transform tool in Flash or Photoshop.
133 stars 58 forks source link

Ipad Gestures #23

Open mjp456789 opened 10 years ago

mjp456789 commented 10 years ago

Your library do everything I planned to create saving me tons of time. I only needed to add the Ipad gestures(rotate/pinch). I'm sending the code I added inside _init function, if you want to add/test it.

$(container).bind('gesturestart', function(evt) {

            evt.stopPropagation();

            var data = sel.data('freetrans'),
                cen = _getBounds(data._p.divs.controls).center,
                pressang = evt.originalEvent.rotation,
                startscale = evt.originalEvent.scale,
                tempScaleX = data.scalex,tempScaleY = data.scaley,
                firstAngle = true;

            rot = Number(data.angle);

            var change = _noSelect(function(evt) {

                if(firstAngle){
                    firstAngle=false;
                    if(Math.abs(evt.originalEvent.rotation)>30){
                        pressang = evt.originalEvent.rotation;
                    }
                }

                var ang = evt.originalEvent.rotation,
                    d = rot + ang - pressang,
                    newscale = evt.originalEvent.scale;

                data.angle = d;
                data._p.rad = d*rad;

                data.scalex = tempScaleX + newscale - startscale
                data.scaley = tempScaleY + newscale - startscale

                data._p.cwid = data._p.wid * data.scalex;
                data._p.chgt = data._p.hgt * data.scaley;

                _draw(sel, data);
            });

            var end = function(evt) {
                $(document).unbind('gesturechange.freetrans', change);
                $(document).unbind('gestureend.freetrans', end);
            };

            $(document).bind('gesturechange.freetrans', change);
            $(document).bind('gestureend.freetrans', end);
        });