PageSourceSearch

https://populatia.ro/wp-content/plugins/wpdatatables/assets/js/wpdatatables/admin/common.js?ver=5.8.1

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

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.