2012-09-09 11:59:15 +02:00
|
|
|
window.updatePage = (data) ->
|
|
|
|
$.ajax({type: "GET", url: location.href, data: data, dataType: "script"})
|
|
|
|
|
|
|
|
window.slugify = (text) ->
|
|
|
|
text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase()
|
|
|
|
|
|
|
|
window.ajaxGet = (url) ->
|
|
|
|
$.ajax({type: "GET", url: url, dataType: "script"})
|
|
|
|
|
2012-12-13 17:42:15 +01:00
|
|
|
window.errorMessage = (message) ->
|
|
|
|
ehtml = $("<p>")
|
|
|
|
ehtml.addClass("error_message")
|
|
|
|
ehtml.html(message)
|
|
|
|
ehtml
|
|
|
|
|
2012-12-18 04:14:05 +01:00
|
|
|
window.split = (val) ->
|
|
|
|
return val.split( /,\s*/ )
|
|
|
|
|
|
|
|
window.extractLast = (term) ->
|
|
|
|
return split( term ).pop()
|
|
|
|
|
2012-10-10 15:41:20 +02:00
|
|
|
# Disable button if text field is empty
|
2012-09-09 11:59:15 +02:00
|
|
|
window.disableButtonIfEmptyField = (field_selector, button_selector) ->
|
|
|
|
field = $(field_selector)
|
|
|
|
closest_submit = field.closest("form").find(button_selector)
|
|
|
|
|
2012-09-09 13:08:13 +02:00
|
|
|
closest_submit.disable() if field.val() is ""
|
2012-09-09 11:59:15 +02:00
|
|
|
|
2012-10-27 17:00:51 +02:00
|
|
|
field.on "input", ->
|
2012-10-10 15:41:20 +02:00
|
|
|
if $(@).val() is ""
|
2012-09-09 13:08:13 +02:00
|
|
|
closest_submit.disable()
|
2012-09-09 11:59:15 +02:00
|
|
|
else
|
2012-09-09 13:08:13 +02:00
|
|
|
closest_submit.enable()
|
2012-09-09 11:59:15 +02:00
|
|
|
|
|
|
|
$ ->
|
2012-09-09 13:17:01 +02:00
|
|
|
# Click a .one_click_select field, select the contents
|
2012-10-10 15:41:20 +02:00
|
|
|
$(".one_click_select").on 'click', -> $(@).select()
|
2012-09-09 11:59:15 +02:00
|
|
|
|
2013-02-11 22:00:12 +01:00
|
|
|
# Click a .appear-link, appear-data fadeout
|
|
|
|
$(".appear-link").on 'click', ->
|
|
|
|
$('.appear-data').fadeIn()
|
|
|
|
|
2012-09-10 08:09:55 +02:00
|
|
|
# Initialize chosen selects
|
|
|
|
$('select.chosen').chosen()
|
|
|
|
|
2012-11-05 19:12:26 +01:00
|
|
|
# Initialize tooltips
|
|
|
|
$('.has_tooltip').tooltip()
|
|
|
|
|
2012-11-21 06:14:05 +01:00
|
|
|
# Bottom tooltip
|
|
|
|
$('.has_bottom_tooltip').tooltip(placement: 'bottom')
|
|
|
|
|
2013-02-18 15:40:11 +01:00
|
|
|
# Form submitter
|
|
|
|
$('.trigger-submit').on 'change', ->
|
|
|
|
$(@).parents('form').submit()
|
|
|
|
|
2012-11-29 22:51:51 +01:00
|
|
|
# Flash
|
|
|
|
if (flash = $("#flash-container")).length > 0
|
|
|
|
flash.click -> $(@).slideUp("slow")
|
|
|
|
flash.slideDown "slow"
|
|
|
|
setTimeout (-> flash.slideUp("slow")), 3000
|
2012-11-21 06:14:05 +01:00
|
|
|
|
2012-09-09 13:08:13 +02:00
|
|
|
# Disable form buttons while a form is submitting
|
2012-09-09 11:59:15 +02:00
|
|
|
$('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) ->
|
2012-10-10 15:41:20 +02:00
|
|
|
buttons = $('[type="submit"]', @)
|
2012-09-09 11:59:15 +02:00
|
|
|
|
|
|
|
switch e.type
|
|
|
|
when 'ajax:beforeSend', 'submit'
|
2012-09-09 13:08:13 +02:00
|
|
|
buttons.disable()
|
2012-09-09 11:59:15 +02:00
|
|
|
else
|
2012-09-09 13:08:13 +02:00
|
|
|
buttons.enable()
|
2012-09-09 11:59:15 +02:00
|
|
|
|
|
|
|
# Show/Hide the profile menu when hovering the account box
|
2012-10-10 15:41:20 +02:00
|
|
|
$('.account-box').hover -> $(@).toggleClass('hover')
|
2012-09-09 11:59:15 +02:00
|
|
|
|
|
|
|
# Focus search field by pressing 's' key
|
|
|
|
$(document).keypress (e) ->
|
|
|
|
# Don't do anything if typing in an input
|
|
|
|
return if $(e.target).is(":input")
|
|
|
|
|
|
|
|
switch e.which
|
|
|
|
when 115
|
|
|
|
$("#search").focus()
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
# Commit show suppressed diff
|
|
|
|
$(".supp_diff_link").bind "click", ->
|
2012-10-10 15:41:20 +02:00
|
|
|
$(@).next('table').show()
|
|
|
|
$(@).remove()
|
2012-09-09 11:59:15 +02:00
|
|
|
|
|
|
|
(($) ->
|
|
|
|
_chosen = $.fn.chosen
|
|
|
|
$.fn.extend chosen: (options) ->
|
|
|
|
default_options = search_contains: "true"
|
|
|
|
$.extend default_options, options
|
2012-10-10 15:41:20 +02:00
|
|
|
_chosen.apply @, [default_options]
|
2012-09-09 11:59:15 +02:00
|
|
|
|
2012-09-09 13:08:13 +02:00
|
|
|
# Disable an element and add the 'disabled' Bootstrap class
|
|
|
|
$.fn.extend disable: ->
|
2012-10-10 15:41:20 +02:00
|
|
|
$(@).attr('disabled', 'disabled').addClass('disabled')
|
2012-09-09 13:08:13 +02:00
|
|
|
|
|
|
|
# Enable an element and remove the 'disabled' Bootstrap class
|
|
|
|
$.fn.extend enable: ->
|
2012-10-10 15:41:20 +02:00
|
|
|
$(@).removeAttr('disabled').removeClass('disabled')
|
2012-09-09 13:08:13 +02:00
|
|
|
|
2012-09-09 11:59:15 +02:00
|
|
|
)(jQuery)
|