forked from albertoarena/jquery-vibrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.vibrate.min.js
19 lines (19 loc) · 3.67 KB
/
jquery.vibrate.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
* jquery.vibrate.js
* jQuery Vibrating Button Plugin
*
* Author: Alberto Arena <[email protected]>
* Modified: Aziz Khambati <[email protected]>
* Version: 1.2.1
* Date: 16/03/2013
* Demo: http://www.dev4web.eu/projects/jquery.vibrate
* Support: https://github.com/albertoarena/jQuery-Vibrate
*
* Changelog
* 1.2.1 29 aug 2013: Added an option of stopAfterTime and added code so that it gets wrapped only once, added callback when vibrations stops
* 1.2 16 mar 2013: optimized code and improved speed
* 1.1 29 oct 2011: added vibrateClass and overClass parameters
* 1.0.117 dec 2010: removed "overflow:hidden" attribute to both wrapping DIVS (to allow transparency outside the vibrating box); added overEffect parameter
* 1.0 14 dec 2010: released first version
*/
(function(e){e.fn.vibrate=function(t){if(true==e(this).data("vibrate.status")){return}e(this).each(function(){var n=e(this);if(e.type(n.attr("id"))=="undefined"){n.attr("id","vibrate_"+Math.round(Math.random()*1e17))}n.id=n.attr("id");n.defaults={reverse:false,speed:50,trigger:"mouseover",overEffect:"stop",overClass:"",vibrateClass:""};n.defaults=e.extend(n.defaults,t);n.defaults.speedBackup=n.defaults.speed;if("true"!=n.data("vibrate-initiated")){var r={"float":n.css("float"),margin:n.css("margin-top")+" "+n.css("margin-right")+" "+n.css("margin-bottom")+" "+n.css("margin-left"),display:n.css("display"),width:n.outerWidth(),height:n.outerHeight(),padding:"0",border:"0"};var i={width:n.outerWidth(),height:n.outerHeight(),padding:"0",margin:"0",border:"0",display:"block"};n.wrap("<div><div></div></div>");n.parent().css(i);n.parent().parent().css(r);n.css({margin:"0"});n.data("vibrate-initiated","true")}n.data("vibrate",n);n.data("vibrate.status",false);if(n.defaults.stopAfterTime){setTimeout(function(){n.vibrationStart();setTimeout(function(){n.vibrationStop()},n.defaults.stopAfterTime*500)},Math.round(Math.random*50))}else{var s="";if(n.defaults.trigger=="mouseover")s="mouseout";else if(n.defaults.trigger=="focus")s="blur";if(n.defaults.overEffect!="stop"&&n.defaults.overEffect!="invert")n.defaults.overEffect="";if(n.defaults.reverse){if(n.defaults.overEffect!=""){n.bind(n.defaults.trigger,function(){n.addClass(n.defaults.overClass);if(n.defaults.overEffect=="stop")n.vibrationStop();else if(n.defaults.overEffect=="invert"){n.defaults.speed=Math.round(n.defaults.speed/3)}}).bind(s,function(){n.removeClass(n.defaults.overClass);if(n.defaults.overEffect=="invert"){n.defaults.speed=n.defaults.speedBackup}else{n.vibrationStart()}})}setTimeout(function(){n.vibrationStart()},Math.round(Math.random*1e3))}else{n.bind(n.defaults.trigger,function(){n.vibrationStart()}).bind(s,function(){n.vibrationStop()})}}});e.fn.vibrationStart=function(){if(e.type(e(this).data("vibrate"))!=="undefined"){e(this).data("vibrate.status",true);e(this).css({margin:"0 0 0 0"});e(this).addClass(e(this).data("vibrate").defaults.vibrateClass);e(this).vibrationLoop()}};e.fn.vibrationStop=function(){if(e.type(e(this).data("vibrate"))!=="undefined"){e(this).stop(false,true);e(this).removeClass(e(this).data("vibrate").defaults.vibrateClass);e(this).data("vibrate.status",false);if(e(this).data("vibrate").defaults.callBack){e(this).data("vibrate").defaults.callBack()}}};e.fn.vibrationLoop=function(){if(e.type(e(this).data("vibrate"))!=="undefined"){var t=e(this).data("vibrate");if(e(this).data("vibrate.status")==true){var n={marginTop:"0px",marginLeft:"0px"};var r=e(this).position();if(parseInt(e(this).css("marginTop"))>0){n.marginTop="-1px";n.marginLeft="-1px"}else{n.marginTop="1px";n.marginLeft="1px"}e(this).animate(n,t.defaults.speed,function(){e(this).vibrationLoop()})}else{e(this).css({margin:"0 0 0 0"})}}}}})(jQuery)