-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_maps.js
More file actions
121 lines (113 loc) · 3.66 KB
/
script_maps.js
File metadata and controls
121 lines (113 loc) · 3.66 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const site = "https://cvlcondorcet.fr/"
function resize(xper, yper) {
$("#place").css("top", $('#map').height()*yper-$('#place').height());
$("#place").css("left", $('#map').width()*xper-$('#place').width()/2);
}
$.fn.animateRotate = function(angle, duration, easing, complete) {
var args = $.speed(duration, easing, complete);
var step = args.step;
return this.each(function(i, e) {
args.complete = $.proxy(args.complete, e);
args.step = function(now) {
$.style(e, 'transform', 'rotate(' + now + 'deg)');
if (step) return step.apply(e, arguments);
};
$({deg: 0}).animate({deg: angle}, args);
});
};
$('document').ready(function(){
$("#place").toggle();
$('#search').keypress(function(e) {
if(e.which == 13) {
$('#launch').trigger('click');
}
});
$('#select_map').click(function() {
$('#map').attr('src', site+'maps/'+$('#select_map option:selected').val()+".png");
$('#place').slideUp();
history.pushState({url: 'maps.php?map='+$('#select_map option:selected').val()}, '', '/maps/location/'+$('#select_map option:selected').val(), false);
});
$('#display_search').click(function() {
var one, two;
if ($(this).hasClass("icon-arrow--down")) {
one = "icon-arrow--down";
two = "icon-arrow--up";
$('#form').slideDown();
} else {
$('#form').slideUp();
two = "icon-arrow--down";
one = "icon-arrow--up";
}
$(this).animateRotate(180, 500, "swing", function() {
$(this).removeClass(one).addClass(two).css("transform", "");
});
});
$('#launch').click(function(){
if ($('#search').val() !== "") {
$.ajax({
url: 'search.php',
type: 'GET',
data: 'query='+$('#search').val(),
datatype: 'json',
success: function(data, code) {
obj = $.parseJSON(data);
$('#results').empty();
$.each(obj, function() {
$('#results').append('<option class="select_result" value="'+this['name']+'" data-plan="'+this['map']+'">'+this['display_name']+'</option>');
});
if (obj.length == 1) {
$('#results option:first-child').attr('selected', true);
$('#results').trigger('change');
}
}
});
}
});
$('#results').on('change click', function() {
$('#map').attr('src', site+"maps/"+$('#results option:selected').attr('data-plan').substr(0,$('#results option:selected').attr('data-plan').indexOf("."))+".png");
$.ajax({
url: 'get_map.php',
type: 'GET',
data: 'query='+$('#results option:selected').val(),
datatype: 'json',
success: function(result, code) {
data = $.parseJSON(result);
$('#title').text(data['display_name']);
$('#desc').text(data['description']);
var obj = $.parseJSON(data['pos']);
$('#map').ready(function() {
$('#script_to_replace').replaceWith("<script id=\"script_to_replace\"> $('document').ready(function() { $(window).on('resize', function() { resize("+obj['x']+","+obj['y']+"); }); $('#place').slideDown(); }); <\/script>");
resize(obj['x'], obj['y']);
});
obj2 = $.parseJSON(data['mark']);
var toshow;
switch (obj2[0]) {
case "0":
toshow = "Rez-de-chaussée";
break;
case "1":
toshow = "1<sup>er</sup> étage";
break;
default:
toshow = obj2[0]+"<sup>ème</sup> étage";
}
switch (obj2[1]) {
case "NU":
toshow = "Bâtiment du Lycée";
break;
case "GL":
toshow += " du Grand Lycée";
break;
case "IN":
toshow += " de l'Internat";
break;
case "PL":
toshow += " du Petit Lycée";
break;
}
$('#location').empty().append("<strong>Emplacement : </strong>"+toshow);
history.pushState({url: 'maps.php/'+data['name']}, '', '/maps/'+data['name'], false);
}
});
});
});