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"})
|
|
|
|
|
|
|
|
# Disable button if text field is empty
|
|
|
|
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
|
|
|
|
|
|
|
field.on "keyup", ->
|
|
|
|
if $(this).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
|
|
|
|
$(".one_click_select").live 'click', -> $(this).select()
|
2012-09-09 11:59:15 +02: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) ->
|
|
|
|
buttons = $('[type="submit"]', this)
|
|
|
|
|
|
|
|
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
|
|
|
|
$('.account-box').hover -> $(this).toggleClass('hover')
|
|
|
|
|
|
|
|
# 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", ->
|
|
|
|
$(this).next('table').show()
|
|
|
|
$(this).remove()
|
|
|
|
|
|
|
|
# Note markdown preview
|
|
|
|
$(document).on 'click', '#preview-link', (e) ->
|
|
|
|
$('#preview-note').text('Loading...')
|
|
|
|
|
|
|
|
previewLinkText = if $(this).text() == 'Preview' then 'Edit' else 'Preview'
|
|
|
|
$(this).text(previewLinkText)
|
|
|
|
|
|
|
|
note = $('#note_note').val()
|
2012-09-09 13:17:01 +02:00
|
|
|
|
|
|
|
if note.trim().length == 0
|
|
|
|
$('#preview-note').text("Nothing to preview.")
|
|
|
|
else
|
|
|
|
$.post $(this).attr('href'), {note: note}, (data) ->
|
|
|
|
$('#preview-note').html(data)
|
2012-09-09 11:59:15 +02:00
|
|
|
|
|
|
|
$('#preview-note, #note_note').toggle()
|
|
|
|
e.preventDefault()
|
|
|
|
false
|
|
|
|
|
|
|
|
(($) ->
|
|
|
|
_chosen = $.fn.chosen
|
|
|
|
$.fn.extend chosen: (options) ->
|
|
|
|
default_options = search_contains: "true"
|
|
|
|
$.extend default_options, options
|
|
|
|
_chosen.apply this, [default_options]
|
|
|
|
|
2012-09-09 13:08:13 +02:00
|
|
|
# Disable an element and add the 'disabled' Bootstrap class
|
|
|
|
$.fn.extend disable: ->
|
|
|
|
$(this).attr('disabled', 'disabled').addClass('disabled')
|
|
|
|
|
|
|
|
# Enable an element and remove the 'disabled' Bootstrap class
|
|
|
|
$.fn.extend enable: ->
|
|
|
|
$(this).removeAttr('disabled').removeClass('disabled')
|
|
|
|
|
2012-09-09 11:59:15 +02:00
|
|
|
)(jQuery)
|