-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
153 lines (133 loc) · 4.49 KB
/
utils.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
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
jQuery(document).ready(function($) {
$(".whoowns_auto_label").autocomplete({
//define callback to format results
source: function(req, add){
//pass request to server
//The alt attribute contains the wordpress callback action
var params = {
action: this.element[0].alt,
term: req.term
};
$.getJSON(whoowns_ajax_object.ajax_url, params, function(data) {
//pass array to callback
add(data);
});
},
minLength: 3,
selectFirst: true,
focus: function( event, ui ) {
$(this).val(ui.item.label);
$(this).next(".whoowns_auto_id").val(ui.item.value);
return false;
},
select: function(e, ui) {
if ($(this).attr('trigger')=='submit') {
$(this).closest('form').submit();
}
var label = ui.item.label;
$(this).val(label);
$(this).next(".whoowns_auto_id").val(ui.item.value);
return false;
},
change: function(e, ui) {
// If the user didn't select any item from the list, the item will be erased
if ( !ui.item && !whoowns_ajax_object.autocomplete_allow_non_listed_value) {
$(this).val("");
$(this).next(".whoowns_auto_id").val("");
}
}
});
/* Auto-adjust factsheet columns */
function whoowns_adjust_columns() {
var o = jQuery("#whoowns-factsheet .one_half");
var t = jQuery("#whoowns-factsheet .two_half_last");
o.height('auto');
if (o.offset().top == t.offset().top && o.height()-100<t.height()) {
o.height(t.height()+120);
} else {
o.height('auto');
}
}
/* Toggle */
jQuery(document).ready(function() {
jQuery('.whoowns-toggle .whoowns-toggle_title').click(function (b) {
var toggled = jQuery(this).parent().find('.whoowns-toggle_content');
jQuery(this).parent().find('.whoowns-toggle_content').not(toggled).slideUp();
if (jQuery(this).hasClass('current')) {
jQuery(this).removeClass('current');
} else {
jQuery(this).addClass('current');
}
toggled.stop(false, true).slideToggle().css( {
display : 'block'
} );
b.preventDefault();
} );
});
/* Add class for small screens (tablet, smartphones) */
whoowns_set_responsive_class();
if (jQuery('#whoowns-factsheet').length>0)
whoowns_adjust_columns();
jQuery(window).resize(function(){
whoowns_set_responsive_class();
if (jQuery('#whoowns-factsheet').length>0) {
whoowns_adjust_columns();
}
});
function whoowns_set_responsive_class() {
w = jQuery(window).width();
whoowns = jQuery('#whoowns');
if (w <= 400) {
whoowns.addClass('whoowns-smartphone');
whoowns.removeClass('whowns-tablet');
} else if (w <= 768) {
whoowns.addClass('whoowns-tablet');
whoowns.removeClass('whoowns-smartphone');
} else {
whoowns.removeClass('whowns-tablet');
whoowns.removeClass('whoowns-smartphone');
}
}
});
/* From http://www.appelsiini.net/download/jquery.viewport.js . Thanks! */
jQuery.abovethetop = function(element, settings) {
var top = jQuery(window).scrollTop();
return top >= jQuery(element).offset().top + jQuery(element).height() - settings.threshold;
};
jQuery.extend(jQuery.expr[':'], {
"above-the-top": function(a, i, m) {
return jQuery.abovethetop(a, {threshold : 100});
}
});
function whoowns_submit_search(e) {
if (jQuery("#"+e.id).prop('checked')==true) {
if (e.id=='checkbox-ranked') {
jQuery("input:checkbox[name='whoowns_filters[]']:checked").each(function() {
if (jQuery(this).val()!='ranked')
jQuery(this).prop('checked', false);
});
} else if (e.id=='checkbox-all') {
jQuery("input:checkbox[name='whoowns_filters[]']:checked").each(function() {
if (jQuery(this).val()!='all')
jQuery(this).prop('checked', false);
});
} else {
jQuery("#checkbox-all,#checkbox-ranked").prop("checked", false);
}
}
document.whoowns_search_form.submit();
}
function whoowns_open_popup(id) {
var whoowns_popup_overlay = jQuery('#'+id+'-overlay');
whoowns_popup_overlay.css({'opacity': 0, 'display': 'block'});
whoowns_popup = jQuery('#'+id);
whoowns_popup.css({'opacity': 0, 'display': 'block'});
whoowns_popup_h = whoowns_popup.find('.'+id+'-wrap').outerHeight();
whoowns_popup_overlay.fadeTo(200, 0.55);
whoowns_popup.css( "z-index", "100002" );
whoowns_popup.animate({'opacity':1, 'height': whoowns_popup_h+20}, 200);
jQuery('#'+id+'-overlay, #'+id+'-close').click(function() {
whoowns_popup_overlay.fadeOut();
whoowns_popup.animate({'opacity' : 0, 'height' : 0}, 200, function(){whoowns_popup.css( "z-index", "0" );});
});
}