forked from kevzlou7979/select2-materialize
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (44 loc) · 1.74 KB
/
index.js
File metadata and controls
56 lines (44 loc) · 1.74 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
$(document).ready(function() {
$(document).on("select2:open select2:focus", "select", function() {
var $this = $(this);
var $parent = $(this).parent();
clearTimeout($this.data("blurring"));
$this.data("blurring", setTimeout(function() {
$parent.children("label").addClass("active").addClass("focus");
$parent.find(".select2-selection").addClass("focus");
}));
});
$(document).on("select2:close", "select", function() {
var $this = $(this);
var $parent = $(this).parent();
var $input = $parent.find("input.select2-search__field");
clearTimeout($this.data("blurring"));
$this.data("blurring", setTimeout(function() {
if ($input.is(":focus")) {
return;
}
$parent.children("label").removeClass("focus");
$parent.find(".select2-selection").removeClass("focus");
if ($this.find("option:selected").length) {
return;
}
$parent.children("label").removeClass("active");
}));
});
$(document).on("blur", ".select2 input.select2-search__field", function() {
setTimeout(function() {
$(this).parents(".select2").siblings("select").trigger("select2:close");
}.bind(this), 100);
});
$(document).on("focus", ".select2 input.select2-search__field", function() {
setTimeout(function() {
$(this).parents(".select2").siblings("select").trigger("select2:open");
}.bind(this), 100);
});
$(document).on("select2:unselect", "select", function(e) {
if (!e.params.originalEvent) {
return;
}
e.params.originalEvent.stopPropagation();
});
});