Skip to content

Instantly share code, notes, and snippets.

@cfc1020
Created April 14, 2015 08:14
Show Gist options
  • Save cfc1020/d3928ef77dd55530d259 to your computer and use it in GitHub Desktop.
Save cfc1020/d3928ef77dd55530d259 to your computer and use it in GitHub Desktop.
advert.coffee
# 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://coffeescript.org/
$ ->
$("input.numeric").numeric()
$('.advert-body-footer, #description').on 'click', =>
$('#description').toggleClass('text-overflow-on')
$(".advert-photos #galleries").on "slid.bs.carousel", =>
slideWidth = 72.265625
showSlideCount = 8
slideNumber = $(".advert-photos .carousel-indicators .active").data().slideTo
leftSlideNumber = slideNumber - showSlideCount / 2
$(".advert-photos .carousel-indicators").animate
scrollLeft: slideWidth * leftSlideNumber,
1000
$('#gallery-open').on 'click', =>
$('#galleryModal').modal('show')
$('.preview').on 'click', (e) =>
id = $(e.target).attr('id')
$('.advert-large-photo').find('.preview-large-photo').not('.hidden').addClass('hidden')
$('.small-photo.preview.active').removeClass('active')
$('.advert-large-photo').find('#' + id).parent().removeClass('hidden')
$('.advert-photos .preview').find('#' + id).parent().addClass('active')
$('.advert-large-photo > .glyphicon-chevron-left, .advert-large-photo > .glyphicon-chevron-right').on 'click', (e) =>
last_id = 9
first_id = 1
active_element = $('.advert-large-photo').find('.preview-large-photo').not('.hidden')
current_id = parseInt(active_element.find('img').attr('id'))
active_element.addClass('hidden')
id =
if $(e.target).hasClass('glyphicon-chevron-left')
prevId(current_id, first_id, last_id)
else
nextId(current_id, first_id, last_id)
$('.advert-large-photo').find('#' + id).parent().removeClass('hidden')
$('.small-photo.preview.active').removeClass('active')
$('.advert-photos .preview').find('#' + id).parent().addClass('active')
nextId = (current_id, first_id, last_id) =>
if current_id < last_id then current_id + 1 else first_id
prevId = (current_id, first_id, last_id) =>
if current_id > first_id then current_id - 1 else last_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment