Permalink
Browse files

stop opening when hovered quickly

  • Loading branch information...
1 parent ef69da7 commit 77e507c16e70cf69cad7a3e0fd4188fbef6df0d9 @Mottie committed Nov 28, 2011
Showing with 49 additions and 9 deletions.
  1. +42 −0 README.markdown
  2. +3 −3 index.html
  3. +2 −3 js/jquery.kwicks.js
  4. +2 −3 js/jquery.kwicks.min.js
View
42 README.markdown
@@ -20,3 +20,45 @@
* [Callbacks](https://github.com/Mottie/Kwicks/wiki/Callbacks)
* [Theming](https://github.com/Mottie/Kwicks/wiki/Theming)
* [Change](https://github.com/Mottie/Kwicks/wiki/Change)
+
+###**Recent Changes**
+
+####Version 2.1.1 (11/28/2011)
+
+* Kwick no longer opens if you mouseenter & mouseleave quickly. Fix for [issue #2](https://github.com/Mottie/Kwicks/issues/2).
+
+####Version 2.1 (11/24/2011)
+
+* Fixed a problem that was happening in jQuery v1.7+ ([bug report](https://github.com/Mottie/Kwicks/issues/1)) where the kwicks would not collapse. Fix for [issue #1](https://github.com/Mottie/Kwicks/issues/1).
+* Added slideshow options:
+ * `showDuration` - Slideshow duration in milliseconds (default is 2000 ms).
+ * `showNext` - Slideshow method; `1` goes forward, `-1` goes backwards and `0` shows a random panel (default is 1).
+ * Start or stop the slideshow as follows:
+
+ ```javascript
+ // start slideshow
+ $('#kwick').kwicks('play');
+ // stop slideshow
+ $('#kwick').kwicks('pause');
+ ```
+
+ * Included `playing` and `paused` callbacks
+ * Included `kwicks-playing` and `kwicks-paused` events.
+ * Hovering over the kwicks will pause the slideshow. If `event` and `eventClose` are set to `click`, then the slideshow will resume when unhovered.
+* Added shortcut method to open and close kwicks:
+ * Open Kwick example (zero based index): `$('#kwick').kwicks(1);`.
+ * Close Kwick example (use any negative number): `$('#kwick').kwicks(-1);`.
+* Added shortcut callback method:
+ * Open or close Kwicks with a callback
+
+ ```javascript
+ $('#kwicks').kwicks(1, function(obj){ // obj = kwicks object
+ alert('Now on panel #' + obj.active);
+ });
+ ```
+
+* The `<ul>` and `<li>` structure is no longer required - use any elements.
+* Added a ".kwicks" namespace to internal events (event, eventClose, etc) - this doesn't change the callback/events that are triggered.
+* Updated demo page to follow HTML5 formatting.
+* General script cleanup.
+* Moved documentation to the wiki pages.
View
6 index.html
@@ -22,7 +22,7 @@
<div class="example-info">
- <h3>Kwicks for jQuery v2.1</h3>
+ <h3>Kwicks for jQuery v2+</h3>
<a class="download" href="http://github.com/Mottie/Kwicks/downloads" title="Download Kwicks">Download</a>
<h4>Examples: </h4>
@@ -40,7 +40,7 @@
<h4>Links: </h4>
<ul class="links">
- <li><a href="https://github.com/Mottie/Kwicks">Documents for Kwicks v2.1</a></li>
+ <li><a href="https://github.com/Mottie/Kwicks/wiki">Documents for Kwicks v2+</a></li>
<li><a href="http://www.jeremymartin.name/projects.php?project=kwicks">Blog Post (version 1.5.1)</a></li>
</ul>
@@ -49,7 +49,7 @@
<a id="top" class="anchor"></a>
<div class="example-wrap">
- <h1>Basic Demo (v2.1) - Click to open &amp; close</h1>
+ <h1>Basic Demo (v2+) - Click to open &amp; close</h1>
<p class="controller">Expand Kwick panel : <a href="#">0</a> <a href="#">1</a> <a href="#">2</a> <a href="#">3</a>, or <a href="#">Collapse</a> | <a href="#">Play</a> | <a href="#">Pause</a> </p>
<ul id="basic">
<li></li>
View
5 js/jquery.kwicks.js
@@ -8,8 +8,7 @@
Any and all use of this script must be accompanied by this copyright/license notice in its present form.
- 11/24/2011: version 2.1 - slideshow & cleanup
- 11/8/2010 : version 2.0 - Changed plugin format, updated & added a github repository - Rob Garrison
+ 11/28/2011: version 2.1.1 - kwick doesn't open if mouseenter & mouseleave quickly
*/
(function($){
@@ -135,7 +134,7 @@
// check time - in case both 'event' and 'eventClose' are 'click'
// timestamp broken in jQuery 1.7+, so grabbing a date instead
var time = (new Date()).getTime();
- if (time - base.lastEvent < 200) { return; }
+ if (time - base.lastEvent < 200 && o.event === o.eventClose) { return; }
base.lastEvent = time;
if ($(this).is('.' + o.activeClass)){
base.closeKwick();
View
5 js/jquery.kwicks.min.js
@@ -8,8 +8,7 @@
Any and all use of this script must be accompanied by this copyright/license notice in its present form.
- 11/24/2011: version 2.1 - slideshow & cleanup
- 11/8/2010 : version 2.0 - Changed plugin format, updated & added a github repository - Rob Garrison
+ 11/28/2011: version 2.1.1 - kwick doesn't open if mouseenter & mouseleave quickly
*/
-(function(g){g.kwicks=function(f,k){var c,a=this;a.$el=g(f).addClass("kwicks");a.el=f;a.$el.data("kwicks",a);a.init=function(){var b,d;a.options=c=g.extend({},g.kwicks.defaultOptions,k);a.$kwicks=a.$el.children().addClass("kwick-panel");a.$el.addClass(c.isVertical?"vertical":"horizontal");a.size=a.$kwicks.size();c.defaultKwick=parseInt(c.defaultKwick,10);if(c.defaultKwick>a.size-1)c.defaultKwick=a.size-1;c.showNext=parseInt(c.showNext,10);a.playing=!1;a.lastActive=c.sticky?c.defaultKwick:-1;a.active= a.lastActive;a.$active=a.$kwicks.eq(a.active);a.WoH=c.isVertical?"height":"width";a.LoT=c.isVertical?"top":"left";a.normWoH=parseInt(a.$kwicks.eq(0).css(a.WoH),10);a.preCalcLoTs=[];a.aniObj={};c.max?c.min=(a.normWoH*a.size-c.max)/(a.size-1):c.max=a.normWoH*a.size-c.min*(a.size-1);c.isVertical?a.$el.css({width:a.$kwicks.eq(0).css("width"),height:a.normWoH*a.size+c.spacing*(a.size-1)}):a.$el.css({width:a.normWoH*a.size+c.spacing*(a.size-1),height:a.$kwicks.eq(0).css("height")});for(b=0;b<a.size;b++){a.preCalcLoTs[b]= [];for(d=1;d<a.size-1;d++)a.preCalcLoTs[b][d]=b===d?d*c.min+d*c.spacing:(d<=b?d*c.min:(d-1)*c.min+c.max)+d*c.spacing}a.$el.bind("mouseenter.kwicksShow",function(){a.playing&&a.pause(!0)}).bind("mouseleave.kwicksShow",function(){a.playing&&a.play()});a.$kwicks.each(function(b){var d=g(this);d.addClass("kwick"+(b+1));0===b?d.css(a.LoT,0):b===a.size-1?d.css(c.isVertical?"bottom":"right",0):c.sticky?d.css(a.LoT,Math.ceil(a.preCalcLoTs[c.defaultKwick][b])):d.css(a.LoT,Math.ceil(b*a.normWoH+b*c.spacing)); c.sticky&&(c.defaultKwick===b?(d.css(a.WoH,c.max),d.addClass(c.activeClass)):d.css(a.WoH,c.min))}).css({margin:0,position:"absolute"}).bind(c.event+".kwicks",function(){var c=g(this).index();a.openKwick(c)}).bind(c.eventClose+".kwicks",function(){var b=(new Date).getTime();if(!(200>b-a.lastEvent))a.lastEvent=b,g(this).is("."+c.activeClass)&&a.closeKwick()})};a.openKwick=function(b,d,e){if(/\d/.test(b)&&!isNaN(b)){var f,m,h,i=[],l=[],j=parseInt(g.trim(b),10),b=a.$kwicks.eq(j);if(0>j||j>a.size-1||b.is("."+ c.activeClass))"function"===typeof e&&e(a);else{a.lastEvent=(new Date).getTime();a.$kwicks.stop().removeClass(c.activeClass);a.lastActive=a.active;a.$active=b;a.active=a.$kwicks.index(b);b.addClass(c.activeClass);!0!==d&&a.pause();a.triggerEvent("init");for(d=0;d<a.size;d++)i[d]=parseInt(a.$kwicks.eq(d).css(a.WoH),10),l[d]=parseInt(a.$kwicks.eq(d).css(a.LoT),10);a.aniObj[a.WoH]=c.max;f=c.max-i[j];m=i[j]/f;a.triggerEvent("expanding");b.animate(a.aniObj,{step:function(b){h=0!==f?b/f-m:1;a.$kwicks.each(function(b){b!== j&&a.$kwicks.eq(b).css(a.WoH,Math.ceil(i[b]-(i[b]-c.min)*h));0<b&&b<a.size-1&&a.$kwicks.eq(b).css(a.LoT,Math.ceil(l[b]-(l[b]-a.preCalcLoTs[j][b])*h))})},duration:c.duration,easing:c.easing,complete:function(){a.triggerEvent("completed");"function"===typeof e&&e(a)}})}}else"function"===typeof e&&e(a)};a.closeKwick=function(b,d){if(!c.sticky){d||a.pause();a.triggerEvent("init");var e,f,g,h=[],i=[];for(e=0;e<a.size;e++)h[e]=parseInt(a.$kwicks.eq(e).css(a.WoH),10),i[e]=parseInt(a.$kwicks.eq(e).css(a.LoT), 10);a.aniObj[a.WoH]=a.normWoH;f=a.normWoH-h[0];a.triggerEvent("collapsing");a.$kwicks.stop().removeClass(c.activeClass).eq(0).animate(a.aniObj,{step:function(b){g=0!==f?(b-h[0])/f:1;for(e=1;e<a.size;e++)a.$kwicks.eq(e).css(a.WoH,Math.ceil(h[e]-(h[e]-a.normWoH)*g)),e<a.size-1&&a.$kwicks.eq(e).css(a.LoT,Math.ceil(i[e]-(i[e]-(e*a.normWoH+e*c.spacing))*g))},duration:c.duration,easing:c.easing,complete:function(){a.triggerEvent("completed")}})}};a.play=function(b,d){d||a.pause();if(!a.playing)a.triggerEvent("playing"), a.playing=!0;b="undefined"===typeof b?-1<a.active?a.active:0:b;if(0===c.showNext){for(b=a.active;b===a.active;)b=Math.round(Math.random()*(a.size-1));a.openKwick(b,!0)}else a[0>b||b>=a.size?"closeKwick":"openKwick"](b,!0),b=b>=a.size?-1:0>b?a.size-1:b,b+=c.showNext;a.timer=setTimeout(function(){a.play(b,!0)},c.showDuration)};a.pause=function(b){clearTimeout(a.timer);a.playing=b||!1;(a.playing||b)&&a.triggerEvent("paused")};a.triggerEvent=function(b){a.$el.trigger("kwicks-"+b,a);if(g.isFunction(c[b]))c[b](a)}; a.isActive=function(){return a.$kwicks.is("."+c.activeClass)};a.getActive=function(){return a.isActive()?a.active:-1};a.init()};g.kwicks.defaultOptions={max:null,min:null,spacing:0,isVertical:!1,sticky:!1,defaultKwick:0,activeClass:"active",event:"mouseenter",eventClose:"mouseleave",duration:500,easing:"swing",showDuration:2E3,showNext:1};g.fn.kwicks=function(f){return this.each(function(){g(this).data("kwicks")||new g.kwicks(this,f)})};g.fn.getkwicks=function(){return this.data("kwicks")};g.fn.kwicks= function(f,k){return this.each(function(){var c,a=g(this).data("kwicks");"object"===typeof f&&!a?new g.kwicks(this,f):a&&("string"===typeof f&&(c=f.toLowerCase(),c.match("play")?a.play():c.match("pause")&&(a.playing&&a.triggerEvent("paused"),a.pause())),(c=/\d/.test(f)&&!isNaN(f))&&0>f?a.closeKwick():c&&a.openKwick(f,!1,k))})}})(jQuery);
+(function(g){g.kwicks=function(f,k){var c,a=this;a.$el=g(f).addClass("kwicks");a.el=f;a.$el.data("kwicks",a);a.init=function(){var b,d;a.options=c=g.extend({},g.kwicks.defaultOptions,k);a.$kwicks=a.$el.children().addClass("kwick-panel");a.$el.addClass(c.isVertical?"vertical":"horizontal");a.size=a.$kwicks.size();c.defaultKwick=parseInt(c.defaultKwick,10);if(c.defaultKwick>a.size-1)c.defaultKwick=a.size-1;c.showNext=parseInt(c.showNext,10);a.playing=!1;a.lastActive=c.sticky?c.defaultKwick:-1;a.active= a.lastActive;a.$active=a.$kwicks.eq(a.active);a.WoH=c.isVertical?"height":"width";a.LoT=c.isVertical?"top":"left";a.normWoH=parseInt(a.$kwicks.eq(0).css(a.WoH),10);a.preCalcLoTs=[];a.aniObj={};c.max?c.min=(a.normWoH*a.size-c.max)/(a.size-1):c.max=a.normWoH*a.size-c.min*(a.size-1);c.isVertical?a.$el.css({width:a.$kwicks.eq(0).css("width"),height:a.normWoH*a.size+c.spacing*(a.size-1)}):a.$el.css({width:a.normWoH*a.size+c.spacing*(a.size-1),height:a.$kwicks.eq(0).css("height")});for(b=0;b<a.size;b++){a.preCalcLoTs[b]= [];for(d=1;d<a.size-1;d++)a.preCalcLoTs[b][d]=b===d?d*c.min+d*c.spacing:(d<=b?d*c.min:(d-1)*c.min+c.max)+d*c.spacing}a.$el.bind("mouseenter.kwicksShow",function(){a.playing&&a.pause(!0)}).bind("mouseleave.kwicksShow",function(){a.playing&&a.play()});a.$kwicks.each(function(b){var d=g(this);d.addClass("kwick"+(b+1));0===b?d.css(a.LoT,0):b===a.size-1?d.css(c.isVertical?"bottom":"right",0):c.sticky?d.css(a.LoT,Math.ceil(a.preCalcLoTs[c.defaultKwick][b])):d.css(a.LoT,Math.ceil(b*a.normWoH+b*c.spacing)); c.sticky&&(c.defaultKwick===b?(d.css(a.WoH,c.max),d.addClass(c.activeClass)):d.css(a.WoH,c.min))}).css({margin:0,position:"absolute"}).bind(c.event+".kwicks",function(){var c=g(this).index();a.openKwick(c)}).bind(c.eventClose+".kwicks",function(){var b=(new Date).getTime();if(!(200>b-a.lastEvent&&c.event===c.eventClose))a.lastEvent=b,g(this).is("."+c.activeClass)&&a.closeKwick()})};a.openKwick=function(b,d,e){if(/\d/.test(b)&&!isNaN(b)){var f,m,h,i=[],l=[],j=parseInt(g.trim(b),10),b=a.$kwicks.eq(j); if(0>j||j>a.size-1||b.is("."+c.activeClass))"function"===typeof e&&e(a);else{a.lastEvent=(new Date).getTime();a.$kwicks.stop().removeClass(c.activeClass);a.lastActive=a.active;a.$active=b;a.active=a.$kwicks.index(b);b.addClass(c.activeClass);!0!==d&&a.pause();a.triggerEvent("init");for(d=0;d<a.size;d++)i[d]=parseInt(a.$kwicks.eq(d).css(a.WoH),10),l[d]=parseInt(a.$kwicks.eq(d).css(a.LoT),10);a.aniObj[a.WoH]=c.max;f=c.max-i[j];m=i[j]/f;a.triggerEvent("expanding");b.animate(a.aniObj,{step:function(b){h= 0!==f?b/f-m:1;a.$kwicks.each(function(b){b!==j&&a.$kwicks.eq(b).css(a.WoH,Math.ceil(i[b]-(i[b]-c.min)*h));0<b&&b<a.size-1&&a.$kwicks.eq(b).css(a.LoT,Math.ceil(l[b]-(l[b]-a.preCalcLoTs[j][b])*h))})},duration:c.duration,easing:c.easing,complete:function(){a.triggerEvent("completed");"function"===typeof e&&e(a)}})}}else"function"===typeof e&&e(a)};a.closeKwick=function(b,d){if(!c.sticky){d||a.pause();a.triggerEvent("init");var e,f,g,h=[],i=[];for(e=0;e<a.size;e++)h[e]=parseInt(a.$kwicks.eq(e).css(a.WoH), 10),i[e]=parseInt(a.$kwicks.eq(e).css(a.LoT),10);a.aniObj[a.WoH]=a.normWoH;f=a.normWoH-h[0];a.triggerEvent("collapsing");a.$kwicks.stop().removeClass(c.activeClass).eq(0).animate(a.aniObj,{step:function(b){g=0!==f?(b-h[0])/f:1;for(e=1;e<a.size;e++)a.$kwicks.eq(e).css(a.WoH,Math.ceil(h[e]-(h[e]-a.normWoH)*g)),e<a.size-1&&a.$kwicks.eq(e).css(a.LoT,Math.ceil(i[e]-(i[e]-(e*a.normWoH+e*c.spacing))*g))},duration:c.duration,easing:c.easing,complete:function(){a.triggerEvent("completed")}})}};a.play=function(b, d){d||a.pause();if(!a.playing)a.triggerEvent("playing"),a.playing=!0;b="undefined"===typeof b?-1<a.active?a.active:0:b;if(0===c.showNext){for(b=a.active;b===a.active;)b=Math.round(Math.random()*(a.size-1));a.openKwick(b,!0)}else a[0>b||b>=a.size?"closeKwick":"openKwick"](b,!0),b=b>=a.size?-1:0>b?a.size-1:b,b+=c.showNext;a.timer=setTimeout(function(){a.play(b,!0)},c.showDuration)};a.pause=function(b){clearTimeout(a.timer);a.playing=b||!1;(a.playing||b)&&a.triggerEvent("paused")};a.triggerEvent=function(b){a.$el.trigger("kwicks-"+ b,a);if(g.isFunction(c[b]))c[b](a)};a.isActive=function(){return a.$kwicks.is("."+c.activeClass)};a.getActive=function(){return a.isActive()?a.active:-1};a.init()};g.kwicks.defaultOptions={max:null,min:null,spacing:0,isVertical:!1,sticky:!1,defaultKwick:0,activeClass:"active",event:"mouseenter",eventClose:"mouseleave",duration:500,easing:"swing",showDuration:2E3,showNext:1};g.fn.kwicks=function(f){return this.each(function(){g(this).data("kwicks")||new g.kwicks(this,f)})};g.fn.getkwicks=function(){return this.data("kwicks")}; g.fn.kwicks=function(f,k){return this.each(function(){var c,a=g(this).data("kwicks");"object"===typeof f&&!a?new g.kwicks(this,f):a&&("string"===typeof f&&(c=f.toLowerCase(),c.match("play")?a.play():c.match("pause")&&(a.playing&&a.triggerEvent("paused"),a.pause())),(c=/\d/.test(f)&&!isNaN(f))&&0>f?a.closeKwick():c&&a.openKwick(f,!1,k))})}})(jQuery);

0 comments on commit 77e507c

Please sign in to comment.