jquery.nivo.slider.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * jQuery Nivo Slider v3.2
  3. * http://nivo.dev7studios.com
  4. *
  5. * Copyright 2012, Dev7studios
  6. * Free to use and abuse under the MIT license.
  7. * http://www.opensource.org/licenses/mit-license.php
  8. */
  9. (function($) {
  10. var NivoSlider = function(element, options){
  11. // Defaults are below
  12. var settings = $.extend({}, $.fn.nivoSlider.defaults, options);
  13. // Useful variables. Play carefully.
  14. var vars = {
  15. currentSlide: 0,
  16. currentImage: '',
  17. totalSlides: 0,
  18. running: false,
  19. paused: false,
  20. stop: false,
  21. controlNavEl: false
  22. };
  23. // Get this slider
  24. var slider = $(element);
  25. slider.data('nivo:vars', vars).addClass('nivoSlider');
  26. // Find our slider children
  27. var kids = slider.children();
  28. kids.each(function() {
  29. var child = $(this);
  30. var link = '';
  31. if(!child.is('img')){
  32. if(child.is('a')){
  33. child.addClass('nivo-imageLink');
  34. link = child;
  35. }
  36. child = child.find('img:first');
  37. }
  38. // Get img width & height
  39. var childWidth = (childWidth === 0) ? child.attr('width') : child.width(),
  40. childHeight = (childHeight === 0) ? child.attr('height') : child.height();
  41. if(link !== ''){
  42. link.css('display','none');
  43. }
  44. child.css('display','none');
  45. vars.totalSlides++;
  46. });
  47. // If randomStart
  48. if(settings.randomStart){
  49. settings.startSlide = Math.floor(Math.random() * vars.totalSlides);
  50. }
  51. // Set startSlide
  52. if(settings.startSlide > 0){
  53. if(settings.startSlide >= vars.totalSlides) { settings.startSlide = vars.totalSlides - 1; }
  54. vars.currentSlide = settings.startSlide;
  55. }
  56. // Get initial image
  57. if($(kids[vars.currentSlide]).is('img')){
  58. vars.currentImage = $(kids[vars.currentSlide]);
  59. } else {
  60. vars.currentImage = $(kids[vars.currentSlide]).find('img:first');
  61. }
  62. // Show initial link
  63. if($(kids[vars.currentSlide]).is('a')){
  64. $(kids[vars.currentSlide]).css('display','block');
  65. }
  66. // Set first background
  67. var sliderImg = $('<img/>').addClass('nivo-main-image');
  68. sliderImg.attr('src', vars.currentImage.attr('src')).show();
  69. slider.append(sliderImg);
  70. // Detect Window Resize
  71. $(window).resize(function() {
  72. slider.children('img').width(slider.width());
  73. sliderImg.attr('src', vars.currentImage.attr('src'));
  74. sliderImg.stop().height('auto');
  75. $('.nivo-slice').remove();
  76. $('.nivo-box').remove();
  77. });
  78. //Create caption
  79. slider.append($('<div class="nivo-caption"></div>'));
  80. // Process caption function
  81. var processCaption = function(settings){
  82. var nivoCaption = $('.nivo-caption', slider);
  83. if(vars.currentImage.attr('title') != '' && vars.currentImage.attr('title') != undefined){
  84. var title = vars.currentImage.attr('title');
  85. if(title.substr(0,1) == '#') title = $(title).html();
  86. if(nivoCaption.css('display') == 'block'){
  87. setTimeout(function(){
  88. nivoCaption.html(title);
  89. }, settings.animSpeed);
  90. } else {
  91. nivoCaption.html(title);
  92. nivoCaption.stop().fadeIn(settings.animSpeed);
  93. }
  94. } else {
  95. nivoCaption.stop().fadeOut(settings.animSpeed);
  96. }
  97. }
  98. //Process initial caption
  99. processCaption(settings);
  100. // In the words of Super Mario "let's a go!"
  101. var timer = 0;
  102. if(!settings.manualAdvance && kids.length > 1){
  103. timer = setInterval(function(){ nivoRun(slider, kids, settings, false); }, settings.pauseTime);
  104. }
  105. // Add Direction nav
  106. if(settings.directionNav){
  107. slider.append('<div class="nivo-directionNav"><a class="nivo-prevNav">'+ settings.prevText +'</a><a class="nivo-nextNav">'+ settings.nextText +'</a></div>');
  108. $(slider).on('click', 'a.nivo-prevNav', function(){
  109. if(vars.running) { return false; }
  110. clearInterval(timer);
  111. timer = '';
  112. vars.currentSlide -= 2;
  113. nivoRun(slider, kids, settings, 'prev');
  114. });
  115. $(slider).on('click', 'a.nivo-nextNav', function(){
  116. if(vars.running) { return false; }
  117. clearInterval(timer);
  118. timer = '';
  119. nivoRun(slider, kids, settings, 'next');
  120. });
  121. }
  122. // Add Control nav
  123. if(settings.controlNav){
  124. vars.controlNavEl = $('<div class="nivo-controlNav"></div>');
  125. slider.after(vars.controlNavEl);
  126. for(var i = 0; i < kids.length; i++){
  127. if(settings.controlNavThumbs){
  128. vars.controlNavEl.addClass('nivo-thumbs-enabled');
  129. var child = kids.eq(i);
  130. if(!child.is('img')){
  131. child = child.find('img:first');
  132. }
  133. if(child.attr('data-thumb')) vars.controlNavEl.append('<a class="nivo-control" rel="'+ i +'"><img src="'+ child.attr('data-thumb') +'" alt="" /></a>');
  134. } else {
  135. vars.controlNavEl.append('<a class="nivo-control" rel="'+ i +'">'+ (i + 1) +'</a>');
  136. }
  137. }
  138. //Set initial active link
  139. $('a:eq('+ vars.currentSlide +')', vars.controlNavEl).addClass('active');
  140. $('a', vars.controlNavEl).bind('click', function(){
  141. if(vars.running) return false;
  142. if($(this).hasClass('active')) return false;
  143. clearInterval(timer);
  144. timer = '';
  145. sliderImg.attr('src', vars.currentImage.attr('src'));
  146. vars.currentSlide = $(this).attr('rel') - 1;
  147. nivoRun(slider, kids, settings, 'control');
  148. });
  149. }
  150. //For pauseOnHover setting
  151. if(settings.pauseOnHover){
  152. slider.hover(function(){
  153. vars.paused = true;
  154. clearInterval(timer);
  155. timer = '';
  156. }, function(){
  157. vars.paused = false;
  158. // Restart the timer
  159. if(timer === '' && !settings.manualAdvance){
  160. timer = setInterval(function(){ nivoRun(slider, kids, settings, false); }, settings.pauseTime);
  161. }
  162. });
  163. }
  164. // Event when Animation finishes
  165. slider.bind('nivo:animFinished', function(){
  166. sliderImg.attr('src', vars.currentImage.attr('src'));
  167. vars.running = false;
  168. // Hide child links
  169. $(kids).each(function(){
  170. if($(this).is('a')){
  171. $(this).css('display','none');
  172. }
  173. });
  174. // Show current link
  175. if($(kids[vars.currentSlide]).is('a')){
  176. $(kids[vars.currentSlide]).css('display','block');
  177. }
  178. // Restart the timer
  179. if(timer === '' && !vars.paused && !settings.manualAdvance){
  180. timer = setInterval(function(){ nivoRun(slider, kids, settings, false); }, settings.pauseTime);
  181. }
  182. // Trigger the afterChange callback
  183. settings.afterChange.call(this);
  184. });
  185. // Add slices for slice animations
  186. var createSlices = function(slider, settings, vars) {
  187. if($(vars.currentImage).parent().is('a')) $(vars.currentImage).parent().css('display','block');
  188. $('img[src="'+ vars.currentImage.attr('src') +'"]', slider).not('.nivo-main-image,.nivo-control img').width(slider.width()).css('visibility', 'hidden').show();
  189. var sliceHeight = ($('img[src="'+ vars.currentImage.attr('src') +'"]', slider).not('.nivo-main-image,.nivo-control img').parent().is('a')) ? $('img[src="'+ vars.currentImage.attr('src') +'"]', slider).not('.nivo-main-image,.nivo-control img').parent().height() : $('img[src="'+ vars.currentImage.attr('src') +'"]', slider).not('.nivo-main-image,.nivo-control img').height();
  190. for(var i = 0; i < settings.slices; i++){
  191. var sliceWidth = Math.round(slider.width()/settings.slices);
  192. if(i === settings.slices-1){
  193. slider.append(
  194. $('<div class="nivo-slice" name="'+i+'"><img src="'+ vars.currentImage.attr('src') +'" style="position:absolute; width:'+ slider.width() +'px; height:auto; display:block !important; top:0; left:-'+ ((sliceWidth + (i * sliceWidth)) - sliceWidth) +'px;" /></div>').css({
  195. left:(sliceWidth*i)+'px',
  196. width:(slider.width()-(sliceWidth*i))+'px',
  197. height:sliceHeight+'px',
  198. opacity:'0',
  199. overflow:'hidden'
  200. })
  201. );
  202. } else {
  203. slider.append(
  204. $('<div class="nivo-slice" name="'+i+'"><img src="'+ vars.currentImage.attr('src') +'" style="position:absolute; width:'+ slider.width() +'px; height:auto; display:block !important; top:0; left:-'+ ((sliceWidth + (i * sliceWidth)) - sliceWidth) +'px;" /></div>').css({
  205. left:(sliceWidth*i)+'px',
  206. width:sliceWidth+'px',
  207. height:sliceHeight+'px',
  208. opacity:'0',
  209. overflow:'hidden'
  210. })
  211. );
  212. }
  213. }
  214. $('.nivo-slice', slider).height(sliceHeight);
  215. sliderImg.stop().animate({
  216. height: $(vars.currentImage).height()
  217. }, settings.animSpeed);
  218. };
  219. // Add boxes for box animations
  220. var createBoxes = function(slider, settings, vars){
  221. if($(vars.currentImage).parent().is('a')) $(vars.currentImage).parent().css('display','block');
  222. $('img[src="'+ vars.currentImage.attr('src') +'"]', slider).not('.nivo-main-image,.nivo-control img').width(slider.width()).css('visibility', 'hidden').show();
  223. var boxWidth = Math.round(slider.width()/settings.boxCols),
  224. boxHeight = Math.round($('img[src="'+ vars.currentImage.attr('src') +'"]', slider).not('.nivo-main-image,.nivo-control img').height() / settings.boxRows);
  225. for(var rows = 0; rows < settings.boxRows; rows++){
  226. for(var cols = 0; cols < settings.boxCols; cols++){
  227. if(cols === settings.boxCols-1){
  228. slider.append(
  229. $('<div class="nivo-box" name="'+ cols +'" rel="'+ rows +'"><img src="'+ vars.currentImage.attr('src') +'" style="position:absolute; width:'+ slider.width() +'px; height:auto; display:block; top:-'+ (boxHeight*rows) +'px; left:-'+ (boxWidth*cols) +'px;" /></div>').css({
  230. opacity:0,
  231. left:(boxWidth*cols)+'px',
  232. top:(boxHeight*rows)+'px',
  233. width:(slider.width()-(boxWidth*cols))+'px'
  234. })
  235. );
  236. $('.nivo-box[name="'+ cols +'"]', slider).height($('.nivo-box[name="'+ cols +'"] img', slider).height()+'px');
  237. } else {
  238. slider.append(
  239. $('<div class="nivo-box" name="'+ cols +'" rel="'+ rows +'"><img src="'+ vars.currentImage.attr('src') +'" style="position:absolute; width:'+ slider.width() +'px; height:auto; display:block; top:-'+ (boxHeight*rows) +'px; left:-'+ (boxWidth*cols) +'px;" /></div>').css({
  240. opacity:0,
  241. left:(boxWidth*cols)+'px',
  242. top:(boxHeight*rows)+'px',
  243. width:boxWidth+'px'
  244. })
  245. );
  246. $('.nivo-box[name="'+ cols +'"]', slider).height($('.nivo-box[name="'+ cols +'"] img', slider).height()+'px');
  247. }
  248. }
  249. }
  250. sliderImg.stop().animate({
  251. height: $(vars.currentImage).height()
  252. }, settings.animSpeed);
  253. };
  254. // Private run method
  255. var nivoRun = function(slider, kids, settings, nudge){
  256. // Get our vars
  257. var vars = slider.data('nivo:vars');
  258. // Trigger the lastSlide callback
  259. if(vars && (vars.currentSlide === vars.totalSlides - 1)){
  260. settings.lastSlide.call(this);
  261. }
  262. // Stop
  263. if((!vars || vars.stop) && !nudge) { return false; }
  264. // Trigger the beforeChange callback
  265. settings.beforeChange.call(this);
  266. // Set current background before change
  267. if(!nudge){
  268. sliderImg.attr('src', vars.currentImage.attr('src'));
  269. } else {
  270. if(nudge === 'prev'){
  271. sliderImg.attr('src', vars.currentImage.attr('src'));
  272. }
  273. if(nudge === 'next'){
  274. sliderImg.attr('src', vars.currentImage.attr('src'));
  275. }
  276. }
  277. vars.currentSlide++;
  278. // Trigger the slideshowEnd callback
  279. if(vars.currentSlide === vars.totalSlides){
  280. vars.currentSlide = 0;
  281. settings.slideshowEnd.call(this);
  282. }
  283. if(vars.currentSlide < 0) { vars.currentSlide = (vars.totalSlides - 1); }
  284. // Set vars.currentImage
  285. if($(kids[vars.currentSlide]).is('img')){
  286. vars.currentImage = $(kids[vars.currentSlide]);
  287. } else {
  288. vars.currentImage = $(kids[vars.currentSlide]).find('img:first');
  289. }
  290. // Set active links
  291. if(settings.controlNav){
  292. $('a', vars.controlNavEl).removeClass('active');
  293. $('a:eq('+ vars.currentSlide +')', vars.controlNavEl).addClass('active');
  294. }
  295. // Process caption
  296. processCaption(settings);
  297. // Remove any slices from last transition
  298. $('.nivo-slice', slider).remove();
  299. // Remove any boxes from last transition
  300. $('.nivo-box', slider).remove();
  301. var currentEffect = settings.effect,
  302. anims = '';
  303. // Generate random effect
  304. if(settings.effect === 'random'){
  305. anims = new Array('sliceDownRight','sliceDownLeft','sliceUpRight','sliceUpLeft','sliceUpDown','sliceUpDownLeft','fold','fade',
  306. 'boxRandom','boxRain','boxRainReverse','boxRainGrow','boxRainGrowReverse');
  307. currentEffect = anims[Math.floor(Math.random()*(anims.length + 1))];
  308. if(currentEffect === undefined) { currentEffect = 'fade'; }
  309. }
  310. // Run random effect from specified set (eg: effect:'fold,fade')
  311. if(settings.effect.indexOf(',') !== -1){
  312. anims = settings.effect.split(',');
  313. currentEffect = anims[Math.floor(Math.random()*(anims.length))];
  314. if(currentEffect === undefined) { currentEffect = 'fade'; }
  315. }
  316. // Custom transition as defined by "data-transition" attribute
  317. if(vars.currentImage.attr('data-transition')){
  318. currentEffect = vars.currentImage.attr('data-transition');
  319. }
  320. // Run effects
  321. vars.running = true;
  322. var timeBuff = 0,
  323. i = 0,
  324. slices = '',
  325. firstSlice = '',
  326. totalBoxes = '',
  327. boxes = '';
  328. if(currentEffect === 'sliceDown' || currentEffect === 'sliceDownRight' || currentEffect === 'sliceDownLeft'){
  329. createSlices(slider, settings, vars);
  330. timeBuff = 0;
  331. i = 0;
  332. slices = $('.nivo-slice', slider);
  333. if(currentEffect === 'sliceDownLeft') { slices = $('.nivo-slice', slider)._reverse(); }
  334. slices.each(function(){
  335. var slice = $(this);
  336. slice.css({ 'top': '0px' });
  337. if(i === settings.slices-1){
  338. setTimeout(function(){
  339. slice.animate({opacity:'1.0' }, settings.animSpeed, '', function(){ slider.trigger('nivo:animFinished'); });
  340. }, (100 + timeBuff));
  341. } else {
  342. setTimeout(function(){
  343. slice.animate({opacity:'1.0' }, settings.animSpeed);
  344. }, (100 + timeBuff));
  345. }
  346. timeBuff += 50;
  347. i++;
  348. });
  349. } else if(currentEffect === 'sliceUp' || currentEffect === 'sliceUpRight' || currentEffect === 'sliceUpLeft'){
  350. createSlices(slider, settings, vars);
  351. timeBuff = 0;
  352. i = 0;
  353. slices = $('.nivo-slice', slider);
  354. if(currentEffect === 'sliceUpLeft') { slices = $('.nivo-slice', slider)._reverse(); }
  355. slices.each(function(){
  356. var slice = $(this);
  357. slice.css({ 'bottom': '0px' });
  358. if(i === settings.slices-1){
  359. setTimeout(function(){
  360. slice.animate({opacity:'1.0' }, settings.animSpeed, '', function(){ slider.trigger('nivo:animFinished'); });
  361. }, (100 + timeBuff));
  362. } else {
  363. setTimeout(function(){
  364. slice.animate({opacity:'1.0' }, settings.animSpeed);
  365. }, (100 + timeBuff));
  366. }
  367. timeBuff += 50;
  368. i++;
  369. });
  370. } else if(currentEffect === 'sliceUpDown' || currentEffect === 'sliceUpDownRight' || currentEffect === 'sliceUpDownLeft'){
  371. createSlices(slider, settings, vars);
  372. timeBuff = 0;
  373. i = 0;
  374. var v = 0;
  375. slices = $('.nivo-slice', slider);
  376. if(currentEffect === 'sliceUpDownLeft') { slices = $('.nivo-slice', slider)._reverse(); }
  377. slices.each(function(){
  378. var slice = $(this);
  379. if(i === 0){
  380. slice.css('top','0px');
  381. i++;
  382. } else {
  383. slice.css('bottom','0px');
  384. i = 0;
  385. }
  386. if(v === settings.slices-1){
  387. setTimeout(function(){
  388. slice.animate({opacity:'1.0' }, settings.animSpeed, '', function(){ slider.trigger('nivo:animFinished'); });
  389. }, (100 + timeBuff));
  390. } else {
  391. setTimeout(function(){
  392. slice.animate({opacity:'1.0' }, settings.animSpeed);
  393. }, (100 + timeBuff));
  394. }
  395. timeBuff += 50;
  396. v++;
  397. });
  398. } else if(currentEffect === 'fold'){
  399. createSlices(slider, settings, vars);
  400. timeBuff = 0;
  401. i = 0;
  402. $('.nivo-slice', slider).each(function(){
  403. var slice = $(this);
  404. var origWidth = slice.width();
  405. slice.css({ top:'0px', width:'0px' });
  406. if(i === settings.slices-1){
  407. setTimeout(function(){
  408. slice.animate({ width:origWidth, opacity:'1.0' }, settings.animSpeed, '', function(){ slider.trigger('nivo:animFinished'); });
  409. }, (100 + timeBuff));
  410. } else {
  411. setTimeout(function(){
  412. slice.animate({ width:origWidth, opacity:'1.0' }, settings.animSpeed);
  413. }, (100 + timeBuff));
  414. }
  415. timeBuff += 50;
  416. i++;
  417. });
  418. } else if(currentEffect === 'fade'){
  419. createSlices(slider, settings, vars);
  420. firstSlice = $('.nivo-slice:first', slider);
  421. firstSlice.css({
  422. 'width': slider.width() + 'px'
  423. });
  424. firstSlice.animate({ opacity:'1.0' }, (settings.animSpeed*2), '', function(){ slider.trigger('nivo:animFinished'); });
  425. } else if(currentEffect === 'slideInRight'){
  426. createSlices(slider, settings, vars);
  427. firstSlice = $('.nivo-slice:first', slider);
  428. firstSlice.css({
  429. 'width': '0px',
  430. 'opacity': '1'
  431. });
  432. firstSlice.animate({ width: slider.width() + 'px' }, (settings.animSpeed*2), '', function(){ slider.trigger('nivo:animFinished'); });
  433. } else if(currentEffect === 'slideInLeft'){
  434. createSlices(slider, settings, vars);
  435. firstSlice = $('.nivo-slice:first', slider);
  436. firstSlice.css({
  437. 'width': '0px',
  438. 'opacity': '1',
  439. 'left': '',
  440. 'right': '0px'
  441. });
  442. firstSlice.animate({ width: slider.width() + 'px' }, (settings.animSpeed*2), '', function(){
  443. // Reset positioning
  444. firstSlice.css({
  445. 'left': '0px',
  446. 'right': ''
  447. });
  448. slider.trigger('nivo:animFinished');
  449. });
  450. } else if(currentEffect === 'boxRandom'){
  451. createBoxes(slider, settings, vars);
  452. totalBoxes = settings.boxCols * settings.boxRows;
  453. i = 0;
  454. timeBuff = 0;
  455. boxes = shuffle($('.nivo-box', slider));
  456. boxes.each(function(){
  457. var box = $(this);
  458. if(i === totalBoxes-1){
  459. setTimeout(function(){
  460. box.animate({ opacity:'1' }, settings.animSpeed, '', function(){ slider.trigger('nivo:animFinished'); });
  461. }, (100 + timeBuff));
  462. } else {
  463. setTimeout(function(){
  464. box.animate({ opacity:'1' }, settings.animSpeed);
  465. }, (100 + timeBuff));
  466. }
  467. timeBuff += 20;
  468. i++;
  469. });
  470. } else if(currentEffect === 'boxRain' || currentEffect === 'boxRainReverse' || currentEffect === 'boxRainGrow' || currentEffect === 'boxRainGrowReverse'){
  471. createBoxes(slider, settings, vars);
  472. totalBoxes = settings.boxCols * settings.boxRows;
  473. i = 0;
  474. timeBuff = 0;
  475. // Split boxes into 2D array
  476. var rowIndex = 0;
  477. var colIndex = 0;
  478. var box2Darr = [];
  479. box2Darr[rowIndex] = [];
  480. boxes = $('.nivo-box', slider);
  481. if(currentEffect === 'boxRainReverse' || currentEffect === 'boxRainGrowReverse'){
  482. boxes = $('.nivo-box', slider)._reverse();
  483. }
  484. boxes.each(function(){
  485. box2Darr[rowIndex][colIndex] = $(this);
  486. colIndex++;
  487. if(colIndex === settings.boxCols){
  488. rowIndex++;
  489. colIndex = 0;
  490. box2Darr[rowIndex] = [];
  491. }
  492. });
  493. // Run animation
  494. for(var cols = 0; cols < (settings.boxCols * 2); cols++){
  495. var prevCol = cols;
  496. for(var rows = 0; rows < settings.boxRows; rows++){
  497. if(prevCol >= 0 && prevCol < settings.boxCols){
  498. /* Due to some weird JS bug with loop vars
  499. being used in setTimeout, this is wrapped
  500. with an anonymous function call */
  501. (function(row, col, time, i, totalBoxes) {
  502. var box = $(box2Darr[row][col]);
  503. var w = box.width();
  504. var h = box.height();
  505. if(currentEffect === 'boxRainGrow' || currentEffect === 'boxRainGrowReverse'){
  506. box.width(0).height(0);
  507. }
  508. if(i === totalBoxes-1){
  509. setTimeout(function(){
  510. box.animate({ opacity:'1', width:w, height:h }, settings.animSpeed/1.3, '', function(){ slider.trigger('nivo:animFinished'); });
  511. }, (100 + time));
  512. } else {
  513. setTimeout(function(){
  514. box.animate({ opacity:'1', width:w, height:h }, settings.animSpeed/1.3);
  515. }, (100 + time));
  516. }
  517. })(rows, prevCol, timeBuff, i, totalBoxes);
  518. i++;
  519. }
  520. prevCol--;
  521. }
  522. timeBuff += 100;
  523. }
  524. }
  525. };
  526. // Shuffle an array
  527. var shuffle = function(arr){
  528. for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i, 10), x = arr[--i], arr[i] = arr[j], arr[j] = x);
  529. return arr;
  530. };
  531. // For debugging
  532. var trace = function(msg){
  533. if(this.console && typeof console.log !== 'undefined') { console.log(msg); }
  534. };
  535. // Start / Stop
  536. this.stop = function(){
  537. if(!$(element).data('nivo:vars').stop){
  538. $(element).data('nivo:vars').stop = true;
  539. trace('Stop Slider');
  540. }
  541. };
  542. this.start = function(){
  543. if($(element).data('nivo:vars').stop){
  544. $(element).data('nivo:vars').stop = false;
  545. trace('Start Slider');
  546. }
  547. };
  548. // Trigger the afterLoad callback
  549. settings.afterLoad.call(this);
  550. return this;
  551. };
  552. $.fn.nivoSlider = function(options) {
  553. return this.each(function(key, value){
  554. var element = $(this);
  555. // Return early if this element already has a plugin instance
  556. if (element.data('nivoslider')) { return element.data('nivoslider'); }
  557. // Pass options to plugin constructor
  558. var nivoslider = new NivoSlider(this, options);
  559. // Store plugin object in this element's data
  560. element.data('nivoslider', nivoslider);
  561. });
  562. };
  563. //Default settings
  564. $.fn.nivoSlider.defaults = {
  565. effect: 'random',
  566. slices: 15,
  567. boxCols: 8,
  568. boxRows: 4,
  569. animSpeed: 500,
  570. pauseTime: 3000,
  571. startSlide: 0,
  572. directionNav: true,
  573. controlNav: false,
  574. controlNavThumbs: false,
  575. pauseOnHover: true,
  576. manualAdvance: false,
  577. prevText: 'Prev',
  578. nextText: 'Next',
  579. randomStart: false,
  580. beforeChange: function(){},
  581. afterChange: function(){},
  582. slideshowEnd: function(){},
  583. lastSlide: function(){},
  584. afterLoad: function(){}
  585. };
  586. $.fn._reverse = [].reverse;
  587. })(jQuery);