common_utils.js.coffee 1.3 KB
Newer Older
1 2 3 4 5
((w) ->

  w.gl       or= {}
  w.gl.utils or= {}

F
Fatih Acet 已提交
6 7
  w.gl.utils.isInGroupsPage = ->

8
    return gl.utils.getPagePath() is 'groups'
F
Fatih Acet 已提交
9 10 11 12


  w.gl.utils.isInProjectPage = ->

13
    return gl.utils.getPagePath() is 'projects'
F
Fatih Acet 已提交
14 15


16 17
  w.gl.utils.getProjectSlug = ->

F
Fatih Acet 已提交
18 19 20 21 22 23
    return if @isInProjectPage() then $('body').data 'project' else null


  w.gl.utils.getGroupSlug = ->

    return if @isInGroupsPage() then $('body').data 'group' else null
24 25


26 27 28 29 30 31 32 33

  gl.utils.updateTooltipTitle = ($tooltipEl, newTitle) ->

    $tooltipEl
      .tooltip 'destroy'
      .attr    'title', newTitle
      .tooltip 'fixTitle'

34

35 36 37 38 39 40 41
  gl.utils.preventDisabledButtons = ->

    $('.btn').click (e) ->
      if $(this).hasClass 'disabled'
        e.preventDefault()
        e.stopImmediatePropagation()
        return false
42

43 44 45
  gl.utils.getPagePath = ->
    return $('body').data('page').split(':')[0]

46

47 48 49 50 51
  jQuery.timefor = (time, suffix, expiredLabel) ->

    return '' unless time

    suffix       or= 'remaining'
52
    expiredLabel or= 'Past due'
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

    jQuery.timeago.settings.allowFuture = yes

    { suffixFromNow } = jQuery.timeago.settings.strings
    jQuery.timeago.settings.strings.suffixFromNow = suffix

    timefor = $.timeago time

    if timefor.indexOf('ago') > -1
      timefor = expiredLabel

    jQuery.timeago.settings.strings.suffixFromNow = suffixFromNow

    return timefor

68
) window