-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.gugg-paintstripper.min.js
More file actions
10 lines (10 loc) · 4.7 KB
/
jquery.gugg-paintstripper.min.js
File metadata and controls
10 lines (10 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
(function(c){c.widget("gugg.paintstripper",{options:{reveal_duration:1E3,rotate_duration:1E3,move_duration:0,zoom_duration:0},ps_w:void 0,ps_h:void 0,ps_orientation:void 0,ps_ratio:void 0,ps_real_w:void 0,ps_real_h:void 0,ps_images:void 0,ps_base:c("<div/>").addClass("ps-base ps-platen"),ps_shade:c("<div/>").addClass("ps-shade"),ps_platen:c("<div/>").addClass("ps-platen"),ps_platens:void 0,ps_handle:c("<div/>").addClass("ps-handle"),has_draggable:void 0!==c.fn.draggable,_create:function(b){var a=
this.element,e=a.find("img"),e=c(e[0]),d={width:"auto",height:"auto",position:"absolute",top:0,left:0};this.lmnt=a;this.ps_images=a.find("img");e=c(this.ps_images[0]);this.ps_base=c("<div/>").addClass("ps-base ps-platen");this._save_style(a);a.addClass("ps-paintstripper");this.options.hasOwnProperty("width")?(this.ps_w=b.width,a.width(this.ps_w)):this.ps_w=a.width();this.options.hasOwnProperty("height")?(this.ps_h=b.height,a.height(this.ps_h)):this.ps_h=a.height();this.ps_real_w=e.width();this.ps_real_h=
e.height();this.ps_real_h>=this.ps_real_w?(this.ps_orientation="portrait",this.ps_ratio=this.ps_h/this.ps_real_h,d.width=this.ps_real_w*this.ps_ratio,d.height=this.ps_h,d.left=(this.ps_w-d.width)/2):(this.ps_orientation="landscape",this.ps_ratio=this.ps_w/this.ps_real_w,d.width=this.ps_w,d.height=this.ps_real_h*this.ps_ratio,d.top=(this.ps_h-d.height)/2);this._save_style(a.find("img")).css({width:d.width,height:d.height});a.append(this.ps_base.append(c("<div/>").addClass("ps-axle").css(d).append(e.detach())).css({width:this.ps_w,
height:this.ps_h,top:0,left:0,position:"absolute"}));a.append(this.ps_shade.append(this.ps_platen.append(c("<div/>").addClass("ps-axle").css(d).append(a.children("img").detach())).css({width:this.ps_w,height:this.ps_h,top:0,left:0,position:"absolute"})).css({width:0,height:this.ps_h,top:0,left:0,overflow:"hidden",position:"absolute"}));this.ps_platens=[this.ps_base,this.ps_platen];this._init_draggable(a)},activate:function(b){this.element.addClass("has-active");this._activate_layer(this.ps_shade.find("img#"+
b));return this},deactivate:function(){this.ps_shade.css({width:0}).find("img").removeClass("active");this.element.removeClass("has-active");return this},max_zoom:function(){return 1/this.ps_ratio},move:function(b,a){if(void 0===b)return this.ps_base.position();a=void 0===a?this.options.move_duration:a;b=c.extend(this.ps_base.position(),b);c.each(this.ps_platens,function(){this.animate(b,a)});return this},ratio:function(){return this.ps_ratio},reset:function(b){var a=this.rotate(),b=void 0===b?0:
b;this.reveal(0,b);this.zoom(100,b);c.each(this.ps_platens,function(){c(this).css({top:0,left:0})});this.deactivate();180<a?this.rotate("+="+(360-a),b):this.rotate("-="+a,b);return this},reveal:function(b,a,c){var d=this.element,f=d.width(),g;if(!d.hasClass("has-active"))return this;if(void 0===b)return this.ps_shade.width();a=void 0===a?a=this.option.reveal_duration:a;"string"===typeof b&&null!==(g=b.match(/^(\d+)\%/))?b=f*(g[1]/100):"number"===typeof b&&(0>b?b=0:b>f&&(b=f));this.ps_shade.animate({width:b},
{duration:a,easing:c,step:this._sync_handle,complete:this._sync_handle});return this},rotate:function(b,a,e){var d=this.element.find(".ps-axle");if(void 0===b)return parseInt(d.first().css("rotate"),10);a=void 0===a?this.options.rotate_duration:a;d.each(function(){c(this).transition({rotate:b},a,e,function(b){var a=parseInt(c(this).css("rotate"),10);360<=a?c(this).css({rotate:a%360}):0>a&&c(this).css({rotate:a%360+360});void 0!==b&&b()})});return this},zoom:function(b,a){if(void 0===b)return this.ps_images.first().css("scale");
a=void 0===a?this.options.zoom_duration:a;c(".ps-platen img").each(function(){c(this).transition({scale:b/100},a)});return this},destroy:function(){},_activate_layer:function(b){b.addClass("active").siblings().removeClass("active");return b},_init_draggable:function(b){if(!1!==this.has_draggable){var a=this,e=b.offset().left,d=b.offset().top,f=e+b.width(),g=d+b.height(),h,i;b.append(a.ps_handle);h=a.ps_handle.outerWidth()/2;i=a.ps_handle.outerHeight()/2;a.ps_handle.css({left:-h,top:(b.height()-i)/
2});a.ps_handle.draggable({axis:"x",containment:[e-h,d,f-h,g],drag:function(b,c){var d=c.position.left,e=c.helper.outerWidth()/2;a.ps_shade.width(d+e)}});c.each([a.ps_base,a.ps_platen],function(){c(this).draggable({drag:function(b,a){c(".ps-platen").css({top:a.position.top,left:a.position.left})}})});return b}},_save_style:function(b){return c.each(b,function(){void 0===c(this).attr("style")?c(this).data("orig-style",c(this).attr("style")):c(this).data("orig-style",null)})},_sync_handle:function(){var b=
c(this),a=b.siblings(".ps-handle").first(),e=b.width(),b=b.closest(".ps-paintstripper").width();0>e?e=0:e>b&&(e=b);0<a.length&&a.css({left:e-a.outerWidth()/2});return this}})})(jQuery);