Commit 92f04733540694ccfddce353cb510e5f1c36f798
1 parent
0b981eb9
Exists in
master
and in
4 other branches
Move search autocomplete call to dispatcher
Showing
4 changed files
with
21 additions
and
11 deletions
Show diff stats
app/assets/javascripts/admin.js.coffee
1 | -@Admin = | |
2 | - init: -> | |
1 | +class Admin | |
2 | + constructor: -> | |
3 | 3 | $('input#user_force_random_password').on 'change', (elem) -> |
4 | 4 | elems = $('#user_password, #user_password_confirmation') |
5 | 5 | |
... | ... | @@ -26,3 +26,5 @@ |
26 | 26 | $('.change-owner-cancel-link').bind "click", -> |
27 | 27 | modal.hide() |
28 | 28 | $('.change-owner-link').show() |
29 | + | |
30 | +@Admin = Admin | ... | ... |
app/assets/javascripts/dispatcher.js.coffee
... | ... | @@ -3,6 +3,10 @@ $ -> |
3 | 3 | |
4 | 4 | class Dispatcher |
5 | 5 | constructor: () -> |
6 | + @initSearch() | |
7 | + @initPageScripts() | |
8 | + | |
9 | + initPageScripts: -> | |
6 | 10 | page = $('body').attr('data-page') |
7 | 11 | project_id = $('body').attr('data-project-id') |
8 | 12 | |
... | ... | @@ -25,6 +29,9 @@ class Dispatcher |
25 | 29 | new Wall(project_id) |
26 | 30 | |
27 | 31 | switch path.first() |
28 | - when 'admin' then Admin.init() | |
32 | + when 'admin' then new Admin() | |
29 | 33 | when 'wikis' then new Wikis() |
30 | 34 | |
35 | + initSearch: -> | |
36 | + autocomplete_json = $('.search-autocomplete-json').data('autocomplete-opts') | |
37 | + new SearchAutocomplete(autocomplete_json) | ... | ... |
app/views/layouts/_search.html.haml
... | ... | @@ -3,11 +3,4 @@ |
3 | 3 | = text_field_tag "search", nil, placeholder: "Search", class: "search-input" |
4 | 4 | = hidden_field_tag :group_id, @group.try(:id) |
5 | 5 | = hidden_field_tag :project_id, @project.try(:id) |
6 | - | |
7 | -:javascript | |
8 | - $(function(){ | |
9 | - $("#search").autocomplete({ | |
10 | - source: #{raw search_autocomplete_source}, | |
11 | - select: function(event, ui) { location.href = ui.item.url } | |
12 | - }); | |
13 | - }); | |
6 | + .search-autocomplete-json.hide{:'data-autocomplete-opts' => search_autocomplete_source } | ... | ... |