|
1 | | -/* |
2 | | -* This script make #search-result-wrapper switch to unloaded or shown automatically. |
3 | | -*/ |
4 | | - |
5 | | -$(function() { |
6 | | - const btnSbTrigger = $("#sidebar-trigger"); |
7 | | - const btnSearchTrigger = $("#search-trigger"); |
8 | | - const btnCancel = $("#search-cancel"); |
9 | | - const main = $("#main"); |
10 | | - const topbarTitle = $("#topbar-title"); |
11 | | - const searchWrapper = $("#search-wrapper"); |
12 | | - const resultWrapper = $("#search-result-wrapper"); |
13 | | - const results = $("#search-results"); |
14 | | - const input = $("#search-input"); |
15 | | - const hints = $("#search-hints"); |
16 | | - |
17 | | - const scrollBlocker = (function () { |
18 | | - let offset = 0; |
19 | | - return { |
20 | | - block() { |
21 | | - offset = window.scrollY; |
22 | | - $("html,body").scrollTop(0); |
23 | | - }, |
24 | | - release() { |
25 | | - $("html,body").scrollTop(offset); |
26 | | - }, |
27 | | - getOffset() { |
28 | | - return offset; |
29 | | - } |
30 | | - }; |
31 | | - }()); |
32 | | - |
33 | | - /*--- Actions in mobile screens (Sidebar hidden) ---*/ |
34 | | - |
35 | | - const mobileSearchBar = (function () { |
36 | | - return { |
37 | | - on() { |
38 | | - btnSbTrigger.addClass("unloaded"); |
39 | | - topbarTitle.addClass("unloaded"); |
40 | | - btnSearchTrigger.addClass("unloaded"); |
41 | | - searchWrapper.addClass("d-flex"); |
42 | | - btnCancel.addClass("loaded"); |
43 | | - }, |
44 | | - off() { |
45 | | - btnCancel.removeClass("loaded"); |
46 | | - searchWrapper.removeClass("d-flex"); |
47 | | - btnSbTrigger.removeClass("unloaded"); |
48 | | - topbarTitle.removeClass("unloaded"); |
49 | | - btnSearchTrigger.removeClass("unloaded"); |
50 | | - } |
51 | | - }; |
52 | | - }()); |
53 | | - |
54 | | - const resultSwitch = (function () { |
55 | | - let visible = false; |
56 | | - |
57 | | - return { |
58 | | - on() { |
59 | | - if (!visible) { |
60 | | - // the block method must be called before $(#main) unloaded. |
61 | | - scrollBlocker.block(); |
62 | | - resultWrapper.removeClass("unloaded"); |
63 | | - main.addClass("unloaded"); |
64 | | - visible = true; |
65 | | - } |
66 | | - }, |
67 | | - off() { |
68 | | - if (visible) { |
69 | | - results.empty(); |
70 | | - if (hints.hasClass("unloaded")) { |
71 | | - hints.removeClass("unloaded"); |
72 | | - } |
73 | | - resultWrapper.addClass("unloaded"); |
74 | | - main.removeClass("unloaded"); |
75 | | - |
76 | | - // now the release method must be called after $(#main) display |
77 | | - scrollBlocker.release(); |
78 | | - |
79 | | - input.val(""); |
80 | | - visible = false; |
81 | | - } |
82 | | - }, |
83 | | - isVisible() { |
84 | | - return visible; |
85 | | - } |
86 | | - }; |
87 | | - |
88 | | - }()); |
89 | | - |
90 | | - function isMobileView() { |
91 | | - return btnCancel.hasClass("loaded"); |
92 | | - } |
93 | | - |
94 | | - btnSearchTrigger.click(function() { |
95 | | - mobileSearchBar.on(); |
96 | | - resultSwitch.on(); |
97 | | - input.focus(); |
98 | | - }); |
99 | | - |
100 | | - btnCancel.click(function() { |
101 | | - mobileSearchBar.off(); |
102 | | - resultSwitch.off(); |
103 | | - }); |
104 | | - |
105 | | - input.focus(function() { |
106 | | - searchWrapper.addClass("input-focus"); |
107 | | - }); |
108 | | - |
109 | | - input.focusout(function() { |
110 | | - searchWrapper.removeClass("input-focus"); |
111 | | - }); |
112 | | - |
113 | | - input.on("input", () => { |
114 | | - if (input.val() === "") { |
115 | | - if (isMobileView()) { |
116 | | - hints.removeClass("unloaded"); |
117 | | - } else { |
118 | | - resultSwitch.off(); |
119 | | - } |
120 | | - |
121 | | - } else { |
122 | | - resultSwitch.on(); |
123 | | - if (isMobileView()) { |
124 | | - hints.addClass("unloaded"); |
125 | | - } |
| 1 | +/** |
| 2 | + * This script make #search-result-wrapper switch to unloaded or shown automatically. |
| 3 | + */ |
| 4 | + |
| 5 | +$(function () { |
| 6 | + const btnSbTrigger = $("#sidebar-trigger"); |
| 7 | + const btnSearchTrigger = $("#search-trigger"); |
| 8 | + const btnCancel = $("#search-cancel"); |
| 9 | + const main = $("#main"); |
| 10 | + const topbarTitle = $("#topbar-title"); |
| 11 | + const searchWrapper = $("#search-wrapper"); |
| 12 | + const resultWrapper = $("#search-result-wrapper"); |
| 13 | + const results = $("#search-results"); |
| 14 | + const input = $("#search-input"); |
| 15 | + const hints = $("#search-hints"); |
| 16 | + |
| 17 | + const scrollBlocker = (function () { |
| 18 | + let offset = 0; |
| 19 | + return { |
| 20 | + block() { |
| 21 | + offset = window.scrollY; |
| 22 | + $("html,body").scrollTop(0); |
| 23 | + }, |
| 24 | + release() { |
| 25 | + $("html,body").scrollTop(offset); |
| 26 | + }, |
| 27 | + getOffset() { |
| 28 | + return offset; |
| 29 | + } |
| 30 | + }; |
| 31 | + }()); |
| 32 | + |
| 33 | + /*--- Actions in mobile screens (Sidebar hidden) ---*/ |
| 34 | + |
| 35 | + const mobileSearchBar = (function () { |
| 36 | + return { |
| 37 | + on() { |
| 38 | + btnSbTrigger.addClass("unloaded"); |
| 39 | + topbarTitle.addClass("unloaded"); |
| 40 | + btnSearchTrigger.addClass("unloaded"); |
| 41 | + searchWrapper.addClass("d-flex"); |
| 42 | + btnCancel.addClass("loaded"); |
| 43 | + }, |
| 44 | + off() { |
| 45 | + btnCancel.removeClass("loaded"); |
| 46 | + searchWrapper.removeClass("d-flex"); |
| 47 | + btnSbTrigger.removeClass("unloaded"); |
| 48 | + topbarTitle.removeClass("unloaded"); |
| 49 | + btnSearchTrigger.removeClass("unloaded"); |
| 50 | + } |
| 51 | + }; |
| 52 | + }()); |
| 53 | + |
| 54 | + const resultSwitch = (function () { |
| 55 | + let visible = false; |
| 56 | + |
| 57 | + return { |
| 58 | + on() { |
| 59 | + if (!visible) { |
| 60 | + // the block method must be called before $(#main) unloaded. |
| 61 | + scrollBlocker.block(); |
| 62 | + resultWrapper.removeClass("unloaded"); |
| 63 | + main.addClass("unloaded"); |
| 64 | + visible = true; |
| 65 | + } |
| 66 | + }, |
| 67 | + off() { |
| 68 | + if (visible) { |
| 69 | + results.empty(); |
| 70 | + if (hints.hasClass("unloaded")) { |
| 71 | + hints.removeClass("unloaded"); |
| 72 | + } |
| 73 | + resultWrapper.addClass("unloaded"); |
| 74 | + main.removeClass("unloaded"); |
| 75 | + |
| 76 | + // now the release method must be called after $(#main) display |
| 77 | + scrollBlocker.release(); |
| 78 | + |
| 79 | + input.val(""); |
| 80 | + visible = false; |
| 81 | + } |
| 82 | + }, |
| 83 | + isVisible() { |
| 84 | + return visible; |
| 85 | + } |
| 86 | + }; |
| 87 | + |
| 88 | + }()); |
| 89 | + |
| 90 | + function isMobileView() { |
| 91 | + return btnCancel.hasClass("loaded"); |
126 | 92 | } |
127 | | - }); |
| 93 | + |
| 94 | + btnSearchTrigger.click(function () { |
| 95 | + mobileSearchBar.on(); |
| 96 | + resultSwitch.on(); |
| 97 | + input.focus(); |
| 98 | + }); |
| 99 | + |
| 100 | + btnCancel.click(function () { |
| 101 | + mobileSearchBar.off(); |
| 102 | + resultSwitch.off(); |
| 103 | + }); |
| 104 | + |
| 105 | + input.focus(function () { |
| 106 | + searchWrapper.addClass("input-focus"); |
| 107 | + }); |
| 108 | + |
| 109 | + input.focusout(function () { |
| 110 | + searchWrapper.removeClass("input-focus"); |
| 111 | + }); |
| 112 | + |
| 113 | + input.on("input", () => { |
| 114 | + if (input.val() === "") { |
| 115 | + if (isMobileView()) { |
| 116 | + hints.removeClass("unloaded"); |
| 117 | + } else { |
| 118 | + resultSwitch.off(); |
| 119 | + } |
| 120 | + |
| 121 | + } else { |
| 122 | + resultSwitch.on(); |
| 123 | + if (isMobileView()) { |
| 124 | + hints.addClass("unloaded"); |
| 125 | + } |
| 126 | + } |
| 127 | + }); |
128 | 128 |
|
129 | 129 | }); |
0 commit comments