Skip to content

#3779: Remove autocomplete js from templates #3805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions readthedocs/core/static-src/core/js/autocomplete.js

This file was deleted.

1 change: 0 additions & 1 deletion readthedocs/core/static/core/js/autocomplete.js

This file was deleted.

9 changes: 0 additions & 9 deletions readthedocs/gold/templates/gold/projects.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
Gold Projects
{% endblock %}

{% block extra_scripts %}
<script type="text/javascript" src="{% static 'core/js/autocomplete.js' %}"></script>
<script type="text/javascript">
var attach_project_autocomplete = require('core/autocomplete');
$(document).ready(function () {
attach_project_autocomplete('#id_project', '{% url "search_autocomplete" %}');
});
</script>
{% endblock %}

{% block edit_content %}

Expand Down
18 changes: 0 additions & 18 deletions readthedocs/projects/urls/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
ProjectIndex.as_view(),
name='projects_list'),

url(r'^search/autocomplete/$',
public.search_autocomplete,
name='search_autocomplete'),

url(r'^autocomplete/version/(?P<project_slug>[-\w]+)/$',
public.version_autocomplete,
name='version_autocomplete'),

url(r'^(?P<project_slug>{project_slug})/$'.format(**pattern_opts),
ProjectDetailView.as_view(),
name='projects_detail'),
Expand All @@ -45,11 +37,6 @@
public.project_embed,
name='project_embed'),

# url((r'^(?P<project_slug>{project_slug})/tools/analytics/$'
# .format(**pattern_opts)),
# public.project_analytics,
# name='project_analytics'),

url(r'^(?P<project_slug>{project_slug})/search/$'.format(**pattern_opts),
public.elastic_project_search,
name='elastic_project_search'),
Expand All @@ -64,11 +51,6 @@
build_views.BuildList.as_view(),
name='builds_project_list'),

url((r'^(?P<project_slug>{project_slug})/autocomplete/file/$'
.format(**pattern_opts)),
public.file_autocomplete,
name='file_autocomplete'),

url(r'^(?P<project_slug>{project_slug})/versions/$'.format(**pattern_opts),
public.project_versions,
name='project_version_list'),
Expand Down
79 changes: 0 additions & 79 deletions readthedocs/projects/views/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,85 +196,6 @@ def project_download_media(request, project_slug, type_, version_slug):
return response


def search_autocomplete(request):
"""Return a json list of project names."""
if 'term' in request.GET:
term = request.GET['term']
else:
raise Http404
queryset = Project.objects.public(
request.user).filter(name__icontains=term)[:20]

ret_list = []
for project in queryset:
ret_list.append({
'label': project.name,
'value': project.slug,
})

json_response = json.dumps(ret_list)
return HttpResponse(json_response, content_type='text/javascript')


def version_autocomplete(request, project_slug):
"""Return a json list of version names."""
queryset = Project.objects.public(request.user)
get_object_or_404(queryset, slug=project_slug)
versions = Version.objects.public(request.user)
if 'term' in request.GET:
term = request.GET['term']
else:
raise Http404
version_queryset = versions.filter(slug__icontains=term)[:20]

names = version_queryset.values_list('slug', flat=True)
json_response = json.dumps(list(names))

return HttpResponse(json_response, content_type='text/javascript')


def version_filter_autocomplete(request, project_slug):
queryset = Project.objects.public(request.user)
project = get_object_or_404(queryset, slug=project_slug)
versions = Version.objects.public(request.user)
resp_format = request.GET.get('format', 'json')

if resp_format == 'json':
names = versions.values_list('slug', flat=True)
json_response = json.dumps(list(names))
return HttpResponse(json_response, content_type='text/javascript')
elif resp_format == 'html':
return render(
request,
'core/version_list.html',
{
'project': project,
'versions': versions,
},
)
return HttpResponse(status=400)


def file_autocomplete(request, project_slug):
"""Return a json list of file names."""
if 'term' in request.GET:
term = request.GET['term']
else:
raise Http404
queryset = ImportedFile.objects.filter(
project__slug=project_slug, path__icontains=term)[:20]

ret_list = []
for filename in queryset:
ret_list.append({
'label': filename.path,
'value': filename.path,
})

json_response = json.dumps(ret_list)
return HttpResponse(json_response, content_type='text/javascript')


def elastic_project_search(request, project_slug):
"""Use elastic search to search in a project."""
queryset = Project.objects.protected(request.user)
Expand Down
16 changes: 2 additions & 14 deletions readthedocs/templates/core/widesearchbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h3>{% trans "Search all the docs" %}</h3>

<form action="{% url "search" %}" method="GET">
<div class="text-input-wrapper">
<input type="text" name="q" value="{{ term }}" id="id_site_search" placeholder="{% trans 'Search Read the Docs' %}">
<input type="text" name="q" value="{{ term }}" placeholder="{% trans 'Search Read the Docs' %}">
</div>
<div class="submit-input-wrapper">
{% comment %} Translators: This is about starting a search {% endcomment %}
Expand All @@ -18,16 +18,4 @@ <h3>{% trans "Search all the docs" %}</h3>
</form>

</div>
</div>
{% comment %}
<script type="text/javascript">
$('.wide-search-bar #id_site_search').autocomplete({
source: '{% url "search_autocomplete" %}',
minLength: 2,
open: function(event, ui) {
ac_top = $('.ui-autocomplete').css('top');
$('.ui-autocomplete').css({'width': '534px', 'top': ac_top + 10 });
}
});
</script>
{% endcomment %}
</div>
14 changes: 2 additions & 12 deletions readthedocs/templates/projects/project_comments_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,10 @@ <h3> {% trans "Existing Translations" %} </h3>
<input style="display: inline;" type="submit" value="{% trans "Submit" %}">
</p>
</form>

{% endcomment %}
{% endblock %}


{% block footerjs %}
$('#id_project').autocomplete({
source: '{% url "search_autocomplete" %}',
minLength: 2,
open: function(event, ui) {
ac_top = $('.ui-autocomplete').css('top');
$('.ui-autocomplete').css({'width': '233px', 'top': ac_top + 10 });
}
});

{% endcomment %}


{% endblock %}
11 changes: 1 addition & 10 deletions readthedocs/templates/search/base_facet.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@

{% block title %}{% blocktrans %}Search: {{ query }}{% endblocktrans %}{% endblock %}

{% block extra_scripts %}
<script type="text/javascript" src="{{ MEDIA_URL }}javascript/instantsearch.js"></script>
<script type="text/javascript">
$(function() {
Search.init();
});
</script>
{% endblock %}

{% block content %}

<!-- BEGIN search form -->
<div class="wide-search-bar">
<div class="wide-search-bar-wrapper clearfix">
<form action="." method="GET">
<div class="text-input-wrapper">
<input type="text" name="q" value="{{ query }}" autocomplete="off" id="id_site_search_2">
<input type="text" name="q" value="{{ query }}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. This ID should stay.

<input type="hidden" name="selected_facets" value="{{ selected_facets }}" id='id_selected_facets'>
</div>
<div class="submit-input-wrapper">
Expand Down
28 changes: 1 addition & 27 deletions readthedocs/templates/search/elastic_project_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,6 @@
{% endwith %}
{% endblock %}

{% block extra_scripts %}
<script type="text/javascript">

$(document).ready(function() {
input_div = $('#id_elastic_project_search')

$('#id_elastic_project_search').autocomplete({
source: '{% url "file_autocomplete" project.slug %}',
minLength: 2,
open: function(event, ui) {
ac_top = $('.ui-autocomplete').css('top');
input_width = parseInt(input_div.css('width'))
input_padding = parseInt(input_div.css('padding'))
$('.ui-autocomplete').css({'cursor': 'pointer', 'width': input_width, 'padding': input_padding, 'top': ac_top + 10 });
},
select: function( event, ui ) {
event.preventDefault()
window.location.replace('/docs/' + '{{ project.slug }}' + '/en/latest/' + ui.item.value)
}
});

})
</script>


{% endblock %}

{% block content %}

Expand Down Expand Up @@ -63,7 +37,7 @@ <h2 class="quiet">Search in this project:</h2>
<div class="wide-search-bar-wrapper clearfix">
<form action="." method="GET">
<div class="text-input-wrapper">
<input type="text" name="q" value="{{ query|default_if_none:"" }}" id="id_elastic_project_search">
<input type="text" name="q" value="{{ query|default_if_none:"" }}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These ID's should stay.

</div>
<div class="submit-input-wrapper">
{% comment %}Translators: This is about starting a search{% endcomment %}
Expand Down