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

261 lines
7.5 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 jquery2
2016-04-02 18:10:28 +05:30
#= require jquery-ui/autocomplete
#= require jquery-ui/datepicker
2016-06-02 11:05:42 +05:30
#= require jquery-ui/draggable
2016-04-02 18:10:28 +05:30
#= require jquery-ui/effect-highlight
#= require jquery-ui/sortable
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
2015-04-26 12:48:37 +05:30
#= require turbolinks
#= require autosave
2016-06-02 11:05:42 +05:30
#= require bootstrap/affix
#= require bootstrap/alert
#= require bootstrap/button
#= require bootstrap/collapse
#= require bootstrap/dropdown
#= require bootstrap/modal
#= require bootstrap/scrollspy
#= require bootstrap/tab
#= require bootstrap/transition
#= require bootstrap/tooltip
#= require bootstrap/popover
2014-09-02 18:07:02 +05:30
#= require select2
#= require raphael
2016-04-02 18:10:28 +05:30
#= require g.raphael
#= require g.bar
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 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
2016-04-02 18:10:28 +05:30
#= require jquery.nicescroll
2016-06-02 11:05:42 +05:30
#= require date.format
#= require_directory ./behaviors
#= require_directory ./blob
#= require_directory ./ci
#= require_directory ./commit
#= require_directory ./extensions
#= require_directory ./lib
#= require_directory ./u2f
#= require_directory .
2016-04-02 18:10:28 +05:30
#= require fuzzaldrin-plus
2016-06-02 11:05:42 +05:30
#= require cropper
#= require u2f
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
$ ->
gl.utils.preventDisabledButtons()
2016-06-02 11:05:42 +05:30
bootstrapBreakpoint = bp.getBreakpointSize()
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(
2016-06-02 11:05:42 +05:30
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'
)
2014-09-02 18:07:02 +05:30
# Form submitter
$('.trigger-submit').on 'change', ->
$(@).parents('form').submit()
2016-06-02 11:05:42 +05:30
gl.utils.localTimeAgo($('abbr.timeago, .js-timeago'), true)
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 .header-logo').toggle()
2015-09-11 14:41:01 +05:30
$('.header-content .navbar-collapse').toggle()
2015-10-24 18:46:33 +05:30
$('.navbar-toggle').toggleClass('active')
2016-06-02 11:05:42 +05:30
$('.navbar-toggle i').toggleClass("fa-angle-right fa-angle-left")
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)
$(document).on 'click', 'button', ->
$(this).blur()
2016-04-02 18:10:28 +05:30
$('input[type="search"]').each ->
$this = $(this)
$this.attr 'value', $this.val()
return
2016-06-02 11:05:42 +05:30
2016-04-02 18:10:28 +05:30
$(document)
.off 'keyup', 'input[type="search"]'
.on 'keyup', 'input[type="search"]' , (e) ->
$this = $(this)
$this.attr 'value', $this.val()
2016-06-02 11:05:42 +05:30
$sidebarGutterToggle = $('.js-sidebar-toggle')
2016-04-02 18:10:28 +05:30
$(document)
.off 'breakpoint:change'
.on 'breakpoint:change', (e, breakpoint) ->
if breakpoint is 'sm' or breakpoint is 'xs'
2016-06-02 11:05:42 +05:30
$gutterIcon = $sidebarGutterToggle.find('i')
2016-04-02 18:10:28 +05:30
if $gutterIcon.hasClass('fa-angle-double-right')
2016-06-02 11:05:42 +05:30
$sidebarGutterToggle.trigger('click')
2016-04-02 18:10:28 +05:30
fitSidebarForSize = ->
oldBootstrapBreakpoint = bootstrapBreakpoint
2016-06-02 11:05:42 +05:30
bootstrapBreakpoint = bp.getBreakpointSize()
2016-04-02 18:10:28 +05:30
if bootstrapBreakpoint != oldBootstrapBreakpoint
$(document).trigger('breakpoint:change', [bootstrapBreakpoint])
checkInitialSidebarSize = ->
2016-06-02 11:05:42 +05:30
bootstrapBreakpoint = bp.getBreakpointSize()
2016-04-02 18:10:28 +05:30
if bootstrapBreakpoint is "xs" or "sm"
$(document).trigger('breakpoint:change', [bootstrapBreakpoint])
$(window)
.off "resize.app"
.on "resize.app", (e) ->
2016-04-02 18:10:28 +05:30
fitSidebarForSize()
gl.awardsHandler = new AwardsHandler()
2016-04-02 18:10:28 +05:30
checkInitialSidebarSize()
2015-04-26 12:48:37 +05:30
new Aside()