kaerus-component-slideshow 0.1.1 → 0.1.2

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: c42ee0299b0b413078cd14398439e471ee1abcfb
4
- data.tar.gz: a5ce0e39c633e36f8b195b7e5609460a50e99766
3
+ metadata.gz: 52b19604b6f001d260096edef9cd4148191fd590
4
+ data.tar.gz: 9e33c37a52f6256994861d2f393d1d14c364cb4f
5
5
  SHA512:
6
- metadata.gz: e9d5b211e83f971527eea2da78c6f6f67376752c9b9d5908f463812322003a76efa315380e46830c1e6adbde7de9154ac80c6b0dd6e9b686754efa9f2ca148f3
7
- data.tar.gz: 14c1bfd9c2dad67ded51cdd6ce773ddf9c9d38b3ecc86598781bdd3e6f88ab07dbc5cc4a66bb7ece3c78bfaa90c30d55b4ce2cc66867dd541e1991afa82467f2
6
+ metadata.gz: 1953b19d35de7f8892f6895fb6e337a27bef589ea6a3cfba42686df68b9fef71811a5a3825cf1d1a358d7e897c1d4c177b5c5d52a2fe12b935866d3b0a96e4aa
7
+ data.tar.gz: 33c63a8f8b156900c584dc415c272409543bb9ab8d26ac827f0b8b5d4be6c9dc9baccb5da34993a325e0a3380226a1bbd74baaedab9f559c5c7401ef742f1e1e
@@ -1,7 +1,7 @@
1
1
  module Kaerus
2
2
  module Component
3
3
  module Slideshow
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
6
6
  end
7
7
  end
@@ -644,11 +644,15 @@ function Slideshow(container,options){
644
644
  (function(){
645
645
  Slideshow.prototype = {
646
646
  init: function(container,options){
647
- var settings = this.settings,
647
+ var self = this,
648
+ settings = this.settings,
648
649
  id = this.id = settings.id,
649
650
  slides = '\n',
650
651
  navItems = '\n',
651
652
  navId = id + '-nav',
653
+ nextId = id + '-next',
654
+ prevId = id + '-prev',
655
+ slideId = id + '-slides',
652
656
  childs = container.childNodes;
653
657
 
654
658
  /* get slides from parent container */
@@ -683,21 +687,33 @@ function Slideshow(container,options){
683
687
  settings.width = container.clientWidth;
684
688
 
685
689
  /* create newcarousel instance */
686
- this.carousel = new Carousel(id+'-slides');
690
+ this.carousel = new Carousel(slideId);
687
691
 
688
692
  this.slides = this.carousel.slides;
689
693
 
690
- attachHandlers(this);
694
+ this.navId = '#' + navId;
691
695
 
692
- this.inTransition = false;
696
+ this.slideId = '#' + slideId;
697
+
698
+ this.nextId = '#' + nextId;
699
+
700
+ this.prevId = '#' + prevId;
693
701
 
694
- this.emit('init');
702
+ transitionHandler(document.getElementById(navId),
703
+ document.getElementById(slideId),
704
+ this);
705
+
706
+ this.inTransition = false;
695
707
 
696
708
  /* autostart on initialization */
697
709
  if(this.settings.auto !== false){
698
710
  this.start(this.settings.auto === true ? 0 : this.settings.auto);
699
711
  }
700
712
 
713
+ setTimeout(function(){
714
+ self.emit('init');
715
+ }, 0 );
716
+
701
717
  return this;
702
718
  },
703
719
  start: function(index){
@@ -737,9 +753,14 @@ function Slideshow(container,options){
737
753
  return this;
738
754
  },
739
755
  show: function(x){
740
- this.carousel.show(x);
741
- this.emit('show');
756
+ if(typeof x === 'string'){
757
+ x = x.match(/\d+$/)[0];
758
+ x = x ? parseInt(x,10) : 0;
759
+ }
742
760
 
761
+ if(this.whenReady('show',x));
762
+ this.emit('show',x);
763
+
743
764
  return this;
744
765
  },
745
766
  display: function(value){
@@ -751,11 +772,11 @@ function Slideshow(container,options){
751
772
 
752
773
  return this;
753
774
  },
754
- whenReady: function(action){
775
+ whenReady: function(action,value){
755
776
  var self = this, handlers, hasHandler;
756
777
 
757
778
  if(!this.inTransition) {
758
- this.carousel[action]();
779
+ this.carousel[action](value);
759
780
  return true;
760
781
  } else {
761
782
  handlers = this.listeners('transition-end');
@@ -767,7 +788,7 @@ function Slideshow(container,options){
767
788
  }
768
789
 
769
790
  if(!hasHandler){
770
- this.once('transition-end', self[action]);
791
+ this.once('transition-end', self[action], value);
771
792
  }
772
793
  }
773
794
 
@@ -776,34 +797,6 @@ function Slideshow(container,options){
776
797
  }
777
798
 
778
799
 
779
- function attachHandlers(slideshow){
780
- var id = slideshow.settings.id,
781
- slides = document.getElementById(id+'-slides'),
782
- nav = document.getElementById(id+'-nav'),
783
- next = document.getElementById(id+'-next'),
784
- prev = document.getElementById(id+'-prev');
785
-
786
- /* add slidshow UI handlers */
787
- addEvent(next,'click',function(event){
788
- event = event ? event : window.event;
789
- slideshow.next();
790
- event.stopPropagation();
791
- });
792
-
793
- addEvent(prev,'click',function(event){
794
- event = event ? event : window.event;
795
- slideshow.prev();
796
- event.stopPropagation();
797
- });
798
-
799
- if(slideshow.settings.canPause)
800
- addPauseHandler(slides, slideshow);
801
-
802
- addNavHandler(nav,slideshow);
803
-
804
- addTransitionHandler(nav, slides, slideshow);
805
- }
806
-
807
800
  function applyStyle(elem,prop,attr){
808
801
  var style = '';
809
802
 
@@ -837,36 +830,8 @@ function Slideshow(container,options){
837
830
  elem.style[prop] = style;
838
831
  }
839
832
 
840
- function addNavHandler(elem,slideshow){
841
- var nav = document.getElementById(slideshow.settings.id+'-nav'),
842
- matchNav = new RegExp(elem.id + '(\\d+)');
843
-
844
- addEvent(elem,'click', function(event){
845
- event = event ? event : window.event;
846
- var target = event.target || event.srcElement,
847
- ix = matchNav.exec(target.id);
848
-
849
- if(ix) {
850
- slideshow.show(ix[1]);
851
- event.stopPropagation();
852
- }
853
- });
854
- }
855
-
856
- /* adds click handler on slide to toggle pause */
857
- function addPauseHandler(elem,slideshow){
858
- elem.addEventListener('click',function(event){
859
- if(slideshow.paused) {
860
- slideshow.resume();
861
- } else {
862
- slideshow.pause();
863
- }
864
- });
865
- }
866
-
867
- function addTransitionHandler(nav,slides,slideshow){
833
+ function transitionHandler(nav,slides,slideshow){
868
834
  var settings = slideshow.settings,
869
- transition = settings.transition,
870
835
  navItems = nav.getElementsByTagName('li'),
871
836
  timer, durationProp, s = 0,
872
837
  ix, fx, lx = navItems.length, slide = [], node;
@@ -878,6 +843,8 @@ function Slideshow(container,options){
878
843
  if(node && node.id && node.id.indexOf(settings.id + '-s') === 0)
879
844
  slide[s++] = node;
880
845
  }
846
+
847
+ applyStyle(slide,'transition',settings.transition);
881
848
 
882
849
  slideshow.carousel.onChange = function(index,from){
883
850
  var current;
@@ -891,11 +858,6 @@ function Slideshow(container,options){
891
858
  slideshow.inTransition = true;
892
859
 
893
860
  navItems[fx].className = "navItem";
894
- // apply transitions after first slide to avoid animations on startup
895
- if(!slideshow.hasTransitions){
896
- applyTransitions(document.getElementById(settings.id + '-slides'));
897
- slideshow.hasTransitions = true;
898
- }
899
861
 
900
862
  s = window.getComputedStyle(slide[ix],null).getPropertyValue(durationProp);
901
863
 
@@ -917,19 +879,6 @@ function Slideshow(container,options){
917
879
 
918
880
  slideshow.carousel.transit(index,from);
919
881
  }
920
-
921
- function applyTransitions(container){
922
- var childs = container.childNodes, elems = [];
923
-
924
- for(var i = 0, l = childs.length; i < l; i++){
925
- if(childs[i].nodeType === 1){
926
- elems.push(childs[i]);
927
- }
928
- }
929
-
930
- applyStyle(elems,'transition',transition);
931
- }
932
-
933
882
  }
934
883
 
935
884
  function getStyleProperty(prop){
@@ -939,25 +888,6 @@ function Slideshow(container,options){
939
888
  return prefixProp[prop];
940
889
  }
941
890
 
942
- function hasTransitionEndEvent(){
943
- var transitionEndEvents = ['transitionend', 'webkitTransitionEnd', 'otransitionend'], e;
944
-
945
- e = transitionEndEvents.filter(function(m){
946
- return ('on'+m.toLowerCase()) in window
947
- });
948
-
949
- return e[0];
950
- }
951
-
952
- function addEvent(el,ev,fn,cap){
953
- if(el.addEventListener){
954
- el.addEventListener(ev, fn, !!cap);
955
- } else if (el.attachEvent){
956
- el.attachEvent('on' + ev, fn);
957
- } else el['on' + ev] = fn;
958
-
959
- return el;
960
- }
961
891
  }());
962
892
 
963
893
  module.exports = Slideshow;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaerus-component-slideshow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anders Elo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-15 00:00:00.000000000 Z
11
+ date: 2014-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler