khardwick

slider.js

Aug 10th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.39 KB | None | 0 0
  1. /* =======================================================
  2. * Auto Slider
  3. * By David Blanco
  4. *
  5. * Contact: http://codecanyon.net/user/davidbo90
  6. *
  7. * Created: April 2, 2013
  8. *
  9. * Copyright (c) 2013, David Blanco. All rights reserved.
  10. * Released under CodeCanyon License http://codecanyon.net/
  11. *
  12. * ======================================================= */
  13.  
  14. (function($) {
  15.  
  16. var AutoSlider = function(element, options){
  17. //FALLBACK FOR OLD BROWSERS LIKE IE8, IE7
  18. var fallback = false;
  19. var supports = (function() {
  20. var div = document.createElement('div'),
  21. vendors = 'Khtml Ms O Moz Webkit'.split(' '),
  22. len = vendors.length;
  23.  
  24. return function(prop) {
  25. if ( prop in div.style ) return true;
  26.  
  27. prop = prop.replace(/^[a-z]/, function(val) {
  28. return val.toUpperCase();
  29. });
  30.  
  31. while(len--) {
  32. if ( vendors[len] + prop in div.style ) {
  33. // browser supports box-shadow. Do what you need.
  34. // Or use a bang (!) to test if the browser doesn't.
  35. return true;
  36. }
  37. }
  38. return false;
  39. };
  40. })();
  41.  
  42. if ( !supports('transform') ) { //IF IT DOES NOT SUPPORT TRANSFORM
  43. fallback = true;
  44. }
  45.  
  46.  
  47.  
  48. //Defaults are below
  49. var settings = $.extend({}, $.fn.autoSlider.defaults, options);
  50.  
  51. var container = $(element).css('background','none'),
  52. imgs = container.find('img').fadeTo( 'fast', 1),
  53. width = settings.width,
  54. current = 0,
  55. before = -1,
  56. ready = true,
  57. play = settings.autoPlay,
  58. thumbNumber = -1;
  59.  
  60.  
  61. if(!settings.rightClickImages) {
  62. imgs.bind('contextmenu', function(e) {
  63. return false;
  64. });
  65. }
  66.  
  67. //Useful variables. Play carefully.
  68. var vars = {
  69. interval: 'none'
  70. };
  71.  
  72. var vars2 = {
  73. timer: 'none'
  74. };
  75.  
  76. //If width is not set then get the width of the largest image
  77. if(width === 0 || width === '0'){
  78. imgs.each(function(){
  79. thisWidth = $(this).width();
  80.  
  81. if(thisWidth > width){
  82. width = thisWidth;
  83. }
  84. });
  85. }
  86.  
  87. //add shadow
  88. if( settings.shadow == true ){
  89. container.addClass('as_slider_shadow');
  90. }
  91.  
  92. //Set the same width to all the images
  93. imgs.css('width', width);
  94. container.css({
  95. 'width': width,
  96. 'height': imgs.first().height()
  97. });
  98.  
  99. //Append timer
  100. if(settings.showTimer){
  101.  
  102. if(settings.circularTimer == true){
  103. container.append('<div class="as_circularTimer as_fill"></div>');
  104. }else{
  105. container.append('<div class="as_timer"/>');
  106. }
  107.  
  108. }
  109.  
  110. //Append captions
  111. if(settings.captions){
  112. container.append('<div class="as_captions"/>');
  113. }
  114.  
  115.  
  116. //Create navigation arrows and control
  117. var arrows = $('<div class="as_prev" /><div class="as_next" />').css('background-image', 'url(img/icons.png)');
  118. container.append(arrows);
  119. var playDiv = $('<div class="as_play"></div>').css('background-image', 'url(img/icons.png)');
  120. container.append(playDiv);
  121.  
  122. //Add themes
  123. container.addClass(settings.theme);
  124.  
  125. if(settings.navBarNumeric){
  126. container.addClass("numeric");
  127. }
  128. //Create the navigation
  129. var btns = '';
  130. var numbers = 1;
  131. for(var i=0; i<imgs.length; i++){
  132.  
  133. var str = "";
  134. if(settings.navBarNumeric){
  135. str = numbers;
  136. }
  137.  
  138. var selected = "";
  139. if(i == 0)selected = "selected";
  140. btns+='<div class="as_navBtn '+selected+'" data-img="'+i+'">'+str+'</div>';
  141.  
  142. numbers++;
  143. }
  144.  
  145. var nav = $('<div class="as_navContainer"> '+btns+' </div>');
  146. container.append(nav);
  147.  
  148. var as_prev = container.find('div.as_prev'),
  149. as_next = container.find('div.as_next'),
  150. as_play = container.find('div.as_play'),
  151. as_navContainer = container.find('div.as_navContainer'),
  152. as_timer = container.find('div.as_timer'),
  153. as_captions = container.find('div.as_captions');
  154.  
  155. if(settings.navArrows == false){
  156. as_prev.hide().remove();
  157. as_next.hide().remove();
  158. }
  159.  
  160. if(settings.playBtn == false){
  161. as_play.hide().remove();
  162. }
  163.  
  164. if(settings.navBar == false){
  165. as_navContainer.hide().remove();
  166. }
  167.  
  168. if(settings.autoHideNavArrows == false){
  169. as_prev.fadeTo('1','1');
  170. as_next.fadeTo('1','1');
  171. }
  172.  
  173. if(settings.autoHidePlayBtn == false){
  174. as_play.fadeTo('1','1');
  175. }
  176.  
  177. if(settings.autoHideNavBar == false){
  178. as_navContainer.fadeTo('1','1');
  179. }
  180.  
  181. if(settings.autoHideCaptions == false){
  182. as_captions.fadeTo('1','1').hide();
  183. }
  184. //Responsive design
  185. var responsive = function(){
  186.  
  187. imgs.css({
  188. 'max-width' : container.width()
  189. });
  190.  
  191. container.css({
  192. 'height' : imgs.eq(current).height()
  193. });
  194.  
  195. if(container.width() <= settings.hideTimerInWidth){
  196. as_timer.hide();
  197. }else{
  198. as_timer.show();
  199. }
  200.  
  201. if(container.width() <= settings.hideIconsInWidth){
  202. as_prev.hide();
  203. as_next.hide();
  204. as_play.hide();
  205. as_navContainer.hide();
  206. }else{
  207. as_prev.show();
  208. as_next.show();
  209. as_play.show();
  210. as_navContainer.show();
  211. }
  212.  
  213. };
  214.  
  215. //Check for responsive design on load and on resize
  216. responsive();
  217. $(window).resize(function(){
  218. responsive();
  219. });
  220.  
  221. //BOXES EFFECT
  222. //Random
  223. var range = function range( min, max, rand ) {
  224. var arr = jQuery.map(new Array( ++max - min ).join('.').split('.'), function(v,i) { return min + i } );
  225.  
  226. if(rand == true){
  227.  
  228. var arr2 = jQuery.map(arr, function( v ) { return [[ Math.random(), v ]] } ).sort();
  229. return jQuery.map(arr2, function( v ) { return v[ 1 ] });
  230. }else{
  231. return arr;
  232. }
  233.  
  234. }
  235.  
  236. var diagonalArray = function (nums, numRows, numCols) {
  237. var numRows = numRows,
  238. numCols = numCols,
  239. sq = numRows + numCols - 1,
  240. d, x, y,
  241. i = 1,
  242. arr = [];
  243.  
  244. diagonalLoop:
  245. for (d = 0; d < sq; d++) {
  246. for (y = d, x = 0; y >= 0; y--, x++) {
  247. if (x === numCols)
  248. continue diagonalLoop;
  249. if (y < numRows){
  250. arr.push(nums[(x*numRows)+y]);
  251. i++;
  252. }
  253.  
  254. }
  255. }
  256.  
  257. return arr;
  258. }
  259.  
  260. var boxes = function(currentImg, effect){
  261. var x = settings.x,
  262. y = settings.y,
  263. random = true;
  264.  
  265. if(effect == 'boxes' || effect == 'boxes-openBookY' || effect == 'boxes-openBookX' || effect == 'boxes-zoomIn' || effect == 'boxes-zoomOut'){
  266. random = true;
  267. }else if(effect == 'boxesOrder' || effect == 'boxesOrder-openBookY' || effect == 'boxesOrder-openBookX' || effect == 'boxesOrder-zoomIn' || effect == 'boxesOrder-zoomOut'){
  268. random = false;
  269. }else if(effect == 'horizontalStripes' || effect == 'horizontalStripes-openBookY' || effect == 'horizontalStripes-openBookX' || effect == 'horizontalStripes-zoomIn' || effect == 'horizontalStripes-zoomOut'){
  270. random = false;
  271. x = 1;
  272. }else if(effect == 'verticalStripes' || effect == 'verticalStripes-openBookY' || effect == 'verticalStripes-openBookX' || effect == 'verticalStripes-zoomIn' || effect == 'verticalStripes-zoomOut'){
  273. random = false;
  274. y = 1;
  275. }else if(effect == 'boxesDiagonal' || effect == 'boxesDiagonal-openBookY' || effect == 'boxesDiagonal-openBookX' || effect == 'boxesDiagonal-zoomIn' || effect == 'boxesDiagonal-zoomOut'){
  276. random = false;
  277. }
  278.  
  279. var width = currentImg.width(),
  280. height = currentImg.height(),
  281. $img = currentImg,
  282. n_boxes = x * y,
  283. boxes = [], $boxesContainer, $boxes;
  284.  
  285. for ( var i = 0; i < n_boxes; i++ ) {
  286. boxes.push('<div class="as_box"/>');
  287. }
  288.  
  289. $boxesContainer = $( '<div class="as_boxesContainer" >'+boxes.join('')+'</div>' );
  290.  
  291. // Hide original image and insert boxes in DOM
  292. $img.hide().after( $boxesContainer );
  293.  
  294. $boxes = $boxesContainer.find('div');
  295.  
  296. //Fix width that is not exact
  297. var widthEach = Math.floor(width/x);
  298. var widthCurrent = widthEach*x;
  299. if(width != widthCurrent){//If width doesn't fit perfect
  300. var diference = width - widthCurrent;
  301.  
  302. var cont = 0;
  303. $boxes.each(function(){
  304. $this = $(this);
  305. cont++;
  306.  
  307. if(cont == x){
  308. $this.css('width', widthEach+diference);
  309.  
  310. cont=0;
  311. }else{
  312. $this.css('width', widthEach);
  313. }
  314. });
  315.  
  316. }else{//If width fits perfect
  317. $boxes.css('width', width / x);
  318. }
  319.  
  320. // Set background
  321.  
  322. $boxes.css({
  323. //width: width / x,
  324. height: Math.ceil(height / y),
  325. 'background-image': 'url('+ encodeURI($img.attr('src')) +')',
  326. 'background-size': width+'px'+' '+height+'px',
  327. 'background-repeat': 'no-repeat'
  328. });
  329.  
  330.  
  331. // Adjust position
  332. $boxes.each(function() {
  333. var pos = $(this).position();
  334. $(this).css( 'backgroundPosition', -pos.left +'px '+ -pos.top +'px' );
  335. });
  336.  
  337. // Animate the party
  338. var boxesArr = range( 0, n_boxes-1, random ),
  339. boxSpeed = settings.transitionSpeed / n_boxes; // time to clear a single box
  340.  
  341. if(effect == 'boxesDiagonal' || effect == 'boxesDiagonal-openBookY' || effect == 'boxesDiagonal-openBookX' || effect == 'boxesDiagonal-zoomIn' || effect == 'boxesDiagonal-zoomOut'){
  342. boxesArr = diagonalArray(boxesArr, x, y);
  343. }
  344. //boxesArr = [8, 1, 18, 11, 13, 10, 6, 21, 0, 4, 16, 23, 9, 14, 3, 15, 12, 7, 2, 5, 22, 19, 20, 17, 24];
  345.  
  346. // FALLBACK FOR IE7, IE8
  347. if(fallback && (effect == 'boxes-openBookY' || effect == 'boxes-openBookX' || effect == 'boxesOrder-openBookY' || effect == 'boxesOrder-openBookX' || effect == 'horizontalStripes-openBookY' || effect == 'horizontalStripes-openBookX' || effect == 'verticalStripes-openBookY' || effect == 'verticalStripes-openBookX' || effect == 'boxesDiagonal-openBookY' || effect == 'boxesDiagonal-openBookX'
  348. || effect == 'boxes-zoomIn' || effect == 'boxes-zoomOut' || effect == 'boxesOrder-zoomIn' || effect == 'boxesOrder-zoomOut' || effect == 'horizontalStripes-zoomIn' || effect == 'horizontalStripes-zoomOut' || effect == 'verticalStripes-zoomIn' || effect == 'verticalStripes-zoomOut' || effect == 'boxesDiagonal-zoomIn' || effect == 'boxesDiagonal-zoomOut') ){
  349. effect = 'boxes';
  350. }
  351.  
  352. //ANIMATIONS FOR FADE EFFECT
  353. if(effect == 'boxes' || effect == 'boxesDiagonal' || effect == 'boxesOrder' || effect == 'horizontalStripes' || effect == 'verticalStripes'){
  354.  
  355. $.each(boxesArr, function( i, box ) {
  356. setTimeout(function(){
  357. $boxes.eq( box ).fadeTo( settings.boxSpeed, 1 , function(){
  358. if(i == boxesArr.length-1){
  359. endEffect();
  360. }
  361. });
  362. }, i * boxSpeed );
  363. });
  364.  
  365. }else if(effect == 'boxes-openBookY' || effect == 'boxes-openBookX' || effect == 'boxesOrder-openBookY' || effect == 'boxesOrder-openBookX' || effect == 'horizontalStripes-openBookY' || effect == 'horizontalStripes-openBookX' || effect == 'verticalStripes-openBookY' || effect == 'verticalStripes-openBookX' || effect == 'boxesDiagonal-openBookY' || effect == 'boxesDiagonal-openBookX'){
  366.  
  367. //ANIMATIONS FOR ROTATION EFFECT
  368. var axis = 'Y';
  369. if(effect == 'boxes-openBookX' || effect == 'boxesOrder-openBookX' || effect == 'horizontalStripes-openBookX' || effect == 'verticalStripes-openBookX' || effect == 'boxesDiagonal-openBookX'){
  370. axis = 'X';
  371. }
  372.  
  373. $.each(boxesArr, function( i, box ) {
  374. setTimeout(function(){
  375. $boxes.eq( box ).data('axis', axis);
  376. $boxes.eq( box ).fadeTo(0, 1).rotate('90').animate({
  377. rotate: '0'
  378. },settings.boxSpeed, function(){
  379. if(i == boxesArr.length-1){
  380. endEffect();
  381. }
  382. });
  383. }, i * boxSpeed );
  384. });
  385.  
  386. }else if(effect == 'boxes-zoomIn' || effect == 'boxes-zoomOut' || effect == 'boxesOrder-zoomIn' || effect == 'boxesOrder-zoomOut' || effect == 'horizontalStripes-zoomIn' || effect == 'horizontalStripes-zoomOut' || effect == 'verticalStripes-zoomIn' || effect == 'verticalStripes-zoomOut' || effect == 'boxesDiagonal-zoomIn' || effect == 'boxesDiagonal-zoomOut' ){
  387.  
  388. //ANIMATIONS FOR SCALE (ZOOM) EFFECT
  389. var scale = '1.5';
  390. if(effect == 'boxes-zoomOut' || effect == 'boxesOrder-zoomOut' || effect == 'horizontalStripes-zoomOut' || effect == 'verticalStripes-zoomOut' || effect == 'boxesDiagonal-zoomOut'){
  391. scale = '0';
  392. }
  393.  
  394. $.each(boxesArr, function( i, box ) {
  395. setTimeout(function(){
  396. $boxes.eq( box ).fadeTo(0, 1).scale(scale).animate({
  397. scale: '1'
  398. },settings.boxSpeed, function(){
  399. //Just make sure the CSS3 transformations are gone!
  400. $boxes.eq( box ).css({
  401. '-webkit-transform' : 'none',
  402. '-moz-transform' : 'none',
  403. '-ms-transform' : 'none',
  404. '-o-transform' : 'none',
  405. 'transform' : 'none'
  406. });
  407.  
  408. if(i >= boxesArr.length-1){
  409. endEffect();
  410. }
  411. });
  412.  
  413.  
  414. }, i * boxSpeed );
  415. });
  416.  
  417. }
  418.  
  419.  
  420.  
  421. };
  422.  
  423. //END BOXES EFFECT
  424.  
  425. var setImages = function(){
  426. var currentImg = imgs.eq(current);
  427. imgs.eq(before).css('zIndex',99).siblings('img').css('zIndex',50);
  428. currentImg.css({
  429. 'zIndex' : 100
  430. });
  431. };
  432.  
  433. //run effect
  434. var runEffect = function(){
  435. container.find('div.as_boxesContainer').remove();
  436. imgs.show();
  437.  
  438. var currentImg = imgs.eq(current);
  439. container.animate({
  440. 'height' : currentImg.height()
  441. }, 300);
  442.  
  443. setImages();
  444.  
  445. var effect = currentImg.data('effect');
  446.  
  447. if(fallback && (effect == 'openBookY' || effect == 'openBookX' || effect == 'zoomIn' || effect == 'zoomOut') ){
  448. effect = 'fade';
  449. }
  450.  
  451. //EFFECTS
  452.  
  453. if(effect == 'fade'){
  454.  
  455. currentImg.hide().fadeIn(settings.transitionSpeed, function(){
  456. endEffect();
  457. });
  458.  
  459. }else if(effect == 'slide'){
  460.  
  461. currentImg.hide().slideDown(settings.transitionSpeed, function(){
  462. endEffect();
  463. });
  464.  
  465. }else if(effect == 'show'){
  466.  
  467. currentImg.hide().show(settings.transitionSpeed, function(){
  468. endEffect();
  469. });
  470.  
  471. }else if(effect == 'fromTop'){
  472.  
  473. currentImg.css({
  474. 'top': -currentImg.outerHeight()
  475. })
  476. .animate({
  477. 'top': '0px'
  478. },settings.transitionSpeed, function(){
  479. endEffect();
  480. });
  481.  
  482. }else if(effect == 'fromBottom'){
  483.  
  484. currentImg.css({
  485. 'top': currentImg.outerHeight()
  486. })
  487. .animate({
  488. 'top': '0px'
  489. },settings.transitionSpeed, function(){
  490. endEffect();
  491. });
  492.  
  493. }else if(effect == 'fromRight'){
  494.  
  495. currentImg.css({
  496. 'left': currentImg.outerWidth()
  497. })
  498. .animate({
  499. 'left': '0px'
  500. },settings.transitionSpeed, function(){
  501. endEffect();
  502. });
  503.  
  504. }else if(effect == 'fromLeft'){
  505.  
  506. currentImg.css({
  507. 'left': -currentImg.outerWidth()
  508. })
  509. .animate({
  510. 'left': '0px'
  511. },settings.transitionSpeed, function(){
  512. endEffect();
  513. });
  514.  
  515. }else if(effect == 'fromTopRight'){
  516.  
  517. currentImg.css({
  518. 'top': -currentImg.outerHeight(),
  519. 'left': currentImg.outerWidth()
  520. })
  521. .animate({
  522. 'top': '0px',
  523. 'left': '0px'
  524. },settings.transitionSpeed, function(){
  525. endEffect();
  526. });
  527.  
  528. }else if(effect == 'fromBottomRight'){
  529.  
  530. currentImg.css({
  531. 'top': currentImg.outerHeight(),
  532. 'left': currentImg.outerWidth()
  533. })
  534. .animate({
  535. 'top': '0px',
  536. 'left': '0px'
  537. },settings.transitionSpeed, function(){
  538. endEffect();
  539. });
  540.  
  541. }else if(effect == 'fromTopLeft'){
  542.  
  543. currentImg.css({
  544. 'top': -currentImg.outerHeight(),
  545. 'left': -currentImg.outerWidth()
  546. })
  547. .animate({
  548. 'top': '0px',
  549. 'left': '0px'
  550. },settings.transitionSpeed, function(){
  551. endEffect();
  552. });
  553.  
  554. }else if(effect == 'fromBottomLeft'){
  555.  
  556. currentImg.css({
  557. 'top': currentImg.outerHeight(),
  558. 'left': -currentImg.outerWidth()
  559. })
  560. .animate({
  561. 'top': '0px',
  562. 'left': '0px'
  563. },settings.transitionSpeed, function(){
  564. endEffect();
  565. });
  566.  
  567. }else if(
  568. effect == 'boxes' || effect == 'boxes-openBookY' || effect == 'boxes-openBookX' || effect == 'boxes-zoomIn' || effect == 'boxes-zoomOut' ||
  569. effect == 'boxesOrder' || effect == 'boxesOrder-openBookY' || effect == 'boxesOrder-openBookX' || effect == 'boxesOrder-zoomIn' || effect == 'boxesOrder-zoomOut' ||
  570. effect == 'horizontalStripes' || effect == 'horizontalStripes-openBookY' || effect == 'horizontalStripes-openBookX' || effect == 'horizontalStripes-zoomIn' || effect == 'horizontalStripes-zoomOut' ||
  571. effect == 'verticalStripes' || effect == 'verticalStripes-openBookY' || effect == 'verticalStripes-openBookX' || effect == 'verticalStripes-zoomIn' || effect == 'verticalStripes-zoomOut' ||
  572. effect == 'boxesDiagonal' || effect == 'boxesDiagonal-openBookY' || effect == 'boxesDiagonal-openBookX' || effect == 'boxesDiagonal-zoomIn' || effect == 'boxesDiagonal-zoomOut'){
  573.  
  574. boxes(currentImg, effect);
  575.  
  576. }else if(effect == 'openBookY'){
  577. currentImg.data('axis', 'Y');
  578. currentImg.rotate('90deg')
  579. .animate({
  580. rotate: '0deg'
  581. },settings.transitionSpeed, function(){
  582. endEffect();
  583. });
  584. }else if(effect == 'openBookX'){
  585. currentImg.data('axis', 'X');
  586. currentImg.rotate('90deg')
  587. .animate({
  588. rotate: '0deg'
  589. },settings.transitionSpeed, function(){
  590. endEffect();
  591. });
  592. }else if(effect == 'zoomIn'){
  593. currentImg.scale('2')
  594. .animate({
  595. scale: '1'
  596. },settings.transitionSpeed, function(){
  597. endEffect();
  598. });
  599. }else if(effect == 'zoomOut'){
  600. currentImg.scale('0')
  601. .animate({
  602. scale: '1'
  603. },settings.transitionSpeed, function(){
  604. endEffect();
  605. });
  606. }
  607.  
  608.  
  609. };
  610.  
  611. var isReady = function(){
  612. var rtn = true;
  613.  
  614. var currentImg = imgs.eq(current);
  615. var effect = currentImg.data('effect');
  616.  
  617. if(!ready){
  618. rtn = false;
  619. }
  620.  
  621. return rtn;
  622. }
  623.  
  624. // ======== CIRCULAR TIMER ======== //
  625.  
  626. //var timer;
  627. var as_circularTimer = container.find('div.as_circularTimer');
  628. var timerCurrent;
  629. var timerFinish;
  630. var timerSeconds = settings.playInterval/1000;
  631. var drawTimer = function(percent){
  632. as_circularTimer.html('<div class="as_percent"></div><div id="as_peace"'+(percent > 50?' class="gt50"':'')+'><div class="as_pie"></div>'+(percent > 50?'<div class="as_pie as_fill"></div>':'')+'</div>');
  633. var deg = 360/100*percent;
  634. container.find('#as_peace .as_pie').css({
  635. '-moz-transform':'rotate('+deg+'deg)',
  636. '-webkit-transform':'rotate('+deg+'deg)',
  637. '-o-transform':'rotate('+deg+'deg)',
  638. 'transform':'rotate('+deg+'deg)'
  639. });
  640. container.find('.as_percent').html(Math.round(percent)+'%');
  641. //vars.timer = setInterval(stopWatch(), 50);
  642. }
  643. var stopWatch = function(){
  644. var seconds = (timerFinish-(new Date().getTime()))/1000;
  645.  
  646. if(seconds <= 0){
  647. drawTimer(100);
  648. clearInterval(vars2.timer);
  649. //alert('Finished counting down from '+timerSeconds);
  650. }else{
  651. var percent = 100-((seconds/timerSeconds)*100);
  652. drawTimer(percent);
  653. }
  654. }
  655.  
  656.  
  657. timerCurrent = 0;
  658.  
  659.  
  660.  
  661. // ======== END CIRCULAR TIMER ======== //
  662.  
  663. //update timer
  664. var updateTimer = function(){
  665. as_timer.animate( { width: '100%' }, settings.playInterval, 'linear' );
  666.  
  667. //Circular Timer
  668. timerFinish = new Date().getTime()+(timerSeconds*1000);
  669. vars2.timer = window.setInterval(function(){
  670. stopWatch();
  671. }, 50);
  672. };
  673.  
  674. //stop timer
  675. var stopTimer = function(){
  676. as_timer.stop( true ).width( 0 );
  677.  
  678. //Circular Timer
  679. container.find('#as_peace .as_pie').css({
  680. '-moz-transform':'rotate(360deg)',
  681. '-webkit-transform':'rotate(360deg)',
  682. '-o-transform':'rotate(360deg)',
  683. 'transform':'rotate(360deg)'
  684. });
  685.  
  686. clearInterval(vars2.timer);
  687.  
  688. as_circularTimer.html('');
  689. };
  690.  
  691. var transitionReady = function(){
  692.  
  693. container.find('.as_boxesContainer').remove();
  694. ready = true;
  695.  
  696. if(play){
  697.  
  698. clearTimeout(vars.interval);
  699.  
  700. if(settings.loop == false && current == imgs.length-1){
  701. settings.onSlideshowEnd();
  702. return;
  703. }
  704.  
  705. vars.interval = setTimeout(function(){
  706. next();
  707. }, settings.playInterval);
  708.  
  709. updateTimer();
  710. }
  711. }
  712.  
  713. var caption = function(){
  714.  
  715. if(settings.captions == false){
  716. return false;
  717. }
  718.  
  719. var imgCurr = imgs.eq(current);
  720.  
  721. //caption
  722. var caption = imgCurr.data('caption');
  723. if(caption != undefined){
  724. var span = $('<span/>').html(caption).fadeTo(1,1);
  725.  
  726. var captionFx = imgCurr.data('captioneffect');
  727. if( captionFx == undefined ){
  728. captionFx = 'fade';
  729. }
  730.  
  731. /*
  732. as_captions.html(span)
  733. .css('margin-left',-imgs.width())
  734. .show()
  735. .animate({
  736. 'margin-left':'0px'
  737. },300, function(){
  738. span.fadeTo(1,1);
  739. transitionReady();
  740. });
  741. */
  742. var bottom = as_captions.css('bottom');
  743.  
  744. var direction = 'right';
  745. var sign = -1;
  746. var right = as_captions.css('right');
  747. if(right == 'auto'){
  748. direction = 'left';
  749. sign = 1;
  750. }
  751.  
  752. if(captionFx == 'fade'){
  753.  
  754. as_captions.html(span).hide().fadeIn(settings.captionSpeed, function(){
  755. //span.fadeTo(1,1);
  756. transitionReady();
  757. });
  758.  
  759. }else if(captionFx == 'slide'){
  760.  
  761. as_captions.html(span).hide().slideDown(settings.captionSpeed, function(){
  762. //span.fadeTo(1,1);
  763. transitionReady();
  764. });
  765.  
  766. }else if(captionFx == 'show'){
  767.  
  768. as_captions.html(span).hide().show(settings.captionSpeed, function(){
  769. //span.fadeTo(1,1);
  770. transitionReady();
  771. });
  772.  
  773. }else if(captionFx == 'fromTop'){
  774.  
  775. as_captions.html(span).show().css({
  776. 'bottom': container.outerHeight()
  777. })
  778. .animate({
  779. 'bottom': bottom
  780. },settings.captionSpeed, function(){
  781. //span.fadeTo(1,1);
  782. transitionReady();
  783. });
  784.  
  785. }else if(captionFx == 'fromBottom'){
  786.  
  787. as_captions.html(span).show().css({
  788. 'bottom': -as_captions.outerHeight()
  789. })
  790. .animate({
  791. 'bottom': bottom
  792. },settings.captionSpeed, function(){
  793. //span.fadeTo(1,1);
  794. transitionReady();
  795. });
  796.  
  797. }else if(captionFx == 'fromRight'){
  798. as_captions.html(span).show().css('margin-'+direction, (imgs.width()*sign) )
  799. .animate({
  800. 'margin-left':'0px',
  801. 'margin-right':'0px'
  802. }, settings.captionSpeed, function(){
  803. //span.fadeTo(1,1);
  804. transitionReady();
  805. });
  806.  
  807. }else if(captionFx == 'fromLeft'){
  808. as_captions.html(span).show().css('margin-'+direction, (-imgs.width()*sign) )
  809. .animate({
  810. 'margin-left' :'0px',
  811. 'margin-right' :'0px'
  812. }, settings.captionSpeed, function(){
  813. //span.fadeTo(1,1);
  814. transitionReady();
  815. });
  816.  
  817. }else if(captionFx == 'openBookY'){
  818. as_captions.html(span).show().data('axis', 'Y');
  819. as_captions.rotate('90deg')
  820. .animate({
  821. rotate: '0deg'
  822. },settings.captionSpeed, function(){
  823. //span.fadeTo(1,1);
  824. transitionReady();
  825. });
  826. }else if(captionFx == 'openBookX'){
  827. as_captions.html(span).show().data('axis', 'X');
  828. as_captions.rotate('90deg')
  829. .animate({
  830. rotate: '0deg'
  831. },settings.captionSpeed, function(){
  832. //span.fadeTo(1,1);
  833. transitionReady();
  834. });
  835. }else if(captionFx == 'zoomIn'){
  836. as_captions.html(span).show().scale('2')
  837. .animate({
  838. scale: '1'
  839. },settings.captionSpeed, function(){
  840. //span.fadeTo(1,1);
  841. transitionReady();
  842. });
  843. }else if(captionFx == 'zoomOut'){
  844. as_captions.html(span).show().scale('0')
  845. .animate({
  846. scale: '1'
  847. },settings.captionSpeed, function(){
  848. //span.fadeTo(1,1);
  849. transitionReady();
  850. });
  851. }
  852.  
  853. return true;
  854. }else{
  855. return false;
  856. }
  857. }
  858.  
  859. //When the effect finish
  860. var endEffect = function(){
  861. //return;
  862. imgs.show();
  863.  
  864. settings.afterTransition();
  865.  
  866. if(!caption()){
  867. transitionReady();
  868. }
  869.  
  870. };
  871.  
  872. //update current to the next
  873. var next = function(){
  874. if(!isReady())return;
  875. ready = false;
  876.  
  877. settings.beforeTransition();
  878. as_captions.hide();
  879.  
  880. before = current;
  881. current++;
  882. if(current > imgs.length-1){
  883. current = 0;
  884. }
  885.  
  886. showThumb();
  887.  
  888. //Update the navigation bar
  889. as_navContainer.children('.as_navBtn').eq(current).addClass('selected').siblings('.as_navBtn').removeClass('selected');
  890.  
  891. stopTimer();
  892. runEffect();
  893. };
  894.  
  895. var prev = function(){
  896. if(!isReady())return;
  897. ready = false;
  898.  
  899. settings.beforeTransition();
  900. as_captions.hide();
  901.  
  902. before = current;
  903. current--;
  904. if(current < 0){
  905. current = imgs.length-1;
  906. }
  907.  
  908. //Update the navigation bar
  909. as_navContainer.children('.as_navBtn').eq(current).addClass('selected').siblings('.as_navBtn').removeClass('selected');
  910.  
  911. stopTimer();
  912. runEffect();
  913. };
  914.  
  915. //next event
  916. as_next.on('click', function(){
  917. next();
  918. });
  919.  
  920. //prev event
  921. as_prev.on('click', function(){
  922. prev();
  923. });
  924.  
  925. //Keyboard navigation
  926. if(settings.keyboardNav){
  927. $(document).keydown(function(event){
  928. //prev keyCode
  929. if(event.keyCode == '37'){
  930. prev();
  931. }
  932. //next keyCode
  933. if(event.keyCode == '39'){
  934. next();
  935. }
  936. });
  937. }
  938.  
  939. //Bar navigation
  940. as_navContainer.on('click', '.as_navBtn', function(){
  941. $this = $(this);
  942.  
  943. //If user clicks on the option that is selected already then do nothing
  944. if($this.hasClass('selected'))return;
  945.  
  946. //If the transition hasn't complete then do nothing as well
  947. if(!isReady())return;
  948.  
  949. $this.addClass('selected').siblings('.as_navBtn').removeClass('selected');
  950.  
  951. goTo($this.data('img'));
  952.  
  953. showThumb();
  954. });
  955.  
  956. var showThumb = function(){
  957. if(!settings.thumbnails)return;
  958.  
  959. if(current == thumbNumber){
  960. as_tip.stop().hide();
  961. return;
  962. }
  963.  
  964. if(thumbNumber == -1)return;
  965.  
  966. var img = thumbs[thumbNumber];
  967.  
  968. var width = $(imgs[thumbNumber]).width() * (settings.thumbnailSize/100);
  969. var height = $(imgs[thumbNumber]).height() * (settings.thumbnailSize/100);
  970.  
  971. $(img).width(width).height(height);
  972. as_tip.width(width).height(height);
  973.  
  974. var navBtnCurrent = as_navContainer.find('div.as_navBtn').eq(thumbNumber);
  975.  
  976. var extra = 5;
  977.  
  978. if(settings.navBarNumeric)extra = 0;
  979.  
  980. as_tip.fadeIn(300).css({
  981. 'top' : $this.offset().top - as_tip.outerHeight() - 10,
  982. 'left' : $this.offset().left - as_tip.outerWidth()/2
  983. }).html(img+'<div class="as_arrow" style="left:'+(as_tip.outerWidth()/2-extra)+'px;"/>');
  984. }
  985.  
  986. if(settings.thumbnails){
  987. //tip
  988. as_tip = $('<div class="as_tip" />');
  989. $('body').append(as_tip.hide());
  990.  
  991. var thumbs = [];
  992. imgs.each(function(i){
  993. var src = $(this).attr('src');
  994. thumbs.push('<img src=\''+src+'\' />');
  995. });
  996.  
  997. //Bar thumbnails
  998. as_navContainer.on('mouseover', '.as_navBtn', function(){
  999. $this = $(this);
  1000.  
  1001.  
  1002. var imgNumber = $this.data('img');
  1003. thumbNumber = imgNumber;
  1004.  
  1005. showThumb();
  1006. });
  1007.  
  1008. as_navContainer.on('mouseout', '.as_navBtn', function(){
  1009. as_tip.stop().hide();
  1010. thumbNumber = -1;
  1011. });
  1012. }
  1013.  
  1014. //go to the specify index
  1015. var goTo = function(index){
  1016. if(!isReady())return;
  1017. ready = false;
  1018.  
  1019. settings.beforeTransition();
  1020. as_captions.hide();
  1021.  
  1022. before = current;
  1023. current = index;
  1024.  
  1025. clearTimeout(vars.interval);
  1026. stopTimer();
  1027.  
  1028. runEffect();
  1029. };
  1030.  
  1031.  
  1032. var playEvt = function(){
  1033. vars.interval = setTimeout(function(){
  1034. next();
  1035. }, settings.playInterval);
  1036.  
  1037. as_play.addClass('as_pause');
  1038. updateTimer();
  1039. };
  1040.  
  1041. //If autoPlay is on then go ahead and begin the party
  1042. if(caption() && settings.autoPlay == true){
  1043. as_play.addClass('as_pause');
  1044. }else if(settings.autoPlay == true){
  1045. playEvt();
  1046. }
  1047.  
  1048. //play button
  1049. as_play.on('click', function(){
  1050. $this = $(this);
  1051. if($this.hasClass('as_pause')){
  1052. $this.removeClass('as_pause');
  1053. play = false;
  1054. clearTimeout(vars.interval);
  1055. stopTimer();
  1056. settings.onPause();
  1057. }else{
  1058. play = true;
  1059. $this.addClass('as_pause');
  1060. playEvt();
  1061. settings.onPlay();
  1062. }
  1063.  
  1064. });
  1065.  
  1066. //swipe support
  1067.  
  1068. //dont allow to drag the images with the mouse
  1069. imgs.on('dragstart', function(event) {
  1070. event.preventDefault();
  1071. });
  1072.  
  1073. imgs.touchSwipeLeft(function() {
  1074. next();
  1075. })
  1076. .touchSwipeRight(function() {
  1077. prev();
  1078. });
  1079.  
  1080. return this;
  1081.  
  1082. };//END OF Auto Slider OBJECT
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093. $.fn.autoSlider = function(options) {
  1094.  
  1095. return this.each(function(key, value){
  1096. var element = $(this);
  1097. // Return early if this element already has a plugin instance
  1098. if (element.data('autoSlider')) return element.data('autoSlider');
  1099. // Pass options to plugin constructor
  1100. var autoSlider = new AutoSlider(this, options);
  1101. // Store plugin object in this element's data
  1102. element.data('autoSlider', autoSlider);
  1103. });
  1104.  
  1105. };
  1106.  
  1107. //Default settings
  1108. $.fn.autoSlider.defaults = {
  1109. theme : 'default', //The theme of the slider (default, theme1, theme2, theme3)
  1110. width : '100%', //The width of the slider, if it set to 0 it will take the width of the largest image
  1111. autoPlay : true, //auto play the images of the slider when is loaded
  1112. rightClickImages : false, //Enable right click on the images of the slider
  1113. showTimer : true, //show the timer line
  1114. circularTimer : false, //Circular Timer
  1115. playInterval : 4000, //Time between transitions when auto play is on
  1116. playBtn : true, //show play button
  1117. loop : true, //when play is on if is set to true start slideshow again when it finishes
  1118. navArrows : true, //show prev and next arrows
  1119. navBar : true, //show the navigation bar
  1120. navBarNumeric : false, //If the navigation bar will show the numbers of images
  1121. autoHideNavArrows : false, //if it set to true then show the prev and next arrow only when you do a mouseover
  1122. autoHidePlayBtn : true, //if it set to true then show the play button only when you do a mouseover
  1123. autoHideNavBar : false, //if it set to true then show the navigation bar only when you do a mouseover
  1124. keyboardNav : true, //navigation with arrows right and left of the keyboard
  1125. transitionSpeed : 700, //The speed between transitions
  1126. boxSpeed : 450, //The animation speed of a single box (must be lower than transitionSpeed)
  1127. captionSpeed : 300, //The animation speed of the caption
  1128. captions : true, //Show captions of the images that have text to show
  1129. autoHideCaptions : false, //if it set to true then show the captions only when you do a mouseover
  1130. thumbnails : true, //Show thumbnails when hovering nav
  1131. thumbnailSize : 20, //Thumbnail size (percentage of the original image)
  1132. x : 8, //when using boxes the x axis
  1133. y : 4, //when using boxes the y axis
  1134. hideIconsInWidth : 500, //Hide the icons(arrows, plat btn, navbar) when the width is 500px or less for responsive design
  1135. hideTimerInWidth : 500, //Hide the timer when the width is 500px or less for responsive design
  1136. shadow : true, //A CSS3 shadow of the slider
  1137. beforeTransition : function(){}, //execute a function before right before the transition begins
  1138. afterTransition : function(){}, //execute a function after the transition completes
  1139. onSlideshowEnd : function() {}, // Runs when the slideshow finishes ( "loop" must be set to false )
  1140. onPlay : function() {}, // Runs when somebody click the button play
  1141. onPause : function() {} // Runs when somebody click the button pause
  1142. };
  1143.  
  1144. $.fn._reverse = [].reverse;
  1145.  
  1146. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment