unified search in header bar. still todo: searches in modals

pull/37/head
Dave Cranwell 2014-02-13 16:51:11 +00:00
rodzic 1e0d63ee72
commit d08ef04dcb
10 zmienionych plików z 59 dodań i 156 usunięć

Wyświetl plik

@ -563,7 +563,7 @@ ul.inline li:first-child, li.inline:first-child{
}
/* search bars (search integrated into header area) */
/* search bars (search integrated into header area) */
.search-bar{
margin-top:-2em;
padding-top:1em;

Wyświetl plik

@ -106,4 +106,29 @@ $(function(){
$('#menu-search').bind('focus click', function(){
$(this).addClass('focussed');
});
/* Header search behaviour */
var search_current_index = 0;
var search_next_index = 0;
$(window.headerSearch.termInput).on('input', function() {
clearTimeout($.data(this, 'timer'));
var wait = setTimeout(search, 200);
$(this).data('timer', wait);
});
function search () {
search_next_index++;
var index = search_next_index;
$.ajax({
url: window.headerSearch.url,
data: {q: $(window.headerSearch.termInput).val()},
success: function(data, status) {
if (index > search_current_index) {
search_current_index = index;
$(window.headerSearch.targetOutput).html(data);
}
},
});
};
});

Wyświetl plik

@ -1,6 +1,7 @@
modal.ajaxifyForm($('form.search-bar', modal.body));
var searchUrl = $('form.search-bar', modal.body).attr('action');
function search() {
$.ajax({
url: searchUrl,
@ -12,6 +13,7 @@ function search() {
});
return false;
}
$('#id_q', modal.body).on('input', function() {
clearTimeout($.data(this, 'timer'));
var wait = setTimeout(search, 200);

Wyświetl plik

@ -31,7 +31,7 @@
<script src="{{ STATIC_URL }}admin/js/urlify.js"></script>
{% endcompress %}
<script type='text/javascript'>
<script>
window.chooserUrls = {
'documentChooser': '{% url "wagtaildocs_chooser" %}',
'imageChooser': '{% url "wagtailimages_chooser" %}',
@ -39,9 +39,7 @@
'pageChooser': '{% url "wagtailadmin_choose_page" %}',
'snippetChooser': '{% url "wagtailsnippets_choose_generic" %}'
};
</script>
<script>
(function() {
function fixPrefix(str) {return str;}

Wyświetl plik

@ -3,35 +3,11 @@
{% block bodyclass %}menu-search{% endblock %}
{% block extra_js %}
<script>
$('#id_q').on('input', function() {
clearTimeout($.data(this, 'timer'));
var wait = setTimeout(search, 200);
$(this).data('timer', wait);
});
$('a.suggested-tag').click(function() {
$('#id_q').val($(this).text());
search();
return false;
})
// These variables keep track of ajax requests to prevent an older request from replacing a new one
var search_current_index = 0;
var search_next_index = 0;
function search () {
search_next_index++;
var index = search_next_index;
$.ajax({
url: "{%url 'wagtailadmin_pages_search' %}",
data: {q: $('#id_q').val()},
success: function(data, status) {
if (index > search_current_index) {
search_current_index = index;
$('#page-results').html(data);
}
},
});
};
window.headerSearch = {
url: "{% url 'wagtailadmin_pages_search' %}",
termInput: "#id_q",
targetOutput: "#page-results"
}
</script>
{% endblock %}

Wyświetl plik

@ -3,29 +3,11 @@
{% block bodyclass %}menu-documents{% endblock %}
{% block extra_js %}
<script>
$('#id_q').on('input', function() {
clearTimeout($.data(this, 'timer'));
var wait = setTimeout(search, 200);
$(this).data('timer', wait);
});
var search_current_index = 0;
var search_next_index = 0;
function search () {
search_next_index++;
var index = search_next_index;
$.ajax({
url: "{% url 'wagtaildocs_index' %}",
data: {q: $('#id_q').val()},
success: function(data, status) {
if (index > search_current_index) {
search_current_index = index;
$('#document-results').html(data);
}
},
});
};
window.headerSearch = {
url: "{% url 'wagtaildocs_index' %}",
termInput: "#id_q",
targetOutput: "#document-results"
}
</script>
{% endblock %}

Wyświetl plik

@ -5,35 +5,11 @@
{% block bodyclass %}menu-images{% endblock %}
{% block extra_js %}
<script>
$('#id_q').on('input', function() {
clearTimeout($.data(this, 'timer'));
var wait = setTimeout(search, 200);
$(this).data('timer', wait);
});
$('a.suggested-tag').click(function() {
$('#id_q').val($(this).text());
search();
return false;
})
// These variables keep track of ajax requests to prevent an older request from replacing a new one
var search_current_index = 0;
var search_next_index = 0;
function search () {
search_next_index++;
var index = search_next_index;
$.ajax({
url: "{% url 'wagtailimages_index' %}",
data: {q: $('#id_q').val()},
success: function(data, status) {
if (index > search_current_index) {
search_current_index = index;
$('#image-results').html(data);
}
},
});
};
window.headerSearch = {
url: "{% url 'wagtailimages_index' %}",
termInput: "#id_q",
targetOutput: "#image-results"
}
</script>
{% endblock %}

Wyświetl plik

@ -4,30 +4,11 @@
{% block extra_js %}
<script>
$('#id_q').on('input', function() {
clearTimeout($.data(this, 'timer'));
var wait = setTimeout(search, 200);
$(this).data('timer', wait);
});
var search_current_index = 0;
var search_next_index = 0;
function search () {
search_next_index++;
var index = search_next_index;
$.ajax({
url: "{%url 'wagtailredirects_index' %}",
data: {q: $('#id_q').val()},
success: function(data, status) {
console.log('here')
if (index > search_current_index) {
search_current_index = index;
$('#redirects-results').html(data);
}
},
});
};
window.headerSearch = {
url: "{% url 'wagtailredirects_index' %}",
termInput: "#id_q",
targetOutput: "#redirects-results"
}
</script>
{% endblock %}

Wyświetl plik

@ -4,30 +4,11 @@
{% block extra_js %}
<script>
$('#id_q').on('input', function() {
clearTimeout($.data(this, 'timer'));
var wait = setTimeout(search, 200);
$(this).data('timer', wait);
});
var search_current_index = 0;
var search_next_index = 0;
function search () {
search_next_index++;
var index = search_next_index;
$.ajax({
url: "{%url 'wagtailsearch_editorspicks_index' %}",
data: {q: $('#id_q').val()},
success: function(data, status) {
console.log('here')
if (index > search_current_index) {
search_current_index = index;
$('#editorspicks-results').html(data);
}
},
});
};
window.headerSearch = {
url: "{% url 'wagtailsearch_editorspicks_index' %}",
termInput: "#id_q",
targetOutput: "#editorspicks-results"
}
</script>
{% endblock %}

Wyświetl plik

@ -4,29 +4,11 @@
{% block bodyclass %}menu-users{% endblock %}
{% block extra_js %}
<script>
$('#id_q').on('input', function() {
clearTimeout($.data(this, 'timer'));
var wait = setTimeout(search, 200);
$(this).data('timer', wait);
});
var search_current_index = 0;
var search_next_index = 0;
function search () {
search_next_index++;
var index = search_next_index;
$.ajax({
url: "{% url 'wagtailusers_index' %}",
data: {q: $('#id_q').val()},
success: function(data, status) {
if (index > search_current_index) {
search_current_index = index;
$('#user-results').html(data);
}
},
});
};
window.headerSearch = {
url: "{% url 'wagtailusers_index' %}",
termInput: "#id_q",
targetOutput: "#user-results"
}
</script>
{% endblock %}