kaerus-component-slideshow 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72670e2a3117f1b09dee06ac66e4dc779eb6de14
4
- data.tar.gz: b673b2987bcce655535569a18a1dd841a5696d3e
3
+ metadata.gz: c42ee0299b0b413078cd14398439e471ee1abcfb
4
+ data.tar.gz: a5ce0e39c633e36f8b195b7e5609460a50e99766
5
5
  SHA512:
6
- metadata.gz: 8941862bcda605072cd69cec6b2b38fadabb644d89f4a6325b9a04d7922336561e8e4581ca4bbc434308835c41b1f9a3c3081250c82bda9dd6c23d1c9acbc111
7
- data.tar.gz: 6e33bd319d6af1cbdb08a18b3876c0b84b335123a9a0154412813dd4a9430c0d40d4a3e90a71dac460228e349cdaef1840fbf3d9a6e8cae5f39a12dc211644b3
6
+ metadata.gz: e9d5b211e83f971527eea2da78c6f6f67376752c9b9d5908f463812322003a76efa315380e46830c1e6adbde7de9154ac80c6b0dd6e9b686754efa9f2ca148f3
7
+ data.tar.gz: 14c1bfd9c2dad67ded51cdd6ce773ddf9c9d38b3ecc86598781bdd3e6f88ab07dbc5cc4a66bb7ece3c78bfaa90c30d55b4ce2cc66867dd541e1991afa82467f2
@@ -1,7 +1,7 @@
1
1
  module Kaerus
2
2
  module Component
3
3
  module Slideshow
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
7
7
  end
@@ -645,7 +645,7 @@ function Slideshow(container,options){
645
645
  Slideshow.prototype = {
646
646
  init: function(container,options){
647
647
  var settings = this.settings,
648
- id = settings.id,
648
+ id = this.id = settings.id,
649
649
  slides = '\n',
650
650
  navItems = '\n',
651
651
  navId = id + '-nav',
@@ -689,6 +689,8 @@ function Slideshow(container,options){
689
689
 
690
690
  attachHandlers(this);
691
691
 
692
+ this.inTransition = false;
693
+
692
694
  this.emit('init');
693
695
 
694
696
  /* autostart on initialization */
@@ -717,26 +719,14 @@ function Slideshow(container,options){
717
719
  return this;
718
720
  },
719
721
  next: function(){
720
- var self = this;
721
-
722
- if(!this.inTransition) {
723
- this.carousel.next();
722
+ if(this.whenReady('next'));
724
723
  this.emit('next');
725
- } else this.once('transition-end',function(){
726
- self.next();
727
- });
728
724
 
729
725
  return this;
730
726
  },
731
727
  prev: function(){
732
- var self = this;
733
-
734
- if(!this.inTransition) {
735
- this.carousel.prev();
728
+ if(this.whenReady('prev'));
736
729
  this.emit('prev');
737
- } else this.once('transition-end',function(){
738
- self.prev();
739
- });
740
730
 
741
731
  return this;
742
732
  },
@@ -760,6 +750,28 @@ function Slideshow(container,options){
760
750
  else slides.style.display = 'none';
761
751
 
762
752
  return this;
753
+ },
754
+ whenReady: function(action){
755
+ var self = this, handlers, hasHandler;
756
+
757
+ if(!this.inTransition) {
758
+ this.carousel[action]();
759
+ return true;
760
+ } else {
761
+ handlers = this.listeners('transition-end');
762
+ for(var h in handlers){
763
+ if(handlers[h]._of && handlers[h]._of === self[action]){
764
+ hasHandler = true;
765
+ break;
766
+ }
767
+ }
768
+
769
+ if(!hasHandler){
770
+ this.once('transition-end', self[action]);
771
+ }
772
+ }
773
+
774
+ return false;
763
775
  }
764
776
  }
765
777
 
@@ -772,21 +784,24 @@ function Slideshow(container,options){
772
784
  prev = document.getElementById(id+'-prev');
773
785
 
774
786
  /* add slidshow UI handlers */
775
- if(slideshow.settings.canPause)
776
- addPauseHandler(slides, slideshow);
777
-
778
- addNavHandler(nav,slideshow);
779
- addTransitionHandler(nav, slides, slideshow);
780
-
781
787
  addEvent(next,'click',function(event){
788
+ event = event ? event : window.event;
782
789
  slideshow.next();
783
790
  event.stopPropagation();
784
791
  });
785
792
 
786
793
  addEvent(prev,'click',function(event){
794
+ event = event ? event : window.event;
787
795
  slideshow.prev();
788
796
  event.stopPropagation();
789
797
  });
798
+
799
+ if(slideshow.settings.canPause)
800
+ addPauseHandler(slides, slideshow);
801
+
802
+ addNavHandler(nav,slideshow);
803
+
804
+ addTransitionHandler(nav, slides, slideshow);
790
805
  }
791
806
 
792
807
  function applyStyle(elem,prop,attr){
@@ -853,11 +868,9 @@ function Slideshow(container,options){
853
868
  var settings = slideshow.settings,
854
869
  transition = settings.transition,
855
870
  navItems = nav.getElementsByTagName('li'),
856
- timer, durationProp, duration, s = 0,
871
+ timer, durationProp, s = 0,
857
872
  ix, fx, lx = navItems.length, slide = [], node;
858
873
 
859
- /* $('#objectID').css('-webkit-transition-duration');*/
860
-
861
874
  durationProp = getStyleProperty('transition-duration',true);
862
875
 
863
876
  for(var x in slides.childNodes){
@@ -872,36 +885,35 @@ function Slideshow(container,options){
872
885
  ix = index % lx;
873
886
  fx = from % lx;
874
887
 
875
- slideshow.inTransition = true;
876
-
877
888
  slideshow.emit('transition',slide[ix],ix);
878
889
 
879
890
  if(from !== undefined){
891
+ slideshow.inTransition = true;
892
+
880
893
  navItems[fx].className = "navItem";
881
894
  // apply transitions after first slide to avoid animations on startup
882
895
  if(!slideshow.hasTransitions){
883
896
  applyTransitions(document.getElementById(settings.id + '-slides'));
884
897
  slideshow.hasTransitions = true;
885
898
  }
886
- }
887
-
888
- navItems[ix].className = "active navItem";
889
899
 
900
+ s = window.getComputedStyle(slide[ix],null).getPropertyValue(durationProp);
890
901
 
891
- s = window.getComputedStyle(slide[ix],null).getPropertyValue(durationProp);
892
-
893
- if(s.indexOf('s') > 0) s = parseInt(s,10) * 1000;
894
- else s = parseInt(s,10);
902
+ if(s.indexOf('s') > 0) s = parseInt(s,10) * 1000;
903
+ else s = parseInt(s,10);
895
904
 
896
- current = ix;
905
+ current = ix;
897
906
 
898
- if(s){
899
- /* note: workaround for problematic transition-end event */
900
- timer = setTimeout(function(){
901
- slideshow.inTransition = false;
902
- slideshow.emit('transition-end',slide[current],current);
903
- },s);
907
+ if(s){
908
+ /* note: workaround for problematic transition-end event */
909
+ timer = setTimeout(function(){
910
+ slideshow.inTransition = false;
911
+ slideshow.emit('transition-end',slide[current],current);
912
+ },s);
913
+ }
904
914
  }
915
+
916
+ navItems[ix].className = "active navItem";
905
917
 
906
918
  slideshow.carousel.transit(index,from);
907
919
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaerus-component-slideshow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anders Elo