PageSourceSearch

https://1office.vn/wp-content/themes/1office/new2023/support/support.js?t=1790246102

js 1office.vn collected 2026-09-24 10:38:04 UTC 5,848 bytes, 192 lines download raw bytes

1/* Common */
2
3document.title = 'Hướng dẫn sử dụng';
4
5let textToSearch = (text) => {
6    return text.normalize("NFD")
7        .replace(/[\u0300-\u036f]/g, "")
8        .replace(/đ/g, "d")
9        .replace(/Đ/g, "D")
10        .toLowerCase();
11}
12
13const watchHash = () => {
14    const hash = window.location.hash.replace('#', '');
15    
16    if (hash) {
17        $('.doc-wrap').find(`.doc-module-section`).removeClass('focused');
18        $('.doc-wrap').find(`.doc-module-section.section-${hash}:first`).each(function() {
19           
20            this.scrollIntoView({ behavior: 'smooth', block: 'center' });
21            this.classList.add('focused');
22
23            setTimeout(() => this.classList.remove('focused'), 5000);
24        });
25    }
26};
27
28watchHash();
29
30window.removeEventListener('hashchange', watchHash);
31window.addEventListener('hashchange', watchHash);
32
33$('.doc-nav-menu').on('click', function() {
34    $('body').toggleClass('doc-collapse');
35});
36
37$('.doc-wrap').on('click', function(e) {
38    const $target = $(e.target);
39
40    if ($target.closest('.doc-nav-menu').length) {
41        return;
42    }
43
44    if ($('body').hasClass('doc-collapse') && !$target.closest('.doc-drawer').length) {
45        $('body').removeClass('doc-collapse');
46    }
47});
48
49$('.doc-wrap').on('scroll', function() {
50    if ($(this).scrollTop() > 64) {
51        $('.doc-nav').addClass('shadow');
52    } else {
53        $('.doc-nav').removeClass('shadow');
54    }
55});
56
57
58
59if (page == 'list') {
60    const $header = $('.doc-header');
61    const $result = $header.find('.doc-search-results');
62    const $search = $header.find('.doc-search');
63    
64    let modules = [];
65    doc.forEach(h => h.items.forEach(a => modules.push(a)));
66    
67    $result.on('mouseenter', '.doc-search-result', function (e) {
68        $result.find('.doc-search-result').removeClass('selected');
69        $(this).addClass('selected');
70    });
71    
72    $header.find('.doc-search > input')
73        .on('blur', function () {
74            setTimeout(() => $search.removeClass('suggest'), 100);
75        })
76        .on('focus', function () {
77            $(this).triggerHandler('keyup');
78        });
79    
80    $header.find('.doc-search > input').on('keyup', function (e) {
81        const DOWN = 40;
82        const UP = 38;
83        const ENTER = 13;
84        const keycode = e.keyCode || e.which;
85        const $selected = $result.find('.selected').first();
86        let $target;
87    
88        if (keycode == ENTER) {
89            let url = $selected.length 
90                ? $selected.first().attr('href') 
91                : window.location.origin + `${supportUrl}?search=${this.value}`;
92    
93            window.location.href = url;
94            return;
95        }
96    
97        if (keycode == DOWN) {
98            $target = $selected.length ? $selected.next() : $result.find('.doc-search-result').first();
99        }
100    
101        if (keycode == UP) {
102            $target = $selected.length ? $selected.prev() : $result.find('.doc-search-result').last();
103        }
104    
105        if ($target && $target.length > 0) {
106            $result.children().removeClass('selected');
107            $target.addClass('selected');
108    
109            const containerTop = $result.scrollTop();
110            const containerBottom = containerTop + $result.height();
111            const itemTop = $target.offset().top - $result.offset().top + containerTop;
112            const itemBottom = itemTop + $target.height();
113    
114            if (itemBottom > containerBottom || itemTop < containerTop) {
115                $result.animate({
116                    scrollTop: itemTop,
117                }, 200);
118            }
119    
120            return;
121        }
122    
123    
124        if (!this.value.trim()) {
125            $result.html('');
126            $search.removeClass('suggest');
127            return;
128        }
129    
130        const s = textToSearch(this.value);
131        const founds = modules.filter(h => textToSearch(h.label).includes(s));
132    
133        if (founds.length) {
134            let colors = ['doc-module-purple', 'doc-module-danger', 'doc-module-success', 'doc-module-info', 'doc-module-warning'];
135            
136            $search.addClass('suggest');
137            $result.html('');
138    
139            founds.forEach(h => {
140                const url = `${window.location.origin}${supportUrl}?module=${h.module}`;
141                const $el = $(`.doc-module-${h.module}`);
142                let color = '';
143    
144                if ($el.length) {
145                    colors.forEach(h => {
146                        if ($el.hasClass(h)) {
147                            color = h;
148                        }
149                    });
150                }
151    
152                $result.append(`<a class="doc-search-result" href="${url}">
153                    <div class="doc-search-result-icon ${color}">
154                        <i class="icon ${h.icon}"></i>
155                    </div>
156                    <div class="doc-search-result-label">${h.label}</div>
157                </a>`);
158            });
159    
160        } else {
161            $result.html('');
162            $search.removeClass('suggest');
163        }
164    });
165}
166
167if (page == 'detail') {
168    $('.doc-detail-go-top > div').on('click', function() {
169        $('body, html, .doc-wrap').animate({ scrollTop: 0 });
170    });
171
172    $('.doc-detail-content').off('click');
173    $('.doc-detail-content').on('click', 'a', function(e) {
174
175        let regex = /support-faq-faq\/view\?ID=(\d+).*module=(\w+)/;
176        let url = $(this).attr('href');   
177        let ms = url.match(regex);
178       
179        if (ms && ms[1] && ms[2]) {
180            e.preventDefault();
181            
182            let newUrl = `/support-docs?ID=${ms[1]}&module=${ms[2]}`;
183            window.location.href = newUrl;
184        }
185
186        regex = /support-faq-faq$/;
187        if (regex.test(url)) {
188            e.preventDefault();
189            window.open('/support-docs');
190        }
191    });
192}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.