forked from pablisco/plusyou-html5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.js
73 lines (66 loc) · 2.21 KB
/
search.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
$(document).delegate('#search', 'pageinit', function() {
var provider_api = '/openplanetideas-plusyou-provider';
var beginDate = new Date();
beginDate.setMonth(beginDate.getMonth() - 10);
var endDate = new Date();
endDate.setMonth(endDate.getMonth() + 1);
var distance = 100;
var latitude = 50.9;
var longitude = 4.4;
var vendor = 1;
// TODO: Use Modernizr.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
getOpportunities();
});
}
var getOpportunities = function() {
var url = provider_api + '/opportunities'
+ ';beginDate=' + beginDate.format("yyyymmdd")
+ ';endDate=' + endDate.format("yyyymmdd")
+ ';distance=' + distance
+ ';latitude=' + latitude
+ ';longitude=' + longitude
+ ';vendor=' + vendor;
$.ajax({
url: url,
success: function(data) {
var json = $.xml2json(data)
var opportunities = $.isArray(json.opportunity) ? json.opportunity : [json.opportunity];
populateSearch(opportunities);
},
});
};
$('#results-list').show();
$('#mapButton').show();
$('#listButton').hide();
$('#map').addClass('hidden');
$('#mapButton').bind("click", function(event, ui) {
$('#map').removeClass('hidden');
$('#results-list').hide();
$('#mapButton').hide();
$('#listButton').show();
$('.ui-listview-filter').hide();
var height = $(window).height();
// var $map = $("#map");
// $map.siblings().each(function() {
// height -= $(this).outerHeight();
// });
// $map.outerHeight(height);
$('#map').height(0);
$('#map').css('margin-bottom:', 0);
var the_height = ($(window).height() - $(this).find('[data-role="header"]').height() - $(this).find('[data-role="footer"]').height() - $('.search-options').height());
$('#map').height(the_height);
});
$('#listButton').bind("click", function(event, ui) {
$('#results-list').show();
$('.ui-listview-filter').show();
$('#mapButton').show();
$('#listButton').hide();
$('#map').addClass('hidden');
$('#map').css('margin-bottom:', -400);
$('#map').height(400);
});
});