Guest User

Untitled

a guest
Mar 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. // Vars defined, global:
  2. var productFullviewTiming='10';
  3. var productImages= [
  4. {
  5. 'src':'product1.png',
  6. 'zoom':''
  7. }, {
  8. 'src':'product2.png',
  9. 'zoom':''
  10. }, {
  11. 'src':'product3.png',
  12. 'zoom':''
  13. }
  14. ];
  15.  
  16. // from an included js file.
  17.  
  18. (function(){
  19.  
  20. /* product switcher */
  21.  
  22. var ProductSwitcher = new Class({
  23.  
  24. timeout : productFullviewTiming*1000,
  25.  
  26. slider : null,
  27.  
  28. bound : {},
  29.  
  30. cloner : null,
  31.  
  32. initialize : function(options) {
  33.  
  34. this.slides = options;
  35.  
  36. this.slider = $('fullview-slider');
  37.  
  38. this.slideOptions = $('slide-options');
  39.  
  40. if ( ! this.slider ) {
  41.  
  42. return;
  43.  
  44. }
  45.  
  46.  
  47.  
  48. this.cloner = new Element('img',{
  49.  
  50. 'id' : 'temp'
  51.  
  52. });
  53.  
  54.  
  55.  
  56. this.timer=productFullviewTiming*1000;
  57.  
  58. this.preloadImages();
  59.  
  60. this.buildSwitchList();
  61.  
  62. this.initRotation();
  63.  
  64. },
  65.  
  66. preloadImages : function() {
  67.  
  68. this.slides.each( function( slide ) {
  69.  
  70. var img = new Image();
  71.  
  72. img.src=slide.src;
  73.  
  74. slide.img = img;
  75.  
  76. });
  77.  
  78. },
  79.  
  80. initRotation : function() {
  81.  
  82. var self = this;
  83.  
  84. if( this.interval !== null ) {
  85.  
  86. window.clearInterval( this.interval );
  87.  
  88. };
  89.  
  90. console.log( "calling timeout for "+this.timeout );
  91.  
  92. this.interval = window.setInterval( function() {
  93.  
  94. self.rotate.apply(self);
  95.  
  96. }, this.timeout);
  97.  
  98. },
  99.  
  100. rotate : function() {
  101. ## working in this section here....
  102. // thought it would be easiest to
  103. "fake" a click on the links
  104. // since they already work and are present.
  105.  
  106. console.log( "rotate() called" );
  107.  
  108. var nextindex=0;
  109.  
  110. var slideopts= $$('ul a', this.slideOptions );
  111.  
  112. slideopts.each( function(item){
  113.  
  114. nextindex++;
  115.  
  116. if ( nextindex > slideopts.length ) {
  117.  
  118. nextindex=0;
  119.  
  120. }
  121.  
  122. // ----
  123.  
  124. if ( $(item).hasClass('current') ) {
  125.  
  126. console.log( "calling fireEvent for click for "+nextindex );
  127.  
  128. console.log( slideopts[nextindex] );
  129.  
  130. slideopts[nextindex].fireEvent('click');
  131.  
  132. return;
  133.  
  134. }
  135.  
  136. });
  137.  
  138. },
  139.  
  140. buildSwitchList : function() {
  141. ## this function creates the links used in the section I'm in, above.
  142.  
  143. var ul = new Element('ul');
  144.  
  145. ul.injectInside(this.slideOptions);
  146.  
  147.  
  148.  
  149. this.bound.click = this.onclick.bindWithEvent(this);
  150.  
  151. var len = this.slides.length;
  152.  
  153. // bookmark
  154.  
  155. var width = len*13;
  156.  
  157. var margin = Math.ceil( width/2 );
  158.  
  159. ul.setStyle( 'width', width+'px' );
  160.  
  161. /*
  162.  
  163. ul.setStyle( 'margin-left', '-'+margin+'px' );
  164.  
  165. */
  166.  
  167.  
  168.  
  169. var i = 1;
  170.  
  171. this.slides.each(function(slide) {
  172.  
  173. var li = new Element('li');
  174.  
  175. var a = new Element('a',{
  176.  
  177. 'href' : '#'
  178.  
  179. });
  180.  
  181. if (i === 1) {
  182.  
  183. a.addClass('current');
  184.  
  185. }
  186.  
  187. a.imgSrc = slide.src;
  188.  
  189. a.zoom = slide.zoom;
  190.  
  191. a.setText(parseInt(i, 10));
  192.  
  193. a.injectInside(li);
  194.  
  195. li.injectInside(ul);
  196.  
  197.  
  198.  
  199. a.addEvent('click', this.bound.click);
  200.  
  201. i = i + 1;
  202.  
  203. }, this);
  204.  
  205. },
  206.  
  207. resetCurrentAnchor : function(el) {
  208.  
  209. $ES('ul a',this.slideOptions).each(function(item){
  210.  
  211. item.removeClass('current');
  212.  
  213. });
  214.  
  215. $(el).addClass('current');
  216.  
  217. },
  218.  
  219. onclick : function(event) {
  220.  
  221. event = new Event(event).stop();
  222.  
  223.  
  224.  
  225. var newSrc = event.target.imgSrc;
  226.  
  227. var zoomSrc = event.target.zoom;
  228.  
  229.  
  230.  
  231. var current = $('gloryshot');
  232.  
  233. if (current.getProperty('src') === newSrc) {
  234.  
  235. return;
  236.  
  237. }
  238.  
  239.  
  240.  
  241. var temporary = this.cloner.clone(false);
  242.  
  243. temporary.setProperty('src',current.getProperty('src'));
  244.  
  245. temporary.injectInside(this.slider);
  246.  
  247.  
  248.  
  249. current.src = newSrc;
  250.  
  251.  
  252.  
  253. var self = this;
  254.  
  255. var mfx = new Fx.Style(temporary,'opacity', {
  256.  
  257. duration: 200,
  258.  
  259. onComplete : function(){
  260.  
  261. temporary.remove();
  262.  
  263. self.resetCurrentAnchor(event.target);
  264.  
  265. }
  266.  
  267. });
  268.  
  269.  
  270.  
  271. var img = new Image();
  272.  
  273. img.onload = function() {
  274.  
  275. mfx.start(1,0);
  276.  
  277. };
  278.  
  279. img.src = newSrc;
  280.  
  281. $('expanded-zoom').removeClass('disabled');
  282.  
  283. $('expanded-zoom').removeEvents( 'click' );
  284.  
  285. if ( zoomSrc.length > 0 ) {
  286.  
  287. this.bound.zoom=this.showZoom.bindWithEvent(this, zoomSrc);
  288.  
  289. // need a new onclick fn for the zoom image thing
  290.  
  291. $('expanded-zoom').addEvent( 'click', this.bound.zoom );
  292.  
  293. }
  294.  
  295. else {
  296.  
  297. $('expanded-zoom').addClass('disabled');
  298.  
  299. }
  300.  
  301. },
  302.  
  303. showZoom : function(event, zoomSrc){
  304.  
  305. event = new Event( event ).stop();
  306.  
  307. var current = $('gloryshot');
  308.  
  309. if ( current.getProperty('src')===zoomSrc) {
  310.  
  311. return;
  312.  
  313. }
  314.  
  315. var temporary = this.cloner.clone(false);
  316.  
  317. temporary.setProperty('src',current.getProperty('src'));
  318.  
  319. temporary.injectInside(this.slider);
  320.  
  321. current.src=zoomSrc;
  322.  
  323. var self = this;
  324.  
  325. var mfx = new Fx.Style( temporary, 'opacity', {
  326.  
  327. duration:200,
  328.  
  329. onComplete : function() {
  330.  
  331. temporary.remove();
  332.  
  333. }
  334.  
  335. });
  336.  
  337. var img = new Image();
  338.  
  339. img.onload = function() {
  340.  
  341. mfx.start(1,0);
  342.  
  343. };
  344.  
  345. img.src = zoomSrc;
  346.  
  347. }
  348.  
  349. });
  350.  
  351.  
  352.  
  353. var ps = new ProductSwitcher(productImages);
  354.  
  355. })();
Add Comment
Please, Sign In to add comment