kopia lustrzana https://github.com/wagtail/wagtail
unified search in header bar. still todo: searches in modals
rodzic
1e0d63ee72
commit
d08ef04dcb
|
@ -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{
|
.search-bar{
|
||||||
margin-top:-2em;
|
margin-top:-2em;
|
||||||
padding-top:1em;
|
padding-top:1em;
|
||||||
|
|
|
@ -106,4 +106,29 @@ $(function(){
|
||||||
$('#menu-search').bind('focus click', function(){
|
$('#menu-search').bind('focus click', function(){
|
||||||
$(this).addClass('focussed');
|
$(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);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
modal.ajaxifyForm($('form.search-bar', modal.body));
|
modal.ajaxifyForm($('form.search-bar', modal.body));
|
||||||
|
|
||||||
var searchUrl = $('form.search-bar', modal.body).attr('action');
|
var searchUrl = $('form.search-bar', modal.body).attr('action');
|
||||||
|
|
||||||
function search() {
|
function search() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: searchUrl,
|
url: searchUrl,
|
||||||
|
@ -12,6 +13,7 @@ function search() {
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#id_q', modal.body).on('input', function() {
|
$('#id_q', modal.body).on('input', function() {
|
||||||
clearTimeout($.data(this, 'timer'));
|
clearTimeout($.data(this, 'timer'));
|
||||||
var wait = setTimeout(search, 200);
|
var wait = setTimeout(search, 200);
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
<script src="{{ STATIC_URL }}admin/js/urlify.js"></script>
|
<script src="{{ STATIC_URL }}admin/js/urlify.js"></script>
|
||||||
{% endcompress %}
|
{% endcompress %}
|
||||||
|
|
||||||
<script type='text/javascript'>
|
<script>
|
||||||
window.chooserUrls = {
|
window.chooserUrls = {
|
||||||
'documentChooser': '{% url "wagtaildocs_chooser" %}',
|
'documentChooser': '{% url "wagtaildocs_chooser" %}',
|
||||||
'imageChooser': '{% url "wagtailimages_chooser" %}',
|
'imageChooser': '{% url "wagtailimages_chooser" %}',
|
||||||
|
@ -39,9 +39,7 @@
|
||||||
'pageChooser': '{% url "wagtailadmin_choose_page" %}',
|
'pageChooser': '{% url "wagtailadmin_choose_page" %}',
|
||||||
'snippetChooser': '{% url "wagtailsnippets_choose_generic" %}'
|
'snippetChooser': '{% url "wagtailsnippets_choose_generic" %}'
|
||||||
};
|
};
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
(function() {
|
(function() {
|
||||||
function fixPrefix(str) {return str;}
|
function fixPrefix(str) {return str;}
|
||||||
|
|
||||||
|
|
|
@ -3,35 +3,11 @@
|
||||||
{% block bodyclass %}menu-search{% endblock %}
|
{% block bodyclass %}menu-search{% endblock %}
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
<script>
|
<script>
|
||||||
$('#id_q').on('input', function() {
|
window.headerSearch = {
|
||||||
clearTimeout($.data(this, 'timer'));
|
url: "{% url 'wagtailadmin_pages_search' %}",
|
||||||
var wait = setTimeout(search, 200);
|
termInput: "#id_q",
|
||||||
$(this).data('timer', wait);
|
targetOutput: "#page-results"
|
||||||
});
|
}
|
||||||
$('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);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -3,29 +3,11 @@
|
||||||
{% block bodyclass %}menu-documents{% endblock %}
|
{% block bodyclass %}menu-documents{% endblock %}
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
<script>
|
<script>
|
||||||
$('#id_q').on('input', function() {
|
window.headerSearch = {
|
||||||
clearTimeout($.data(this, 'timer'));
|
url: "{% url 'wagtaildocs_index' %}",
|
||||||
var wait = setTimeout(search, 200);
|
termInput: "#id_q",
|
||||||
$(this).data('timer', wait);
|
targetOutput: "#document-results"
|
||||||
});
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -5,35 +5,11 @@
|
||||||
{% block bodyclass %}menu-images{% endblock %}
|
{% block bodyclass %}menu-images{% endblock %}
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
<script>
|
<script>
|
||||||
$('#id_q').on('input', function() {
|
window.headerSearch = {
|
||||||
clearTimeout($.data(this, 'timer'));
|
url: "{% url 'wagtailimages_index' %}",
|
||||||
var wait = setTimeout(search, 200);
|
termInput: "#id_q",
|
||||||
$(this).data('timer', wait);
|
targetOutput: "#image-results"
|
||||||
});
|
}
|
||||||
$('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);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -4,30 +4,11 @@
|
||||||
|
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
<script>
|
<script>
|
||||||
$('#id_q').on('input', function() {
|
window.headerSearch = {
|
||||||
clearTimeout($.data(this, 'timer'));
|
url: "{% url 'wagtailredirects_index' %}",
|
||||||
var wait = setTimeout(search, 200);
|
termInput: "#id_q",
|
||||||
$(this).data('timer', wait);
|
targetOutput: "#redirects-results"
|
||||||
});
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -4,30 +4,11 @@
|
||||||
|
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
<script>
|
<script>
|
||||||
$('#id_q').on('input', function() {
|
window.headerSearch = {
|
||||||
clearTimeout($.data(this, 'timer'));
|
url: "{% url 'wagtailsearch_editorspicks_index' %}",
|
||||||
var wait = setTimeout(search, 200);
|
termInput: "#id_q",
|
||||||
$(this).data('timer', wait);
|
targetOutput: "#editorspicks-results"
|
||||||
});
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -4,29 +4,11 @@
|
||||||
{% block bodyclass %}menu-users{% endblock %}
|
{% block bodyclass %}menu-users{% endblock %}
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
<script>
|
<script>
|
||||||
$('#id_q').on('input', function() {
|
window.headerSearch = {
|
||||||
clearTimeout($.data(this, 'timer'));
|
url: "{% url 'wagtailusers_index' %}",
|
||||||
var wait = setTimeout(search, 200);
|
termInput: "#id_q",
|
||||||
$(this).data('timer', wait);
|
targetOutput: "#user-results"
|
||||||
});
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue