-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
executable file
·77 lines (65 loc) · 1.63 KB
/
script.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
$(function(){
/**
*
*/
$('.checkbox_table tr').on('click', function(evt){
var $this = $(this);
var $input = $this.find('input');
if( evt.target.nodeName != 'INPUT' ){
if( $input.prop('checked') ){
$input.prop('checked', false);
}else{
$input.prop('checked', true);
}
}
if( $input.prop('checked') ){
$this.addClass('checked');
}else{
$this.removeClass('checked');
}
});
/**
* Use jquery ui autocomplete in place of <select>
*
*/
$(document).on('mousedown', 'span.combobox', function(evt){
if( evt.target.nodeName != 'INPUT' ){
evt.preventDefault();
$(this).find('input').focus();
}
});
$(document).on('focus', 'input.combobox', function(){
//once the comobox is initiated, we dont' need to create it again
var $search = $(this).removeClass('combobox');
var $parent = $search.parent();
var source = $( $parent.data('source') ).data('json');
// create autocomplete
var $autocomplete = $search.not(':ui-autocomplete')
.autocomplete({
source : source,
delay : 100,
minLength : 1,
appendTo : '#gp_admin_boxc',
select: function(event, ui){
if( ui.item ){
$search.val(ui.item[0]);
$parent.css({
'border-color' : ''
});
return false;
}
}
});
// support jqueryui changes
var data_key = 'autocomplete';
if( $autocomplete.data('ui-autocomplete') ){
data_key = 'ui-autocomplete';
}
$autocomplete.data(data_key)._renderItem = function(ul, item){
return $('<li></li>')
.data('item.autocomplete', item)
.append('<a>' + item[0] + '<span>' + item[1] + '</span></a>')
.appendTo(ul);
};
});
});