debian-mirror-gitlab/app/assets/javascripts/application.js.coffee

207 lines
5.8 KiB
CoffeeScript
Raw Normal View History

2014-09-02 18:07:02 +05:30
# This is a manifest file that'll be compiled into including all the files listed below.
# Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
# be included in the compiled file accessible from http://example.com/assets/application.js
# It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
# the compiled file.
#
#= require jquery
#= require jquery-ui
2014-09-02 18:07:02 +05:30
#= require jquery_ujs
#= require jquery.cookie
#= require jquery.endless-scroll
#= require jquery.highlight
#= require jquery.waitforimages
#= require jquery.atwho
#= require jquery.scrollTo
#= require jquery.turbolinks
#= require d3
#= require cal-heatmap
2015-04-26 12:48:37 +05:30
#= require turbolinks
#= require autosave
2014-09-02 18:07:02 +05:30
#= require bootstrap
#= require select2
#= require raphael
#= require g.raphael-min
#= require g.bar-min
2015-04-26 12:48:37 +05:30
#= require chart-lib.min
2014-09-02 18:07:02 +05:30
#= require branch-graph
#= require ace/ace
2015-04-26 12:48:37 +05:30
#= require ace/ext-searchbox
2014-09-02 18:07:02 +05:30
#= require underscore
#= require nprogress
#= require nprogress-turbolinks
#= require dropzone
2015-04-26 12:48:37 +05:30
#= require mousetrap
#= require mousetrap/pause
#= require shortcuts
#= require shortcuts_navigation
#= require shortcuts_dashboard_navigation
2015-09-11 14:41:01 +05:30
#= require shortcuts_issuable
2015-04-26 12:48:37 +05:30
#= require shortcuts_network
2015-09-11 14:41:01 +05:30
#= require jquery.nicescroll.min
2014-09-02 18:07:02 +05:30
#= require_tree .
#= require fuzzaldrin-plus.min
2014-09-02 18:07:02 +05:30
window.slugify = (text) ->
text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase()
window.ajaxGet = (url) ->
$.ajax({type: "GET", url: url, dataType: "script"})
window.split = (val) ->
return val.split( /,\s*/ )
window.extractLast = (term) ->
return split( term ).pop()
window.rstrip = (val) ->
2015-04-26 12:48:37 +05:30
return if val then val.replace(/\s+$/, '') else val
2014-09-02 18:07:02 +05:30
# Disable button if text field is empty
window.disableButtonIfEmptyField = (field_selector, button_selector) ->
field = $(field_selector)
closest_submit = field.closest('form').find(button_selector)
closest_submit.disable() if rstrip(field.val()) is ""
field.on 'input', ->
if rstrip($(@).val()) is ""
closest_submit.disable()
else
closest_submit.enable()
# Disable button if any input field with given selector is empty
window.disableButtonIfAnyEmptyField = (form, form_selector, button_selector) ->
closest_submit = form.find(button_selector)
2015-04-26 12:48:37 +05:30
updateButtons = ->
filled = true
2014-09-02 18:07:02 +05:30
form.find('input').filter(form_selector).each ->
2015-04-26 12:48:37 +05:30
filled = rstrip($(this).val()) != "" || !$(this).attr('required')
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
if filled
2014-09-02 18:07:02 +05:30
closest_submit.enable()
2015-04-26 12:48:37 +05:30
else
closest_submit.disable()
updateButtons()
form.keyup(updateButtons)
2014-09-02 18:07:02 +05:30
window.sanitize = (str) ->
return str.replace(/<(?:.|\n)*?>/gm, '')
window.unbindEvents = ->
$(document).off('scroll')
2015-04-26 12:48:37 +05:30
window.shiftWindow = ->
2015-09-25 12:07:36 +05:30
scrollBy 0, -100
2015-04-26 12:48:37 +05:30
2014-09-02 18:07:02 +05:30
document.addEventListener("page:fetch", unbindEvents)
2015-04-26 12:48:37 +05:30
window.addEventListener "hashchange", shiftWindow
2015-09-25 12:07:36 +05:30
window.onload = ->
# Scroll the window to avoid the topnav bar
# https://github.com/twitter/bootstrap/issues/1768
if location.hash
setTimeout shiftWindow, 100
2014-09-02 18:07:02 +05:30
$ ->
2015-09-11 14:41:01 +05:30
$(".nicescroll").niceScroll(cursoropacitymax: '0.4', cursorcolor: '#FFF', cursorborder: "1px solid #FFF")
# Click a .js-select-on-focus field, select the contents
$(".js-select-on-focus").on "focusin", ->
# Prevent a mouseup event from deselecting the input
$(this).select().one 'mouseup', (e) ->
e.preventDefault()
2014-09-02 18:07:02 +05:30
$('.remove-row').bind 'ajax:success', ->
$(this).closest('li').fadeOut()
2015-09-11 14:41:01 +05:30
$('.js-remove-tr').bind 'ajax:before', ->
$(this).hide()
$('.js-remove-tr').bind 'ajax:success', ->
$(this).closest('tr').fadeOut()
2014-09-02 18:07:02 +05:30
# Initialize select2 selects
$('select.select2').select2(width: 'resolve', dropdownAutoWidth: true)
2015-04-26 12:48:37 +05:30
# Close select2 on escape
$('.js-select2').bind 'select2-close', ->
setTimeout ( ->
$('.select2-container-active').removeClass('select2-container-active')
$(':focus').blur()
), 1
2014-09-02 18:07:02 +05:30
# Initialize tooltips
2015-12-23 02:04:40 +05:30
$('body').tooltip(
selector: '.has_tooltip, [data-toggle="tooltip"]'
2015-09-11 14:41:01 +05:30
placement: (_, el) ->
$el = $(el)
2015-12-23 02:04:40 +05:30
$el.data('placement') || 'bottom'
)
$('.header-logo .home').tooltip(
placement: (_, el) ->
$el = $(el)
if $('.page-with-sidebar').hasClass('page-sidebar-collapsed') then 'right' else 'bottom'
container: 'body'
)
$('.page-with-sidebar').tooltip(
selector: '.sidebar-collapsed .nav-sidebar a, .sidebar-collapsed a.sidebar-user'
placement: 'right'
container: 'body'
)
2014-09-02 18:07:02 +05:30
# Form submitter
$('.trigger-submit').on 'change', ->
$(@).parents('form').submit()
2015-09-11 14:41:01 +05:30
$('abbr.timeago, .js-timeago').timeago()
2014-09-02 18:07:02 +05:30
# Flash
if (flash = $(".flash-container")).length > 0
flash.click -> $(@).fadeOut()
flash.show()
# Disable form buttons while a form is submitting
$('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) ->
buttons = $('[type="submit"]', @)
switch e.type
when 'ajax:beforeSend', 'submit'
buttons.disable()
else
buttons.enable()
# Show/Hide the profile menu when hovering the account box
$('.account-box').hover -> $(@).toggleClass('hover')
# Commit show suppressed diff
2015-09-11 14:41:01 +05:30
$(document).on 'click', '.diff-content .js-show-suppressed-diff', ->
$container = $(@).parent()
$container.next('table').show()
$container.remove()
$('.navbar-toggle').on 'click', ->
$('.header-content .title').toggle()
$('.header-content .navbar-collapse').toggle()
2015-10-24 18:46:33 +05:30
$('.navbar-toggle').toggleClass('active')
2014-09-02 18:07:02 +05:30
# Show/hide comments on diff
$("body").on "click", ".js-toggle-diff-comments", (e) ->
2015-04-26 12:48:37 +05:30
$(@).toggleClass('active')
2014-09-02 18:07:02 +05:30
$(@).closest(".diff-file").find(".notes_holder").toggle()
e.preventDefault()
2015-09-11 14:41:01 +05:30
$(document).off "click", '.js-confirm-danger'
2015-04-26 12:48:37 +05:30
$(document).on "click", '.js-confirm-danger', (e) ->
e.preventDefault()
btn = $(e.target)
text = btn.data("confirm-danger-message")
form = btn.closest("form")
new ConfirmDangerModal(form, text)
new Aside()