Skip to content

Instantly share code, notes, and snippets.

@oleglukashev
Created April 26, 2015 15:14
Show Gist options
  • Save oleglukashev/c44963ed167398c081b4 to your computer and use it in GitHub Desktop.
Save oleglukashev/c44963ed167398c081b4 to your computer and use it in GitHub Desktop.
Coffee
$ ->
if window.location.hash.indexOf("open_auth") > -1
$(window).on 'load', () ->
$('.tours-header__menu-item__auth a,header__menu-item__auth a').click()
$('.tours-popular__list-item a').on "click", (e) ->
e.preventDefault()
index = $(@).parent().data("index")
$('.tours-popular__list-item').removeClass "active"
$(@).parent().addClass "active"
$('.tours-by-city__list-page').removeClass "active"
$('.tours-by-city__list-page[data-index=' + index + ']').addClass "active"
$('.tours-header-menu__menu-item__tours,.tours-footer__menu-item__tours').on "click", (e) ->
e.preventDefault()
$("html, body").animate({ scrollTop: 1900 });
fotorama_div = $('.tour-images__fotorama').fotorama
allowfullscreen: true
nav: 'thumbs'
loop: true
fotorama = fotorama_div.data('fotorama')
$('.tour-images__list').on 'click', (e) ->
fotorama.requestFullScreen()
$('.tour-organizator__book').not('[class*="auth-reg-link"]').on 'click', (e) ->
e.preventDefault()
$('.tour-organizator__price').fadeOut(100).addClass('hide')
$('.tour-organizator__book').fadeOut(100).addClass('hide')
$('.tour-brone-form').fadeIn(300).removeClass('hide')
$('.form-item-cancel-brone_btn .btn').on 'click', (e) ->
e.preventDefault()
$('.tour-organizator__price').fadeIn(300).removeClass('hide')
$('.tour-organizator__book').fadeIn(300).removeClass('hide')
$('.tour-brone-form').fadeOut(100).addClass('hide')
$('.form-item-cancel-question .btn').on 'click', (e) ->
e.preventDefault()
$('.tour-question-form').fadeOut(100).addClass('hide')
$('.tour-organizator__question').fadeIn(300).removeClass('hide')
$('.tour-organizator__question').not('[class*="auth-reg-link"]').on 'click', (e) ->
e.preventDefault()
$('.tour-organizator__question').fadeOut(100).addClass('hide')
$('.tour-question-form').fadeIn(300).removeClass('hide')
addCommas = (nStr) ->
nStr += ''
x = nStr.split('.')
x1 = x[0]
x2 = if x.length > 1 then '.' + x[1] else ''
rgx = /(\d+)(\d{3})/
while rgx.test(x1)
x1 = x1.replace(rgx, '$1' + ' ' + '$2')
x1 + x2
setResultPrice = (result_price) ->
$('#order_result_price').val result_price
setGroupPrice = (result_price) ->
$('#order_group_price').val result_price
setMinMaxSize = (min_size, max_size) ->
$('#order_group_min_size').val min_size
$('#order_group_max_size').val max_size
eventHandlerPriceInput = (e) ->
order_people = $('#order_people')
show_price_tag = $('.tour-brone-form__price-value')
personal_price = $('.tour-brone__personal-price').data('price-value')
group_price = $('.tour-brone__dynamic-price').data('price-value')
addit_price = $('.tour-brone__dynamic-price').data('addit-value')
max_people_group = $('.tour-brone__dynamic-price').data('max-people-group')
if order_people.data("price-type") == "personal"
result_price = parseInt(personal_price * order_people.val())
else if order_people.data("price-type") == "dynamic"
if order_people.val() <= max_people_group
result_price = parseInt(group_price * order_people.val())
else
result_price = parseInt(group_price * max_people_group) + parseInt((order_people.val() - max_people_group) * addit_price)
unless isNaN(result_price)
if parseInt(order_people.val()) <= 20
animatePrice result_price
setResultPrice result_price
numberWithCommas = (number) ->
number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
animatePrice = (price) ->
old_price = parseInt($('#order_result_price').val())
per = $('.tour-brone-form__price-value')
.prop('number', old_price)
.stop()
.animateNumber
number: price
numberStep: (now, tween) ->
price = Math.floor now
$('.tour-brone-form__price-value')
.html numberWithCommas(price) + "<span class='rouble'>a</span>"
500
'linear'
$('#order_people').mousewheel((e) ->
setTimeout ->
eventHandlerPriceInput(e)
, 300
)
$('#order_people').on 'click keyup', (e) ->
eventHandlerPriceInput(e)
if $('.tour-brone__group-prices').length
$('#order_people').selectric
onChange: () ->
show_price_tag = $('.tour-brone-form__price-value')
active_price_data_tag = $('.tour-brone__group-prices div[data-max-people-group="'+$(@).val()+'"]')
min_people_group = active_price_data_tag.data('min-people-group')
max_people_group = active_price_data_tag.data('max-people-group')
price_by_group = active_price_data_tag.data('price-value')
result_price = price_by_group
animatePrice result_price
setResultPrice result_price
setGroupPrice result_price
setMinMaxSize min_people_group, max_people_group
$('#new_discussion_message').on('ajax:success', (e, data, status, xhr) ->
$(@).hide(300).delay(200).queue ->
$('.tour-question-form-success').removeClass('hide')
$('.tour-organizator__question').removeClass('hide')
).on 'ajax:error', (e, xhr, status, error) ->
if xhr.status == 422
errors = xhr.responseJSON
for error of errors
if $('#discussion_message_' + error).length
$('#discussion_message_' + error).addClass('error-form-input')
$('#discussion_message_' + error)
.closest('.form-item')
.find('.error')
.text(errors[error][0])
.addClass('is_showed')
$('#new_order').on('ajax:success', (e, data, status, xhr) ->
if data.order_path
window.location.href = data.order_path
).on 'ajax:error', (e, xhr, status, error) ->
if xhr.status == 422
errors = xhr.responseJSON
for error of errors
if $('#order_' + error).length
$('#order_' + error).addClass('error-form-input')
$('#order_' + error)
.closest('.form-item')
.find('.error')
.text(errors[error][0])
.addClass('is_showed')
if error == 'book_on'
$('#_order_full_book_on').addClass('error-form-input')
$('#_order_full_book_on')
.closest('.form-item')
.find('.error')
.text(errors[error][0])
.addClass('is_showed')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment