Skip to content

Instantly share code, notes, and snippets.

@xecutioner
Created February 13, 2017 02:14
Show Gist options
  • Save xecutioner/4c84c99304ea2d303a8960cd9dcb91d5 to your computer and use it in GitHub Desktop.
Save xecutioner/4c84c99304ea2d303a8960cd9dcb91d5 to your computer and use it in GitHub Desktop.
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
# \etrack
class @StopWatch
MAX_HOUR: 12
MAX_MINUTE: 59
constructor: ->
that = @
@timer_show_button = $('#timer_show')
@stop_watch = $('#stop_watch')
@start_stop = $('#start_stop_timer')
@reset = $('#reset')
@running = false
@time_second = 0
@time_minute = 0
@time_hour = 0
@time_field_second = $('#seconds')
@time_field_minute = $('#minutes')
@time_field_hour = $('#hours')
@interval_handler = null
# @start_time = new Date()
@start_stop.on 'click', ->
that.start_stop_timer()
@timer_show_button.on 'click', ->
that.show_hide_stop_watch()
@reset.on 'click', ->
that.reset_timer()
$('#watch').removeClass('fa-pause')
$('#watch').addClass('fa-play')
reset_timer: =>
if confirm "Reset Timer ?"
@running = false
@time_second = 0
@time_minute = 0
@time_hour = 0
@time_field_second.val(0)
@time_field_hour.val(0)
@time_field_minute.val(0)
@.stop_timing()
start_stop_timer: =>
if @running == false
$('#timer-flash').show()
@.start_timing()
$('#watch').toggleClass('fa-pause')
else
$('#timer-stop-flash').show()
@.stop_timing()
$('#watch').removeClass('fa-pause')
$('#watch').addClass('fa-play')
stop_timing: =>
start = $("#timepicker1 :input")[0].value
end_time = new Date(moment(start, [ 'hh:mm A' ]))
hours = end_time.getHours() + this.time_hour
minutes = end_time.getMinutes() + this.time_minute
if minutes > @MAX_MINUTE
minutes = minutes % 60
hours = hours + 1
if hours < @MAX_HOUR
hour = hours
AP = " AM"
else
hour = hours - @MAX_HOUR
if hour == 0
hour = @MAX_HOUR
AP = " PM"
end_time = hour + ':' + minutes + AP
$("#timepicker2 :input")[0].value=end_time
@running = false
clearInterval(@interval_handler)
start_timing: =>
start = $('#timepicker1 :input').val()
end = $('#timepicker2 :input').val()
time_diff_in_msec = new Date(moment(end, [ 'hh:mm A' ])) - new Date(moment(start, [ 'hh:mm A' ]))
if time_diff_in_msec>=0
t = Math.floor(time_diff_in_msec / 1000).toString()
hh = Math.floor(t / 3600) % 24
mm = Math.floor(t / 60) % 60
@time_minute = mm
@time_hour = hh
if $('#timepicker1 :input').val() == ""
now = new Date
if now.getHours() < @MAX_HOUR
hour = now.getHours()
AP = " AM"
else
hour = now.getHours() - @MAX_HOUR
AP = " PM"
now = hour + ':' + now.getMinutes() + AP
$("#timepicker1 :input")[0].value=now
@running = true
@interval_handler = setInterval(@.increament_time, 1000)
show_hide_stop_watch: =>
#@stop_watch.toggleClass('')
increament_time: =>
@time_field_second.val(@time_second)
@time_field_minute.val(@time_minute)
@time_field_hour.val(@time_hour)
@time_second = @time_second + 1
if @time_second > @MAX_MINUTE
@time_second = 0
@time_minute = @time_minute + 1
if @time_minute > @MAX_MINUTE
@time_minute = 0
@time_hour = @time_hour + 1
class @TimeAccordion
display_time_tracks: =>
$('#accordion').accordion
icons:
'header': 'ui-icon-plus'
'activeHeader': 'ui-icon-minus'
collapsible: true
# heightStyle: 'content'
heightStyle: "fill"
$('#accordion-resizer').resizable
minHeight: 300
minWidth: 300
resize: ->
$('#accordion').accordion 'refresh'
return
$(document).ready ->
stop_watch = new StopWatch
stop_watch.show_hide_stop_watch()
time_accordion = new TimeAccordion()
time_accordion.display_time_tracks()
# _StopWatch = new StopWatch()
$(window).click ->
$('#timer-flash').fadeOut(4000)
$('#timer-stop-flash').fadeOut(4000)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment