jquery.nivo.slider.js 24 KB

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