Skip to content

Commit

Permalink
separate application.js into separate initializers
Browse files Browse the repository at this point in the history
closes #3588, closes #3605
  • Loading branch information
seanlinsley committed Nov 22, 2015
1 parent c6510db commit 01ad42f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 38 deletions.
37 changes: 0 additions & 37 deletions app/assets/javascripts/active_admin/application.js.coffee

This file was deleted.

2 changes: 1 addition & 1 deletion app/assets/javascripts/active_admin/base.js.coffee
Expand Up @@ -4,6 +4,6 @@
#= require_self
#= require_tree ./lib
#= require_tree ./ext
#= require ./application
#= require_tree ./initializers

window.ActiveAdmin = {}
@@ -0,0 +1,7 @@
$(document).on 'ready page:load', ->
# In order for index scopes to overflow properly onto the next line, we have
# to manually set its width based on the width of the batch action button.
if (batch_actions_selector = $('.table_tools .batch_actions_selector')).length
batch_actions_selector.next().css
width: "calc(100% - 10px - #{batch_actions_selector.outerWidth()}px)"
'float': 'right'
@@ -0,0 +1,10 @@
$(document).on 'ready page:load', ->
$(document).on 'focus', 'input.datepicker:not(.hasDatepicker)', ->
input = $(@)

# Only create datepickers in compatible browsers
return if input[0].type is 'date'

defaults = dateFormat: 'yy-mm-dd'
options = input.data 'datepicker-options'
input.datepicker $.extend(defaults, options)
15 changes: 15 additions & 0 deletions app/assets/javascripts/active_admin/initializers/filters.js.coffee
@@ -0,0 +1,15 @@
$(document).on 'ready page:load', ->
# Clear Filters button
$('.clear_filters_btn').click ->
params = window.location.search.slice(1).split('&')
regex = /^(q\[|q%5B|q%5b|page|commit)/
window.location.search = (param for param in params when not param.match(regex)).join('&')

# Filter form: don't send any inputs that are empty
$('.filter_form').submit ->
$(@).find(':input').filter(-> @value is '').prop 'disabled', true

# Filter form: for filters that let you choose the query method from
# a dropdown, apply that choice to the filter input field.
$('.filter_form_field.select_and_search select').change ->
$(@).siblings('input').prop name: "q[#{@value}]"
@@ -0,0 +1,3 @@
$(document).on 'ready page:load', ->
# Tab navigation
$('#active_admin_content .tabs').tabs()

0 comments on commit 01ad42f

Please sign in to comment.