jquery.slides.coffee 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. # SlidesJS 3.0.4
  2. # Documentation and examples http://slidesjs.com
  3. # Support forum http://groups.google.com/group/slidesjs
  4. # Created by Nathan Searles http://nathansearles.com
  5. # Version: 3.0.4
  6. # Updated: June 26th, 2013
  7. # SlidesJS is an open source project, contribute at GitHub:
  8. # https://github.com/nathansearles/Slides
  9. # (c) 2013 by Nathan Searles
  10. # Licensed under the Apache License, Version 2.0 (the "License");
  11. # you may not use this file except in compliance with the License.
  12. # You may obtain a copy of the License at
  13. # http://www.apache.org/licenses/LICENSE-2.0
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS,
  16. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # See the License for the specific language governing permissions and
  18. # limitations under the License.
  19. (($, window, document) ->
  20. pluginName = "slidesjs"
  21. defaults =
  22. width: 940
  23. # Set the default width of the slideshow.
  24. height: 528
  25. # Set the default height of the slideshow.
  26. start: 1
  27. # Set the first slide in the slideshow.
  28. navigation:
  29. # Next and previous button settings.
  30. active: true
  31. # [boolean] Create next and previous buttons.
  32. # You can set to false and use your own next/prev buttons.
  33. # User defined next/prev buttons must have the following:
  34. # previous: class="slidesjs-previous slidesjs-navigation"
  35. # next: class="slidesjs-next slidesjs-navigation"
  36. effect: "slide"
  37. # [string] Can be either "slide" or "fade".
  38. pagination:
  39. # Pagination settings
  40. active: true
  41. # [boolean] Create pagination items.
  42. # You cannot use your own pagination.
  43. effect: "slide"
  44. # [string] Can be either "slide" or "fade".
  45. play:
  46. # Play and stop button setting.
  47. active: false
  48. # [boolean] Create the play and stop buttons.
  49. # You cannot use your own pagination.
  50. effect: "slide"
  51. # [string] Can be either "slide" or "fade".
  52. interval: 5000
  53. # [number] Time spent on each slide in milliseconds.
  54. auto: false
  55. # [boolean] Start playing the slideshow on load
  56. swap: true
  57. # [boolean] show/hide stop and play buttons
  58. pauseOnHover: false
  59. # [boolean] pause a playing slideshow on hover
  60. restartDelay: 2500
  61. # [number] restart delay on an inactive slideshow
  62. effect:
  63. slide:
  64. # Slide effect settings.
  65. speed: 500
  66. # [number] Speed in milliseconds of the slide animation.
  67. fade:
  68. speed: 300
  69. # [number] Speed in milliseconds of the fade animation.
  70. crossfade: true
  71. # [boolean] Cross-fade the transition
  72. callback:
  73. loaded: () ->
  74. # [function] Called when slides is loaded
  75. start: () ->
  76. # [function] Called when animation has started
  77. complete: () ->
  78. # [function] Called when animation is complete
  79. class Plugin
  80. constructor: (@element, options) ->
  81. @options = $.extend true, {}, defaults, options
  82. @_defaults = defaults
  83. @_name = pluginName
  84. @init()
  85. Plugin::init = ->
  86. $element = $(@element)
  87. @data = $.data this
  88. # Set data
  89. $.data this, "animating", false
  90. $.data this, "total", $element.children().not(".slidesjs-navigation", $element).length
  91. $.data this, "current", @options.start - 1
  92. $.data this, "vendorPrefix", @_getVendorPrefix()
  93. # Detect touch device
  94. if typeof TouchEvent != "undefined"
  95. $.data this, "touch", true
  96. # Set slide speed to half for touch
  97. @options.effect.slide.speed = this.options.effect.slide.speed / 2
  98. # Hide overflow
  99. $element.css overflow: "hidden"
  100. # Create container
  101. $element.slidesContainer = $element.children().not(".slidesjs-navigation", $element).wrapAll("<div class='slidesjs-container'>", $element).parent().css
  102. overflow: "hidden"
  103. position: "relative"
  104. # Create control div
  105. $(".slidesjs-container", $element)
  106. .wrapInner("<div class='slidesjs-control'>", $element)
  107. .children()
  108. # Setup control div
  109. $(".slidesjs-control", $element)
  110. .css
  111. position: "relative"
  112. left: 0
  113. # Setup slides
  114. $(".slidesjs-control", $element)
  115. .children()
  116. .addClass("slidesjs-slide")
  117. .css
  118. position: "absolute"
  119. top: 0
  120. left: 0
  121. width: "100%"
  122. zIndex: 0
  123. display: "none"
  124. webkitBackfaceVisibility: "hidden"
  125. # Assign an index to each slide
  126. $.each( $(".slidesjs-control", $element).children(), (i) ->
  127. $slide = $(this)
  128. $slide.attr("slidesjs-index", i)
  129. )
  130. if @data.touch
  131. # Bind touch events, if supported
  132. $(".slidesjs-control", $element).on("touchstart", (e) =>
  133. @_touchstart(e)
  134. )
  135. $(".slidesjs-control", $element).on("touchmove", (e) =>
  136. @_touchmove(e)
  137. )
  138. $(".slidesjs-control", $element).on("touchend", (e) =>
  139. @_touchend(e)
  140. )
  141. # Fades in slideshow, your slideshow ID must be display:none in your CSS
  142. $element.fadeIn 0
  143. # Update sets width/height of slideshow
  144. @update()
  145. # If touch device setup next slides
  146. @_setuptouch() if @data.touch
  147. # Fade in start slide
  148. $(".slidesjs-control", $element)
  149. .children(":eq(" + @data.current + ")")
  150. .eq(0)
  151. .fadeIn 0, ->
  152. $(this).css zIndex: 10
  153. if @options.navigation.active
  154. # Create next/prev buttons
  155. prevButton = $("<a>"
  156. class: "slidesjs-previous slidesjs-navigation"
  157. href: "#"
  158. title: "Previous"
  159. text: "Previous"
  160. ).appendTo($element)
  161. nextButton = $("<a>"
  162. class: "slidesjs-next slidesjs-navigation"
  163. href: "#"
  164. title: "Next"
  165. text: "Next"
  166. ).appendTo($element)
  167. # bind click events
  168. $(".slidesjs-next", $element).click (e) =>
  169. e.preventDefault()
  170. @stop(true)
  171. @next(@options.navigation.effect)
  172. $(".slidesjs-previous", $element).click (e) =>
  173. e.preventDefault()
  174. @stop(true)
  175. @previous(@options.navigation.effect)
  176. if @options.play.active
  177. playButton = $("<a>",
  178. class: "slidesjs-play slidesjs-navigation"
  179. href: "#"
  180. title: "Play"
  181. text: "Play"
  182. ).appendTo($element)
  183. stopButton = $("<a>",
  184. class: "slidesjs-stop slidesjs-navigation"
  185. href: "#"
  186. title: "Stop"
  187. text: "Stop"
  188. ).appendTo($element)
  189. playButton.click (e) =>
  190. e.preventDefault()
  191. @play(true)
  192. stopButton.click (e) =>
  193. e.preventDefault()
  194. @stop(true)
  195. if @options.play.swap
  196. stopButton.css
  197. display: "none"
  198. if @options.pagination.active
  199. # Create unordered list pagination
  200. pagination = $("<ul>"
  201. class: "slidesjs-pagination"
  202. ).appendTo($element)
  203. # Create a list item and anchor for each slide
  204. $.each(new Array(@data.total), (i) =>
  205. paginationItem = $("<li>"
  206. class: "slidesjs-pagination-item"
  207. ).appendTo(pagination)
  208. paginationLink = $("<a>"
  209. href: "#"
  210. "data-slidesjs-item": i
  211. html: i + 1
  212. ).appendTo(paginationItem)
  213. # bind click events
  214. paginationLink.click (e) =>
  215. e.preventDefault()
  216. # Stop play
  217. @stop(true)
  218. # Goto to selected slide
  219. @goto( ($(e.currentTarget).attr("data-slidesjs-item") * 1) + 1 )
  220. )
  221. # Bind update on browser resize
  222. $(window).bind("resize", () =>
  223. @update()
  224. )
  225. # Set start pagination item to active
  226. @_setActive()
  227. # Auto play slideshow
  228. if @options.play.auto
  229. @play()
  230. # Slides has loaded
  231. @options.callback.loaded(@options.start)
  232. # @_setActive()
  233. # Sets the active slide in the pagination
  234. Plugin::_setActive = (number) ->
  235. $element = $(@element)
  236. @data = $.data this
  237. # Get the current slide index
  238. current = if number > -1 then number else @data.current
  239. # Set active slide in pagination
  240. $(".active", $element).removeClass "active"
  241. $(".slidesjs-pagination li:eq(" + current + ") a", $element).addClass "active"
  242. # @update()
  243. # Update the slideshow size on browser resize
  244. Plugin::update = ->
  245. $element = $(@element)
  246. @data = $.data this
  247. # Hide all slides expect current
  248. $(".slidesjs-control", $element).children(":not(:eq(" + @data.current + "))").css
  249. display: "none"
  250. left: 0
  251. zIndex: 0
  252. # Get the new width and height
  253. width = $element.width()
  254. height = (@options.height / @options.width) * width
  255. # Store new width and height
  256. @options.width = width
  257. @options.height = height
  258. # Set new width and height
  259. $(".slidesjs-control, .slidesjs-container", $element).css
  260. width: width
  261. height: height
  262. # @next()
  263. # Next mechanics
  264. Plugin::next = (effect) ->
  265. $element = $(@element)
  266. @data = $.data this
  267. # Set the direction
  268. $.data this, "direction", "next"
  269. # Slides or fade effect
  270. if effect is undefined then effect = @options.navigation.effect
  271. if effect is "fade" then @_fade() else @_slide()
  272. # @previous()
  273. # Previous mechanics
  274. Plugin::previous = (effect) ->
  275. $element = $(@element)
  276. @data = $.data this
  277. # Set the direction
  278. $.data this, "direction", "previous"
  279. # Slides or fade effect
  280. if effect is undefined then effect = @options.navigation.effect
  281. if effect is "fade" then @_fade() else @_slide()
  282. # @goto()
  283. # Pagination mechanics
  284. Plugin::goto = (number) ->
  285. $element = $(@element)
  286. @data = $.data this
  287. # Set effect to default if not defined
  288. if effect is undefined then effect = @options.pagination.effect
  289. # Error correction if slide doesn't exists
  290. if number > @data.total
  291. number = @data.total
  292. else if number < 1
  293. number = 1
  294. if typeof number is "number"
  295. if effect is "fade" then @_fade(number) else @_slide(number)
  296. else if typeof number is "string"
  297. if number is "first"
  298. if effect is "fade" then @_fade(0) else @_slide(0)
  299. else if number is "last"
  300. if effect is "fade" then @_fade(@data.total) else @_slide(@data.total)
  301. # @_setuptouch()
  302. # Setup slideshow for touch
  303. Plugin::_setuptouch = () ->
  304. $element = $(@element)
  305. @data = $.data this
  306. # Define slides control
  307. slidesControl = $(".slidesjs-control", $element)
  308. # Get next/prev slides around current slide
  309. next = @data.current + 1
  310. previous = @data.current - 1
  311. # Create the loop
  312. previous = @data.total - 1 if previous < 0
  313. next = 0 if next > @data.total - 1
  314. # By default next/prev slides are hidden, show them when on touch device
  315. slidesControl.children(":eq(" + next + ")").css
  316. display: "block"
  317. left: @options.width
  318. slidesControl.children(":eq(" + previous + ")").css
  319. display: "block"
  320. left: -@options.width
  321. # @_touchstart()
  322. # Start touch
  323. Plugin::_touchstart = (e) ->
  324. $element = $(@element)
  325. @data = $.data this
  326. touches = e.originalEvent.touches[0]
  327. # Setup the next and previous slides for swiping
  328. @_setuptouch()
  329. # Start touch timer
  330. $.data this, "touchtimer", Number(new Date())
  331. # Set touch position
  332. $.data this, "touchstartx", touches.pageX
  333. $.data this, "touchstarty", touches.pageY
  334. # Stop event from bubbling up
  335. e.stopPropagation()
  336. # @_touchend()
  337. # Animates the slideshow when touch is complete
  338. Plugin::_touchend = (e) ->
  339. $element = $(@element)
  340. @data = $.data this
  341. touches = e.originalEvent.touches[0]
  342. # Define slides control
  343. slidesControl = $(".slidesjs-control", $element)
  344. # Slide has been dragged to the right, goto previous slide
  345. if slidesControl.position().left > @options.width * 0.5 || slidesControl.position().left > @options.width * 0.1 && (Number(new Date()) - @data.touchtimer < 250)
  346. $.data this, "direction", "previous"
  347. @_slide()
  348. # Slide has been dragged to the left, goto next slide
  349. else if slidesControl.position().left < -(@options.width * 0.5) || slidesControl.position().left < -(@options.width * 0.1) && (Number(new Date()) - @data.touchtimer < 250)
  350. $.data this, "direction", "next"
  351. @_slide()
  352. else
  353. # Slide has not been dragged far enough, animate back to 0 and reset
  354. # Get the browser's vendor prefix
  355. prefix = @data.vendorPrefix
  356. # Create CSS3 styles based on vendor prefix
  357. transform = prefix + "Transform"
  358. duration = prefix + "TransitionDuration"
  359. timing = prefix + "TransitionTimingFunction"
  360. # Set CSS3 styles
  361. slidesControl[0].style[transform] = "translateX(0px)"
  362. slidesControl[0].style[duration] = @options.effect.slide.speed * 0.85 + "ms"
  363. # Rest slideshow
  364. slidesControl.on "transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd", =>
  365. # Get the browser's vendor prefix
  366. prefix = @data.vendorPrefix
  367. # Create CSS3 styles based on vendor prefix
  368. transform = prefix + "Transform"
  369. duration = prefix + "TransitionDuration"
  370. timing = prefix + "TransitionTimingFunction"
  371. # Set CSS3 styles
  372. slidesControl[0].style[transform] = ""
  373. slidesControl[0].style[duration] = ""
  374. slidesControl[0].style[timing] = ""
  375. # Stop event from bubbling up
  376. e.stopPropagation()
  377. # @_touchmove()
  378. # Moves the slide on touch
  379. Plugin::_touchmove = (e) ->
  380. $element = $(@element)
  381. @data = $.data this
  382. touches = e.originalEvent.touches[0]
  383. # Get the browser's vendor prefix
  384. prefix = @data.vendorPrefix
  385. # Define slides control
  386. slidesControl = $(".slidesjs-control", $element)
  387. # Create CSS3 styles based on vendor prefix
  388. transform = prefix + "Transform"
  389. # Check if user is trying to scroll vertically
  390. $.data this, "scrolling", Math.abs(touches.pageX - @data.touchstartx) < Math.abs(touches.pageY - @data.touchstarty)
  391. # Set CSS3 styles
  392. if !@data.animating && !@data.scrolling
  393. # Prevent default scrolling
  394. e.preventDefault()
  395. @_setuptouch()
  396. slidesControl[0].style[transform] = "translateX(" + (touches.pageX - @data.touchstartx) + "px)"
  397. # Stop event from bubbling up
  398. e.stopPropagation()
  399. # @play()
  400. # Play the slideshow
  401. Plugin::play = (next) ->
  402. $element = $(@element)
  403. @data = $.data this
  404. # Check if the slideshow is already playing
  405. if not @data.playInterval
  406. # If next is true goto next slide
  407. if next
  408. currentSlide = @data.current
  409. @data.direction = "next"
  410. if @options.play.effect is "fade" then @_fade() else @_slide()
  411. # Set and store interval
  412. $.data this, "playInterval", setInterval ( =>
  413. currentSlide = @data.current
  414. @data.direction = "next"
  415. if @options.play.effect is "fade" then @_fade() else @_slide()
  416. ), @options.play.interval
  417. # Define slides container
  418. slidesContainer = $(".slidesjs-container", $element)
  419. if @options.play.pauseOnHover
  420. # Prevent event build up
  421. slidesContainer.unbind()
  422. # Stop/pause slideshow on mouse enter
  423. slidesContainer.bind "mouseenter", =>
  424. clearTimeout @data.restartDelay
  425. $.data this, "restartDelay", null
  426. @stop()
  427. # Play slideshow on mouse leave
  428. slidesContainer.bind "mouseleave", =>
  429. if @options.play.restartDelay
  430. $.data this, "restartDelay", setTimeout ( =>
  431. @play(true)
  432. ), @options.play.restartDelay
  433. else
  434. @play()
  435. $.data this, "playing", true
  436. # Add "slidesjs-playing" class to "slidesjs-play" button
  437. $(".slidesjs-play", $element).addClass("slidesjs-playing")
  438. if @options.play.swap
  439. $(".slidesjs-play", $element).hide()
  440. $(".slidesjs-stop", $element).show()
  441. # @stop()
  442. # Stops a playing slideshow
  443. Plugin::stop = (clicked) ->
  444. $element = $(@element)
  445. @data = $.data this
  446. # Clear play interval
  447. clearInterval @data.playInterval
  448. if @options.play.pauseOnHover && clicked
  449. # Prevent event build up
  450. $(".slidesjs-container", $element).unbind()
  451. # Reset slideshow
  452. $.data this, "playInterval", null
  453. $.data this, "playing", false
  454. $(".slidesjs-play", $element).removeClass("slidesjs-playing")
  455. if @options.play.swap
  456. $(".slidesjs-stop", $element).hide()
  457. $(".slidesjs-play", $element).show()
  458. # @_slide()
  459. # CSS3 and JavaScript slide animations
  460. Plugin::_slide = (number) ->
  461. $element = $(@element)
  462. @data = $.data this
  463. if not @data.animating and number isnt @data.current + 1
  464. # Set animating to true
  465. $.data this, "animating", true
  466. # Get current slide
  467. currentSlide = @data.current
  468. if number > -1
  469. number = number - 1
  470. value = if number > currentSlide then 1 else -1
  471. direction = if number > currentSlide then -@options.width else @options.width
  472. next = number
  473. else
  474. value = if @data.direction is "next" then 1 else -1
  475. direction = if @data.direction is "next" then -@options.width else @options.width
  476. next = currentSlide + value
  477. # Loop from first to last slide
  478. next = @data.total - 1 if next is -1
  479. # Loop from last to first slide
  480. next = 0 if next is @data.total
  481. # Set next slide pagination item to active
  482. @_setActive(next)
  483. # Define slides control
  484. slidesControl = $(".slidesjs-control", $element)
  485. # When changing from touch to pagination reset touch slide setup
  486. if number > -1
  487. # Hide all slides expect current
  488. slidesControl.children(":not(:eq(" + currentSlide + "))").css
  489. display: "none"
  490. left: 0
  491. zIndex: 0
  492. # Setup the next slide
  493. slidesControl.children(":eq(" + next + ")").css
  494. display: "block"
  495. left: value * @options.width
  496. zIndex: 10
  497. # Start the slide animation
  498. @options.callback.start(currentSlide + 1)
  499. if @data.vendorPrefix
  500. # If supported use CSS3 for the animation
  501. # Get the browser's vendor prefix
  502. prefix = @data.vendorPrefix
  503. # Create CSS3 styles based on vendor prefix
  504. transform = prefix + "Transform"
  505. duration = prefix + "TransitionDuration"
  506. timing = prefix + "TransitionTimingFunction"
  507. # Set CSS3 styles
  508. slidesControl[0].style[transform] = "translateX(" + direction + "px)"
  509. slidesControl[0].style[duration] = @options.effect.slide.speed + "ms"
  510. slidesControl.on "transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd", =>
  511. # Clear styles
  512. slidesControl[0].style[transform] = ""
  513. slidesControl[0].style[duration] = ""
  514. # Reset slideshow
  515. slidesControl.children(":eq(" + next + ")").css left: 0
  516. slidesControl.children(":eq(" + currentSlide + ")").css
  517. display: "none"
  518. left: 0
  519. zIndex: 0
  520. # Set the new slide to the current
  521. $.data this, "current", next
  522. # # Set animating to false
  523. $.data this, "animating", false
  524. # Unbind transition callback to prevent build up
  525. slidesControl.unbind("transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd")
  526. # Hide all slides expect current
  527. slidesControl.children(":not(:eq(" + next + "))").css
  528. display: "none"
  529. left: 0
  530. zIndex: 0
  531. # If touch device setup next slides
  532. @_setuptouch() if @data.touch
  533. # End of the animation, call complete callback
  534. @options.callback.complete(next + 1)
  535. else
  536. # If CSS3 isn't support use JavaScript for the animation
  537. slidesControl.stop().animate
  538. left: direction
  539. , @options.effect.slide.speed, (=>
  540. slidesControl.css left: 0
  541. slidesControl.children(":eq(" + next + ")").css left: 0
  542. slidesControl.children(":eq(" + currentSlide + ")").css
  543. display: "none"
  544. left: 0
  545. zIndex: 0
  546. # Set the new slide to the current
  547. $.data this, "current", next
  548. # Set animating to false
  549. $.data this, "animating", false
  550. # End of the animation, call complete callback
  551. @options.callback.complete(next + 1)
  552. )
  553. # @_fade()
  554. # Fading and cross fading
  555. Plugin::_fade = (number) ->
  556. $element = $(@element)
  557. @data = $.data this
  558. # Check if not currently animating and the selected slide is not the current slide
  559. if not @data.animating and number isnt @data.current + 1
  560. # Set animating to true
  561. $.data this, "animating", true
  562. # Get current slide
  563. currentSlide = @data.current
  564. if number
  565. # Specific slide has been called
  566. number = number - 1
  567. value = if number > currentSlide then 1 else -1
  568. next = number
  569. else
  570. # Next/prev slide has been called
  571. value = if @data.direction is "next" then 1 else -1
  572. next = currentSlide + value
  573. # Loop from first to last slide
  574. next = @data.total - 1 if next is -1
  575. # Loop from last to first slide
  576. next = 0 if next is @data.total
  577. # Set next slide pagination item to active
  578. @_setActive next
  579. # Define slides control
  580. slidesControl = $(".slidesjs-control", $element)
  581. # Setup the next slide
  582. slidesControl.children(":eq(" + next + ")").css
  583. display: "none"
  584. left: 0
  585. zIndex: 10
  586. # Start of the animation, call the start callback
  587. @options.callback.start(currentSlide + 1)
  588. if @options.effect.fade.crossfade
  589. # Fade out current slide to next slide
  590. slidesControl.children(":eq(" + @data.current + ")")
  591. .stop()
  592. .fadeOut @options.effect.fade.speed
  593. # Fade in to next slide
  594. slidesControl.children(":eq(" + next + ")")
  595. .stop()
  596. .fadeIn @options.effect.fade.speed, (=>
  597. # Reset slides
  598. slidesControl.children(":eq(" + next + ")").css zIndex: 0
  599. # Set animating to false
  600. $.data this, "animating", false
  601. # Set the new slide to the current
  602. $.data this, "current", next
  603. # End of the animation, call complete callback
  604. @options.callback.complete(next + 1)
  605. )
  606. else
  607. # Fade to next slide
  608. slidesControl.children(":eq(" + currentSlide + ")")
  609. .stop()
  610. .fadeOut @options.effect.fade.speed, (=>
  611. # Reset slides
  612. slidesControl.children(":eq(" + next + ")")
  613. .stop()
  614. .fadeIn @options.effect.fade.speed, (=>
  615. # Reset slides
  616. slidesControl.children(":eq(" + next + ")").css zIndex: 10
  617. )
  618. # Set animating to false
  619. $.data this, "animating", false
  620. # Set the new slide to the current
  621. $.data this, "current", next
  622. # End of the animation, call complete callback
  623. @options.callback.complete(next + 1)
  624. )
  625. # @_getVendorPrefix()
  626. # Check if the browser supports CSS3 Transitions
  627. Plugin::_getVendorPrefix = () ->
  628. body = document.body or document.documentElement
  629. style = body.style
  630. transition = "transition"
  631. vendor = ["Moz", "Webkit", "Khtml", "O", "ms"]
  632. transition = transition.charAt(0).toUpperCase() + transition.substr(1)
  633. i = 0
  634. while i < vendor.length
  635. return vendor[i] if typeof style[vendor[i] + transition] is "string"
  636. i++
  637. false
  638. # Plugin constructor
  639. $.fn[pluginName] = (options) ->
  640. @each ->
  641. if !$.data(@, "plugin_#{pluginName}")
  642. $.data(@, "plugin_#{pluginName}", new Plugin(@, options))
  643. )(jQuery, window, document)