vendor/javascripts/prez-controller.js.coffee in prez-0.0.5 vs vendor/javascripts/prez-controller.js.coffee in prez-0.0.6

- old
+ new

@@ -6,17 +6,19 @@ class Prez DEFAULT_OPTIONS = useHash: true duration: 0 + slideElementStyle: "hide" constructor: (options) -> @options = $.extend {}, DEFAULT_OPTIONS, options @window = options.window @document = @window.document @document.write $("#slides-document").text() @document.close() + @options.beforeStart?(@) @start() start: -> changeToHashSlide = => return false unless @options.useHash @@ -35,15 +37,18 @@ @changeSlideTo slide, element return true false + slideElementClass = "#{@options.slideElementStyle}-style" + $(".prez-slide", @document).each (i) -> $(@).attr "data-slide", "#{i + 1}" $(@).find(".prez-element").each (j) -> $(@).attr "data-slide-element", "#{j + 1}" + $(@).addClass("hidden #{slideElementClass}") @startTime = Date.now() @changeSlideTo 1 unless changeToHashSlide() $(@window).on "hashchange", changeToHashSlide $(@document).on "keydown", Prez.handlers.keyDown @@ -70,35 +75,43 @@ $(".prez-slide", @document).hide() $next.show() @slideStarted $next if nextElement == 0 - $next.find(".prez-element").hide() + $next.find(".prez-element").addClass("hidden").removeClass("visible") else if @currentElement() > nextElement for i in [@currentElement()..(nextElement + 1)] - $next.find(".prez-element[data-slide-element='#{i}']").hide() + $next.find(".prez-element[data-slide-element='#{i}']").addClass("hidden").removeClass("visible") else if @currentElement() < nextElement for i in [(@currentElement() + 1)..nextElement] - $next.find(".prez-element[data-slide-element='#{i}']").show() + $next.find(".prez-element[data-slide-element='#{i}']").removeClass("hidden").addClass("visible") + # Hack to fix Chrome sometimes not rendering opacity changes, + # thanks to http://stackoverflow.com/a/8840703/122 + if @options.slideElementStyle == "opacity" + $next.hide().show(0) + @options.slideChanged? $next, nextValue, nextElement true currentSlide: -> return null if $(".prez-slide:visible", @document).size() == 0 parseInt $(".prez-slide:visible", @document).data("slide"), 10 currentElement: -> return null if @currentSlide() == null - return 0 if $(".prez-element:visible", @document).size() == 0 - parseInt $(".prez-element:visible:last", @document).data("slide-element"), 10 + return 0 if $(".prez-slide:visible .prez-element.visible", @document).size() == 0 + parseInt $(".prez-slide:visible .prez-element.visible:last", @document).data("slide-element"), 10 countSlideElements: (slide) -> $slide = $(".prez-slide[data-slide='#{slide}']", @document) return 0 if $slide.size() == 0 $slide.find(".prez-element").size() + countSlides: -> + $(".prez-slide", @document).size() + changeSlideBy: (amount) -> slide = @currentSlide() element = @currentElement() nextSlide = slide nextElement = element @@ -239,22 +252,29 @@ iframe.contentDocument iframePrez = new Prez window: iframe useHash: false + slideElementStyle: "opacity" Prez.current = new Prez duration: Prez.timeToSeconds($("#prez-duration").val()) window: window.open("", "prez", "width=640,height=480") slideChanged: ($slide, slideNumber, elementNumber) -> notes = $slide.find(".prez-notes").html() || "" $("#slide-notes").html notes - $(".current-slide-number").text $slide.data("slide") + $(".current-slide-number:not(select)").text $slide.data("slide") + $("select.current-slide-number").val $slide.data("slide") Prez.handlers.timeChange() iframePrez.changeSlideTo slideNumber, elementNumber + beforeStart: (prez) -> + $("select.current-slide-number").empty() - $(".total-slides").text $(".prez-slide", Prez.current.document).size() + for i in [1..prez.countSlides()] + $("select.current-slide-number").append """<option value="#{i}">#{i}</option>""" + + $(".total-slides").text Prez.current.countSlides() $("#pre-launch").hide() $("#post-launch").show() $(Prez.current.window).bind "beforeunload", -> $("#post-launch").hide() @@ -270,9 +290,16 @@ e.preventDefault() Prez.current?.prevSlide() $(document).on "click", ".end-prez", (e) -> e.preventDefault() + Prez.current?.end() + +$(document).on "change", "select.current-slide-number", (e) -> + Prez.current?.changeSlideTo parseInt($(@).val(), 10) + $(@).blur() + +$(window).bind "beforeunload", -> Prez.current?.end() $(document).on "keydown", Prez.handlers.keyDown $.setInterval 50, Prez.handlers.timeChange