PageRenderTime 60ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/js/iview.js

https://github.com/johnko/iView
JavaScript | 1747 lines | 1445 code | 200 blank | 102 comment | 311 complexity | 75a20ab05894db34cb4dc738de46832f MD5 | raw file
Possible License(s): LGPL-3.0
  1. /**
  2. * jQuery iView Slider v2.0
  3. *
  4. * @version: 2.0.1 - August 17, 2012
  5. *
  6. * @author: Hemn Chawroka
  7. * hemn@iprodev.com
  8. * http://iprodev.com/
  9. *
  10. */ (function ($, window, undefined) {
  11. var iView = function (el, options) {
  12. //Get slider holder
  13. var iv = this;
  14. iv.options = options;
  15. iv.sliderContent = el, iv.sliderInner = iv.sliderContent.html();
  16. iv.sliderContent.html("<div class='iviewSlider'>" + iv.sliderInner + "</div>");
  17. //Get slider
  18. iv.slider = $('.iviewSlider', iv.sliderContent);
  19. iv.slider.css('position', 'relative');
  20. //Necessary variables.
  21. iv.defs = {
  22. slide: 0,
  23. total: 0,
  24. image: '',
  25. images: [],
  26. width: iv.sliderContent.width(),
  27. height: iv.sliderContent.height(),
  28. timer: options.timer.toLowerCase(),
  29. lock: false,
  30. paused: (options.autoAdvance) ? false : true,
  31. time: options.pauseTime,
  32. easing: options.easing
  33. };
  34. //Disable slider text selection
  35. iv.disableSelection(iv.slider[0]);
  36. //Find slides
  37. iv.slides = iv.slider.children();
  38. iv.slides.each(function (i) {
  39. var slide = $(this);
  40. //Find images & thumbnails
  41. iv.defs.images.push(slide.data("iview:image"));
  42. if (slide.data("iview:thumbnail")) iv.defs.images.push(slide.data("iview:thumbnail"));
  43. slide.css('display', 'none');
  44. //Find videos
  45. if (slide.data("iview:type") == "video") {
  46. var element = slide.children().eq(0),
  47. video = $('<div class="iview-video-show"><div class="iview-video-container"><a class="iview-video-close" title="' + options.closeLabel + '">&#735;</a></div></div>');
  48. slide.append(video);
  49. element.appendTo($('div.iview-video-container', video));
  50. video.css({
  51. width: iv.defs.width,
  52. height: iv.defs.height,
  53. top: '-' + iv.defs.height + 'px'
  54. }).hide();
  55. slide.addClass('iview-video').css({
  56. 'cursor': 'pointer'
  57. });
  58. }
  59. iv.defs.total++;
  60. }).css({
  61. width: iv.defs.width,
  62. height: iv.defs.height
  63. });
  64. //Set Preloader Element
  65. iv.sliderContent.append('<div id="iview-preloader"><div></div></div>');
  66. var iviewPreloader = $('#iview-preloader', iv.sliderContent);
  67. var preloaderBar = $('div', iviewPreloader);
  68. iviewPreloader.css({
  69. top: ((iv.defs.height / 2) - (iviewPreloader.height() / 2)) + 'px',
  70. left: ((iv.defs.width / 2) - (iviewPreloader.width() / 2)) + 'px'
  71. });
  72. //Set Timer Element
  73. iv.sliderContent.append('<div id="iview-timer"><div></div></div>');
  74. iv.iviewTimer = $('#iview-timer', iv.sliderContent);
  75. iv.iviewTimer.hide();
  76. //Find captions
  77. $('.iview-caption', iv.slider).each(function (i) {
  78. var caption = $(this);
  79. caption.html('<div class="caption-contain">' + caption.html() + '</div>');
  80. });
  81. //If randomStart
  82. options.startSlide = (options.randomStart) ? Math.floor(Math.random() * iv.defs.total) : options.startSlide;
  83. //Set startSlide
  84. options.startSlide = (options.startSlide > 0 && options.startSlide >= iv.defs.total) ? iv.defs.total - 1 : options.startSlide;
  85. iv.defs.slide = options.startSlide;
  86. //Set first image
  87. iv.defs.image = iv.slides.eq(iv.defs.slide);
  88. //Set pauseTime
  89. iv.defs.time = (iv.defs.image.data('iview:pausetime')) ? iv.defs.image.data('iview:pausetime') : options.pauseTime;
  90. //Set easing
  91. iv.defs.easing = (iv.defs.image.data('iview:easing')) ? iv.defs.image.data('iview:easing') : options.easing;
  92. iv.pieDegree = 0;
  93. var padding = options.timerPadding,
  94. diameter = options.timerDiameter,
  95. stroke = options.timerStroke;
  96. if (iv.defs.total > 1 && iv.defs.timer != "bar") {
  97. //Start the Raphael
  98. stroke = (iv.defs.timer == "360bar") ? options.timerStroke : 0;
  99. var width = (diameter + (padding * 2) + (stroke * 2)),
  100. height = width,
  101. r = Raphael(iv.iviewTimer[0], width, height);
  102. iv.R = (diameter / 2);
  103. var param = {
  104. stroke: options.timerBg,
  105. "stroke-width": (stroke + (padding * 2))
  106. },
  107. param2 = {
  108. stroke: options.timerColor,
  109. "stroke-width": stroke,
  110. "stroke-linecap": "round"
  111. },
  112. param3 = {
  113. fill: options.timerColor,
  114. stroke: 'none',
  115. "stroke-width": 0
  116. },
  117. bgParam = {
  118. fill: options.timerBg,
  119. stroke: 'none',
  120. "stroke-width": 0
  121. };
  122. // Custom Arc Attribute
  123. r.customAttributes.arc = function (value, R) {
  124. var total = 360,
  125. alpha = 360 / total * value,
  126. a = (90 - alpha) * Math.PI / 180,
  127. cx = ((diameter / 2) + padding + stroke),
  128. cy = ((diameter / 2) + padding + stroke),
  129. x = cx + R * Math.cos(a),
  130. y = cy - R * Math.sin(a),
  131. path;
  132. if (total == value) {
  133. path = [["M", cx, cy - R], ["A", R, R, 0, 1, 1, 299.99, cy - R]];
  134. } else {
  135. path = [["M", cx, cy - R], ["A", R, R, 0, +(alpha > 180), 1, x, y]];
  136. }
  137. return {
  138. path: path
  139. };
  140. };
  141. // Custom Segment Attribute
  142. r.customAttributes.segment = function (angle, R) {
  143. var a1 = -90;
  144. R = R - 1;
  145. angle = (a1 + angle);
  146. var flag = (angle - a1) > 180,
  147. x = ((diameter / 2) + padding),
  148. y = ((diameter / 2) + padding);
  149. a1 = (a1 % 360) * Math.PI / 180;
  150. angle = (angle % 360) * Math.PI / 180;
  151. return {
  152. path: [["M", x, y], ["l", R * Math.cos(a1), R * Math.sin(a1)], ["A", R, R, 0, +flag, 1, x + R * Math.cos(angle), y + R * Math.sin(angle)], ["z"]]
  153. };
  154. };
  155. if (iv.defs.total > 1 && iv.defs.timer == "pie") {
  156. r.circle(iv.R + padding, iv.R + padding, iv.R + padding - 1).attr(bgParam);
  157. }
  158. iv.timerBgPath = r.path().attr(param), iv.timerPath = r.path().attr(param2), iv.pieTimer = r.path().attr(param3);
  159. }
  160. iv.barTimer = $('div', iv.iviewTimer);
  161. if (iv.defs.total > 1 && iv.defs.timer == "360bar") {
  162. iv.timerBgPath.attr({
  163. arc: [359.9, iv.R]
  164. });
  165. }
  166. //Set Timer Styles
  167. if (iv.defs.timer == "bar") {
  168. iv.iviewTimer.css({
  169. opacity: options.timerOpacity,
  170. width: diameter,
  171. height: stroke,
  172. border: options.timerBarStroke + 'px ' + options.timerBarStrokeColor + ' ' + options.timerBarStrokeStyle,
  173. padding: padding,
  174. background: options.timerBg
  175. });
  176. iv.barTimer.css({
  177. width: 0,
  178. height: stroke,
  179. background: options.timerColor,
  180. 'float': 'left'
  181. });
  182. } else {
  183. iv.iviewTimer.css({
  184. opacity: options.timerOpacity,
  185. width: width,
  186. height: height
  187. });
  188. }
  189. //Set Timer Position
  190. iv.setTimerPosition();
  191. // Run Preloader
  192. new ImagePreload(iv.defs.images, function (i) {
  193. var percent = (i * 10);
  194. preloaderBar.stop().animate({
  195. width: percent + '%'
  196. });
  197. }, function () {
  198. preloaderBar.stop().animate({
  199. width: '100%'
  200. }, function () {
  201. iviewPreloader.remove();
  202. iv.startSlider();
  203. //Trigger the onAfterLoad callback
  204. options.onAfterLoad.call(this);
  205. });
  206. });
  207. //Touch navigation
  208. iv.sliderContent.bind('swipeleft', function () {
  209. if (iv.defs.lock) return false;
  210. iv.cleanTimer();
  211. iv.goTo('next');
  212. }).bind('swiperight', function () {
  213. if (iv.defs.lock) return false;
  214. iv.cleanTimer();
  215. iv.defs.slide -= 2;
  216. iv.goTo('prev');
  217. });
  218. //Keyboard Navigation
  219. if (options.keyboardNav) {
  220. $(document).bind('keyup.iView', function (event) {
  221. //Left
  222. if (event.keyCode == '37') {
  223. if (iv.defs.lock) return false;
  224. iv.cleanTimer();
  225. iv.defs.slide -= 2;
  226. iv.goTo('prev');
  227. }
  228. //Right
  229. if (event.keyCode == '39') {
  230. if (iv.defs.lock) return false;
  231. iv.cleanTimer();
  232. iv.goTo('next');
  233. }
  234. });
  235. }
  236. //Play/Pause action
  237. iv.iviewTimer.live('click', function () {
  238. if (iv.iviewTimer.hasClass('paused')) {
  239. iv.playSlider();
  240. } else {
  241. iv.stopSlider();
  242. }
  243. });
  244. //Bind the stop action
  245. iv.sliderContent.bind('iView:pause', function () {
  246. iv.stopSlider();
  247. });
  248. //Bind the start action
  249. iv.sliderContent.bind('iView:play', function () {
  250. iv.playSlider();
  251. });
  252. //Bind the start action
  253. iv.sliderContent.bind('iView:previous', function () {
  254. if (iv.defs.lock) return false;
  255. iv.cleanTimer();
  256. iv.defs.slide -= 2;
  257. iv.goTo('prev');
  258. });
  259. //Bind the start action
  260. iv.sliderContent.bind('iView:next', function () {
  261. if (iv.defs.lock) return false;
  262. iv.cleanTimer();
  263. iv.goTo('next');
  264. });
  265. //Bind the goSlide action
  266. iv.sliderContent.bind('iView:goSlide', function (event, slide) {
  267. if (iv.defs.lock || iv.defs.slide == slide) return false;
  268. if ($(this).hasClass('active')) return false;
  269. iv.cleanTimer();
  270. iv.slider.css('background', 'url("' + iv.defs.image.data('iview:image') + '") no-repeat');
  271. iv.defs.slide = slide - 1;
  272. iv.goTo('control');
  273. });
  274. //Bind the resize action
  275. iv.sliderContent.bind('resize', function () {
  276. t = $(this),
  277. tW = t.width(),
  278. tH = t.height(),
  279. width = iv.slider.width(),
  280. height = iv.slider.height();
  281. if(iv.defs.width != tW){
  282. var ratio = (tW / width),
  283. newHeight = Math.round(iv.defs.height * ratio);
  284. iv.slider.css({
  285. '-webkit-transform-origin' : '0 0',
  286. '-moz-transform-origin' : '0 0',
  287. '-o-transform-origin' : '0 0',
  288. '-ms-transform-origin' : '0 0',
  289. 'transform-origin' : '0 0',
  290. '-webkit-transform' : 'scale('+ ratio +')',
  291. '-moz-transform' : 'scale('+ ratio +')',
  292. '-o-transform' : 'scale('+ ratio +')',
  293. '-ms-transform' : 'scale('+ ratio +')',
  294. 'transform' : 'scale('+ ratio +')'
  295. });
  296. t.css({ height: newHeight });
  297. iv.defs.width = tW;
  298. //Set Timer Position
  299. iv.setTimerPosition();
  300. }
  301. });
  302. //Bind video display
  303. $('.iview-video', iv.slider).click(function(e){
  304. var t = $(this),
  305. video = $('.iview-video-show', t);
  306. if(!$(e.target).hasClass('iview-video-close') && !$(e.target).hasClass('iview-caption') && !$(e.target).parents().hasClass('iview-caption')){
  307. video.show().animate({ top: 0 }, 1000, 'easeOutBounce');
  308. iv.sliderContent.trigger('iView:pause');
  309. }
  310. });
  311. //Bind the video closer
  312. $('.iview-video-close', iv.slider).click(function(){
  313. var video = $(this).parents('.iview-video-show'),
  314. iframe = $('iframe', video),
  315. src = iframe.attr('src');
  316. iframe.removeAttr('src').attr('src',src);
  317. video.animate({ top: '-' + iv.defs.height + 'px' }, 1000, 'easeOutBounce', function(){
  318. video.hide();
  319. iv.sliderContent.trigger('iView:play');
  320. });
  321. });
  322. };
  323. //iView helper functions
  324. iView.prototype = {
  325. timer: null,
  326. //Start Slider
  327. startSlider: function () {
  328. var iv = this;
  329. var img = new Image();
  330. img.src = iv.slides.eq(0).data('iview:image');
  331. imgWidth = img.width;
  332. if(imgWidth != iv.defs.width){
  333. iv.defs.width = imgWidth;
  334. iv.sliderContent.trigger('resize');
  335. }
  336. iv.iviewTimer.show();
  337. //Show slide
  338. iv.slides.eq(iv.defs.slide).css('display', 'block');
  339. //Set first background
  340. iv.slider.css('background', 'url("' + iv.defs.image.data('iview:image') + '") no-repeat');
  341. //Set initial caption
  342. iv.setCaption(iv.options);
  343. iv.iviewTimer.addClass('paused').attr('title', iv.options.playLabel);
  344. if (iv.options.autoAdvance && iv.defs.total > 1) {
  345. iv.iviewTimer.removeClass('paused').attr('title', iv.options.pauseLabel);
  346. iv.setTimer();
  347. }
  348. //Add Direction nav
  349. if (iv.options.directionNav) {
  350. iv.sliderContent.append('<div class="iview-directionNav"><a class="iview-prevNav" title="' + iv.options.previousLabel + '">' + iv.options.previousLabel + '</a><a class="iview-nextNav" title="' + iv.options.nextLabel + '">' + iv.options.nextLabel + '</a></div>');
  351. //Animate Direction nav
  352. $('.iview-directionNav', iv.sliderContent).css({
  353. opacity: iv.options.directionNavHoverOpacity
  354. });
  355. iv.sliderContent.hover(function () {
  356. $('.iview-directionNav', iv.sliderContent).stop().animate({
  357. opacity: 1
  358. }, 300);
  359. }, function () {
  360. $('.iview-directionNav', iv.sliderContent).stop().animate({
  361. opacity: iv.options.directionNavHoverOpacity
  362. }, 300);
  363. });
  364. $('a.iview-prevNav', iv.sliderContent).live('click', function () {
  365. if (iv.defs.lock) return false;
  366. iv.cleanTimer();
  367. iv.defs.slide -= 2;
  368. iv.goTo('prev');
  369. });
  370. $('a.iview-nextNav', iv.sliderContent).live('click', function () {
  371. if (iv.defs.lock) return false;
  372. iv.cleanTimer();
  373. iv.goTo('next');
  374. });
  375. }
  376. //Add Control nav
  377. if (iv.options.controlNav) {
  378. var iviewControl = '<div class="iview-controlNav">',
  379. iviewTooltip = '';
  380. if (!iv.options.directionNav && iv.options.controlNavNextPrev) iviewControl += '<a class="iview-controlPrevNav" title="' + iv.options.previousLabel + '">' + iv.options.previousLabel + '</a>';
  381. iviewControl += '<div class="iview-items"><ul>';
  382. for (var i = 0; i < iv.defs.total; i++) {
  383. var slide = iv.slides.eq(i);
  384. iviewControl += '<li>';
  385. if (iv.options.controlNavThumbs) {
  386. var thumb = (slide.data('iview:thumbnail')) ? slide.data('iview:thumbnail') : slide.data('iview:image');
  387. iviewControl += '<a class="iview-control" rel="' + i + '"><img src="' + thumb + '" /></a>';
  388. } else {
  389. var thumb = (slide.data('iview:thumbnail')) ? slide.data('iview:thumbnail') : slide.data('iview:image');
  390. iviewControl += '<a class="iview-control" rel="' + i + '">' + (i + 1) + '</a>';
  391. if (iv.options.controlNavTooltip) iviewTooltip += '<div rel="' + i + '"><img src="' + thumb + '" /></div>';
  392. }
  393. iviewControl += '</li>';
  394. }
  395. iviewControl += '</ul></div>';
  396. if (!iv.options.directionNav && iv.options.controlNavNextPrev) iviewControl += '<a class="iview-controlNextNav" title="' + iv.options.nextLabel + '">' + iv.options.nextLabel + '</a>';
  397. iviewControl += '</div>';
  398. if (!iv.options.controlNavThumbs && iv.options.controlNavTooltip) iviewControl += '<div id="iview-tooltip"><div class="holder"><div class="container">' + iviewTooltip + '</div></div></div>';
  399. iv.sliderContent.append(iviewControl);
  400. //Set initial active link
  401. $('.iview-controlNav a.iview-control:eq(' + iv.defs.slide + ')', iv.sliderContent).addClass('active');
  402. $('a.iview-controlPrevNav', iv.sliderContent).live('click', function () {
  403. if (iv.defs.lock) return false;
  404. iv.cleanTimer();
  405. iv.defs.slide -= 2;
  406. iv.goTo('prev');
  407. });
  408. $('a.iview-controlNextNav', iv.sliderContent).live('click', function () {
  409. if (iv.defs.lock) return false;
  410. iv.cleanTimer();
  411. iv.goTo('next');
  412. });
  413. $('.iview-controlNav a.iview-control', iv.sliderContent).live('click', function () {
  414. if (iv.defs.lock) return false;
  415. if ($(this).hasClass('active')) return false;
  416. iv.cleanTimer();
  417. iv.slider.css('background', 'url("' + iv.defs.image.data('iview:image') + '") no-repeat');
  418. iv.defs.slide = $(this).attr('rel') - 1;
  419. iv.goTo('control');
  420. });
  421. //Animate Control nav
  422. $('.iview-controlNav', iv.sliderContent).css({
  423. opacity: iv.options.controlNavHoverOpacity
  424. });
  425. iv.sliderContent.hover(function () {
  426. $('.iview-controlNav', iv.sliderContent).stop().animate({
  427. opacity: 1
  428. }, 300);
  429. iv.sliderContent.addClass('iview-hover');
  430. }, function () {
  431. $('.iview-controlNav', iv.sliderContent).stop().animate({
  432. opacity: iv.options.controlNavHoverOpacity
  433. }, 300);
  434. iv.sliderContent.removeClass('iview-hover');
  435. });
  436. //Show Tooltip
  437. var tooltipTimer = null;
  438. $('.iview-controlNav a.iview-control', iv.sliderContent).hover(function (e) {
  439. var t = $(this),
  440. i = t.attr('rel'),
  441. tooltip = $('#iview-tooltip', iv.sliderContent),
  442. holder = $('div.holder', tooltip),
  443. x = t.offset().left - iv.sliderContent.offset().left - (tooltip.outerWidth() / 2) + iv.options.tooltipX,
  444. y = t.offset().top - iv.sliderContent.offset().top - tooltip.outerHeight() + iv.options.tooltipY,
  445. imD = $('div[rel=' + i + ']')
  446. scrollLeft = (i * imD.width());
  447. tooltip.stop().animate({
  448. left: x,
  449. top: y,
  450. opacity: 1
  451. }, 300);
  452. //tooltip.css({ opacity: 1 });
  453. if (tooltip.not(':visible')) tooltip.fadeIn(300);
  454. holder.stop().animate({
  455. scrollLeft: scrollLeft
  456. }, 300);
  457. clearTimeout(tooltipTimer);
  458. }, function (e) {
  459. var tooltip = $('#iview-tooltip', iv.sliderContent);
  460. tooltipTimer = setTimeout(function () {
  461. tooltip.animate({
  462. opacity: 0
  463. }, 300, function () {
  464. tooltip.hide();
  465. });
  466. }, 200);
  467. });
  468. }
  469. //Bind hover setting
  470. iv.sliderContent.bind('mouseover.iView mousemove.iView', function () {
  471. //Clear the timer
  472. if (iv.options.pauseOnHover && !iv.defs.paused) iv.cleanTimer();
  473. iv.sliderContent.addClass('iview-hover');
  474. }).bind('mouseout.iView', function () {
  475. //Restart the timer
  476. if (iv.options.pauseOnHover && !iv.defs.paused && iv.timer == null && iv.pieDegree <= 359 && iv.options.autoAdvance) iv.setTimer();
  477. iv.sliderContent.removeClass('iview-hover');
  478. });
  479. },
  480. // setCaption function
  481. setCaption: function () {
  482. var iv = this,
  483. slide = iv.slides.eq(iv.defs.slide),
  484. captions = $('.iview-caption', slide),
  485. timeEx = 0;
  486. captions.each(function (i) {
  487. var caption = $(this),
  488. fx = (caption.data('transition')) ? $.trim(caption.data('transition').toLowerCase()) : "fade",
  489. speed = (caption.data('speed')) ? caption.data('speed') : iv.options.captionSpeed,
  490. easing = (caption.data('easing')) ? caption.data('easing') : iv.options.captionEasing,
  491. x = (caption.data('x')!="undefined") ? caption.data('x') : "center",
  492. y = (caption.data('y')!="undefined") ? caption.data('y') : "center",
  493. w = (caption.data('width')) ? caption.data('width') : caption.width(),
  494. h = (caption.data('height')) ? caption.data('height') : caption.height(),
  495. oW = caption.outerWidth(),
  496. oH = caption.outerHeight();
  497. if(x == "center") x = ((iv.defs.width/2) - (oW/2));
  498. if(y == "center") y = ((iv.defs.height/2) - (oH/2));
  499. var captionContain = $('.caption-contain', caption);
  500. caption.css({
  501. opacity: 0
  502. });
  503. captionContain.css({
  504. opacity: 0,
  505. position: 'relative',
  506. width: w,
  507. height: h
  508. });
  509. switch (fx) {
  510. case "wipedown":
  511. caption.css({
  512. top: (y - h),
  513. left: x
  514. });
  515. captionContain.css({
  516. top: (h + (h * 3)),
  517. left: 0
  518. });
  519. break;
  520. case "wipeup":
  521. caption.css({
  522. top: (y + h),
  523. left: x
  524. });
  525. captionContain.css({
  526. top: (h - (h * 3)),
  527. left: 0
  528. });
  529. break;
  530. case "wiperight":
  531. caption.css({
  532. top: y,
  533. left: (x - w)
  534. });
  535. captionContain.css({
  536. top: 0,
  537. left: (w + (w * 2))
  538. });
  539. break;
  540. case "wipeleft":
  541. caption.css({
  542. top: y,
  543. left: (x + w)
  544. });
  545. captionContain.css({
  546. top: 0,
  547. left: (w - (w * 2))
  548. });
  549. break;
  550. case "fade":
  551. caption.css({
  552. top: y,
  553. left: x
  554. });
  555. captionContain.css({
  556. top: 0,
  557. left: 0
  558. });
  559. break;
  560. case "expanddown":
  561. caption.css({
  562. top: y,
  563. left: x,
  564. height: 0
  565. });
  566. captionContain.css({
  567. top: (h + (h * 3)),
  568. left: 0
  569. });
  570. break;
  571. case "expandup":
  572. caption.css({
  573. top: (y + h),
  574. left: x,
  575. height: 0
  576. });
  577. captionContain.css({
  578. top: (h - (h * 3)),
  579. left: 0
  580. });
  581. break;
  582. case "expandright":
  583. caption.css({
  584. top: y,
  585. left: x,
  586. width: 0
  587. });
  588. captionContain.css({
  589. top: 0,
  590. left: (w + (w * 2))
  591. });
  592. break;
  593. case "expandleft":
  594. caption.css({
  595. top: y,
  596. left: (x + w),
  597. width: 0
  598. });
  599. captionContain.css({
  600. top: 0,
  601. left: (w - (w * 2))
  602. });
  603. break;
  604. }
  605. setTimeout(function () {
  606. caption.animate({
  607. opacity: iv.options.captionOpacity,
  608. top: y,
  609. left: x,
  610. width: w,
  611. height: h
  612. }, speed, easing, function () {});
  613. }, timeEx);
  614. setTimeout(function () {
  615. captionContain.animate({
  616. opacity: iv.options.captionOpacity,
  617. top: 0,
  618. left: 0
  619. }, speed, easing);
  620. }, (timeEx + 100));
  621. timeEx += 250;
  622. });
  623. },
  624. //Process the timer
  625. processTimer: function () {
  626. var iv = this;
  627. if (iv.defs.timer == "360bar") {
  628. var degree = (iv.pieDegree == 0) ? 0 : iv.pieDegree + .9;
  629. iv.timerPath.attr({
  630. arc: [degree, iv.R]
  631. });
  632. } else if (iv.defs.timer == "pie") {
  633. var degree = (iv.pieDegree == 0) ? 0 : iv.pieDegree + .9;
  634. iv.pieTimer.attr({
  635. segment: [degree, iv.R]
  636. });
  637. } else {
  638. iv.barTimer.css({
  639. width: ((iv.pieDegree / 360) * 100) + '%'
  640. });
  641. }
  642. iv.pieDegree += 3;
  643. },
  644. //When Animation finishes
  645. transitionEnd: function (iv) {
  646. //Trigger the onAfterChange callback
  647. iv.options.onAfterChange.call(this);
  648. //Lock the slider
  649. iv.defs.lock = false;
  650. //Hide slider slides
  651. iv.slides.css('display', 'none');
  652. //Diplay the current slide
  653. iv.slides.eq(iv.defs.slide).show();
  654. iv.slider.css('background', 'url("' + iv.defs.image.data('iview:image') + '") no-repeat');
  655. // Remove any strips and blocks from last transition
  656. $('.iview-strip, .iview-block', iv.slider).remove();
  657. //Set slide pauseTime
  658. iv.defs.time = (iv.defs.image.data('iview:pausetime')) ? iv.defs.image.data('iview:pausetime') : iv.options.pauseTime;
  659. //Process timer
  660. iv.iviewTimer.animate({
  661. opacity: iv.options.timerOpacity
  662. });
  663. iv.pieDegree = 0;
  664. iv.processTimer();
  665. //Set caption
  666. iv.setCaption(iv.options);
  667. //Restart the timer
  668. if (iv.timer == null && !iv.defs.paused) iv.timer = setInterval(function () {
  669. iv.timerCall(iv);
  670. }, (iv.defs.time / 120));
  671. },
  672. // Add strips
  673. addStrips: function (vertical, opts) {
  674. var iv = this;
  675. opts = (opts) ? opts : iv.options;
  676. for (var i = 0; i < opts.strips; i++) {
  677. var stripWidth = Math.round(iv.slider.width() / opts.strips),
  678. stripHeight = Math.round(iv.slider.height() / opts.strips),
  679. bgPosition = '-' + ((stripWidth + (i * stripWidth)) - stripWidth) + 'px 0%',
  680. top = ((vertical) ? (stripHeight * i) + 'px' : '0px'),
  681. left = ((vertical) ? '0px' : (stripWidth * i) + 'px');
  682. if (vertical) bgPosition = '0% -' + ((stripHeight + (i * stripHeight)) - stripHeight) + 'px';
  683. if (i == opts.strips - 1) {
  684. var width = ((vertical) ? '0px' : (iv.slider.width() - (stripWidth * i)) + 'px'),
  685. height = ((vertical) ? (iv.slider.height() - (stripHeight * i)) + 'px' : '0px');
  686. } else {
  687. var width = ((vertical) ? '0px' : stripWidth + 'px'),
  688. height = ((vertical) ? stripHeight + 'px' : '0px');
  689. }
  690. var strip = $('<div class="iview-strip"></div>').css({
  691. width: width,
  692. height: height,
  693. top: top,
  694. left: left,
  695. background: 'url("' + iv.defs.image.data('iview:image') + '") no-repeat ' + bgPosition,
  696. opacity: 0
  697. });
  698. iv.slider.append(strip);
  699. }
  700. },
  701. // Add blocks
  702. addBlocks: function () {
  703. var iv = this,
  704. blockWidth = Math.round(iv.slider.width() / iv.options.blockCols),
  705. blockHeight = Math.round(iv.slider.height() / iv.options.blockRows);
  706. for (var rows = 0; rows < iv.options.blockRows; rows++) {
  707. for (var columns = 0; columns < iv.options.blockCols; columns++) {
  708. var top = (rows * blockHeight) + 'px',
  709. left = (columns * blockWidth) + 'px',
  710. width = blockWidth + 'px',
  711. height = blockHeight + 'px',
  712. bgPosition = '-' + ((blockWidth + (columns * blockWidth)) - blockWidth) + 'px -' + ((blockHeight + (rows * blockHeight)) - blockHeight) + 'px';
  713. if (columns == iv.options.blockCols - 1) width = (iv.slider.width() - (blockWidth * columns)) + 'px';
  714. var block = $('<div class="iview-block"></div>').css({
  715. width: blockWidth + 'px',
  716. height: blockHeight + 'px',
  717. top: (rows * blockHeight) + 'px',
  718. left: (columns * blockWidth) + 'px',
  719. background: 'url("' + iv.defs.image.data('iview:image') + '") no-repeat ' + bgPosition,
  720. opacity: 0
  721. });
  722. iv.slider.append(block);
  723. }
  724. }
  725. },
  726. runTransition: function (fx) {
  727. var iv = this;
  728. switch (fx) {
  729. case 'strip-up-right':
  730. case 'strip-up-left':
  731. iv.addStrips();
  732. var timeDelay = 0;
  733. i = 0, strips = $('.iview-strip', iv.slider);
  734. if (fx == 'strip-up-left') strips = $('.iview-strip', iv.slider).reverse();
  735. strips.each(function () {
  736. var strip = $(this);
  737. strip.css({
  738. top: '',
  739. bottom: '0px'
  740. });
  741. setTimeout(function () {
  742. strip.animate({
  743. height: '100%',
  744. opacity: '1.0'
  745. }, iv.options.animationSpeed, iv.defs.easing, function () {
  746. if (i == iv.options.strips - 1) iv.transitionEnd(iv);
  747. i++;
  748. });
  749. }, (100 + timeDelay));
  750. timeDelay += 50;
  751. });
  752. break;
  753. case 'strip-down':
  754. case 'strip-down-right':
  755. case 'strip-down-left':
  756. iv.addStrips();
  757. var timeDelay = 0,
  758. i = 0,
  759. strips = $('.iview-strip', iv.slider);
  760. if (fx == 'strip-down-left') strips = $('.iview-strip', iv.slider).reverse();
  761. strips.each(function () {
  762. var strip = $(this);
  763. strip.css({
  764. bottom: '',
  765. top: '0px'
  766. });
  767. setTimeout(function () {
  768. strip.animate({
  769. height: '100%',
  770. opacity: '1.0'
  771. }, iv.options.animationSpeed, iv.defs.easing, function () {
  772. if (i == iv.options.strips - 1) iv.transitionEnd(iv);
  773. i++;
  774. });
  775. }, (100 + timeDelay));
  776. timeDelay += 50;
  777. });
  778. break;
  779. case 'strip-left-right':
  780. case 'strip-left-right-up':
  781. case 'strip-left-right-down':
  782. iv.addStrips(true);
  783. var timeDelay = 0,
  784. i = 0,
  785. v = 0,
  786. strips = $('.iview-strip', iv.slider);
  787. if (fx == 'strip-left-right-down') strips = $('.iview-strip', iv.slider).reverse();
  788. strips.each(function () {
  789. var strip = $(this);
  790. if (i == 0) {
  791. strip.css({
  792. right: '',
  793. left: '0px'
  794. });
  795. i++;
  796. } else {
  797. strip.css({
  798. left: '',
  799. right: '0px'
  800. });
  801. i = 0;
  802. }
  803. setTimeout(function () {
  804. strip.animate({
  805. width: '100%',
  806. opacity: '1.0'
  807. }, iv.options.animationSpeed, iv.defs.easing, function () {
  808. if (v == iv.options.strips - 1) iv.transitionEnd(iv);
  809. v++;
  810. });
  811. }, (100 + timeDelay));
  812. timeDelay += 50;
  813. });
  814. break;
  815. case 'strip-up-down':
  816. case 'strip-up-down-right':
  817. case 'strip-up-down-left':
  818. iv.addStrips();
  819. var timeDelay = 0,
  820. i = 0,
  821. v = 0,
  822. strips = $('.iview-strip', iv.slider);
  823. if (fx == 'strip-up-down-left') strips = $('.iview-strip', iv.slider).reverse();
  824. strips.each(function () {
  825. var strip = $(this);
  826. if (i == 0) {
  827. strip.css({
  828. bottom: '',
  829. top: '0px'
  830. });
  831. i++;
  832. } else {
  833. strip.css({
  834. top: '',
  835. bottom: '0px'
  836. });
  837. i = 0;
  838. }
  839. setTimeout(function () {
  840. strip.animate({
  841. height: '100%',
  842. opacity: '1.0'
  843. }, iv.options.animationSpeed, iv.defs.easing, function () {
  844. if (v == iv.options.strips - 1) iv.transitionEnd(iv);
  845. v++;
  846. });
  847. }, (100 + timeDelay));
  848. timeDelay += 50;
  849. });
  850. break;
  851. case 'left-curtain':
  852. case 'right-curtain':
  853. case 'top-curtain':
  854. case 'bottom-curtain':
  855. if (fx == 'left-curtain' || fx == 'right-curtain') iv.addStrips();
  856. else iv.addStrips(true);
  857. var timeDelay = 0,
  858. i = 0,
  859. strips = $('.iview-strip', iv.slider);
  860. if (fx == 'right-curtain' || fx == 'bottom-curtain') strips = $('.iview-strip', iv.slider).reverse();
  861. strips.each(function () {
  862. var strip = $(this);
  863. var width = strip.width();
  864. var height = strip.height();
  865. if (fx == 'left-curtain' || fx == 'right-curtain') strip.css({
  866. top: '0px',
  867. height: '100%',
  868. width: '0px'
  869. });
  870. else strip.css({
  871. left: '0px',
  872. height: '0px',
  873. width: '100%'
  874. });
  875. setTimeout(function () {
  876. if (fx == 'left-curtain' || fx == 'right-curtain') strip.animate({
  877. width: width,
  878. opacity: '1.0'
  879. }, iv.options.animationSpeed, iv.defs.easing, function () {
  880. if (i == iv.options.strips - 1) iv.transitionEnd(iv);
  881. i++;
  882. });
  883. else strip.animate({
  884. height: height,
  885. opacity: '1.0'
  886. }, iv.options.animationSpeed, iv.defs.easing, function () {
  887. if (i == iv.options.strips - 1) iv.transitionEnd(iv);
  888. i++;
  889. });
  890. }, (100 + timeDelay));
  891. timeDelay += 50;
  892. });
  893. break;
  894. case 'strip-up-right':
  895. case 'strip-up-left':
  896. iv.addStrips();
  897. var timeDelay = 0,
  898. i = 0,
  899. strips = $('.iview-strip', iv.slider);
  900. if (fx == 'strip-up-left') strips = $('.iview-strip', iv.slider).reverse();
  901. strips.each(function () {
  902. var strip = $(this);
  903. strip.css({
  904. 'bottom': '0px'
  905. });
  906. setTimeout(function () {
  907. strip.animate({
  908. height: '100%',
  909. opacity: '1.0'
  910. }, iv.options.animationSpeed, iv.defs.easing, function () {
  911. if (i == iv.options.strips - 1) iv.transitionEnd(iv);
  912. i++;
  913. });
  914. }, (100 + timeDelay));
  915. timeDelay += 50;
  916. });
  917. break;
  918. case 'strip-left-fade':
  919. case 'strip-right-fade':
  920. case 'strip-top-fade':
  921. case 'strip-bottom-fade':
  922. if (fx == 'strip-left-fade' || fx == 'strip-right-fade') iv.addStrips();
  923. else iv.addStrips(true);
  924. var timeDelay = 0,
  925. i = 0,
  926. strips = $('.iview-strip', iv.slider);
  927. if (fx == 'strip-right-fade' || fx == 'strip-bottom-fade') strips = $('.iview-strip', iv.slider).reverse();
  928. strips.each(function () {
  929. var strip = $(this);
  930. var width = strip.width();
  931. var height = strip.height();
  932. if (fx == 'strip-left-fade' || fx == 'strip-right-fade') strip.css({
  933. top: '0px',
  934. height: '100%',
  935. width: width
  936. });
  937. else strip.css({
  938. left: '0px',
  939. height: height,
  940. width: '100%'
  941. });
  942. setTimeout(function () {
  943. strip.animate({
  944. opacity: '1.0'
  945. }, iv.options.animationSpeed * 1.7, iv.defs.easing, function () {
  946. if (i == iv.options.strips - 1) iv.transitionEnd(iv);
  947. i++;
  948. });
  949. }, (100 + timeDelay));
  950. timeDelay += 35;
  951. });
  952. break;
  953. case 'slide-in-up':
  954. case 'slide-in-down':
  955. opts = {
  956. strips: 1
  957. };
  958. iv.addStrips(false, opts);
  959. var strip = $('.iview-strip:first', iv.slider),
  960. top = 0;
  961. if (fx == 'slide-in-up') top = '-' + iv.defs.height + 'px';
  962. else top = iv.defs.height + 'px';
  963. strip.css({
  964. top: top,
  965. 'height': '100%',
  966. 'width': iv.defs.width
  967. });
  968. strip.animate({
  969. 'top': '0px',
  970. opacity: 1
  971. }, (iv.options.animationSpeed * 2), iv.defs.easing, function () {
  972. iv.transitionEnd(iv);
  973. });
  974. break;
  975. case 'zigzag-top':
  976. case 'zigzag-bottom':
  977. case 'zigzag-grow-top':
  978. case 'zigzag-grow-bottom':
  979. case 'zigzag-drop-top':
  980. case 'zigzag-drop-bottom':
  981. iv.addBlocks();
  982. var totalBlocks = (iv.options.blockCols * iv.options.blockRows),
  983. timeDelay = 0,
  984. blockToArr = new Array(),
  985. blocks = $('.iview-block', iv.slider);
  986. for (var rows = 0; rows < iv.options.blockRows; rows++) {
  987. var odd = (rows % 2),
  988. start = (rows * iv.options.blockCols),
  989. end = ((rows + 1) * iv.options.blockCols);
  990. if (odd == 1) {
  991. for (var columns = end - 1; columns >= start; columns--) {
  992. blockToArr.push($(blocks[columns]));
  993. }
  994. } else {
  995. for (var columns = start; columns < end; columns++) {
  996. blockToArr.push($(blocks[columns]));
  997. }
  998. }
  999. }
  1000. if (fx == 'zigzag-bottom' || fx == 'zigzag-grow-bottom' || fx == 'zigzag-drop-bottom') blockToArr.reverse();
  1001. // Run animation
  1002. blocks.each(function (i) {
  1003. var block = $(blockToArr[i]),
  1004. h = block.height(),
  1005. w = block.width(),
  1006. top = block.css('top');
  1007. if (fx == 'zigzag-grow-top' || fx == 'zigzag-grow-bottom') block.width(0).height(0);
  1008. else if (fx == 'zigzag-drop-top' || fx == 'zigzag-drop-bottom') block.css({
  1009. top: '-=50'
  1010. });
  1011. setTimeout(function () {
  1012. if (fx == 'zigzag-grow-top' || fx == 'zigzag-grow-bottom') block.animate({
  1013. opacity: '1',
  1014. height: h,
  1015. width: w
  1016. }, iv.options.animationSpeed, iv.defs.easing, function () {
  1017. if (i == totalBlocks - 1) iv.transitionEnd(iv);
  1018. });
  1019. else if (fx == 'zigzag-drop-top' || fx == 'zigzag-drop-bottom') block.animate({
  1020. top: top,
  1021. opacity: '1'
  1022. }, iv.options.animationSpeed, iv.defs.easing, function () {
  1023. if (i == totalBlocks - 1) iv.transitionEnd(iv);
  1024. });
  1025. else block.animate({
  1026. opacity: '1'
  1027. }, (iv.options.animationSpeed * 2), 'easeInOutExpo', function () {
  1028. if (i == totalBlocks - 1) iv.transitionEnd(iv);
  1029. });
  1030. }, (100 + timeDelay));
  1031. timeDelay += 20;
  1032. });
  1033. break;
  1034. case 'block-fade':
  1035. case 'block-fade-reverse':
  1036. case 'block-expand':
  1037. case 'block-expand-reverse':
  1038. iv.addBlocks();
  1039. var totalBlocks = (iv.options.blockCols * iv.options.blockRows),
  1040. i = 0,
  1041. timeDelay = 0;
  1042. // Split blocks into array
  1043. var rowIndex = 0;
  1044. var colIndex = 0;
  1045. var blockToArr = new Array();
  1046. blockToArr[rowIndex] = new Array();
  1047. var blocks = $('.iview-block', iv.slider);
  1048. if (fx == 'block-fade-reverse' || fx == 'block-expand-reverse') {
  1049. blocks = $('.iview-block', iv.slider).reverse();
  1050. }
  1051. blocks.each(function () {
  1052. blockToArr[rowIndex][colIndex] = $(this);
  1053. colIndex++;
  1054. if (colIndex == iv.options.blockCols) {
  1055. rowIndex++;
  1056. colIndex = 0;
  1057. blockToArr[rowIndex] = new Array();
  1058. }
  1059. });
  1060. // Run animation
  1061. for (var columns = 0; columns < (iv.options.blockCols * 2); columns++) {
  1062. var Col = columns;
  1063. for (var rows = 0; rows < iv.options.blockRows; rows++) {
  1064. if (Col >= 0 && Col < iv.options.blockCols) {
  1065. (function () {
  1066. var block = $(blockToArr[rows][Col]);
  1067. var w = block.width();
  1068. var h = block.height();
  1069. if (fx == 'block-expand' || fx == 'block-expand-reverse') {
  1070. block.width(0).height(0);
  1071. }
  1072. setTimeout(function () {
  1073. block.animate({
  1074. opacity: '1',
  1075. width: w,
  1076. height: h
  1077. }, iv.options.animationSpeed / 1.3, iv.defs.easing, function () {
  1078. if (i == totalBlocks - 1) iv.transitionEnd(iv);
  1079. i++;
  1080. });
  1081. }, (100 + timeDelay));
  1082. })();
  1083. }
  1084. Col--;
  1085. }
  1086. timeDelay += 100;
  1087. }
  1088. break;
  1089. case 'block-random':
  1090. case 'block-expand-random':
  1091. case 'block-drop-random':
  1092. iv.addBlocks();
  1093. var totalBlocks = (iv.options.blockCols * iv.options.blockRows),
  1094. timeDelay = 0;
  1095. var blocks = iv.shuffle($('.iview-block', iv.slider));
  1096. blocks.each(function (i) {
  1097. var block = $(this),
  1098. h = block.height(),
  1099. w = block.width(),
  1100. top = block.css('top');
  1101. if (fx == 'block-expand-random') block.width(0).height(0);
  1102. if (fx == 'block-drop-random') block.css({
  1103. top: '-=50'
  1104. });
  1105. setTimeout(function () {
  1106. block.animate({
  1107. top: top,
  1108. opacity: '1',
  1109. height: h,
  1110. width: w
  1111. }, iv.options.animationSpeed, iv.defs.easing, function () {
  1112. if (i == totalBlocks - 1) iv.transitionEnd(iv);
  1113. });
  1114. }, (100 + timeDelay));
  1115. timeDelay += 20;
  1116. });
  1117. break;
  1118. case 'slide-in-right':
  1119. case 'slide-in-left':
  1120. case 'fade':
  1121. default:
  1122. opts = {
  1123. strips: 1
  1124. };
  1125. iv.addStrips(false, opts);
  1126. var strip = $('.iview-strip:first', iv.slider);
  1127. strip.css({
  1128. 'height': '100%',
  1129. 'width': iv.defs.width
  1130. });
  1131. if (fx == 'slide-in-right') strip.css({
  1132. 'height': '100%',
  1133. 'width': iv.defs.width,
  1134. 'left': iv.defs.width + 'px',
  1135. 'right': ''
  1136. });
  1137. else if (fx == 'slide-in-left') strip.css({
  1138. 'left': '-' + iv.defs.width + 'px'
  1139. });
  1140. strip.animate({
  1141. left: '0px',
  1142. opacity: 1
  1143. }, (iv.options.animationSpeed * 2), iv.defs.easing, function () {
  1144. iv.transitionEnd(iv);
  1145. });
  1146. break;
  1147. }
  1148. },
  1149. // Shuffle an array
  1150. shuffle: function (oldArray) {
  1151. var newArray = oldArray.slice();
  1152. var len = newArray.length;
  1153. var i = len;
  1154. while (i--) {
  1155. var p = parseInt(Math.random() * len);
  1156. var t = newArray[i];
  1157. newArray[i] = newArray[p];
  1158. newArray[p] = t;
  1159. }
  1160. return newArray;
  1161. },
  1162. // Timer interval caller
  1163. timerCall: function (iv) {
  1164. iv.processTimer();
  1165. if (iv.pieDegree >= 360) {
  1166. iv.cleanTimer();
  1167. iv.goTo(false);
  1168. }
  1169. },
  1170. //Set the timer function
  1171. setTimer: function () {
  1172. var iv = this;
  1173. iv.timer = setInterval(function () {
  1174. iv.timerCall(iv);
  1175. }, (iv.defs.time / 120));
  1176. },
  1177. //Clean the timer function
  1178. cleanTimer: function () {
  1179. var iv = this;
  1180. clearInterval(iv.timer);
  1181. iv.timer = null;
  1182. },
  1183. // goTo function
  1184. goTo: function (action) {
  1185. var iv = this;
  1186. //Trigger the onLastSlide callback
  1187. if (iv.defs && (iv.defs.slide == iv.defs.total - 1)) {
  1188. iv.options.onLastSlide.call(this);
  1189. }
  1190. iv.cleanTimer();
  1191. iv.iviewTimer.animate({
  1192. opacity: 0
  1193. });
  1194. //Trigger the onBeforeChange callback
  1195. iv.options.onBeforeChange.call(this);
  1196. //Set current background before change
  1197. if (!action) {
  1198. iv.slider.css('background', 'url("' + iv.defs.image.data('iview:image') + '") no-repeat');
  1199. } else {
  1200. if (action == 'prev' || action == 'next') {
  1201. iv.slider.css('background', 'url("' + iv.defs.image.data('iview:image') + '") no-repeat');
  1202. }
  1203. }
  1204. iv.defs.slide++;
  1205. //Trigger the onSlideShowEnd callback
  1206. if (iv.defs.slide == iv.defs.total) {
  1207. iv.defs.slide = 0;
  1208. iv.options.onSlideShowEnd.call(this);
  1209. }
  1210. if (iv.defs.slide < 0) iv.defs.slide = (iv.defs.total - 1);
  1211. //Set iv.defs.image
  1212. iv.defs.image = iv.slides.eq(iv.defs.slide);
  1213. //Set active links
  1214. if (iv.options.controlNav) {
  1215. $('.iview-controlNav a.iview-control', iv.sliderContent).removeClass('active');
  1216. $('.iview-controlNav a.iview-control:eq(' + iv.defs.slide + ')', iv.sliderContent).addClass('active');
  1217. }
  1218. var fx = iv.options.fx;
  1219. //Generate random transition
  1220. if (iv.options.fx.toLowerCase() == 'random') {
  1221. var transitions = new Array('left-curtain', 'right-curtain', 'top-curtain', 'bottom-curtain', 'strip-down-right', 'strip-down-left', 'strip-up-right', 'strip-up-left', 'strip-up-down', 'strip-up-down-left', 'strip-left-right', 'strip-left-right-down', 'slide-in-right', 'slide-in-left', 'slide-in-up', 'slide-in-down', 'fade', 'block-random', 'block-fade', 'block-fade-reverse', 'block-expand', 'block-expand-reverse', 'block-expand-random', 'zigzag-top', 'zigzag-bottom', 'zigzag-grow-top', 'zigzag-grow-bottom', 'zigzag-drop-top', 'zigzag-drop-bottom', 'strip-left-fade', 'strip-right-fade', 'strip-top-fade', 'strip-bottom-fade', 'block-drop-random');
  1222. fx = transitions[Math.floor(Math.random() * (transitions.length + 1))];
  1223. if (fx == undefined) fx = 'fade';
  1224. fx = $.trim(fx.toLowerCase());
  1225. }
  1226. //Run random transition from specified set (eg: effect:'strip-left-fade,right-curtain')
  1227. if (iv.options.fx.indexOf(',') != -1) {
  1228. var transitions = iv.options.fx.split(',');
  1229. fx = transitions[Math.floor(Math.random() * (transitions.length))];
  1230. if (fx == undefined) fx = 'fade';
  1231. fx = $.trim(fx.toLowerCase());
  1232. }
  1233. //Custom transition as defined by "data-iview:transition" attribute
  1234. if (iv.defs.image.data('iview:transition')) {
  1235. var transitions = iv.defs.image.data('iview:transition').split(',');
  1236. fx = transitions[Math.floor(Math.random() * (transitions.length))];
  1237. fx = $.trim(fx.toLowerCase());
  1238. }
  1239. //Set slide easing
  1240. iv.defs.easing = (iv.defs.image.data('iview:easing')) ? iv.defs.image.data('iview:easing') : iv.options.easing;
  1241. //Start Transition
  1242. iv.defs.lock = true;
  1243. iv.runTransition(fx);
  1244. },
  1245. playSlider: function () {
  1246. var iv = this;
  1247. if (iv.timer == null && iv.defs.paused) {
  1248. iv.iviewTimer.removeClass('paused').attr('title', iv.options.pauseLabel);
  1249. iv.setTimer();
  1250. iv.defs.paused = false;
  1251. //Trigger the onPlay callback
  1252. iv.options.onPlay.call(this);
  1253. }
  1254. },
  1255. stopSlider: function () {
  1256. var iv = this;
  1257. iv.iviewTimer.addClass('paused').attr('title', iv.options.playLabel);
  1258. iv.cleanTimer();
  1259. iv.defs.paused = true;
  1260. //Trigger the onPause callback
  1261. iv.options.onPause.call(this);
  1262. },
  1263. //Set Timer Position function
  1264. setTimerPosition: function(){
  1265. var iv = this,
  1266. position = iv.options.timerPosition.toLowerCase().split('-');
  1267. for (var i = 0; i < position.length; i++) {
  1268. if (position[i] == 'top') {
  1269. iv.iviewTimer.css({
  1270. top: iv.options.timerY + 'px',
  1271. bottom: ''
  1272. });
  1273. } else if (position[i] == 'middle') {
  1274. iv.iviewTimer.css({
  1275. top: (iv.options.timerY + (iv.defs.height / 2) - (iv.options.timerDiameter / 2)) + 'px',
  1276. bottom: ''
  1277. });
  1278. } else if (position[i] == 'bottom') {
  1279. iv.iviewTimer.css({
  1280. bottom: iv.options.timerY + 'px',
  1281. top: ''
  1282. });
  1283. } else if (position[i] == 'left') {
  1284. iv.iviewTimer.css({
  1285. left: iv.options.timerX + 'px',
  1286. right: ''
  1287. });
  1288. } else if (position[i] == 'center') {
  1289. iv.iviewTimer.css({
  1290. left: (iv.options.timerX + (iv.defs.width / 2) - (iv.options.timerDiameter / 2)) + 'px',
  1291. right: ''
  1292. });
  1293. } else if (position[i] == 'right') {
  1294. iv.iviewTimer.css({
  1295. right: iv.options.timerX + 'px',
  1296. left: ''
  1297. });
  1298. }
  1299. }
  1300. },
  1301. disableSelection: function (target) {
  1302. if (typeof target.onselectstart != "undefined") target.onselectstart = function () {
  1303. return false;
  1304. };
  1305. else if (typeof target.style.MozUserSelect != "undefined") target.style.MozUserSelect = "none";
  1306. else if (typeof target.style.webkitUserSelect != "undefined") target.style.webkitUserSelect = "none";
  1307. else if (typeof target.style.userSelect != "undefined") target.style.userSelect = "none";
  1308. else target.onmousedown = function () {
  1309. return false;
  1310. };
  1311. target.unselectable = "on";
  1312. },
  1313. //touch
  1314. isTouch: function () {
  1315. return !!('ontouchstart' in window);
  1316. }
  1317. };
  1318. //Image Preloader Function
  1319. var ImagePreload = function (p_aImages, p_pfnPercent, p_pfnFinished) {
  1320. this.m_pfnPercent = p_pfnPercent;
  1321. this.m_pfnFinished = p_pfnFinished;
  1322. this.m_nLoaded = 0;
  1323. this.m_nProcessed = 0;
  1324. this.m_aImages = new Array;
  1325. this.m_nICount = p_aImages.length;
  1326. for (var i = 0; i < p_aImages.length; i++) this.Preload(p_aImages[i])
  1327. };
  1328. ImagePreload.prototype = {
  1329. Preload: function (p_oImage) {
  1330. var oImage = new Image;
  1331. this.m_aImages.push(oImage);
  1332. oImage.onload = ImagePreload.prototype.OnLoad;
  1333. oImage.onerror = ImagePreload.prototype.OnError;
  1334. oImage.onabort = ImagePreload.prototype.OnAbort;
  1335. oImage.oImagePreload = this;
  1336. oImage.bLoaded = false;
  1337. oImage.source = p_oImage;
  1338. oImage.src = p_oImage
  1339. },
  1340. OnComplete: function () {
  1341. this.m_nProcessed++;
  1342. if (this.m_nProcessed == this.m_nICount) this.m_pfnFinished();
  1343. else this.m_pfnPercent(Math.round((this.m_nProcessed / this.m_nICount) * 10))
  1344. },
  1345. OnLoad: function () {
  1346. this.bLoaded = true;
  1347. this.oImagePreload.m_nLoaded++;
  1348. this.oImagePreload.OnComplete()
  1349. },
  1350. OnError: function () {
  1351. this.bError = true;
  1352. this.oImagePreload.OnComplete()
  1353. },
  1354. OnAbort: function () {
  1355. this.bAbort = true;
  1356. this.oImagePreload.OnComplete()
  1357. }
  1358. }
  1359. // Begin the iView plugin
  1360. $.fn.iView = function (options) {
  1361. // Default options. Play carefully.
  1362. options = jQuery.extend({
  1363. fx: 'random',
  1364. easing: 'easeOutQuad',
  1365. strips: 20,
  1366. blockCols: 10,
  1367. blockRows: 5,
  1368. animationSpeed: 500,
  1369. pauseTime: 5000,
  1370. startSlide: 0,
  1371. directionNav: true,
  1372. directionNavHoverOpacity: 0.6,
  1373. controlNav: false,
  1374. controlNavNextPrev: true,
  1375. controlNavHoverOpacity: 0.6,
  1376. controlNavThumbs: false,
  1377. controlNavTooltip: true,
  1378. captionSpeed: 500,
  1379. captionEasing: 'easeInOutSine',
  1380. captionOpacity: 1,
  1381. autoAdvance: true,
  1382. keyboardNav: true,
  1383. touchNav: true,
  1384. pauseOnHover: false,
  1385. nextLabel: "Next",
  1386. previousLabel: "Previous",
  1387. playLabel: "Play",
  1388. pauseLabel: "Pause",
  1389. closeLabel: "Close",
  1390. randomStart: false,
  1391. timer: 'Pie',
  1392. timerBg: '#000',
  1393. timerColor: '#EEE',
  1394. timerOpacity: 0.5,
  1395. timerDiameter: 30,
  1396. timerPadding: 4,
  1397. timerStroke: 3,
  1398. timerBarStroke: 1,
  1399. timerBarStrokeColor: '#EEE',
  1400. timerBarStrokeStyle: 'solid',
  1401. timerPosition: 'top-right',
  1402. timerX: 10,
  1403. timerY: 10,
  1404. tooltipX: 5,
  1405. tooltipY: -5,
  1406. onBeforeChange: function () {},
  1407. onAfterChange: function () {},
  1408. onAfterLoad: function () {},
  1409. onLastSlide: function () {},
  1410. onSlideShowEnd: function () {},
  1411. onPause: function () {},
  1412. onPlay: function () {}
  1413. }, options);
  1414. $(this).each(function () {
  1415. var el = $(this);
  1416. new iView(el, options);
  1417. });
  1418. };
  1419. $.fn.reverse = [].reverse;
  1420. var elems = $([]),
  1421. jq_resize = $.resize = $.extend($.resize, {}),
  1422. timeout_id, str_setTimeout = "setTimeout",
  1423. str_resize = "resize",
  1424. str_data = str_resize + "-special-event",
  1425. str_delay = "delay",
  1426. str_throttle = "throttleWindow";
  1427. jq_resize[str_delay] = 250;
  1428. jq_resize[str_throttle] = true;
  1429. $.event.special[str_resize] = {
  1430. setup: function () {
  1431. if (!jq_resize[str_throttle] && this[str_setTimeout]) {
  1432. return false
  1433. }
  1434. var elem = $(this);
  1435. elems = elems.add(elem);
  1436. $.data(this, str_data, {
  1437. w: elem.width(),
  1438. h: elem.height()
  1439. });
  1440. if (elems.length === 1) {
  1441. loopy()
  1442. }
  1443. },
  1444. teardown: function () {
  1445. if (!jq_resize[str_throttle] && this[str_setTimeout]) {
  1446. return false
  1447. }
  1448. var elem = $(this);
  1449. elems = elems.not(elem);
  1450. elem.removeData(str_data);
  1451. if (!elems.length) {
  1452. clearTimeout(timeout_id)
  1453. }
  1454. },
  1455. add: function (handleObj) {
  1456. if (!jq_resize[str_throttle] && this[str_setTimeout]) {
  1457. return false
  1458. }
  1459. var old_handler;
  1460. function new_handler(e, w, h) {
  1461. var elem = $(this),
  1462. data = $.data(this, str_data);
  1463. data.w = w !== undefined ? w : elem.width();
  1464. data.h = h !== undefined ? h : elem.height();
  1465. old_handler.apply(this, arguments)
  1466. }
  1467. if ($.isFunction(handleObj)) {
  1468. old_handler = handleObj;
  1469. return new_handler
  1470. } else {
  1471. old_handler = handleObj.handler;
  1472. handleObj.handler = new_handler
  1473. }
  1474. }
  1475. };
  1476. function loopy() {
  1477. timeout_id = window[str_setTimeout](function () {
  1478. elems.each(function () {
  1479. var elem = $(this),
  1480. width = elem.width(),
  1481. height = elem.height(),
  1482. data = $.data(this, str_data);
  1483. if (width !== data.w || height !== data.h) {
  1484. elem.trigger(str_resize, [data.w = width, data.h = height])
  1485. }
  1486. });
  1487. loopy()
  1488. }, jq_resize[str_delay])
  1489. }
  1490. var supportTouch = !! ('ontouchstart' in window),
  1491. touchStartEvent = supportTouch ? "touchstart" : "mousedown",
  1492. touchStopEvent = supportTouch ? "touchend" : "mouseup",
  1493. touchMoveEvent = supportTouch ? "touchmove" : "mousemove";
  1494. // also handles swipeleft, swiperight
  1495. $.event.special.swipe = {
  1496. scrollSupressionThreshold: 10, // More than this horizontal displacement, and we will suppress scrolling.
  1497. durationThreshold: 1000, // More time than this, and it isn't a swipe.
  1498. horizontalDistanceThreshold: 30, // Swipe horizontal displacement must be more than this.
  1499. verticalDistanceThreshold: 75, // Swipe vertical displacement must be less than this.
  1500. setup: function () {
  1501. var thisObject = this,
  1502. $this = $(thisObject);
  1503. $this.bind(touchStartEvent, function (event) {
  1504. var data = event.originalEvent.touches ? event.originalEvent.touches[0] : event,
  1505. start = {
  1506. time: (new Date()).getTime(),
  1507. coords: [data.pageX, data.pageY],
  1508. origin: $(event.target)
  1509. },
  1510. stop;
  1511. function moveHandler(event) {
  1512. if (!start) {
  1513. return;
  1514. }
  1515. var data = event.originalEvent.touches ? event.originalEvent.touches[0] : event;
  1516. stop = {
  1517. time: (new Date()).getTime(),
  1518. coords: [data.pageX, data.pageY]
  1519. };
  1520. // prevent scrolling
  1521. if (Math.abs(start.coords[0] - stop.coords[0]) > $.event.special.swipe.scrollSupressionThreshold) {
  1522. event.preventDefault();
  1523. }
  1524. }
  1525. $this.bind(touchMoveEvent, moveHandler).one(touchStopEvent, function (event) {
  1526. $this.unbind(touchMoveEvent, moveHandler);
  1527. if (start && stop) {
  1528. if (stop.time - start.time < $.event.special.swipe.durationThreshold && Math.abs(start.coords[0] - stop.coords[0]) > $.event.special.swipe.horizontalDistanceThreshold && Math.abs(start.coords[1] - stop.coords[1]) < $.event.special.swipe.verticalDistanceThreshold) {
  1529. start.origin.trigger("swipe").trigger(start.coords[0] > stop.coords[0] ? "swipeleft" : "swiperight");
  1530. }
  1531. }
  1532. start = stop = undefined;
  1533. });
  1534. });
  1535. }
  1536. };
  1537. $.each({
  1538. swipeleft: "swipe",
  1539. swiperight: "swipe"
  1540. }, function (event, sourceEvent) {
  1541. $.event.special[event] = {
  1542. setup: function () {
  1543. $(this).bind(sourceEvent, $.noop);
  1544. }
  1545. };
  1546. });
  1547. })(jQuery, this);