PageSourceSearch

https://nbs.gov.so/wp-content/plugins/wpdatatables/assets/js/wpdatatables/admin/common.js?ver=8.0.2

js nbs.gov.so collected 2026-09-24 18:48:18 UTC 18,272 bytes, 550 lines download raw bytes

1/**
2 * Controller for common methods in the admin section
3 *
4 * @author Alexander Gilmanov
5 * @since 18.10.2016
6 */
7
8var wdtInteractiveTooltipHideTimeout;
9
10/**
11 * Hide tooltip on button click or on mouseout event
12 */
13var wdtHideTooltip = function () {
14    jQuery('.wdt-datatables-admin-wrap [data-toggle="tooltip"]:not(.wdt-tooltip-interactive)').on('click', function () {
15        jQuery(this).wdtBootstrapTooltip('hide');
16    }).on('mouseout', function (event) {
17        var e = event.toElement || event.relatedTarget;
18        if (e != null && (e.parentNode == this || e == this)) {
19            return;
20        }
21        jQuery(this).wdtBootstrapTooltip('hide');
22    });
23};
24
25/**
26 * Keep tooltips with links open while hovering over the tooltip itself
27 */
28var wdtInteractiveTooltip = function () {
29    if (typeof jQuery.fn.wdtBootstrapTooltip === 'undefined') {
30        return;
31    }
32
33    var $tooltips = jQuery('.wdt-datatables-admin-wrap .wdt-tooltip-interactive[data-toggle="tooltip"]');
34
35    if (!$tooltips.length) {
36        return;
37    }
38
39    $tooltips.wdtBootstrapTooltip({
40        html: true,
41        trigger: 'manual'
42    });
43
44    $tooltips.on('mouseenter', function () {
45        var $el = jQuery(this);
46        clearTimeout(wdtInteractiveTooltipHideTimeout);
47        $el.wdtBootstrapTooltip('show');
48    }).on('mouseleave', function () {
49        var $el = jQuery(this);
50        wdtInteractiveTooltipHideTimeout = setTimeout(function () {
51            if (!jQuery('.tooltip:hover').length) {
52                $el.wdtBootstrapTooltip('hide');
53            }
54        }, 100);
55    });
56
57    jQuery(document).on('mouseenter', '.tooltip', function () {
58        clearTimeout(wdtInteractiveTooltipHideTimeout);
59    }).on('mouseleave', '.tooltip', function () {
60        wdtInteractiveTooltipHideTimeout = setTimeout(function () {
61            jQuery('.wdt-tooltip-interactive[data-toggle="tooltip"]').wdtBootstrapTooltip('hide');
62        }, 100);
63    });
64};
65
66/**
67 * Extend jQuery to use our custom function for tooltip
68 */
69jQuery.fn.wdtBootstrapTooltip = jQuery.fn.tooltip;
70
71/**
72 * Extend jQuery to use our custom function for popover
73 */
74jQuery.fn.wdtBootstrapPopover = jQuery.fn.popover;
75/**
76 * Extend jQuery to use our custom function for tabs
77 */
78jQuery.fn.wdtBootstrapTabs = jQuery.fn.tab;
79
80let lastClickedElement = null;
81jQuery(document).on('click', '*', function (e) {
82    lastClickedElement = this;
83});
84
85/**
86
87 /**
88 * Extend jQuery to use AnimateCSS
89 */
90jQuery.fn.extend({
91    animateCss: function (animationName, onEnd) {
92        var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
93        jQuery(this).addClass('animated ' + animationName).one(animationEnd, function () {
94            jQuery(this).removeClass('animated ' + animationName);
95            if (typeof onEnd == 'function') {
96                onEnd();
97            }
98        });
99    },
100    fadeInDown: function () {
101        jQuery(this)
102            .removeClass('hidden')
103            .show()
104            .animateCss('fadeInDown');
105    },
106    fadeInRight: function (onEnd) {
107        jQuery(this)
108            .removeClass('hidden')
109            .show()
110            .animateCss('fadeInRight');
111        if (typeof onEnd == 'function') {
112            onEnd();
113        }
114    },
115    fadeOutDown: function () {
116        var $this = jQuery(this);
117        jQuery(this).animateCss('fadeOutDown', function () {
118            $this
119                .addClass('hidden')
120                .hide();
121        });
122    },
123    fadeOutRight: function () {
124        var $this = jQuery(this);
125        if (!jQuery(lastClickedElement).is('.wdt-apply,.wdt-column-apply, .wdt-apply *')) {
126            return;
127        }
128        jQuery(this).animateCss('fadeOutRight', function () {
129            $this
130                .addClass('hidden')
131                .hide();
132        });
133    },
134    animateFadeIn: function () {
135        var $this = jQuery(this);
136        jQuery(this)
137            .removeClass('hidden')
138            .show()
139            .removeClass('fadeOut')
140            .animateCss('fadeIn', function () {
141                $this
142                    .removeClass('fadeIn')
143                    .removeClass('hidden')
144                    .show()
145            });
146    },
147    animateFadeOut: function (onEnd) {
148        var $this = jQuery(this);
149        jQuery(this)
150            .removeClass('fadeIn')
151            .animateCss('fadeOut', function () {
152                $this
153                    .addClass('hidden')
154                    .removeClass('fadeOut')
155                    .hide();
156                if (typeof onEnd == 'function') {
157                    onEnd();
158                }
159            });
160    }
161});
162
163/**
164 * Helper method to insert at textarea cursor position
165 */
166jQuery.fn.extend({
167    insertAtCaret: function (myValue) {
168        return this.each(function (i) {
169            if (document.selection) {
170                //For browsers like Internet Explorer
171                this.focus();
172                var sel = document.selection.createRange();
173                sel.text = myValue;
174                this.focus();
175            } else if (this.selectionStart || this.selectionStart == '0') {
176                //For browsers like Firefox and Webkit based
177                var startPos = this.selectionStart;
178                var endPos = this.selectionEnd;
179                var scrollTop = this.scrollTop;
180                this.value = this.value.substring(0, startPos) + myValue + this.value.substring(endPos, this.value.length);
181                this.focus();
182                this.selectionStart = startPos + myValue.length;
183                this.selectionEnd = startPos + myValue.length;
184                this.scrollTop = scrollTop;
185            } else {
186                this.value += myValue;
187                this.focus();
188            }
189        });
190    }
191});
192
193(function ($) {
194
195    $(function () {
196
197        /**
198         * Show WordPress warnings before wpDataTables data
199         */
200        $('.card-header:eq(0) > *').not('img, h2, ul.actions, button#wdt-table-id, .clear').prependTo('div.wdt-datatables-admin-wrap');
201
202
203        /**
204         * Attach tooltips
205         */
206        if ($('.wdt-datatables-admin-wrap') && typeof jQuery.fn.wdtBootstrapTooltip !== 'undefined') {
207            $('.wdt-datatables-admin-wrap [data-toggle="tooltip"]:not(.wdt-tooltip-interactive)').wdtBootstrapTooltip();
208            wdtHideTooltip();
209            wdtInteractiveTooltip();
210        }
211
212        /**
213         * Attach HTML Popovers (Hints with images)
214         */
215        if ($('.wdt-datatables-admin-wrap') && typeof jQuery.fn.wdtBootstrapPopover !== 'undefined') {
216            $('[data-toggle="html-popover"]').wdtBootstrapPopover({
217                html: true,
218                content: function () {
219                    var content = $(this).attr("data-popover-content");
220                    return $(content).children(".popover-body").html();
221                },
222                title: function () {
223                    var title = $(this).attr("data-popover-content");
224                    return $(title).children(".popover-heading").html();
225                }
226            });
227        }
228
229        /**
230         * Apply selectpicker
231         */
232        $('.wpdt-c select.selectpicker').selectpicker();
233
234
235        /**
236         * Hide modal dialog on Esc button
237         */
238        $(document).on('keyup', '.modal', function (e) {
239            e.preventDefault();
240            e.stopImmediatePropagation();
241            if (e.which == 27) {
242                $('.modal').modal('hide');
243            }
244        });
245
246        $(document).on('click', 'button.wdt-backend-close', function () {
247            $('#wdt-backend-close-modal').modal('show');
248
249            $('#wdt-backend-close-button').click(function () {
250                $(location).attr('href', wdtWpDataTablesPage.browseTablesUrl);
251            });
252        });
253
254        $(document).on('click', 'button.wdt-backend-chart-close', function () {
255            $('#wdt-backend-close-modal').modal('show');
256
257            $('#wdt-backend-close-button').click(function () {
258                $(location).attr('href', wdtWpDataTablesPage.browseChartsUrl);
259            });
260        });
261
262        $(".wpdt-c .wdt-datatables-admin-wrap div.toggle-switch input[hidden='hidden']").each(function (index, value) {
263            $(this).removeAttr("hidden")
264        });
265
266
267        /**
268         * Get only text when copy shortcode from browse
269         */
270
271        $('.wpdt-c').on('click', '.wdt-copy-shortcode-browse', function (e) {
272            e.preventDefault();
273            e.stopImmediatePropagation();
274
275            var $temp = $("<input>");
276            $($temp).insertAfter($(this));
277            $temp.val($(this).data('shortcode')).select();
278            document.execCommand("copy");
279            $temp.remove();
280            wdtNotify(
281                wpdatatables_edit_strings.success_common,
282                wpdatatables_edit_strings.shortcodeSaved_common,
283                'success'
284            );
285        });
286
287        /**
288         * Logic for plus and minus button on number input field
289         */
290        $('.wdt-btn-number').on("click", function (e) {
291            e.preventDefault();
292
293            var fieldName = $(this).attr('data-field');
294            var type = $(this).attr('data-type');
295            var input = $("input[name='" + fieldName + "']");
296            var currentVal = parseInt(input.val());
297            var fontSizesArr = ['font-size', 'wdt-font-size', 'wdt-table-font-size'];
298            if (!isNaN(currentVal)) {
299                if (type == 'minus') {
300
301                    if (currentVal > input.attr('min')) {
302                        input.val(currentVal - 1).trigger("change");
303                    }
304                    if (parseInt(input.val()) == input.attr('min')) {
305                        $(this).attr('disabled', true);
306                    }
307
308                } else if (type == 'plus') {
309                    input.val(currentVal + 1).trigger("change");
310                    $('.wdt-button-minus').attr('disabled', false);
311                }
312            } else {
313                if (fontSizesArr.includes(fieldName)) {
314                    input.val(parseInt(input.attr('min')));
315                } else {
316                    input.val(1).trigger("change");
317                }
318
319            }
320        });
321        $(".input-number").on("change", function (e) {
322            var inputValue = $(this).val();
323            if (isNaN(inputValue)) {
324                e.preventDefault();
325            }
326        });
327
328        /**
329         * Get only text when copy shortcode
330         */
331        $('.wpdt-c').on('click', '.wdt-copy-shortcode', function (e) {
332            e.preventDefault();
333            e.stopImmediatePropagation();
334
335            var $temp = $("<input>");
336            var $shortcodeType = $(this).data('shortcode-type');
337            $($temp).insertAfter($(this));
338            $temp.val($('#wdt-' + $shortcodeType + '-shortcode-id').text()).select();
339            document.execCommand("copy");
340            $temp.remove();
341            wdtNotify(
342                wpdatatables_edit_strings.success_common,
343                wpdatatables_edit_strings.shortcodeSaved_common,
344                'success'
345            );
346        });
347
348        /**
349         * Input underline animations
350         */
351        $(".collapse")[0] && ($(".collapse").on("show.bs.collapse", function (e) {
352            $(this).closest(".panel").find(".panel-heading").addClass("active")
353        }), $(".collapse").on("hide.bs.collapse", function (e) {
354            $(this).closest(".panel").find(".panel-heading").removeClass("active")
355        }), $(".collapse.in").each(function () {
356            $(this).closest(".panel").find(".panel-heading").addClass("active")
357        }));
358
359        $(".fg-line")[0] && ($("body").on("focus", ".fg-line .form-control:not(.bootstrap-select)", function () {
360            $(this).closest(".fg-line").addClass("fg-toggled")
361        }));
362
363        $("body").on("blur", ".form-control", function () {
364            var p = $(this).closest(".form-group, .input-group")
365                , i = p.find(".form-control").val();
366            p.hasClass("fg-float") ? 0 == i.length && $(this).closest(".fg-line").removeClass("fg-toggled") : $(this).closest(".fg-line").removeClass("fg-toggled")
367        });
368
369        $(".fg-float")[0] && $(".fg-float .form-control").each(function () {
370            var i = $(this).val();
371            0 == !i.length && $(this).closest(".fg-line").addClass("fg-toggled")
372        })
373
374        $('#wpdt-views .nav-item').on('click', function (e) {
375            e.preventDefault()
376            e.stopImmediatePropagation()
377            var view = $(this).data('view'),
378                viewContainer = $('#wpdt-view-container');
379            if (wpdatatable_config.table_type == 'simple') {
380                switch (view) {
381                    case 'desktop':
382                        viewContainer.width('100%');
383                        $('.wpDataTableContainerSimpleTable .wpdtSimpleTable').each(function (i) {
384                            var tempID = '#' + $(this)[i].id;
385                            if (wpdatatable_config.simpleResponsive) {
386                                if ($(tempID).data('basictable'))
387                                    $(tempID).basictable('destroy');
388                            }
389                        })
390                        break;
391                    case 'tablet':
392                        viewContainer.width('1024').css('margin', '0 auto');
393                        if (wpdatatable_config.simpleResponsive) {
394                            $('.wpDataTableContainerSimpleTable .wpdtSimpleTable').each(function (i) {
395                                var tempID = '#' + $(this)[i].id;
396                                $(tempID).basictable({
397                                    containerBreakpoint: 1024,
398                                    tableWrap: true,
399                                    header: !!$(tempID + ' thead').length
400                                });
401                            })
402                        }
403                        break;
404                    case 'mobile':
405                        viewContainer.width('400').css('margin', '0 auto');
406                        if (wpdatatable_config.simpleResponsive) {
407                            $('.wpDataTableContainerSimpleTable .wpdtSimpleTable').each(function (i) {
408                                var tempID = '#' + $(this)[i].id;
409                                $(tempID).basictable({
410                                    containerBreakpoint: 400,
411                                    tableWrap: true,
412                                    showEmptyCells: true,
413                                    header: !!$(tempID + ' thead').length
414                                });
415                            })
416                        }
417                        break;
418                    default:
419                        viewContainer.width('100%');
420                        break;
421                }
422            }
423
424            $(this).addClass('active').siblings().removeClass('active');
425        })
426
427
428    });
429
430})(jQuery);
431
432/**
433 * Hide preloader on window load
434 */
435jQuery(window).on('load', function () {
436    jQuery('.wdt-preload-layer').animateFadeOut();
437});
438
439/**
440 * Show preloader before leaving the page
441 */
442window.onbeforeunload = function (e) {
443    if (window.reportbuilderobj == 'undifined') jQuery('.wdt-preload-layer').animateFadeIn();
444};
445
446
447/**
448 * Growl notification in the right top corner
449 * @param title
450 * @param message
451 * @param type
452 */
453function wdtNotify(title, message, type) {
454
455    if (typeof title == 'undefined') {
456        title = 'info';
457    }
458    if (typeof message == 'undefined') {
459        message = 'info';
460    }
461    if (typeof type == 'undefined') {
462        type = 'info';
463    }
464
465
466    switch (type) {
467        case 'danger':
468            icon = 'wpdt-icon-exclamation-triangle';
469            break;
470        case 'success':
471        default:
472            icon = 'wpdt-icon-check-circle-full';
473            break;
474    }
475
476    let closeString = typeof (wpdatatables_edit_strings) !== 'undefined' ? wpdatatables_edit_strings.close_common : wpdatatables_frontend_strings.close_common_wpdatatables;
477
478    jQuery.growl({
479        icon: icon,
480        title: ' ' + title + ' ',
481        message: message,
482        url: ''
483    }, {
484        element: 'body',
485        type: type,
486        allow_dismiss: true,
487        placement: {
488            from: 'top',
489            align: 'right'
490        },
491        offset: {
492            x: 20,
493            y: 40
494        },
495        spacing: 10,
496        z_index: 100002,
497        delay: 2500,
498        timer: 1000,
499        url_target: '_blank',
500        mouse_over: false,
501        animate: {
502            enter: 'animated fadeIn',
503            exit: 'animated fadeOut'
504        },
505        icon_type: 'class',
506        template: '<div data-growl="container" class="wpdt-c alert" role="alert">' +
507            '<span class="sr-only">' + closeString + '</span>' +
508            '</button>' +
509            '<span data-growl="icon"></span>' +
510            '<span data-growl="title"></span>' +
511            '<span data-growl="message"></span>' +
512            '<a href="#" data-growl="url"></a>' +
513            '</div>'
514    });
515}
516
517/**
518 * Opens WP media uploader on browse button click
519 * @param customUploader
520 */
521
522function openCustomMediaUploader(customUploader = null) {
523    (function ($) {
524        let attachment = '';
525
526        //If the uploader object has already been created, reopen the dialog
527        if (customUploader) {
528            customUploader.open();
529            return;
530        }
531
532        customUploader = wp.media.frames.file_frame = wp.media({
533            title: wpdatatables_edit_strings.selectExcelCsv_common,
534            button: {
535                text: wpdatatables_edit_strings.chooseFile_common
536            },
537            multiple: false,
538            library: {
539                type: 'application/vnd.ms-excel,text/csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
540            }
541        });
542
543        customUploader.on('select', function () {
544            attachment = customUploader.state().get('selection').first().toJSON();
545            $('.input-url-path').val(attachment.url);
546        });
547
548        customUploader.open();
549    })(jQuery);
550}

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.