Вход Регистрация
Файл: adultscript-2.0.3-pro/files/misc/jquery-guillotine/jquery.guillotine.js
Строк: 469
<?php
// Generated by CoffeeScript 1.8.0

/*
 * jQuery Guillotine Plugin v1.3.0
 * http://matiasgagliano.github.com/guillotine/
 *
 * Copyright 2014, Matías Gagliano.
 * Dual licensed under the MIT or GPLv3 licenses.
 * http://opensource.org/licenses/MIT
 * http://opensource.org/licenses/GPL-3.0
 *
 */

(function() {
  
"use strict";
  var $, 
GuillotinecanTransformdefaultseventsgetPointerPositionhardwareAccelerateisTouchpluginNamescopetouchRegExpvalidEventwhitelist,
    
__bind = function(fnme){ return function(){ return fn.apply(mearguments); }; },
    
__indexOf = [].indexOf || function(item) { for (var 0this.lengthli++) { if (i in this && this[i] === item) return i; } return -1; };

  $ = 
jQuery;

  
pluginName 'guillotine';

  
scope 'guillotine';

  
events = {
    
start"touchstart." scope " mousedown." scope,
    
move"touchmove." scope " mousemove." scope,
    
stop"touchend." scope " mouseup." scope
  
};

  
defaults = {
    
width400,
    
height300,
    
zoomStep0.1,
    
initnull,
    
eventOnChangenull,
    
onChangenull
  
};

  
touchRegExp = /touch/i;

  
isTouch = function(e) {
    return 
touchRegExp.test(e.type);
  };

  
validEvent = function(e) {
    if (
isTouch(e)) {
      return 
e.originalEvent.changedTouches.length === 1;
    } else {
      return 
e.which === 1;
    }
  };

  
getPointerPosition = function(e) {
    if (
isTouch(e)) {
      
e.originalEvent.touches[0];
    }
    return {
      
xe.pageX,
      
ye.pageY
    
};
  };

  
canTransform = function() {
    var 
hasTransformhelperprefixprefixesproptesttestsvalue_i_len;
    
hasTransform false;
    
prefixes = ['webkit''Moz''O''ms''Khtml'];
    
tests = {
      
transform'transform'
    
};
    for (
_i 0_len prefixes.length_i _len_i++) {
      
prefix prefixes[_i];
      
tests[prefix 'Transform'] = '-' prefix.toLowerCase() + '-transform';
    }
    
helper document.createElement('img');
    
document.body.insertBefore(helpernull);
    for (
test in tests) {
      
prop tests[test];
      if (
helper.style[test] === void 0) {
        continue;
      }
      
helper.style[test] = 'rotate(90deg)';
      
value window.getComputedStyle(helper).getPropertyValue(prop);
      if ((
value != null) && value.length && value !== 'none') {
        
hasTransform true;
        break;
      }
    }
    
document.body.removeChild(helper);
    
canTransform hasTransform ? (function() {
      return 
true;
    }) : (function() {
      return 
false;
    });
    return 
canTransform();
  };

  
hardwareAccelerate = function(el) {
    return $(
el).css({
      
'-webkit-perspective'1000,
      
'perspective'1000,
      
'-webkit-backface-visibility''hidden',
      
'backface-visibility''hidden'
    
});
  };

  
Guillotine = (function() {
    function 
Guillotine(elementoptions) {
      
this._drag __bind(this._dragthis);
      
this._unbind __bind(this._unbindthis);
      
this._start __bind(this._startthis);
      
this.op = $.extend(true, {}, defaultsoptions, $(element).data(pluginName));
      
this.enabled true;
      
this.zoomInFactor this.op.zoomStep;
      
this.zoomOutFactor this.zoomInFactor;
      
this.glltRatio this.op.height this.op.width;
      
this.width this.height this.left this.top this.angle 0;
      
this.data = {
        
scale1,
        
angle0,
        
x0,
        
y0,
        
wthis.op.width,
        
hthis.op.height
      
};
      
this._wrap(element);
      if (
this.op.init != null) {
        
this._init();
      }
      if (
this.width || this.height 1) {
        
this._fit() && this._center();
      }
      
hardwareAccelerate(this.$el);
      
this.$el.on(events.startthis._start);
    }

    
Guillotine.prototype._wrap = function(element) {
      var 
canvaselguillotineheightpaddingTopwidth;
      
el = $(element);
      if (
element.tagName === 'IMG') {
        if (
element.naturalWidth) {
          
width element.naturalWidth;
          
height element.naturalHeight;
        } else {
          
el.addClass('guillotine-sample');
          
width el.width();
          
height el.height();
          
el.removeClass('guillotine-sample');
        }
      } else {
        
width el.width();
        
height el.height();
      }
      
this.width width this.op.width;
      
this.height height this.op.height;
      
canvas = $('<div>').addClass('guillotine-canvas');
      
canvas.css({
        
widththis.width 100 '%',
        
heightthis.height 100 '%',
        
top0,
        
left0
      
});
      
canvas el.wrap(canvas).parent();
      
paddingTop this.op.height this.op.width 100 '%';
      
guillotine = $('<div>').addClass('guillotine-window');
      
guillotine.css({
        
width'100%',
        
height'auto',
        
'padding-top'paddingTop
      
});
      
guillotine canvas.wrap(guillotine).parent();
      
this.$el el;
      
this.el el[0];
      
this.$canvas canvas;
      
this.canvas canvas[0];
      
this.$gllt guillotine;
      
this.gllt guillotine[0];
      
this.$document = $(element.ownerDocument);
      return 
this.$body = $('body'this.$document);
    };

    
Guillotine.prototype._unwrap = function() {
      
this.$el.removeAttr('style');
      
this.$el.insertBefore(this.gllt);
      return 
this.$gllt.remove();
    };

    
Guillotine.prototype._init = function() {
      var 
angleoscale;
      
this.op.init;
      if ((
scale parseFloat(o.scale))) {
        
this._zoom(scale);
      }
      if ((
angle parseInt(o.angle))) {
        
this._rotate(angle);
      }
      return 
this._offset(parseInt(o.x) / this.op.width || 0parseInt(o.y) / this.op.height || 0);
    };

    
Guillotine.prototype._start = function(e) {
      if (!(
this.enabled && validEvent(e))) {
        return;
      }
      
e.preventDefault();
      
e.stopImmediatePropagation();
      
this.getPointerPosition(e);
      return 
this._bind();
    };

    
Guillotine.prototype._bind = function() {
      
this.$body.addClass('guillotine-dragging');
      
this.$document.on(events.movethis._drag);
      return 
this.$document.on(events.stopthis._unbind);
    };

    
Guillotine.prototype._unbind = function(e) {
      
this.$body.removeClass('guillotine-dragging');
      
this.$document.off(events.movethis._drag);
      
this.$document.off(events.stopthis._unbind);
      if (
!= null) {
        return 
this._trigger('drag');
      }
    };

    
Guillotine.prototype._trigger = function(action) {
      if (
this.op.eventOnChange != null) {
        
this.$el.trigger(this.op.eventOnChange, [this.dataaction]);
      }
      if (
typeof this.op.onChange === 'function') {
        return 
this.op.onChange.call(this.elthis.dataaction);
      }
    };

    
Guillotine.prototype._drag = function(e) {
      var 
dxdyleftptop;
      
e.preventDefault();
      
e.stopImmediatePropagation();
      
getPointerPosition(e);
      
dx p.this.p.x;
      
dy p.this.p.y;
      
this.p;
      
left dx === null this.left dx this.gllt.clientWidth;
      
top dy === null this.top dy this.gllt.clientHeight;
      return 
this._offset(lefttop);
    };

    
Guillotine.prototype._offset = function(lefttop) {
      if (
left || left === 0) {
        if (
left 0) {
          
left 0;
        }
        if (
left this.width 1) {
          
left this.width 1;
        }
        
this.canvas.style.left = (-left 100).toFixed(2) + '%';
        
this.left left;
        
this.data.Math.round(left this.op.width);
      }
      if (
top || top === 0) {
        if (
top 0) {
          
top 0;
        }
        if (
top this.height 1) {
          
top this.height 1;
        }
        
this.canvas.style.top = (-top 100).toFixed(2) + '%';
        
this.top top;
        return 
this.data.Math.round(top this.op.height);
      }
    };

    
Guillotine.prototype._zoom = function(factor) {
      var 
hlefttopw;
      if (
factor <= || factor === 1) {
        return;
      }
      
this.width;
      
this.height;
      if (
factor && factor 1) {
        
this.width *= factor;
        
this.height *= factor;
        
this.canvas.style.width = (this.width 100).toFixed(2) + '%';
        
this.canvas.style.height = (this.height 100).toFixed(2) + '%';
        
this.data.scale *= factor;
      } else {
        
this._fit();
        
factor this.width w;
      }
      
left = (this.left 0.5) * factor 0.5;
      
top = (this.top 0.5) * factor 0.5;
      return 
this._offset(lefttop);
    };

    
Guillotine.prototype._fit = function() {
      var 
prevWidthrelativeRatio;
      
prevWidth this.width;
      
relativeRatio this.height this.width;
      if (
relativeRatio 1) {
        
this.width 1;
        
this.height relativeRatio;
      } else {
        
this.width relativeRatio;
        
this.height 1;
      }
      
this.canvas.style.width = (this.width 100).toFixed(2) + '%';
      
this.canvas.style.height = (this.height 100).toFixed(2) + '%';
      return 
this.data.scale *= this.width prevWidth;
    };

    
Guillotine.prototype._center = function() {
      return 
this._offset((this.width 1) / 2, (this.height 1) / 2);
    };

    
Guillotine.prototype._rotate = function(angle) {
      var 
canvasRatioglltRatiohw_ref_ref1_ref2;
      if (!
canTransform()) {
        return;
      }
      if (!(
angle !== && angle 90 === 0)) {
        return;
      }
      
this.angle = (this.angle angle) % 360;
      if (
this.angle 0) {
        
this.angle 360 this.angle;
      }
      if (
angle 180 !== 0) {
        
glltRatio this.op.height this.op.width;
        
_ref = [this.height glltRatiothis.width glltRatio], this.width _ref[0], this.height _ref[1];
        if (
this.width >= && this.height >= 1) {
          
this.canvas.style.width this.width 100 '%';
          
this.canvas.style.height this.height 100 '%';
        } else {
          
this._fit();
        }
      }
      
_ref1 = [11], _ref1[0], _ref1[1];
      if (
this.angle 180 !== 0) {
        
canvasRatio this.height this.width glltRatio;
        
_ref2 = [canvasRatiocanvasRatio], _ref2[0], _ref2[1];
      }
      
this.el.style.width 100 '%';
      
this.el.style.height 100 '%';
      
this.el.style.left = (w) / 100 '%';
      
this.el.style.top = (h) / 100 '%';
      
this.$el.css({
        
transform"rotate(" this.angle "deg)"
      
});
      
this._center();
      return 
this.data.angle this.angle;
    };

    
Guillotine.prototype.rotateLeft = function() {
      return 
this.enabled && (this._rotate(-90), this._trigger('rotateLeft'));
    };

    
Guillotine.prototype.rotateRight = function() {
      return 
this.enabled && (this._rotate(90), this._trigger('rotateRight'));
    };

    
Guillotine.prototype.center = function() {
      return 
this.enabled && (this._center(), this._trigger('center'));
    };

    
Guillotine.prototype.fit = function() {
      return 
this.enabled && (this._fit(), this._center(), this._trigger('fit'));
    };

    
Guillotine.prototype.zoomIn = function() {
      return 
this.enabled && (this._zoom(this.zoomInFactor), this._trigger('zoomIn'));
    };

    
Guillotine.prototype.zoomOut = function() {
      return 
this.enabled && (this._zoom(this.zoomOutFactor), this._trigger('zoomOut'));
    };

    
Guillotine.prototype.getData = function() {
      return 
this.data;
    };

    
Guillotine.prototype.enable = function() {
      return 
this.enabled true;
    };

    
Guillotine.prototype.disable = function() {
      return 
this.enabled false;
    };

    
Guillotine.prototype.remove = function() {
      
this._unbind();
      
this._unwrap();
      
this.disable();
      
this.$el.off(events.startthis._start);
      return 
this.$el.removeData(pluginName 'Instance');
    };

    return 
Guillotine;

  })();

  
whitelist = ['rotateLeft''rotateRight''center''fit''zoomIn''zoomOut''instance''getData''enable''disable''remove'];

  $.
fn[pluginName] = function(options) {
    if (
typeof options !== 'string') {
      return 
this.each(function() {
        var 
guillotine;
        if (!$.
data(thispluginName 'Instance')) {
          
guillotine = new Guillotine(thisoptions);
          return $.
data(thispluginName 'Instance'guillotine);
        }
      });
    } else if (
__indexOf.call(whitelistoptions) >= 0) {
      if (
options === 'instance') {
        return $.
data(this[0], pluginName 'Instance');
      }
      if (
options === 'getData') {
        return $.
data(this[0], pluginName 'Instance')[options]();
      }
      return 
this.each(function() {
        var 
guillotine;
        
guillotine = $.data(thispluginName 'Instance');
        if (
guillotine) {
          return 
guillotine[options]();
        }
      });
    }
  };

}).
call(this);
?>
Онлайн: 0
Реклама