-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmevents.js
More file actions
160 lines (134 loc) · 6.05 KB
/
mevents.js
File metadata and controls
160 lines (134 loc) · 6.05 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* Mobile GUI for the chemistry DB
* Version: 0.5.5ce
*/
"use strict";
function register_events(){
$('#search_trigger').click(function(){
var search_obj = wmgui.selectize.read();
var urlstr = $.param(search_obj);
if (window.location.hash == '#inquiry/' + urlstr){
// hash-hack FIXME?
if (urlstr.slice(-1) == '=') urlstr = urlstr.substr(0, urlstr.length-1);
else urlstr += '=';
}
window.location.hash = '#inquiry/' + urlstr;
return false;
});
$('#mini_branding').click(function(){
window.location.hash = '#start';
});
$('#legend').on('click', 'a', function(){
var that = $(this),
search_obj = {},
second_facet = that.attr('data-facet-b');
search_obj[ that.attr('data-facet-a') ] = that.attr('data-term-a');
if (search_obj[second_facet] && second_facet == 'elements'){
search_obj[second_facet] += '-' + that.attr('data-term-b');
} else if (search_obj[second_facet] && second_facet == 'classes'){
search_obj[second_facet] += ',' + that.attr('data-term-b');
} else search_obj[second_facet] = that.attr('data-term-b');
window.location.hash = '#inquiry/' + $.param(search_obj);
return false;
});
$('#input').on('click', 'li', function(){
var link = $(this).attr('rel');
if (!!link){ // search only ... arity
window.location.hash = link;
return;
}
window.scrollTo(0, document.body.scrollHeight);
$('#search_field-selectized').focus();
});
$('#summary').on('click', 'a.extd_refine', function(){
var facet = $(this).attr('rel'),
given_search = {extd_refine: facet};
$.extend(given_search, wmgui.search);
$.ajax({type: 'GET', url: wmgui.rfn_endpoint, data: {q: JSON.stringify(given_search)}}).done(function(data){
if (data.error) return wmgui.notify(data.error);
var html = '';
delete given_search['extd_refine'];
$.each(data.payload, function(i, found){
// FIXME: duplicating
var link_text = found[0],
orepr = {};
$.each(given_search, function(key, val){
if (facet == 'elements' && (key == 'elements' || key == 'formulae')) return true;
else if (facet == 'props' && key == 'props') return true;
orepr[key] = val;
});
if (facet == 'props'){
found[0] = found[0].replace(/\(|\)/g, "").replace(/\/[\w\-]*/g, ""); // FIXME!
}
orepr[facet] = found[0];
if (orepr['elements']) orepr['elements'] = orepr['elements'].replaceAll(', ', '-');
html += '<li class="extd_rfns fct_' + facet + '"><a href="#inquiry/' + $.param(orepr) + '">' + link_text + '</a></li>';
});
$('a.extd_refine[rel=' + facet + ']').parent().hide().after(z(html));
}).fail(function(xhr, textStatus, errorThrown){
if (textStatus != 'abort') wmgui.notify('Connection to server is lost, please try to reload');
});
return false;
});
$('#navicon').click(function(){
if ($(this).hasClass('opened')){
$(this).removeClass('opened');
$('#hamburger').addClass('closed');
$('#overlay, #menu_content').hide();
} else {
$(this).addClass('opened');
$('#hamburger').removeClass('closed');
$('#overlay, #menu_content').show();
}
});
$('#menu_content > ul > li > a').click(function(){
$('#navicon').removeClass('opened');
$('#hamburger').addClass('closed');
$('#overlay, #menu_content').hide();
return true;
});
$('#login_trigger').click(function(){
if ($(this).data('busy')) return;
$(this).data('busy', true);
$.ajax({type: 'POST', url: wmgui.login_endpoint, data: {login: $('#login_email').val().trim(), pass: $('#login_password').val()}, beforeSend: show_preloader}).always(function(){
$('#login_trigger').data('busy', false);
hide_preloader();
}).done(function(data){
if (data.error) return wmgui.notify(data.error);
if (!data.sid || !data.name || !data.acclogin) return wmgui.notify('Connection to server is lost, please try to reload');
user_login(data.sid, data.name, data.acclogin, data.admin);
window.location.hash = '#start';
$('#navicon').trigger('click');
$('#loginbox, #restorebox').hide();
}).fail(function(xhr, textStatus, errorThrown){
wmgui.notify("Login unsuccessful");
});
});
$('#restore_trigger').click(function(){
if ($(this).data('busy')) return;
$(this).data('busy', true);
$.ajax({type: 'POST', url: wmgui.restore_endpoint, data: {login: $('#restore_by_email').val().trim()}, beforeSend: show_preloader}).always(function(){
$('#restore_trigger').data('busy', false);
hide_preloader();
}).done(function(data){
if (data.error) return wmgui.notify(data.error);
wmgui.notify('Please, check your inbox (and spam)');
$('#navicon').trigger('click');
$('#loginbox, #restorebox').hide();
}).fail(function(xhr, textStatus, errorThrown){
if (textStatus != 'abort') wmgui.notify('A network error occured. Please, try again');
});
});
$('div.cross').click(function(){
window.location.hash = '#start';
});
$('#logout_item').click(function(){
$.ajax({type: 'POST', url: wmgui.logout_endpoint, data: {sid: wmgui.sid}}).done(function(data){}).fail(function(xhr, textStatus, errorThrown){});
user_logout();
});
$(document).keydown(function(e){
var key = window.event ? e.keyCode : e.which;
if (key == 13) $('#search_trigger').trigger('click');
});
$(window).bind('hashchange', url_redraw_react);
}