Skip to content
This repository was archived by the owner on Sep 19, 2018. It is now read-only.

Commit d40d941

Browse files
committed
Fixed darn IE9 bug with history
1 parent a85457b commit d40d941

File tree

12 files changed

+51
-43
lines changed

12 files changed

+51
-43
lines changed

static/js/faceted-search-events.js

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,56 @@ var Codeweek = window.Codeweek || {};
1919
var data = $('#faceted-search-events').serialize();
2020
var url = $('#faceted-search-events').attr('action');
2121

22-
$.get(url, data, function(fragment) {
23-
History.replaceState({}, document.title, url+'?'+data);
24-
container.empty();
25-
container.html(fragment);
26-
var no_results = $('body').data('all_results');
27-
var result_string = '';
28-
29-
if (no_results > 0 ) {
30-
result_string = (no_results > 1 ? ' events match ' : ' event matches ');
31-
search_counter_container.html(no_results + result_string + 'your search criteria: ');
32-
$('#all-search-results').show();
33-
} else {
34-
$('#all-search-results').hide();
35-
}
36-
37-
});
22+
if (is_modern_browser()) {
23+
$.get(url, data, function(fragment) {
24+
history.replaceState({}, document.title, '?' + data);
25+
container.empty();
26+
container.html(fragment);
27+
var no_results = $('body').data('all_results');
28+
var result_string = '';
29+
30+
if (no_results > 0 ) {
31+
result_string = (no_results > 1 ? ' events match ' : ' event matches ');
32+
search_counter_container.html(no_results + result_string + 'your search criteria: ');
33+
search_counter_container.show();
34+
} else {
35+
search_counter_container.hide();
36+
}
37+
38+
});
39+
} else {
40+
document.getElementById('faceted-search-events').submit();
41+
}
42+
3843
});
3944
});
4045
};
4146

47+
function is_modern_browser() {
48+
49+
var ie_version = msieversion();
50+
51+
if('querySelector' in document
52+
&& 'localStorage' in window
53+
&& 'addEventListener' in window
54+
&& ( ie_version==0 || ie_version > 9)) {
55+
// bootstrap the javascript application
56+
return true;
57+
}
58+
59+
return false;
60+
}
61+
62+
function msieversion() {
63+
64+
var ua = window.navigator.userAgent;
65+
var msie = ua.indexOf("MSIE ");
66+
67+
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer, return version number
68+
return parseInt(ua.substring(msie + 5, ua.indexOf(".", msie)));
69+
return 0;
70+
}
71+
4272
Codeweek.FacetedSearch = {};
4373
Codeweek.FacetedSearch.init = init;
4474

static/js/history.js/scripts/bundled/html4+html5/dojo.history.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

static/js/history.js/scripts/bundled/html4+html5/extjs.history.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

static/js/history.js/scripts/bundled/html4+html5/jquery.history.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

static/js/history.js/scripts/bundled/html4+html5/mootools.history.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

static/js/history.js/scripts/bundled/html4+html5/native.history.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

static/js/history.js/scripts/bundled/html4+html5/right.history.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

static/js/history.js/scripts/bundled/html4+html5/zepto.history.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

web/templates/pages/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<div class="clearfix">
4444
<div id="search-events-link">
4545
<a class="btn btn-primary btn-lg"
46-
href="{% url 'web.search_events' %}?country_code={{ country.country_code }}&amp;past={{ past }}">
46+
href="{% url 'web.search_events' %}?country={{ country.country_code }}&amp;past={{ past }}">
4747
<i class="fa fa-list"></i> List all events {% if country %}in
4848
<span id="country"> {{ country.country_name }}</span>{% endif %}
4949
</a>

web/templates/pages/search_events.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858

5959
{% block custom_js %}
6060
{{ block.super }}
61-
<script type="text/javascript" src="{% static "js/history.js/scripts/bundled/html4+html5/jquery.history.js" %}" ></script>
6261
<script type="text/javascript" src="{% static "js/endless_pagination/endless-pagination.js" %}" ></script>
6362
<script type="text/javascript" src="{% static "js/faceted-search-events.js" %}" ></script>
6463
<script type="text/javascript">

web/tests/test_event_views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_search_with_theme_multiple_events(self):
131131
def test_search_with_theme_multiple_events_all_countries(self):
132132
approved1 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="SI")
133133
approved2 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="AT")
134-
response = self.client.get(reverse('web.search_events'), {'country_code':'00', 'theme':1}, REMOTE_ADDR='93.103.53.11')
134+
response = self.client.get(reverse('web.search_events'), {'country':'00', 'theme':1}, REMOTE_ADDR='93.103.53.11')
135135

136136
self.assertEquals(2,response.context['events'].count())
137137

@@ -152,7 +152,7 @@ def test_search_events_with_search_query_all_countries_multiple_results(self):
152152
approved1 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="SI")
153153
approved2 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="AT")
154154

155-
response = self.client.get(reverse('web.search_events'), {'q':'arglebargle', 'country_code':'00'}, REMOTE_ADDR='93.103.53.11')
155+
response = self.client.get(reverse('web.search_events'), {'q':'arglebargle', 'country':'00'}, REMOTE_ADDR='93.103.53.11')
156156

157157
self.assertEquals(2,response.context['events'].count())
158158

web/views/events.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,7 @@ def created_events(request):
253253

254254
def search_events(request):
255255

256-
country_filter = request.GET.get('country_code', None)
257-
258-
if not country_filter:
259-
country_filter = request.GET.get('country', None)
256+
country_filter = request.GET.get('country', None)
260257

261258
if not country_filter :
262259
user_ip = get_client_ip(forwarded=request.META.get('HTTP_X_FORWARDED_FOR'),
@@ -274,18 +271,7 @@ def search_events(request):
274271

275272
template = 'pages/search_events.html'
276273

277-
if request.method == 'POST':
278-
form = SearchEventForm(request.POST)
279-
280-
if form.is_valid():
281-
search_filter = form.cleaned_data.get('q', None)
282-
country_filter = form.cleaned_data.get('country', None)
283-
theme_filter = form.cleaned_data.get('theme', None)
284-
audience_filter = form.cleaned_data.get('audience', None)
285-
past_events = form.cleaned_data.get('past',None)
286-
287-
events = get_filtered_events(search_filter, country_filter, theme_filter, audience_filter, past_events)
288-
else:
274+
if request.method == 'GET':
289275
theme_filter = request.GET.getlist('theme', None)
290276
audience_filter =request.GET.getlist('audience', None)
291277

0 commit comments

Comments
 (0)