PageSourceSearch

https://plantsghar.pk/public/assets/js/aiz-core.js?v=8009

js plantsghar.pk collected 2026-10-10 01:22:04 UTC 133,430 bytes, 3,299 lines download raw bytes

1//custom jquery method for toggle attr
2$.fn.toggleAttr = function (attr, attr1, attr2) {
3    return this.each(function () {
4        var self = $(this);
5        if (self.attr(attr) == attr1) self.attr(attr, attr2);
6        else self.attr(attr, attr1);
7    });
8};
9(function ($) {
10    // USE STRICT
11    "use strict";
12
13    AIZ.data = {
14        csrf: $('meta[name="csrf-token"]').attr("content"),
15        appUrl: $('meta[name="app-url"]').attr("content"),
16        fileBaseUrl: $('meta[name="file-base-url"]').attr("content"),
17    };
18    AIZ.uploader = {
19        data: {
20            selectedFiles: [],
21            selectedFilesObject: [],
22            clickedForDelete: null,
23            allFiles: [],
24            multiple: false,
25            type: "all",
26            next_page_url: null,
27            prev_page_url: null,
28        },
29        removeInputValue: function (id, array, elem) {
30            var selected = array.filter(function (item) {
31                return item !== id;
32            });
33            if (selected.length > 0) {
34                $(elem)
35                    .find(".file-amount")
36                    .html(AIZ.uploader.updateFileHtml(selected));
37            } else {
38                elem.find(".file-amount").html(AIZ.local.choose_file);
39            }
40            $(elem).find(".selected-files").val(selected);
41        },
42        removeAttachment: function () {
43            $(document).on("click", ".remove-attachment", function () {
44                var value = $(this).closest(".file-preview-item").data("id");
45                var selected = $(this)
46                    .closest(".file-preview")
47                    .prev('[data-toggle="aizuploader"]')
48                    .find(".selected-files")
49                    .val()
50                    .split(",")
51                    .map(Number);
52
53                AIZ.uploader.removeInputValue(
54                    value,
55                    selected,
56                    $(this)
57                        .closest(".file-preview")
58                        .prev('[data-toggle="aizuploader"]')
59                );
60                $(this).closest(".file-preview-item").remove();
61            });
62        },
63        deleteUploaderFile: function () {
64            $(".aiz-uploader-delete").each(function () {
65                $(this).on("click", function (e) {
66                    e.preventDefault();
67                    var id = $(this).data("id");
68                    AIZ.uploader.data.clickedForDelete = id;
69                    $("#aizUploaderDelete").modal("show");
70
71                    $(".aiz-uploader-confirmed-delete").on(
72                        "click",
73                        function (e) {
74                            e.preventDefault();
75                            if (e.detail === 1) {
76                                var clickedForDeleteObject =
77                                    AIZ.uploader.data.allFiles[
78                                        AIZ.uploader.data.allFiles.findIndex(
79                                            (x) =>
80                                                x.id ===
81                                                AIZ.uploader.data
82                                                    .clickedForDelete
83                                        )
84                                    ];
85                                $.ajax({
86                                    url:
87                                        AIZ.data.appUrl +
88                                        "/aiz-uploader/destroy/" +
89                                        AIZ.uploader.data.clickedForDelete,
90                                    type: "DELETE",
91                                    dataType: "JSON",
92                                    data: {
93                                        id: AIZ.uploader.data.clickedForDelete,
94                                        _method: "DELETE",
95                                        _token: AIZ.data.csrf,
96                                    },
97                                    success: function () {
98                                        AIZ.uploader.data.selectedFiles =
99                                            AIZ.uploader.data.selectedFiles.filter(
100                                                function (item) {
101                                                    return (
102                                                        item !==
103                                                        AIZ.uploader.data
104                                                            .clickedForDelete
105                                                    );
106                                                }
107                                            );
108                                        AIZ.uploader.data.selectedFilesObject =
109                                            AIZ.uploader.data.selectedFilesObject.filter(
110                                                function (item) {
111                                                    return (
112                                                        item !==
113                                                        clickedForDeleteObject
114                                                    );
115                                                }
116                                            );
117                                        AIZ.uploader.updateUploaderSelected();
118                                        AIZ.uploader.getAllUploads(
119                                            AIZ.data.appUrl +
120                                                "/aiz-uploader/get-uploaded-files"
121                                        );
122                                        AIZ.uploader.data.clickedForDelete =
123                                            null;
124                                        $("#aizUploaderDelete").modal("hide");
125                                    },
126                                });
127                            }
128                        }
129                    );
130                });
131            });
132        },
133        uploadSelect: function () {
134            $(".aiz-uploader-select").each(function () {
135                var elem = $(this);
136                elem.on("click", function (e) {
137                    var value = $(this).data("value");
138                    var valueObject =
139                        AIZ.uploader.data.allFiles[
140                            AIZ.uploader.data.allFiles.findIndex(
141                                (x) => x.id === value
142                            )
143                        ];
144                    // console.log(valueObject);
145
146                    elem.closest(".aiz-file-box-wrap").toggleAttr(
147                        "data-selected",
148                        "true",
149                        "false"
150                    );
151                    if (!AIZ.uploader.data.multiple) {
152                        elem.closest(".aiz-file-box-wrap")
153                            .siblings()
154                            .attr("data-selected", "false");
155                    }
156                    if (!AIZ.uploader.data.selectedFiles.includes(value)) {
157                        if (!AIZ.uploader.data.multiple) {
158                            AIZ.uploader.data.selectedFiles = [];
159                            AIZ.uploader.data.selectedFilesObject = [];
160                        }
161                        AIZ.uploader.data.selectedFiles.push(value);
162                        AIZ.uploader.data.selectedFilesObject.push(valueObject);
163                    } else {
164                        AIZ.uploader.data.selectedFiles =
165                            AIZ.uploader.data.selectedFiles.filter(function (
166                                item
167                            ) {
168                                return item !== value;
169                            });
170                        AIZ.uploader.data.selectedFilesObject =
171                            AIZ.uploader.data.selectedFilesObject.filter(
172                                function (item) {
173                                    return item !== valueObject;
174                                }
175                            );
176                    }
177                    AIZ.uploader.addSelectedValue();
178                    AIZ.uploader.updateUploaderSelected();
179                });
180            });
181        },
182        updateFileHtml: function (array) {
183            var fileText = "";
184            if (array.length > 1) {
185                var fileText = AIZ.local.files_selected;
186            } else {
187                var fileText = AIZ.local.file_selected;
188            }
189            return array.length + " " + fileText;
190        },
191        updateUploaderSelected: function () {
192            $(".aiz-uploader-selected").html(
193                AIZ.uploader.updateFileHtml(AIZ.uploader.data.selectedFiles)
194            );
195        },
196        clearUploaderSelected: function () {
197            $(".aiz-uploader-selected-clear").on("click", function () {
198                AIZ.uploader.data.selectedFiles = [];
199                AIZ.uploader.addSelectedValue();
200                AIZ.uploader.addHiddenValue();
201                AIZ.uploader.resetFilter();
202                AIZ.uploader.updateUploaderSelected();
203                AIZ.uploader.updateUploaderFiles();
204            });
205        },
206        resetFilter: function () {
207            $('[name="aiz-uploader-search"]').val("");
208            $('[name="aiz-show-selected"]').prop("checked", false);
209            $('[name="aiz-uploader-sort"] option[value=newest]').prop(
210                "selected",
211                true
212            );
213        },
214        getAllUploads: function (url, search_key = null, sort_key = null) {
215            $(".aiz-uploader-all").html(
216                '<div class="align-items-center d-flex h-100 justify-content-center w-100"><div class="spinner-border" role="status"></div></div>'
217            );
218            var params = {};
219            if (search_key != null && search_key.length > 0) {
220                params["search"] = search_key;
221            }
222            if (sort_key != null && sort_key.length > 0) {
223                params["sort"] = sort_key;
224            } else {
225                params["sort"] = "newest";
226            }
227            $.get(url, params, function (data, status) {
228                //console.log(data);
229                if (typeof data == "string") {
230                    data = JSON.parse(data);
231                }
232                AIZ.uploader.data.allFiles = data.data;
233                AIZ.uploader.allowedFileType();
234                AIZ.uploader.addSelectedValue();
235                AIZ.uploader.addHiddenValue();
236                //AIZ.uploader.resetFilter();
237                AIZ.uploader.updateUploaderFiles();
238                if (data.next_page_url != null) {
239                    AIZ.uploader.data.next_page_url = data.next_page_url;
240                    $("#uploader_next_btn").removeAttr("disabled");
241                } else {
242                    $("#uploader_next_btn").attr("disabled", true);
243                }
244                if (data.prev_page_url != null) {
245                    AIZ.uploader.data.prev_page_url = data.prev_page_url;
246                    $("#uploader_prev_btn").removeAttr("disabled");
247                } else {
248                    $("#uploader_prev_btn").attr("disabled", true);
249                }
250            });
251        },
252        showSelectedFiles: function () {
253            $('[name="aiz-show-selected"]').on("change", function () {
254                if ($(this).is(":checked")) {
255                    // for (
256                    //     var i = 0;
257                    //     i < AIZ.uploader.data.allFiles.length;
258                    //     i++
259                    // ) {
260                    //     if (AIZ.uploader.data.allFiles[i].selected) {
261                    //         AIZ.uploader.data.allFiles[
262                    //             i
263                    //         ].aria_hidden = false;
264                    //     } else {
265                    //         AIZ.uploader.data.allFiles[
266                    //             i
267                    //         ].aria_hidden = true;
268                    //     }
269                    // }
270                    AIZ.uploader.data.allFiles =
271                        AIZ.uploader.data.selectedFilesObject;
272                } else {
273                    // for (
274                    //     var i = 0;
275                    //     i < AIZ.uploader.data.allFiles.length;
276                    //     i++
277                    // ) {
278                    //     AIZ.uploader.data.allFiles[
279                    //         i
280                    //     ].aria_hidden = false;
281                    // }
282                    AIZ.uploader.getAllUploads(
283                        AIZ.data.appUrl + "/aiz-uploader/get-uploaded-files"
284                    );
285                }
286                AIZ.uploader.updateUploaderFiles();
287            });
288        },
289        searchUploaderFiles: function () {
290            $('[name="aiz-uploader-search"]').on("keyup", function () {
291                var value = $(this).val();
292                AIZ.uploader.getAllUploads(
293                    AIZ.data.appUrl + "/aiz-uploader/get-uploaded-files",
294                    value,
295                    $('[name="aiz-uploader-sort"]').val()
296                );
297                // if (AIZ.uploader.data.allFiles.length > 0) {
298                //     for (
299                //         var i = 0;
300                //         i < AIZ.uploader.data.allFiles.length;
301                //         i++
302                //     ) {
303                //         if (
304                //             AIZ.uploader.data.allFiles[
305                //                 i
306                //             ].file_original_name
307                //                 .toUpperCase()
308                //                 .indexOf(value) > -1
309                //         ) {
310                //             AIZ.uploader.data.allFiles[
311                //                 i
312                //             ].aria_hidden = false;
313                //         } else {
314                //             AIZ.uploader.data.allFiles[
315                //                 i
316                //             ].aria_hidden = true;
317                //         }
318                //     }
319                // }
320                //AIZ.uploader.updateUploaderFiles();
321            });
322        },
323        sortUploaderFiles: function () {
324            $('[name="aiz-uploader-sort"]').on("change", function () {
325                var value = $(this).val();
326                AIZ.uploader.getAllUploads(
327                    AIZ.data.appUrl + "/aiz-uploader/get-uploaded-files",
328                    $('[name="aiz-uploader-search"]').val(),
329                    value
330                );
331
332                // if (value === "oldest") {
333                //     AIZ.uploader.data.allFiles = AIZ.uploader.data.allFiles.sort(
334                //         function(a, b) {
335                //             return (
336                //                 new Date(a.created_at) - new Date(b.created_at)
337                //             );
338                //         }
339                //     );
340                // } else if (value === "smallest") {
341                //     AIZ.uploader.data.allFiles = AIZ.uploader.data.allFiles.sort(
342                //         function(a, b) {
343                //             return a.file_size - b.file_size;
344                //         }
345                //     );
346                // } else if (value === "largest") {
347                //     AIZ.uploader.data.allFiles = AIZ.uploader.data.allFiles.sort(
348                //         function(a, b) {
349                //             return b.file_size - a.file_size;
350                //         }
351                //     );
352                // } else {
353                //     AIZ.uploader.data.allFiles = AIZ.uploader.data.allFiles.sort(
354                //         function(a, b) {
355                //             a = new Date(a.created_at);
356                //             b = new Date(b.created_at);
357                //             return a > b ? -1 : a < b ? 1 : 0;
358                //         }
359                //     );
360                // }
361                //AIZ.uploader.updateUploaderFiles();
362            });
363        },
364        addSelectedValue: function () {
365            for (var i = 0; i < AIZ.uploader.data.allFiles.length; i++) {
366                if (
367                    !AIZ.uploader.data.selectedFiles.includes(
368                        AIZ.uploader.data.allFiles[i].id
369                    )
370                ) {
371                    AIZ.uploader.data.allFiles[i].selected = false;
372                } else {
373                    AIZ.uploader.data.allFiles[i].selected = true;
374                }
375            }
376        },
377        addHiddenValue: function () {
378            for (var i = 0; i < AIZ.uploader.data.allFiles.length; i++) {
379                AIZ.uploader.data.allFiles[i].aria_hidden = false;
380            }
381        },
382        allowedFileType: function () {
383            if (AIZ.uploader.data.type !== "all") {
384                let type = AIZ.uploader.data.type.split(",");
385                AIZ.uploader.data.allFiles = AIZ.uploader.data.allFiles.filter(
386                    function (item) {
387                        return type.includes(item.type);
388                    }
389                );
390            }
391        },
392        updateUploaderFiles: function () {
393            $(".aiz-uploader-all").html(
394                '<div class="align-items-center d-flex h-100 justify-content-center w-100"><div class="spinner-border" role="status"></div></div>'
395            );
396
397            var data = AIZ.uploader.data.allFiles;
398
399            setTimeout(function () {
400                $(".aiz-uploader-all").html(null);
401
402                if (data.length > 0) {
403                    for (var i = 0; i < data.length; i++) {
404                        var thumb = "";
405                        var hidden = "";
406                        if (data[i].type === "image") {
407                            thumb =
408                                '<img src="' +
409                                AIZ.data.fileBaseUrl +
410                                data[i].file_name +
411                                '" class="img-fit">';
412                        } else if(data[i].type === 'video') {
413                            thumb = '<video width="100%" height="100%" controls><source src="'+AIZ.data.fileBaseUrl +  data[i].file_name +'" type="video/mp4">Your browser does not support the video tag.</video>'
414                        } else {
415                            thumb = '<i class="la la-file-text"></i>';
416                        }
417                        var html =
418                            '<div class="aiz-file-box-wrap" aria-hidden="' +
419                            data[i].aria_hidden +
420                            '" data-selected="' +
421                            data[i].selected +
422                            '">' +
423                            '<div class="aiz-file-box">' +
424                            // '<div class="dropdown-file">' +
425                            // '<a class="dropdown-link" data-toggle="dropdown">' +
426                            // '<i class="la la-ellipsis-v"></i>' +
427                            // "</a>" +
428                            // '<div class="dropdown-menu dropdown-menu-right">' +
429                            // '<a href="' +
430                            // AIZ.data.fileBaseUrl +
431                            // data[i].file_name +
432                            // '" target="_blank" download="' +
433                            // data[i].file_original_name +
434                            // "." +
435                            // data[i].extension +
436                            // '" class="dropdown-item"><i class="la la-download mr-2"></i>Download</a>' +
437                            // '<a href="#" class="dropdown-item aiz-uploader-delete" data-id="' +
438                            // data[i].id +
439                            // '"><i class="la la-trash mr-2"></i>Delete</a>' +
440                            // "</div>" +
441                            // "</div>" +
442                            '<div class="card card-file aiz-uploader-select" title="' +
443                            data[i].file_original_name +
444                            "." +
445                            data[i].extension +
446                            '" data-value="' +
447                            data[i].id +
448                            '">' +
449                            '<div class="card-file-thumb">' +
450                            thumb +
451                            "</div>" +
452                            '<div class="card-body ">' +
453                            '<h6 class="d-flex">' +
454                            '<span class="text-truncate title">' +
455                            data[i].file_original_name +
456                            "</span>" +
457                            '<span class="ext flex-shrink-0">.' +
458                            data[i].extension +
459                            "</span>" +
460                            "</h6>" +
461                            "<p>" +
462                            AIZ.extra.bytesToSize(data[i].file_size) +
463                            "</p>" +
464                            "</div>" +
465                            "</div>" +
466                            "</div>" +
467                            "</div>";
468
469                        $(".aiz-uploader-all").append(html);
470                    }
471                } else {
472                    $(".aiz-uploader-all").html(
473                        '<div class="align-items-center d-flex h-100 justify-content-center w-100 nav-tabs"><div class="text-center"><h3>No files found</h3></div></div>'
474                    );
475                }
476                AIZ.uploader.uploadSelect();
477                AIZ.uploader.deleteUploaderFile();
478            }, 300);
479        },
480        inputSelectPreviewGenerate: function (elem) {
481            elem.find(".selected-files").val(AIZ.uploader.data.selectedFiles);
482            elem.next(".file-preview").html(null);
483
484            if (AIZ.uploader.data.selectedFiles.length > 0) {
485                $.post(
486                    AIZ.data.appUrl + "/aiz-uploader/get_file_by_ids",
487                    {
488                        _token: AIZ.data.csrf,
489                        ids: AIZ.uploader.data.selectedFiles.toString(),
490                    },
491                    function (data) {
492                        elem.next(".file-preview").html(null);
493
494                        if (data.length > 0) {
495                            elem.find(".file-amount").html(
496                                AIZ.uploader.updateFileHtml(data)
497                            );
498                            for (var i = 0; i < data.length; i++) {
499                                var thumb = "";
500                                if (data[i].type === "image") {
501                                    thumb =
502                                        '<img src="' +
503                                        data[i].file_name +
504                                        '" class="img-fit">';
505                                }else if(data[i].type === 'video') {
506                                    thumb = '<video width="320" height="240" controls><source src="'+ data[i].file_name +'" type="video/mp4">Your browser does not support the video tag.</video>'
507                                } else {
508                                    thumb = '<i class="la la-file-text"></i>';
509                                }
510                                var html =
511                                    '<div class="d-flex justify-content-between align-items-center mt-2 file-preview-item" data-id="' +
512                                    data[i].id +
513                                    '" title="' +
514                                    data[i].file_original_name +
515                                    "." +
516                                    data[i].extension +
517                                    '">' +
518                                    '<div class="align-items-center align-self-stretch d-flex justify-content-center thumb">' +
519                                    thumb +
520                                    "</div>" +
521                                    '<div class="col body">' +
522                                    '<h6 class="d-flex">' +
523                                    '<span class=" text-truncate " >' +
524                                    data[i].file_original_name +
525                                    "</span>" +
526                                    '<span class="flex-shrink-0 ext">.' +
527                                    data[i].extension +
528                                    "</span>" +
529                                    "</h6>" +
530                                    "<p>" +
531                                    AIZ.extra.bytesToSize(data[i].file_size) +
532                                    "</p>" +
533                                    "</div>" +
534                                    '<div class="remove">' +
535                                    '<button class="btn btn-sm btn-link remove-attachment" type="button">' +
536                                    '<i class="la la-close"></i>' +
537                                    "</button>" +
538                                    "</div>" +
539                                    "</div>";
540
541                                elem.next(".file-preview").append(html);
542                            }
543                        } else {
544                            elem.find(".file-amount").html(
545                                AIZ.local.choose_file
546                            );
547                        }
548                    }
549                );
550            } else {
551                elem.find(".file-amount").html(AIZ.local.choose_file);
552            }
553
554            // if (AIZ.uploader.data.selectedFiles.length > 0) {
555            //     elem.find(".file-amount").html(
556            //         AIZ.uploader.updateFileHtml(AIZ.uploader.data.selectedFiles)
557            //     );
558            //     for (
559            //         var i = 0;
560            //         i < AIZ.uploader.data.selectedFiles.length;
561            //         i++
562            //     ) {
563            //         var index = AIZ.uploader.data.allFiles.findIndex(
564            //             (x) => x.id === AIZ.uploader.data.selectedFiles[i]
565            //         );
566            //         var thumb = "";
567            //         if (AIZ.uploader.data.allFiles[index].type == "image") {
568            //             thumb =
569            //                 '<img src="' +
570            //                 AIZ.data.appUrl +
571            //                 "/public/" +
572            //                 AIZ.uploader.data.allFiles[index].file_name +
573            //                 '" class="img-fit">';
574            //         } else {
575            //             thumb = '<i class="la la-file-text"></i>';
576            //         }
577            //         var html =
578            //             '<div class="d-flex justify-content-between align-items-center mt-2 file-preview-item" data-id="' +
579            //             AIZ.uploader.data.allFiles[index].id +
580            //             '" title="' +
581            //             AIZ.uploader.data.allFiles[index].file_original_name +
582            //             "." +
583            //             AIZ.uploader.data.allFiles[index].extension +
584            //             '">' +
585            //             '<div class="align-items-center align-self-stretch d-flex justify-content-center thumb">' +
586            //             thumb +
587            //             "</div>" +
588            //             '<div class="col body">' +
589            //             '<h6 class="d-flex">' +
590            //             '<span class="text-truncate title">' +
591            //             AIZ.uploader.data.allFiles[index].file_original_name +
592            //             "</span>" +
593            //             '<span class="ext">.' +
594            //             AIZ.uploader.data.allFiles[index].extension +
595            //             "</span>" +
596            //             "</h6>" +
597            //             "<p>" +
598            //             AIZ.extra.bytesToSize(
599            //                 AIZ.uploader.data.allFiles[index].file_size
600            //             ) +
601            //             "</p>" +
602            //             "</div>" +
603            //             '<div class="remove">' +
604            //             '<button class="btn btn-sm btn-link remove-attachment" type="button">' +
605            //             '<i class="la la-close"></i>' +
606            //             "</button>" +
607            //             "</div>" +
608            //             "</div>";
609
610            //         elem.next(".file-preview").append(html);
611            //     }
612            // } else {
613            //     elem.find(".file-amount").html("Choose File");
614            // }
615        },
616        editorImageGenerate: function (elem) {
617            if (AIZ.uploader.data.selectedFiles.length > 0) {
618                for (
619                    var i = 0;
620                    i < AIZ.uploader.data.selectedFiles.length;
621                    i++
622                ) {
623                    var index = AIZ.uploader.data.allFiles.findIndex(
624                        (x) => x.id === AIZ.uploader.data.selectedFiles[i]
625                    );
626                    var thumb = "";
627                    if (AIZ.uploader.data.allFiles[index].type === "image") {
628                        thumb =
629                            '<img src="' +
630                            AIZ.data.fileBaseUrl +
631                            AIZ.uploader.data.allFiles[index].file_name +
632                            '">';
633                        elem[0].insertHTML(thumb);
634                        // console.log(elem);
635                    }
636                }
637            }
638        },
639        dismissUploader: function () {
640            $("#aizUploaderModal").on("hidden.bs.modal", function () {
641                $(".aiz-uploader-backdrop").remove();
642                $("#aizUploaderModal").remove();
643            });
644        },
645        trigger: function (
646            elem = null,
647            from = "",
648            type = "all",
649            selectd = "",
650            multiple = false,
651            callback = null
652        ) {
653            // $("body").append('<div class="aiz-uploader-backdrop"></div>');
654
655            var elem = $(elem);
656            var multiple = multiple;
657            var type = type;
658            var oldSelectedFiles = selectd;
659            if (oldSelectedFiles !== "") {
660                AIZ.uploader.data.selectedFiles = oldSelectedFiles
661                    .split(",")
662                    .map(Number);
663            } else {
664                AIZ.uploader.data.selectedFiles = [];
665            }
666            if ("undefined" !== typeof type && type.length > 0) {
667                AIZ.uploader.data.type = type;
668            }
669
670            if (multiple) {
671                AIZ.uploader.data.multiple = true;
672            } else {
673                AIZ.uploader.data.multiple = false;
674            }
675
676            // setTimeout(function() {
677            $.post(
678                AIZ.data.appUrl + "/aiz-uploader",
679                { _token: AIZ.data.csrf },
680                function (data) {
681                    $("body").append(data);
682                    $("#aizUploaderModal").modal("show");
683                    AIZ.plugins.aizUppy();
684                    AIZ.uploader.getAllUploads(
685                        AIZ.data.appUrl + "/aiz-uploader/get-uploaded-files",
686                        null,
687                        $('[name="aiz-uploader-sort"]').val()
688                    );
689                    AIZ.uploader.updateUploaderSelected();
690                    AIZ.uploader.clearUploaderSelected();
691                    AIZ.uploader.sortUploaderFiles();
692                    AIZ.uploader.searchUploaderFiles();
693                    AIZ.uploader.showSelectedFiles();
694                    AIZ.uploader.dismissUploader();
695
696                    $("#uploader_next_btn").on("click", function () {
697                        if (AIZ.uploader.data.next_page_url != null) {
698                            $('[name="aiz-show-selected"]').prop(
699                                "checked",
700                                false
701                            );
702                            AIZ.uploader.getAllUploads(
703                                AIZ.uploader.data.next_page_url
704                            );
705                        }
706                    });
707
708                    $("#uploader_prev_btn").on("click", function () {
709                        if (AIZ.uploader.data.prev_page_url != null) {
710                            $('[name="aiz-show-selected"]').prop(
711                                "checked",
712                                false
713                            );
714                            AIZ.uploader.getAllUploads(
715                                AIZ.uploader.data.prev_page_url
716                            );
717                        }
718                    });
719
720                    $(".aiz-uploader-search i").on("click", function () {
721                        $(this).parent().toggleClass("open");
722                    });
723
724                    $('[data-toggle="aizUploaderAddSelected"]').on(
725                        "click",
726                        function () {
727                            if (from === "input") {
728                                AIZ.uploader.inputSelectPreviewGenerate(elem);
729                            } else if (from === "direct") {
730                                callback(AIZ.uploader.data.selectedFiles);
731                            }
732                            $("#aizUploaderModal").modal("hide");
733                        }
734                    );
735                }
736            );
737            // }, 50);
738        },
739        initForInput: function () {
740            $(document).on(
741                "click",
742                '[data-toggle="aizuploader"]',
743                function (e) {
744                    if (e.detail === 1) {
745                        var elem = $(this);
746                        var multiple = elem.data("multiple");
747                        var type = elem.data("type");
748                        var oldSelectedFiles = elem
749                            .find(".selected-files")
750                            .val();
751
752                        multiple = !multiple ? "" : multiple;
753                        type = !type ? "" : type;
754                        oldSelectedFiles = !oldSelectedFiles
755                            ? ""
756                            : oldSelectedFiles;
757
758                        AIZ.uploader.trigger(
759                            this,
760                            "input",
761                            type,
762                            oldSelectedFiles,
763                            multiple
764                        );
765                    }
766                }
767            );
768        },
769        previewGenerate: function () {
770            $('[data-toggle="aizuploader"]').each(function () {
771                var $this = $(this);
772                var files = $this.find(".selected-files").val();
773                if (files != "") {
774                    $.post(
775                        AIZ.data.appUrl + "/aiz-uploader/get_file_by_ids",
776                        { _token: AIZ.data.csrf, ids: files },
777                        function (data) {
778                            $this.next(".file-preview").html(null);
779
780                            if (data.length > 0) {
781                                $this
782                                    .find(".file-amount")
783                                    .html(AIZ.uploader.updateFileHtml(data));
784                                for (var i = 0; i < data.length; i++) {
785                                    var thumb = "";
786                                    if (data[i].type === "image") {
787                                        thumb =
788                                            '<img src="' +
789                                            data[i].file_name +
790                                            '" class="img-fit">';
791                                    } else if(data[i].type === 'video') {
792                                        thumb = '<video width="320" height="240" controls><source src="'+ data[i].file_name +'" type="video/mp4">Your browser does not support the video tag.</video>'
793                                    } else {
794                                        thumb = '<i class="la la-file-text"></i>';
795                                    }
796                                    var html =
797                                        '<div class="d-flex justify-content-between align-items-center mt-2 file-preview-item" data-id="' +
798                                        data[i].id +
799                                        '" title="' +
800                                        data[i].file_original_name +
801                                        "." +
802                                        data[i].extension +
803                                        '">' +
804                                        '<div class="align-items-center align-self-stretch d-flex justify-content-center thumb">' +
805                                        thumb +
806                                        "</div>" +
807                                        '<div class="col body">' +
808                                        '<h6 class="d-flex">' +
809                                        '<span class="text-truncate title">' +
810                                        data[i].file_original_name +
811                                        "</span>" +
812                                        '<span class="ext flex-shrink-0">.' +
813                                        data[i].extension +
814                                        "</span>" +
815                                        "</h6>" +
816                                        "<p>" +
817                                        AIZ.extra.bytesToSize(
818                                            data[i].file_size
819                                        ) +
820                                        "</p>" +
821                                        "</div>" +
822                                        '<div class="remove">' +
823                                        '<button class="btn btn-sm btn-link remove-attachment" type="button">' +
824                                        '<i class="la la-close"></i>' +
825                                        "</button>" +
826                                        "</div>" +
827                                        "</div>";
828
829                                    $this.next(".file-preview").append(html);
830                                }
831                            } else {
832                                $this
833                                    .find(".file-amount")
834                                    .html(AIZ.local.choose_file);
835                            }
836                        }
837                    );
838                }
839            });
840        },
841    };
842    AIZ.plugins = {
843        metismenu: function () {
844            $('[data-toggle="aiz-side-menu"]').metisMenu();
845        },
846        bootstrapSelect: function (refresh = "") {
847            $(".aiz-selectpicker").each(function (el) {
848                var $this = $(this);
849                if (!$this.parent().hasClass("bootstrap-select")) {
850                    var selected = $this.data("selected");
851                    if (typeof selected !== "undefined") {
852                        $this.val(selected);
853                    }
854                    $this.selectpicker({
855                        size: 5,
856                        noneSelectedText: AIZ.local.nothing_selected,
857                        virtualScroll: false,
858                    });
859                }
860                if (refresh === "refresh") {
861                    $this.selectpicker("refresh");
862                }
863                if (refresh === "destroy") {
864                    $this.selectpicker("destroy");
865                }
866            });
867        },
868        tagify: function () {
869            $(".aiz-tag-input")
870                .not(".tagify")
871                .each(function () {
872                    var $this = $(this);
873
874                    var maxTags = $this.data("max-tags");
875                    var whitelist = $this.data("whitelist");
876                    var onchange = $this.data("on-change");
877
878                    maxTags = !maxTags ? Infinity : maxTags;
879                    whitelist = !whitelist ? [] : whitelist;
880
881                    $this.tagify({
882                        maxTags: maxTags,
883                        whitelist: whitelist,
884                        dropdown: {
885                            enabled: 1,
886                        },
887                    });
888                    try {
889                        callback = eval(onchange);
890                    } catch (e) {
891                        var callback = "";
892                    }
893                    if (typeof callback == "function") {
894                        $this.on("removeTag", function () {
895                            callback();
896                        });
897                        $this.on("add", function () {
898                            callback();
899                        });
900                    }
901                });
902        },
903        textEditor: function () {
904            $(".aiz-text-editor").each(function (el) {
905                var $this = $(this);
906                var buttons = $this.data("buttons");
907                var minHeight = $this.data("min-height");
908                var placeholder = $this.attr("placeholder");
909                var format = $this.data("format");
910
911                buttons = !buttons
912                    ? [
913                          ["font", ["bold", "underline", "italic", "clear"]],
914                          ["para", ["ul", "ol", "paragraph"]],
915                          ["style", ["style"]],
916                          ["color", ["color"]],
917                          ["table", ["table"]],
918                          ["insert", ["link", "picture", "video"]],
919                          ["view", ["fullscreen", "undo", "redo"]],
920                      ]
921                    : buttons;
922                placeholder = !placeholder ? "" : placeholder;
923                minHeight = !minHeight ? 200 : minHeight;
924                format = typeof format == "undefined" ? false : format;
925
926                $this.summernote({
927                    toolbar: buttons,
928                    placeholder: placeholder,
929                    disableDragAndDrop: true,
930                    height: minHeight,
931                    callbacks: {
932                        onImageUpload: function (data) {
933                            data.pop();
934                        },
935                        onPaste: function (e) {
936                            if (format) {
937                                var bufferText = (
938                                    (e.originalEvent || e).clipboardData ||
939                                    window.clipboardData
940                                ).getData("Text");
941                                e.preventDefault();
942                                document.execCommand(
943                                    "insertText",
944                                    false,
945                                    bufferText
946                                );
947                            }
948                        },
949                    },
950                });
951
952                var nativeHtmlBuilderFunc = $this.summernote(
953                    "module",
954                    "videoDialog"
955                ).createVideoNode;
956
957                $this.summernote("module", "videoDialog").createVideoNode =
958                    function (url) {
959                        var wrap = $(
960                            '<div class="embed-responsive embed-responsive-16by9"></div>'
961                        );
962                        var html = nativeHtmlBuilderFunc(url);
963                        html = $(html).addClass("embed-responsive-item");
964                        return wrap.append(html)[0];
965                    };
966            });
967        },
968        dateRange: function () {
969            $(".aiz-date-range").each(function () {
970                var $this = $(this);
971                var today = moment().startOf("day");
972                var value = $this.val();
973                var startDate = false;
974                var minDate = false;
975                var maxDate = false;
976                var advncdRange = false;
977                var ranges = {
978                    Today: [moment(), moment()],
979                    Yesterday: [
980                        moment().subtract(1, "days"),
981                        moment().subtract(1, "days"),
982                    ],
983                    "Last 7 Days": [moment().subtract(6, "days"), moment()],
984                    "Last 30 Days": [moment().subtract(29, "days"), moment()],
985                    "This Month": [
986                        moment().startOf("month"),
987                        moment().endOf("month"),
988                    ],
989                    "Last Month": [
990                        moment().subtract(1, "month").startOf("month"),
991                        moment().subtract(1, "month").endOf("month"),
992                    ],
993                };
994
995                var single = $this.data("single");
996                var monthYearDrop = $this.data("show-dropdown");
997                var format = $this.data("format");
998                var separator = $this.data("separator");
999                var pastDisable = $this.data("past-disable");
1000                var futureDisable = $this.data("future-disable");
1001                var timePicker = $this.data("time-picker");
1002                var timePickerIncrement = $this.data("time-gap");
1003                var advncdRange = $this.data("advanced-range");
1004
1005                single = !single ? false : single;
1006                monthYearDrop = !monthYearDrop ? false : monthYearDrop;
1007                format = !format ? "YYYY-MM-DD" : format;
1008                separator = !separator ? " / " : separator;
1009                minDate = !pastDisable ? minDate : today;
1010                maxDate = !futureDisable ? maxDate : today;
1011                timePicker = !timePicker ? false : timePicker;
1012                timePickerIncrement = !timePickerIncrement
1013                    ? 1
1014                    : timePickerIncrement;
1015                ranges = !advncdRange ? "" : ranges;
1016
1017                $this.daterangepicker({
1018                    singleDatePicker: single,
1019                    showDropdowns: monthYearDrop,
1020                    minDate: minDate,
1021                    maxDate: maxDate,
1022                    timePickerIncrement: timePickerIncrement,
1023                    autoUpdateInput: false,
1024                    ranges: ranges,
1025                    locale: {
1026                        format: format,
1027                        separator: separator,
1028                        applyLabel: "Select",
1029                        cancelLabel: "Clear",
1030                    },
1031                });
1032                if (single) {
1033                    $this.on("apply.daterangepicker", function (ev, picker) {
1034                        $this.val(picker.startDate.format(format));
1035                    });
1036                } else {
1037                    $this.on("apply.daterangepicker", function (ev, picker) {
1038                        $this.val(
1039                            picker.startDate.format(format) +
1040                                separator +
1041                                picker.endDate.format(format)
1042                        );
1043                    });
1044                }
1045
1046                $this.on("cancel.daterangepicker", function (ev, picker) {
1047                    $this.val("");
1048                });
1049            });
1050        },
1051        timePicker: function () {
1052            $(".aiz-time-picker").each(function () {
1053                var $this = $(this);
1054
1055                var minuteStep = $this.data("minute-step");
1056                var defaultTime = $this.data("default");
1057
1058                minuteStep = !minuteStep ? 10 : minuteStep;
1059                defaultTime = !defaultTime ? "00:00" : defaultTime;
1060
1061                $this.timepicker({
1062                    template: "dropdown",
1063                    minuteStep: minuteStep,
1064                    defaultTime: defaultTime,
1065                    icons: {
1066                        up: "las la-angle-up",
1067                        down: "las la-angle-down",
1068                    },
1069                    showInputs: false,
1070                });
1071            });
1072        },
1073        colorPicker: function () {
1074            $(".aiz-color-picker").on("change", function () {
1075                var $this = $(this);
1076                let value = $this.val();
1077                $this.parent().parent().siblings(".aiz-color-input").val(value);
1078            });
1079            $(".aiz-color-input").on("change", function () {
1080                var $this = $(this);
1081                let value = $this.val();
1082                $(this)
1083                    .siblings(".input-group-append")
1084                    .children(".input-group-text")
1085                    .children(".aiz-color-picker")
1086                    .val(value);
1087            });
1088        },
1089        fooTable: function () {
1090            $(".aiz-table").each(function () {
1091                var $this = $(this);
1092
1093                var empty = $this.data("empty");
1094                empty = !empty ? AIZ.local.nothing_found : empty;
1095
1096                $this.footable({
1097                    breakpoints: {
1098                        xs: 576,
1099                        sm: 768,
1100                        md: 992,
1101                        lg: 1200,
1102                        xl: 1400,
1103                    },
1104                    cascade: true,
1105                    on: {
1106                        "ready.ft.table": function (e, ft) {
1107                            AIZ.extra.deleteConfirm();
1108                            AIZ.plugins.bootstrapSelect("refresh");
1109                        },
1110                    },
1111                    empty: empty,
1112                });
1113            });
1114        },
1115        sectionFooTable: function (section) {
1116            var $this = $(section+" .aiz-table");
1117
1118            var empty = $this.data("empty");
1119            empty = !empty ? AIZ.local.nothing_found : empty;
1120
1121            $this.footable({
1122                breakpoints: {
1123                    xs: 576,
1124                    sm: 768,
1125                    md: 992,
1126                    lg: 1200,
1127                    xl: 1400,
1128                },
1129                cascade: true,
1130                on: {
1131                    "ready.ft.table": function (e, ft) {
1132                        AIZ.extra.deleteConfirm();
1133                        AIZ.plugins.bootstrapSelect("refresh");
1134                    },
1135                },
1136                empty: empty,
1137            });
1138        },
1139        notify: function (type = "dark", message = "") {
1140            $.notify(
1141                {
1142                    // options
1143                    message: message,
1144                },
1145                {
1146                    // settings
1147                    showProgressbar: true,
1148                    delay: 2500,
1149                    mouse_over: "pause",
1150                    placement: {
1151                        from: "bottom",
1152                        align: "left",
1153                    },
1154                    animate: {
1155                        enter: "animated fadeInUp",
1156                        exit: "animated fadeOutDown",
1157                    },
1158                    type: type,
1159                    template:
1160                        '<div data-notify="container" class="aiz-notify alert alert-{0}" role="alert">
1160' +
1161                        '<button type="button" aria-hidden="true" data-notify="dismiss" class="close"><i class="las la-times"></i></button>' +
1162                        '<span data-notify="message">{2}</span>' +
1163                        '<div class="progress" data-notify="progressbar">' +
1164                        '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"></div>' +
1165                        "</div>" +
1166                        "</div>",
1167                }
1168            );
1169        },
1170        aizUppy: function () {
1171            if ($("#aiz-upload-files").length > 0) {
1172                var IMAGE_EXTENSIONS = ['jpg','jpeg','png','svg','webp','gif'];
1173                var MAX_IMAGE_SIZE = 614400; // 600 KB in bytes
1174
1175                var uppy = Uppy.Core({
1176                    autoProceed: true,
1177                    onBeforeFileAdded: function (currentFile) {
1178                        var ext = currentFile.name.split('.').pop().toLowerCase();
1179                        if (IMAGE_EXTENSIONS.indexOf(ext) !== -1 && currentFile.size > MAX_IMAGE_SIZE) {
1180                            AIZ.plugins.notify('danger', currentFile.name + ': ' + 'Image size must not exceed 600 KB.');
1181                            return false;
1182                        }
1183                        return true;
1184                    },
1185                });
1186                uppy.use(Uppy.Dashboard, {
1187                    target: "#aiz-upload-files",
1188                    inline: true,
1189                    showLinkToFileUploadResult: false,
1190                    showProgressDetails: true,
1191                    hideCancelButton: true,
1192                    hidePauseResumeButton: true,
1193                    hideUploadButton: true,
1194                    proudlyDisplayPoweredByUppy: false,
1195                    locale: {
1196                        strings: {
1197                            addMoreFiles: AIZ.local.add_more_files,
1198                            addingMoreFiles: AIZ.local.adding_more_files,
1199                            dropPaste:
1200                                AIZ.local.drop_files_here_paste_or +
1201                                " %{browse}",
1202                            browse: AIZ.local.browse,
1203                            uploadComplete: AIZ.local.upload_complete,
1204                            uploadPaused: AIZ.local.upload_paused,
1205                            resumeUpload: AIZ.local.resume_upload,
1206                            pauseUpload: AIZ.local.pause_upload,
1207                            retryUpload: AIZ.local.retry_upload,
1208                            cancelUpload: AIZ.local.cancel_upload,
1209                            xFilesSelected: {
1210                                0: "%{smart_count} " + AIZ.local.file_selected,
1211                                1: "%{smart_count} " + AIZ.local.files_selected,
1212                            },
1213                            uploadingXFiles: {
1214                                0:
1215                                    AIZ.local.uploading +
1216                                    " %{smart_count} " +
1217                                    AIZ.local.file,
1218                                1:
1219                                    AIZ.local.uploading +
1220                                    " %{smart_count} " +
1221                                    AIZ.local.files,
1222                            },
1223                            processingXFiles: {
1224                                0:
1225                                    AIZ.local.processing +
1226                                    " %{smart_count} " +
1227                                    AIZ.local.file,
1228                                1:
1229                                    AIZ.local.processing +
1230                                    " %{smart_count} " +
1231                                    AIZ.local.files,
1232                            },
1233                            uploading: AIZ.local.uploading,
1234                            complete: AIZ.local.complete,
1235                        },
1236                    },
1237                });
1238                uppy.use(Uppy.XHRUpload, {
1239
1240                    endpoint: AIZ.data.appUrl + "/aiz-uploader/upload",
1241                    fieldName: "aiz_file",
1242                    formData: true,
1243                    headers: {
1244                        "X-CSRF-TOKEN": AIZ.data.csrf,
1245                    },
1246                });
1247                uppy.on("upload-success", function (file, response) {
1248                    // Server returned a 422 with an error message (e.g. image > 600 KB)
1249                    if (response && response.status === 422) {
1250                        var body = response.body;
1251                        var msg = (body && body.error) ? body.error : AIZ.local.something_went_wrong;
1252                        AIZ.plugins.notify('danger', msg);
1253                        uppy.removeFile(file.id);
1254                        return;
1255                    }
1256                    AIZ.uploader.getAllUploads(
1257                        AIZ.data.appUrl + "/aiz-uploader/get-uploaded-files"
1258                    );
1259                });
1260                uppy.on("upload-error", function (file, error, response) {
1261                    var msg = AIZ.local.something_went_wrong;
1262                    if (response && response.body && response.body.error) {
1263                        msg = response.body.error;
1264                    } else if (error && error.message) {
1265                        msg = error.message;
1266                    }
1267                    AIZ.plugins.notify('danger', msg);
1268                    uppy.removeFile(file.id);
1269                });
1270            }
1271        },
1272        tooltip: function () {
1273            $("body")
1274                .tooltip({ selector: '[data-toggle="tooltip"]' })
1275                .click(function () {
1276                    $('[data-toggle="tooltip"]').tooltip("hide");
1277                });
1278        },
1279        countDown: function () {
1280            if ($(".aiz-count-down").length > 0) {
1281                $(".aiz-count-down").each(function () {
1282                    var $this = $(this);
1283                    var date = $this.data("date");
1284                    // console.log(date)
1285
1286                    $this
1287                        .countdown(date)
1288                        .on("update.countdown", function (event) {
1289                            var $this = $(this).html(
1290                                event.strftime(
1291                                    "" +
1292                                        '<div class="countdown-item"><span class="countdown-digit">%-D</span></div><span class="countdown-separator">:</span>' +
1293                                        '<div class="countdown-item"><span class="countdown-digit">%H</span></div><span class="countdown-separator">:</span>' +
1294                                        '<div class="countdown-item"><span class="countdown-digit">%M</span></div><span class="countdown-separator">:</span>' +
1295                                        '<div class="countdown-item"><span class="countdown-digit">%S</span></div>'
1296                                )
1297                            );
1298                        });
1299                });
1300            }
1301        },
1302        countDownBox: function () {
1303            if ($(".aiz-count-down-box").length > 0) {
1304                $(".aiz-count-down-box").each(function () {
1305                    var $this = $(this);
1306                    var date = $this.data("date");
1307                    // console.log(date)
1308
1309                    $this
1310                        .countdown(date)
1311                        .on("update.countdown", function (event) {
1312                            var $this = $(this).html(
1313                                event.strftime(
1314                                    "" +
1315                                        '<div class="countdown-item"><span class="countdown-digit">%-D</span><span class="countdown-name">DAY</span></div><span class="countdown-separator">:</span>' +
1316                                        '<div class="countdown-item"><span class="countdown-digit">%H</span><span class="countdown-name">HRS</span></div><span class="countdown-separator">:</span>' +
1317                                        '<div class="countdown-item"><span class="countdown-digit">%M</span><span class="countdown-name">MIN</span></div><span class="countdown-separator">:</span>' +
1318                                        '<div class="countdown-item"><span class="countdown-digit">%S</span><span class="countdown-name">SEC</span></div>'
1319                                )
1320                            );
1321                        });
1322                });
1323            }
1324        },
1325        countDownCircle: function () {
1326
1327            // default values
1328            let cx = 30, cy = 30, r = 30, stroke_length=190;
1329
1330            let homepage = $("#selected_homepage").val();
1331
1332            if (homepage && homepage == "thecore") {
1333                cx = cy = r = 23;
1334                stroke_length=138;
1335            }
1336
1337            let html =
1338                '<div id="time">' +
1339                    '<div class="circle"><svg><circle cx="'+cx+'" cy="'+cy+'" r="'+r+'"></circle><circle cx="'+cx+'" cy="'+cy+'" r="'+r+'" id="dd"></circle></svg><div id="days" class="mb-2">00 <br><span>Day</span></div></div>' +
1340                    '<div class="circle"><svg><circle cx="'+cx+'" cy="'+cy+'" r="'+r+'"></circle><circle cx="'+cx+'" cy="'+cy+'" r="'+r+'" id="hh"></circle></svg><div id="hours" class="mb-2">00 <br><span>Hrs</span></div></div>' +
1341                    '<div class="circle"><svg><circle cx="'+cx+'" cy="'+cy+'" r="'+r+'"></circle><circle cx="'+cx+'" cy="'+cy+'" r="'+r+'" id="mm"></circle></svg><div id="minutes" class="mb-2">00 <br><span>Min</span></div></div>' +
1342                    '<div class="circle"><svg><circle cx="'+cx+'" cy="'+cy+'" r="'+r+'"></circle><circle cx="'+cx+'" cy="'+cy+'" r="'+r+'" id="ss"></circle></svg><div id="seconds" class="mb-2">00 <br><span>Sec</span></div></div>' +
1343                '</div>';
1344
1345            if ($(".aiz-count-down-circle").length > 0) {
1346                $(".aiz-count-down-circle").each(function () {
1347                    var $this = $(this);
1348                    $this.html(html);
1349
1350                    let days = $this.find("#days");
1351                    let hours = $this.find("#hours");
1352                    let minutes = $this.find("#minutes");
1353                    let seconds = $this.find("#seconds");
1354
1355                    let dd = $this.find("#dd");
1356                    let hh = $this.find("#hh");
1357                    let mm = $this.find("#mm");
1358                    let ss = $this.find("#ss");
1359
1360                    // Date Format mm/dd/yyyy
1361                    var endDate = $this.attr("end-date");
1362                    let now = new Date(endDate).getTime();
1363                    let x = setInterval(function () {
1364                        let CountDown = new Date().getTime();
1365                        let distance = now - CountDown;
1366                        if (distance > 0) {
1367                            // Time calculation for days, hours, minutes & seconds
1368                            let d = Math.floor(
1369                                distance / (1000 * 60 * 60 * 24)
1370                            );
1371                            let h = Math.floor(
1372                                (distance % (1000 * 60 * 60 * 24)) /
1373                                    (1000 * 60 * 60)
1374                            );
1375                            let m = Math.floor(
1376                                (distance % (1000 * 60 * 60)) / (1000 * 60)
1377                            );
1378                            let s = Math.floor((distance % (1000 * 60)) / 1000);
1379
1380                            // Output the results in elements with id
1381                            days.html(d + "<br><span>Day</span>");
1382                            hours.html(h + "<br><span>Hrs</span>");
1383                            minutes.html(m + "<br><span>Min</span>");
1384                            seconds.html(s + "<br><span>Sec</span>");
1385
1386                            // Animate stroke
1387                            dd.css("strokeDashoffset", stroke_length - (stroke_length * d) / 365); // 365 days in a year
1388                            hh.css("strokeDashoffset", stroke_length - (stroke_length * h) / 24); // 24 hours in a day
1389                            mm.css("strokeDashoffset", stroke_length - (stroke_length * m) / 60); // 60 minutes in an hour
1390                            ss.css("strokeDashoffset", stroke_length - (stroke_length * s) / 60);
1390 // 60 seconds in a minute
1391                        } else {
1392                            // If Countdown is over
1393                            clearInterval(x);
1394                        }
1395                    });
1396                });
1397            }
1398        },
1399       slickCarousel: function () {
1400            // Initialize category section slider on mobile
1401            $(document).ready(function () {
1402                function initCategorySlider() {
1403                    if (window.innerWidth <= 576) {
1404                        // Destroy existing slider if any
1405                        if ($('.mobile-category-slider').hasClass('slick-initialized')) {
1406                            $('.mobile-category-slider').slick('unslick');
1407                        }
1408                        // Initialize new slider
1409                        $('.mobile-category-slider').slick({
1410                            slidesToShow: 1.5,
1411                            slidesToScroll: 1,
1412                            arrows: false,
1413                            dots: false,
1414                            infinite: false,
1415                            variableWidth: false,
1416                            centerMode: false,
1417                            adaptiveHeight: false,
1418                            autoplay: true,
1419                            utoplaySpeed: 3000 // 3 seconds
1420                        });
1421                        // Equalize heights after initialization
1422                        setTimeout(equalizeSlideHeights, 100);
1423                    } else {
1424                        // Destroy slider on larger screens
1425                        if ($('.mobile-category-slider').hasClass('slick-initialized')) {
1426                            $('.mobile-category-slider').slick('unslick');
1427                        }
1428                    }
1429                }
1430                function equalizeSlideHeights() {
1431                    let maxHeight = 0;
1432                    $('.category-slide').each(function () {
1433                        $(this).css('height', 'auto');
1434                        const slideHeight = $(this).outerHeight();
1435                        if (slideHeight > maxHeight) {
1436                            maxHeight = slideHeight;
1437                        }
1438                    });
1439                    $('.category-slide').css('height', maxHeight + 'px');
1440                    $('.mobile-category-slider').slick('setPosition');
1441                }
1442                // Initialize on load
1443                initCategorySlider();
1444
1445                // Reinitialize on resize
1446                $(window).on('resize', function () {
1447                    initCategorySlider();
1448                });
1449            });
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459            $(".aiz-carousel")
1460                .not(".slick-initialized")
1461                .each(function () {
1462                    var $this = $(this);
1463
1464                    var slidesPerViewXs = $this.data("xs-items");
1465                    var slidesPerViewSm = $this.data("sm-items");
1466                    var slidesPerViewMd = $this.data("md-items");
1467                    var slidesPerViewLg = $this.data("lg-items");
1468                    var slidesPerViewXl = $this.data("xl-items");
1469                    var slidesPerView = $this.data("items");
1470
1471                    var slidesCenterMode = $this.data("center");
1472                    var slidesArrows = $this.data("arrows");
1473                    var slidesDots = $this.data("dots");
1474                    var slidesRows = $this.data("rows");
1475                    var slidesAutoplay = $this.data("autoplay");
1476                    var slidesAutoplaySpeed = $this.data("autoplay-speed");
1477                    var slidesFade = $this.data("fade");
1478                    var asNavFor = $this.data("nav-for");
1479                    var infinite = $this.data("infinite");
1480                    var focusOnSelect = $this.data("focus-select");
1481                    var adaptiveHeight = $this.data("auto-height");
1482                    var variableWidth = $this.data("variableWidth");
1483
1484                    var vertical = $this.data("vertical");
1485                    var verticalXs = $this.data("vertical-xs");
1486                    var verticalSm = $this.data("vertical-sm");
1487                    var verticalMd = $this.data("vertical-md");
1488                    var verticalLg = $this.data("vertical-lg");
1489                    var verticalXl = $this.data("vertical-xl");
1490
1491                    slidesPerView = !slidesPerView ? 1 : slidesPerView;
1492                    slidesPerViewXl = !slidesPerViewXl
1493                        ? slidesPerView
1494                        : slidesPerViewXl;
1495                    slidesPerViewLg = !slidesPerViewLg
1496                        ? slidesPerViewXl
1497                        : slidesPerViewLg;
1498                    slidesPerViewMd = !slidesPerViewMd
1499                        ? slidesPerViewLg
1500                        : slidesPerViewMd;
1501                    slidesPerViewSm = !slidesPerViewSm
1502                        ? slidesPerViewMd
1503                        : slidesPerViewSm;
1504                    slidesPerViewXs = !slidesPerViewXs
1505                        ? slidesPerViewSm
1506                        : slidesPerViewXs;
1507
1508                    vertical = !vertical ? false : vertical;
1509                    verticalXl =
1510                        typeof verticalXl == "undefined"
1511                            ? vertical
1512                            : verticalXl;
1513                    verticalLg =
1514                        typeof verticalLg == "undefined"
1515                            ? verticalXl
1516                            : verticalLg;
1517                    verticalMd =
1518                        typeof verticalMd == "undefined"
1519                            ? verticalLg
1520                            : verticalMd;
1521                    verticalSm =
1522                        typeof verticalSm == "undefined"
1523                            ? verticalMd
1524                            : verticalSm;
1525                    verticalXs =
1526                        typeof verticalXs == "undefined"
1527                            ? verticalSm
1528                            : verticalXs;
1529
1530                    slidesCenterMode = !slidesCenterMode
1531                        ? false
1532                        : slidesCenterMode;
1533                    slidesArrows = !slidesArrows ? false : slidesArrows;
1534                    slidesDots = !slidesDots ? false : slidesDots;
1535                    slidesRows = !slidesRows ? 1 : slidesRows;
1536                    slidesAutoplay = !slidesAutoplay ? false : slidesAutoplay;
1537                    slidesAutoplaySpeed = !slidesAutoplaySpeed
1538                        ? "5000"
1539                        : slidesAutoplaySpeed;
1540                    slidesFade = !slidesFade ? false : slidesFade;
1541                    asNavFor = !asNavFor ? null : asNavFor;
1542                    infinite = !infinite ? false : infinite;
1543                    focusOnSelect = !focusOnSelect ? false : focusOnSelect;
1544                    adaptiveHeight = !adaptiveHeight ? false : adaptiveHeight;
1545                    variableWidth = !variableWidth ? false : variableWidth;
1546
1547                    var slidesRtl =
1548                        $("html").attr("dir") === "rtl" && !vertical
1549                            ? true
1550                            : false;
1551                    var slidesRtlXL =
1552                        $("html").attr("dir") === "rtl" && !verticalXl
1553                            ? true
1554                            : false;
1555                    var slidesRtlLg =
1556                        $("html").attr("dir") === "rtl" && !verticalLg
1557                            ? true
1558                            : false;
1559                    var slidesRtlMd =
1560                        $("html").attr("dir") === "rtl" && !verticalMd
1561                            ? true
1562                            : false;
1563                    var slidesRtlSm =
1564                        $("html").attr("dir") === "rtl" && !verticalSm
1565                            ? true
1566                            : false;
1567                    var slidesRtlXs =
1568                        $("html").attr("dir") === "rtl" && !verticalXs
1569                            ? true
1570                            : false;
1571
1572                    $this.slick({
1573                        slidesToShow: slidesPerView,
1574                        autoplay: slidesAutoplay,
1575                        autoplaySpeed: slidesAutoplaySpeed,
1576                        dots: slidesDots,
1577                        arrows: slidesArrows,
1578                        infinite: infinite,
1579                        vertical: vertical,
1580                        rtl: slidesRtl,
1581                        rows: slidesRows,
1582                        centerPadding: "0px",
1583                        centerMode: slidesCenterMode,
1584                        fade: slidesFade,
1585                        asNavFor: asNavFor,
1586                        focusOnSelect: focusOnSelect,
1587                        adaptiveHeight: adaptiveHeight,
1588                        slidesToScroll: 1,
1589                        variableWidth: variableWidth,
1590                        prevArrow:
1591                            '<button type="button" class="slick-prev"><i class="las la-angle-left"></i></button>',
1592                        nextArrow:
1593                            '<button type="button" class="slick-next"><i class="las la-angle-right"></i></button>',
1594                        responsive: [
1595                            {
1596                                breakpoint: 1500,
1597                                settings: {
1598                                    slidesToShow: slidesPerViewXl,
1599                                    vertical: verticalXl,
1600                                    rtl: slidesRtlXL,
1601                                },
1602                            },
1603                            {
1604                                breakpoint: 1200,
1605                                settings: {
1606                                    slidesToShow: slidesPerViewLg,
1607                                    vertical: verticalLg,
1608                                    rtl: slidesRtlLg,
1609                                },
1610                            },
1611                            {
1612                                breakpoint: 992,
1613                                settings: {
1614                                    slidesToShow: slidesPerViewMd,
1615                                    vertical: verticalMd,
1616                                    rtl: slidesRtlMd,
1617                                },
1618                            },
1619                            {
1620                                breakpoint: 768,
1621                                settings: {
1622                                    slidesToShow: slidesPerViewSm,
1623                                    vertical: verticalSm,
1624                                    rtl: slidesRtlSm,
1625                                },
1626                            },
1627                            {
1628                                breakpoint: 576,
1629                                settings: {
1630                                    slidesToShow: slidesPerViewXs,
1631                                    vertical: verticalXs,
1632                                    rtl: slidesRtlXs,
1633                                },
1634                            },
1635                        ],
1636                    });
1637                });
1638        },
1639        chart: function (selector, config) {
1640            if (!$(selector).length) return;
1641
1642            $(selector).each(function () {
1643                var $this = $(this);
1644
1645                var aizChart = new Chart($this, config);
1646            });
1647        },
1648        noUiSlider: function () {
1649            if ($(".aiz-range-slider")[0]) {
1650                $(".aiz-range-slider").each(function () {
1651                    var c = document.getElementById("input-slider-range"),
1652                        d = document.getElementById("input-slider-range-value-low"),
1653                        e = document.getElementById("input-slider-range-value-high"),
1654                        f = [d, e];
1655
1656                    noUiSlider.create(c, {
1657                        start: [
1658                            parseInt(d.getAttribute("data-range-value-low")),
1659                            parseInt(e.getAttribute("data-range-value-high")),
1660                        ],
1661                        connect: true,
1662                        range: {
1663                            min: parseInt(c.getAttribute("data-range-value-min")),
1664                            max: parseInt(c.getAttribute("data-range-value-max")),
1665                        },
1666                    });
1667
1668
1669                    const handles = c.querySelectorAll(".noUi-handle");
1670
1671                    handles.forEach((handle, index) => {
1672                        const touchArea = handle.querySelector(".noUi-touch-area");
1673
1674
1675                        const valueText = document.createElement("span");
1676                        valueText.classList.add("slider-value-text");
1677                        valueText.textContent = f[index].textContent || 0;
1678                        touchArea.appendChild(valueText);
1679
1680                        valueText.style.position = "absolute";
1681                        valueText.style.top = "-30px";
1682                        valueText.style.left = "50%";
1683                        valueText.style.transform = "translateX(-50%)";
1684                        valueText.style.fontSize = "14px";
1685                        valueText.style.color = "#fff";
1686                        valueText.style.background = "rgba(0, 0, 0, 0.4)";
1687                        valueText.style.padding = "4px 8px";
1688                        valueText.style.borderRadius = "4px";
1689                        valueText.style.whiteSpace = "nowrap";
1690                        valueText.style.pointerEvents = "none";
1691                        valueText.style.transition = "opacity 0.3s ease";
1692
1693
1694                    });
1695
1696
1697                    c.noUiSlider.on("update", function (a, b) {
1698                        f[b].textContent = a[b]; // existing element
1699                        const handle = c.querySelectorAll(".noUi-handle")[b];
1700                        const label = handle.querySelector(".slider-value-text");
1701                        let value = Math.round(a[b]);
1702                        if (label) label.textContent = value.toLocaleString();
1703                        d.textContent = "0";
1704                        e.textContent = parseInt(c.getAttribute("data-range-value-max")).toLocaleString();
1705                        // label.style.display = "none";
1706                    });
1707
1708
1709                    c.noUiSlider.on("change", function (a, b) {
1710                        rangefilter(a);
1711                    });
1712                });
1713            }
1714        },
1715
1716        zoom: function () {
1717            if ($(".img-zoom")[0]) {
1718                $(".img-zoom").zoom({
1719                    magnify: 1.5,
1720                });
1721                if (
1722                    "ontouchstart" in window ||
1723                    navigator.maxTouchPoints > 0 ||
1724                    navigator.msMaxTouchPoints > 0
1725                ) {
1726                    $(".img-zoom").trigger("zoom.destroy");
1727                }
1728            }
1729        },
1730        jsSocials: function () {
1731            if ($(".aiz-share")[0]) {
1732                $(".aiz-share").jsSocials({
1733                    showLabel: false,
1734                    showCount: false,
1735                    shares: [
1736                        {
1737                            share: "email",
1738                            logo: "lar la-envelope",
1739                        },
1740                        {
1741                            share: "twitter",
1742                            logo: "aiz-custom-x-logo",
1743                        },
1744                        {
1745                            share: "facebook",
1746                            logo: "lab la-facebook-f",
1747                        },
1748                        {
1749                            share: "linkedin",
1750                            logo: "lab la-linkedin-in",
1751                        },
1752                        {
1753                            share: "whatsapp",
1754                            logo: "lab la-whatsapp",
1755                        },
1756                    ],
1757                });
1758            }
1759        },
1760        particles: function () {
1761            particlesJS(
1762                "particles-js",
1763
1764                {
1765                    particles: {
1766                        number: {
1767                            value: 80,
1768                            density: {
1769                                enable: true,
1770                                value_area: 800,
1771                            },
1772                        },
1773                        color: {
1774                            value: "#dfdfe6",
1775                        },
1776                        shape: {
1777                            type: "circle",
1778                            stroke: {
1779                                width: 0,
1780                                color: "#000000",
1781                            },
1782                            polygon: {
1783                                nb_sides: 5,
1784                            },
1785                            image: {
1786                                src: "img/github.svg",
1787                                width: 100,
1788                                height: 100,
1789                            },
1790                        },
1791                        opacity: {
1792                            value: 0.5,
1793                            random: false,
1794                            anim: {
1795                                enable: false,
1796                                speed: 1,
1797                                opacity_min: 0.1,
1798                                sync: false,
1799                            },
1800                        },
1801                        size: {
1802                            value: 5,
1803                            random: true,
1804                            anim: {
1805                                enable: false,
1806                                speed: 40,
1807                                size_min: 0.1,
1808                                sync: false,
1809                            },
1810                        },
1811                        line_linked: {
1812                            enable: true,
1813                            distance: 150,
1814                            color: "#dfdfe6",
1815                            opacity: 0.4,
1816                            width: 1,
1817                        },
1818                        move: {
1819                            enable: true,
1820                            speed: 6,
1821                            direction: "none",
1822                            random: false,
1823                            straight: false,
1824                            out_mode: "out",
1825                            attract: {
1826                                enable: false,
1827                                rotateX: 600,
1828                                rotateY: 1200,
1829                            },
1830                        },
1831                    },
1832                    interactivity: {
1833                        detect_on: "canvas",
1834                        events: {
1835                            onhover: {
1836                                enable: true,
1837                                mode: "repulse",
1838                            },
1839                            onclick: {
1840                                enable: true,
1841                                mode: "push",
1842                            },
1843                            resize: true,
1844                        },
1845                        modes: {
1846                            grab: {
1847                                distance: 400,
1848                                line_linked: {
1849                                    opacity: 1,
1850                                },
1851                            },
1852                            bubble: {
1853                                distance: 400,
1854                                size: 40,
1855                                duration: 2,
1856                                opacity: 8,
1857                                speed: 3,
1858                            },
1859                            repulse: {
1860                                distance: 200,
1861                            },
1862                            push: {
1863                                particles_nb: 4,
1864                            },
1865                            remove: {
1866                                particles_nb: 2,
1867                            },
1868                        },
1869                    },
1870                    retina_detect: true,
1871                    config_demo: {
1872                        hide_card: false,
1873                        background_color: "#b61924",
1874                        background_image: "",
1875                        background_position: "50% 50%",
1876                        background_repeat: "no-repeat",
1877                        background_size: "cover",
1878                    },
1879                }
1880            );
1881        },
1882    };
1883    AIZ.extra = {
1884        refreshToken: function () {
1885            $.get(AIZ.data.appUrl + "/refresh-csrf").done(function (data) {
1886                AIZ.data.csrf = data;
1887            });
1888            // console.log(AIZ.data.csrf);
1889        },
1890        mobileNavToggle: function () {
1891            if (window.matchMedia("(max-width: 1200px)").matches) {
1892                $("body").addClass("side-menu-closed");
1893            }
1894            $('[data-toggle="aiz-mobile-nav"]').on("click", function () {
1895                if ($("body").hasClass("side-menu-open")) {
1896                    $("body")
1897                        .addClass("side-menu-closed")
1898                        .removeClass("side-menu-open");
1899                } else if ($("body").hasClass("side-menu-closed")) {
1900                    $("body")
1901                        .removeClass("side-menu-closed")
1902                        .addClass("side-menu-open");
1903                } else {
1904                    $("body")
1905                        .removeClass("side-menu-open")
1906                        .addClass("side-menu-closed");
1907                }
1908            });
1909            $(".aiz-sidebar-overlay").on("click", function () {
1910                $("body")
1911                    .removeClass("side-menu-open")
1912                    .addClass("side-menu-closed");
1913            });
1914        },
1915        initActiveMenu: function () {
1916            $('[data-toggle="aiz-side-menu"] a').each(function () {
1917                var pageUrl = window.location.href.split(/[?#]/)[0];
1918                if (this.href == pageUrl || $(this).hasClass("active")) {
1919                    $(this).addClass("active");
1920                    $(this).closest(".aiz-side-nav-item").addClass("mm-active");
1921                    $(this)
1922                        .closest(".level-2")
1923                        .siblings("a")
1924                        .addClass("level-2-active");
1925                    $(this)
1926                        .closest(".level-3")
1927                        .siblings("a")
1928                        .addClass("level-3-active");
1929                }
1930            });
1931        },
1932        deleteConfirm: function () {
1933            $(".confirm-delete").click(function (e) {
1934                e.preventDefault();
1935                var url = $(this).data("href");
1936                $("#delete-modal").modal("show");
1937                $("#delete-link").attr("href", url);
1938            });
1939
1940            $(".confirm-cancel").click(function (e) {
1941                e.preventDefault();
1942                var url = $(this).data("href");
1943                $("#cancel-modal").modal("show");
1944                $("#cancel-link").attr("href", url);
1945            });
1946
1947            $(".confirm-complete").click(function (e) {
1948                e.preventDefault();
1949                var url = $(this).data("href");
1950                $("#complete-modal").modal("show");
1951                $("#comfirm-link").attr("href", url);
1952            });
1953
1954            $(".confirm-alert").click(function (e) {
1955                e.preventDefault();
1956                var url = $(this).data("href");
1957                var target = $(this).data("target");
1958                $(target).modal("show");
1959                $(target).find(".comfirm-link").attr("href", url);
1960                $("#comfirm-link").attr("href", url);
1961            });
1962        },
1963        bytesToSize: function (bytes) {
1964            var sizes = ["Bytes", "KB", "MB", "GB", "TB"];
1965            if (bytes == 0) return "0 Byte";
1966            var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
1967            return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i];
1968        },
1969        multiModal: function () {
1970            $(document).on("show.bs.modal", ".modal", function (event) {
1971                var zIndex = 1040 + 10 * $(".modal:visible").length;
1972                $(this).css("z-index", zIndex);
1973                setTimeout(function () {
1974                    $(".modal-backdrop")
1975                        .not(".modal-stack")
1976                        .css("z-index", zIndex - 1)
1977                        .addClass("modal-stack");
1978                }, 0);
1979            });
1980            $(document).on("hidden.bs.modal", function () {
1981                if ($(".modal.show").length > 0) {
1982                    $("body").addClass("modal-open");
1983                }
1984            });
1985        },
1986        bsCustomFile: function () {
1987            $(".custom-file input").change(function (e) {
1988                var files = [];
1989                for (var i = 0; i < $(this)[0].files.length; i++) {
1990                    files.push($(this)[0].files[i].name);
1991                }
1992                if (files.length === 1) {
1993                    $(this).next(".custom-file-name").html(files[0]);
1994                } else if (files.length > 1) {
1995                    $(this)
1996                        .next(".custom-file-name")
1997                        .html(files.length + " " + AIZ.local.files_selected);
1998                } else {
1999                    $(this)
2000                        .next(".custom-file-name")
2001                        .html(AIZ.local.choose_file);
2002                }
2003            });
2004        },
2005        stopPropagation: function () {
2006            $(document).on("click", ".stop-propagation", function (e) {
2007                e.stopPropagation();
2008            });
2009        },
2010        outsideClickHide: function () {
2011            $(document).on("click", function (e) {
2012                $(".document-click-d-none").addClass("d-none");
2013            });
2014        },
2015        inputRating: function () {
2016            $(".rating-input").each(function () {
2017                $(this)
2018                    .find("label")
2019                    .on({
2020                        mouseover: function (event) {
2021                            $(this).find("i").addClass("hover");
2022                            $(this).prevAll().find("i").addClass("hover");
2023                        },
2024                        mouseleave: function (event) {
2025                            $(this).find("i").removeClass("hover");
2026                            $(this).prevAll().find("i").removeClass("hover");
2027                        },
2028                        click: function (event) {
2029                            $(this).siblings().find("i").removeClass("active");
2030                            $(this).find("i").addClass("active");
2031                            $(this).prevAll().find("i").addClass("active");
2032                        },
2033                    });
2034                if ($(this).find("input").is(":checked")) {
2035                    $(this)
2036                        .find("label")
2037                        .siblings()
2038                        .find("i")
2039                        .removeClass("active");
2040                    $(this)
2041                        .find("input:checked")
2042                        .closest("label")
2043                        .find("i")
2044                        .addClass("active");
2045                    $(this)
2046                        .find("input:checked")
2047                        .closest("label")
2048                        .prevAll()
2049                        .find("i")
2050                        .addClass("active");
2051                }
2052            });
2053        },
2054        scrollToBottom: function () {
2055            $(".scroll-to-btm").each(function (i, el) {
2056                el.scrollTop = el.scrollHeight;
2057            });
2058        },
2059        classToggle: function () {
2060            $(document).on(
2061                "click",
2062                '[data-toggle="class-toggle"]',
2063                function () {
2064                    var $this = $(this);
2065                    var target = $this.data("target");
2066                    var sameTriggers = $this.data("same");
2067                    var backdrop = $(this).data("backdrop");
2068
2069                    if ($(target).hasClass("active")) {
2070                        $(target).removeClass("active");
2071                        $(sameTriggers).removeClass("active");
2072                        $this.removeClass("active");
2073                        $("body").removeClass("overflow-hidden");
2074                    } else {
2075                        $(target).addClass("active");
2076                        $this.addClass("active");
2077                        if (backdrop == "static") {
2078                            $("body").addClass("overflow-hidden");
2079                        }
2080                    }
2081                }
2082            );
2083        },
2084        collapseSidebar: function () {
2085            $(document).on(
2086                "click",
2087                '[data-toggle="collapse-sidebar"]',
2088                function (i, el) {
2089                    var $this = $(this);
2090                    var target = $(this).data("target");
2091                    var sameTriggers = $(this).data("siblings");
2092
2093                    // var showOverlay = $this.data('overlay');
2094                    // var overlayMarkup = '<div class="overlay overlay-fixed dark c-pointer" data-toggle="collapse-sidebar" data-target="'+target+'"></div>';
2095
2096                    // showOverlay = !showOverlay ? true : showOverlay;
2097
2098                    // if (showOverlay && $(target).siblings('.overlay').length !== 1) {
2099                    //     $(target).after(overlayMarkup);
2100                    // }
2101
2102                    e.preventDefault();
2103                    if ($(target).hasClass("opened")) {
2104                        $(target).removeClass("opened");
2105                        $(sameTriggers).removeClass("opened");
2106                        $($this).removeClass("opened");
2107                    } else {
2108                        $(target).addClass("opened");
2109                        $($this).addClass("opened");
2110                    }
2111                }
2112            );
2113        },
2114        autoScroll: function () {
2115            if ($(".aiz-auto-scroll").length > 0) {
2116                $(".aiz-auto-scroll").each(function () {
2117                    var options = $(this).data("options");
2118
2119                    options = !options
2120                        ? '{"delay" : 2000 ,"amount" : 70 }'
2121                        : options;
2122
2123                    options = JSON.parse(options);
2124
2125                    this.delay = parseInt(options["delay"]) || 2000;
2126                    this.amount = parseInt(options["amount"]) || 70;
2127                    this.autoScroll = $(this);
2128                    this.iScrollHeight = this.autoScroll.prop("scrollHeight");
2129                    this.iScrollTop = this.autoScroll.prop("scrollTop");
2130                    this.iHeight = this.autoScroll.height();
2131
2132                    var self = this;
2133                    this.timerId = setInterval(function () {
2134                        if (
2135                            self.iScrollTop + self.iHeight <
2136                            self.iScrollHeight
2137                        ) {
2138                            self.iScrollTop = self.autoScroll.prop("scrollTop");
2139                            self.iScrollTop += self.amount;
2140                            self.autoScroll.animate(
2141                                { scrollTop: self.iScrollTop },
2142                                "slow",
2143                                "linear"
2144                            );
2145                        } else {
2146                            self.iScrollTop -= self.iScrollTop;
2147                            self.autoScroll.animate(
2148                                { scrollTop: "0px" },
2149                                "fast",
2150                                "swing"
2151                            );
2152                        }
2153                    }, self.delay);
2154                });
2155            }
2156        },
2157        addMore: function () {
2158            $('[data-toggle="add-more"]').each(function () {
2159                var $this = $(this);
2160                var content = $this.data("content");
2161                var target = $this.data("target");
2162
2163                $this.on("click", function (e) {
2164                    e.preventDefault();
2165                    $(target).append(content);
2166                    AIZ.plugins.bootstrapSelect();
2167                });
2168            });
2169        },
2170        removeParent: function () {
2171            $(document).on(
2172                "click",
2173                '[data-toggle="remove-parent"]',
2174                function () {
2175                    var $this = $(this);
2176                    var parent = $this.data("parent");
2177                    $this.closest(parent).remove();
2178                }
2179            );
2180        },
2181        selectHideShow: function () {
2182            $('[data-show="selectShow"]').each(function () {
2183                var target = $(this).data("target");
2184                $(this).on("change", function () {
2185                    var value = $(this).val();
2186                    // console.log(value);
2187                    $(target)
2188                        .children()
2189                        .not("." + value)
2190                        .addClass("d-none");
2191                    $(target)
2192                        .find("." + value)
2193                        .removeClass("d-none");
2194                });
2195            });
2196        },
2197        plusMinus: function () {
2198            $(".aiz-plus-minus input").each(function () {
2199                var $this = $(this);
2200                var min = parseInt($(this).attr("min"));
2201                var max = parseInt($(this).attr("max"));
2202                var value = parseInt($(this).val());
2203                if (value <= min) {
2204                    $this
2205                        .siblings('[data-type="minus"]')
2206                        .attr("disabled", true);
2207                } else if (
2208                    $this.siblings('[data-type="minus"]').attr("disabled")
2209                ) {
2210                    $this
2211                        .siblings('[data-type="minus"]')
2212                        .removeAttr("disabled");
2213                }
2214                if (value >= max) {
2215                    $this.siblings('[data-type="plus"]').attr("disabled", true);
2216                } else if (
2217                    $this.siblings('[data-type="plus"]').attr("disabled")
2218                ) {
2219                    $this.siblings('[data-type="plus"]').removeAttr("disabled");
2220                }
2221            });
2222            $(".aiz-plus-minus button")
2223                .off("click")
2224                .on("click", function (e) {
2225                    e.preventDefault();
2226
2227                    var fieldName = $(this).attr("data-field");
2228                    var type = $(this).attr("data-type");
2229                    var input = $("input[name='" + fieldName + "']");
2230                    var currentVal = parseInt(input.val());
2231
2232                    if (!isNaN(currentVal)) {
2233                        if (type == "minus") {
2234                            if (currentVal > input.attr("min")) {
2235                                input.val(currentVal - 1).change();
2236                            }
2237                            if (parseInt(input.val()) == input.attr("min")) {
2238                                $(this).attr("disabled", true);
2239                            }
2240                        } else if (type == "plus") {
2241                            if (currentVal < input.attr("max")) {
2242                                input.val(currentVal + 1).change();
2243                            }
2244                            if (parseInt(input.val()) == input.attr("max")) {
2245                                $(this).attr("disabled", true);
2246                            }
2247                        }
2248                    } else {
2249                        input.val(0);
2250                    }
2251                });
2252            $(".aiz-plus-minus input")
2253                .off("change")
2254                .on("change", function () {
2255                    var minValue = parseInt($(this).attr("min"));
2256                    var maxValue = parseInt($(this).attr("max"));
2257                    var valueCurrent = parseInt($(this).val());
2258
2259                    name = $(this).attr("name");
2260                    if (valueCurrent >= minValue) {
2261                        $(this)
2262                            .siblings("[data-type='minus']")
2263                            .removeAttr("disabled");
2264                    } else {
2265                        alert(
2266                            translate(
2267                                "Sorry, the minimum limit has been reached"
2268                            )
2269                        );
2270                        $(this).val(minValue);
2271                    }
2272                    if (valueCurrent <= maxValue) {
2273                        $(this)
2274                            .siblings("[data-type='plus']")
2275                            .removeAttr("disabled");
2276                    } else {
2277                        alert(
2278                            translate(
2279                                "Sorry, the maximum limit has been reached"
2280                            )
2281                        );
2282                        $(this).val(maxValue);
2283                    }
2284
2285                    if (typeof getVariantPrice === "function") {
2286                        getVariantPrice();
2287                    }
2288                });
2289        },
2290        hovCategoryMenu: function () {
2291            $("#category-menu-icon, #category-sidebar")
2292                .on("mouseover", function (event) {
2293                    $("#hover-category-menu")
2294                        .addClass("active")
2295                        .removeClass("d-none");
2296                })
2297                .on("mouseout", function (event) {
2298                    $("#hover-category-menu")
2299                        .addClass("d-none")
2300                        .removeClass("active");
2301                });
2302        },
2303        clickCategoryMenu: function () {
2304            var menu = $("#click-category-menu");
2305            menu.hide();
2306            menu.removeClass("d-none");
2307            $("#category-menu-bar").on("click", function (event) {
2308                if (event.target.closest('.categoriesAll')) {
2309                    event.stopPropagation();
2310                }else{
2311                    menu.slideToggle(500);
2312                    if ($("#category-menu-bar-icon").hasClass("show")) {
2313                        $("#category-menu-bar-icon").removeClass("show");
2314                    } else {
2315                        $("#category-menu-bar-icon").addClass("show");
2316                    }
2317                }
2318
2319            });
2320        },
2321        hovUserTopMenu: function () {
2322            var timeout;
2323            $(document).on("mouseenter", "#nav-user-info, .hover-user-top-menu", function () {
2324                clearTimeout(timeout);
2325                $(".hover-user-top-menu").addClass("active");
2326            });
2327            $(document).on("mouseleave", "#nav-user-info, .hover-user-top-menu", function () {
2328                timeout = setTimeout(function () {
2329                    $(".hover-user-top-menu").removeClass("active");
2330                }, 300);
2331            });
2332        },
2333        trimAppUrl: function () {
2334            if (AIZ.data.appUrl.slice(-1) == "/") {
2335                AIZ.data.appUrl = AIZ.data.appUrl.slice(
2336                    0,
2337                    AIZ.data.appUrl.length - 1
2338                );
2339                // console.log(AIZ.data.appUrl);
2340            }
2341        },
2342        setCookie: function (cname, cvalue, exdays) {
2343            var d = new Date();
2344            d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
2345            var expires = "expires=" + d.toUTCString();
2346            document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
2347        },
2348        getCookie: function (cname) {
2349            var name = cname + "=";
2350            var decodedCookie = decodeURIComponent(document.cookie);
2351            var ca = decodedCookie.split(";");
2352            for (var i = 0; i < ca.length; i++) {
2353                var c = ca[i];
2354                while (c.charAt(0) === " ") {
2355                    c = c.substring(1);
2356                }
2357                if (c.indexOf(name) === 0) {
2358                    return c.substring(name.length, c.length);
2359                }
2360            }
2361            return "";
2362        },
2363
2364        acceptCookie: function () {
2365            if (!AIZ.extra.getCookie("acceptCookies")) {
2366                $(".aiz-cookie-alert:not(.club-point-alert)").addClass("show");
2367            }
2368            if (!AIZ.extra.getCookie("acceptClubPointAlert")) {
2369                $(".club-point-alert").addClass("show");
2370            }
2371
2372            $(".aiz-cookie-accept").on("click", function () {
2373                AIZ.extra.setCookie("acceptCookies", true, 60);
2374                $(".aiz-cookie-alert:not(.club-point-alert)").fadeOut(600, function() {
2375                    $(this).removeClass("show");
2376                });
2377            });
2378
2379            $(".aiz-cookie-accept-club-point").on("click", function () {
2380                AIZ.extra.setCookie("acceptClubPointAlert", true, 60);
2381                $(".aiz-cookie-alert").fadeOut(600, function() {
2382                    $(this).removeClass("show");
2383                });
2384          });
2385        },
2386        setSession: function () {
2387            $(".set-session").each(function () {
2388                var $this = $(this);
2389                var key = $this.data("key");
2390                var value = $this.data("value");
2391
2392                const now = new Date();
2393                const item = {
2394                    value: value,
2395                    expiry: now.getTime() + 3600000,
2396                };
2397
2398                $this.on("click", function () {
2399                    localStorage.setItem(key, JSON.stringify(item));
2400                });
2401            });
2402        },
2403        showSessionPopup: function () {
2404            $(".removable-session").each(function () {
2405                var $this = $(this);
2406                var key = $this.data("key");
2407                var value = $this.data("value");
2408                var item = {};
2409                if (localStorage.getItem(key)) {
2410                    item = localStorage.getItem(key);
2411                    item = JSON.parse(item);
2412                }
2413                const now = new Date();
2414                if (
2415                    typeof item.expiry == "undefined" ||
2416                    now.getTime() > item.expiry
2417                ) {
2418                    $this.removeClass("d-none");
2419                }
2420            });
2421        },
2422    };
2423
2424    setInterval(function () {
2425        AIZ.extra.refreshToken();
2426    }, 3600000);
2427
2428    // init aiz plugins, extra options
2429    AIZ.extra.initActiveMenu();
2430    AIZ.extra.mobileNavToggle();
2431    AIZ.extra.deleteConfirm();
2432    AIZ.extra.multiModal();
2433    AIZ.extra.inputRating();
2434    AIZ.extra.bsCustomFile();
2435    AIZ.extra.stopPropagation();
2436    AIZ.extra.outsideClickHide();
2437    AIZ.extra.scrollToBottom();
2438    AIZ.extra.classToggle();
2439    AIZ.extra.collapseSidebar();
2440    AIZ.extra.autoScroll();
2441    AIZ.extra.addMore();
2442    AIZ.extra.removeParent();
2443    AIZ.extra.selectHideShow();
2444    AIZ.extra.plusMinus();
2445    AIZ.extra.hovCategoryMenu();
2446    AIZ.extra.clickCategoryMenu();
2447    AIZ.extra.hovUserTopMenu();
2448    AIZ.extra.trimAppUrl();
2449    AIZ.extra.acceptCookie();
2450    AIZ.extra.setSession();
2451    AIZ.extra.showSessionPopup();
2452
2453    AIZ.plugins.metismenu();
2454    AIZ.plugins.bootstrapSelect();
2455    //AIZ.plugins.tagify();
2456    AIZ.plugins.textEditor();
2457    AIZ.plugins.tooltip();
2458    AIZ.plugins.countDown();
2459    AIZ.plugins.countDownBox();
2460    AIZ.plugins.countDownCircle();
2461    AIZ.plugins.dateRange();
2462    AIZ.plugins.timePicker();
2463    AIZ.plugins.colorPicker();
2464    AIZ.plugins.fooTable();
2465    AIZ.plugins.slickCarousel();
2466    AIZ.plugins.noUiSlider();
2467    AIZ.plugins.zoom();
2468    AIZ.plugins.jsSocials();
2469
2470    // initialization of aiz uploader
2471    AIZ.uploader.initForInput();
2472    AIZ.uploader.removeAttachment();
2473    AIZ.uploader.previewGenerate();
2474
2475    // $(document).ajaxComplete(function(){
2476    //     AIZ.plugins.bootstrapSelect('refresh');
2477    // });
2478})(jQuery);
2479
2480
2481 // Footer description expand
2482    const toggleButton = document.getElementById("toggle-btn");
2483    const textParagraph = document.querySelector(".footer-text-control");
2484
2485    if (toggleButton && textParagraph) {
2486    toggleButton.addEventListener("click", () => {
2487        const isExpanded =
2488        textParagraph.style.maxHeight &&
2489        textParagraph.style.maxHeight !== "80px";
2490
2491        // Toggle between expanded and collapsed state
2492        textParagraph.style.maxHeight = isExpanded
2493        ? "80px"
2494        : `${textParagraph.scrollHeight}px`;
2495
2496        toggleButton.textContent = isExpanded ? "Read More" : "Show Less";
2497    });
2498    }
2499
2500
2501
2502document.querySelectorAll('.video-container').forEach(container => {
2503    const video = container.querySelector('.upload_video');
2504    const playBtn = container.querySelector('.playButton');
2505    const playPauseBtn = container.querySelector('.playPauseBtn');
2506    const muteBtn = container.querySelector('.muteBtn');
2507    const progress = container.querySelector('.progress');
2508    const currentTimeText = container.querySelector('.currentTime');
2509    const durationText = container.querySelector('.duration');
2510    const openPopupBtn = container.querySelector('.openPopupBtn');
2511    const popupVideo = document.getElementById('popupVideo');
2512    const videoModal = document.getElementById('videoModal');
2513    const closeModalBtn = document.getElementById('closeModalBtn');
2514
2515    // Format time (mm:ss)
2516    function formatTime(time) {
2517        const minutes = Math.floor(time / 60);
2518        const seconds = Math.floor(time % 60);
2519        return `${minutes}:${seconds.toString().padStart(2, '0')}`;
2520    }
2521
2522    // Initial metadata load
2523    video.addEventListener('loadedmetadata', () => {
2524        durationText.innerText = formatTime(video.duration);
2525    });
2526
2527    // Play button
2528    playBtn.addEventListener('click', () => {
2529        video.play();
2530        playBtn.classList.add('hidden');
2531        playPauseBtn.innerText = '⏸';
2532    });
2533
2534    // Toggle play/pause on video click
2535    video.addEventListener('click', () => {
2536        if (video.paused) {
2537            video.play();
2538            playBtn.classList.add('hidden');
2539            playPauseBtn.innerText = '⏸';
2540        } else {
2541            video.pause();
2542            playBtn.classList.remove('hidden');
2543            playPauseBtn.innerText = '▶';
2544        }
2545    });
2546
2547    // Play/Pause Button
2548    playPauseBtn.addEventListener('click', () => {
2549        if (video.paused) {
2550            video.play();
2551            playBtn.classList.add('hidden');
2552            playPauseBtn.innerText = '⏸';
2553        } else {
2554            video.pause();
2555            playBtn.classList.remove('hidden');
2556            playPauseBtn.innerText = '▶';
2557        }
2558    });
2559
2560    // Mute / Unmute
2561    muteBtn.addEventListener('click', () => {
2562        video.muted = !video.muted;
2563        muteBtn.innerText = video.muted ? '🔈' : '🔊';
2564    });
2565
2566    // Video ended
2567    video.addEventListener('ended', () => {
2568        playBtn.classList.remove('hidden');
2569        playPauseBtn.innerText = '▶';
2570    });
2571
2572    // Update progress and time
2573    video.addEventListener('timeupdate', () => {
2574        if (!isNaN(video.duration)) {
2575            progress.value = (video.currentTime / video.duration) * 100;
2576            currentTimeText.innerText = formatTime(video.currentTime);
2577        }
2578    });
2579
2580    // Seek video
2581    progress.addEventListener('input', () => {
2582        const seekTime = (progress.value / 100) * video.duration;
2583        video.currentTime = seekTime;
2584    });
2585
2586    // Open modal popup
2587if (openPopupBtn) {
2588    openPopupBtn.addEventListener('click', () => {
2589        popupVideo.innerHTML = '';
2590        Array.from(video.getElementsByTagName('source')).forEach(source => {
2591            const cloned = document.createElement('source');
2592            cloned.src = source.src;
2593            cloned.type = source.type;
2594            popupVideo.appendChild(cloned);
2595        });
2596
2597
2598        popupVideo.muted = false;
2599
2600        popupVideo.load();
2601        popupVideo.currentTime = video.currentTime;
2602        popupVideo.play();
2603        videoModal.classList.add('active');
2604    });
2605}
2606
2607// Close modal popup
2608if (closeModalBtn) {
2609    closeModalBtn.addEventListener('click', () => {
2610        popupVideo.pause();
2611        popupVideo.currentTime = 0;
2612        videoModal.classList.remove('active');
2613    });
2614}
2615
2616
2617
2618});
2619
2620
2621
2622// header 5 js
2623
2624document.addEventListener('DOMContentLoaded', function () {
2625    const gearToggle = document.querySelector('.gear-toggle');
2626    const topBarContent = document.querySelector('.top-bar-content');
2627
2628    if (gearToggle && topBarContent) {
2629        gearToggle.addEventListener('click', function () {
2630            this.classList.toggle('active');
2631            topBarContent.classList.toggle('show');
2632        });
2633    }
2634});
2635
2636document.addEventListener('DOMContentLoaded', function () {
2637    const searchIconDesktop = document.querySelector('.search-icon-desktop');
2638    const searchIconMobile = document.querySelector('.search-icon-mobile');
2639    const searchContainer = document.querySelector('.desktop-search-container');
2640    const searchClose = document.querySelector('.search-close-desktop');
2641    const headerMenus = document.querySelector('.header-menus-container');
2642    const searchInput = document.getElementById('search');
2643
2644    function openSearch() {
2645        if (searchContainer) {
2646            searchContainer.classList.remove('d-none');
2647            setTimeout(() => {
2648                searchContainer.classList.add('expanded');
2649                $('.search-icon-mobile-hide').addClass('d-none');
2650                if (headerMenus) headerMenus.classList.add('hidden');
2651            }, 10);
2652            if (searchInput) searchInput.focus();
2653        }
2654    }
2655
2656    function closeSearch() {
2657        if (searchContainer) {
2658            searchContainer.classList.remove('expanded');
2659            setTimeout(() => {
2660                $('.search-icon-mobile-hide').removeClass('d-none');
2661                searchContainer.classList.add('d-none');
2662                if (headerMenus) headerMenus.classList.remove('hidden');
2663            }, 300);
2664        }
2665    }
2666
2667    [searchIconDesktop, searchIconMobile].forEach(icon => {
2668        if (icon) {
2669            icon.addEventListener('click', function (e) {
2670                e.preventDefault();
2671                openSearch();
2672            });
2673        }
2674    });
2675
2676    if (searchClose && searchInput) {
2677        searchClose.addEventListener('click', function (e) {
2678            e.preventDefault();
2679            if (searchInput.value.trim() !== '') {
2680                searchInput.value = '';
2681                searchInput.focus();
2682            } else {
2683                closeSearch();
2684            }
2685        });
2686    }
2687
2688    document.addEventListener('keydown', function (e) {
2689        if (e.key === 'Escape' && !searchContainer.classList.contains('d-none')) {
2690            closeSearch();
2691        }
2692    });
2693
2694    document.addEventListener('click', function (e) {
2695    if (
2696        (!searchContainer || !searchContainer.contains(e.target)) &&
2697        (!searchIconDesktop || !searchIconDesktop.contains(e.target)) &&
2698        (!searchIconMobile || !searchIconMobile.contains(e.target))
2699    ) {
2700        if (searchContainer && !searchContainer.classList.contains('d-none')) {
2701            closeSearch();
2702        }
2703    }
2704});
2705
2706
2707    if (searchInput && searchClose) {
2708    searchInput.addEventListener('input', function () {
2709        const icon = searchClose.querySelector('i');
2710        if (!icon) return;
2711
2712        if (this.value.trim()) {
2713            icon.classList.remove('la-search');
2714            icon.classList.add('la-times');
2715        } else {
2716            icon.classList.remove('la-times');
2717            icon.classList.add('la-search');
2718        }
2719    });
2720}
2721});
2722
2723
2724
2725function toggleChildDropdown(el, event) {
2726    if (event) event.stopPropagation();
2727
2728    let $submenu = $(el).next('.child-dropdown');
2729    if ($submenu.hasClass('show')) {
2730        $submenu.removeClass('show');
2731    } else {
2732        $('.child-dropdown').removeClass('show');
2733        $submenu.addClass('show');
2734    }
2735}
2736
2737
2738
2739$('#category-menu-bar').on('click', function () {
2740    $(this).find('.menu-icon').toggleClass('rotated');
2741});
2742
2743
2744//product details gallery
2745$('.product-gallery-carousel').on('beforeChange', function(event, slick, currentSlide, nextSlide){
2746    $(slick.$slides[currentSlide]).find('iframe').each(function(){
2747        let src = $(this).attr('src');
2748        $(this).attr('src', src);
2749    });
2750});
2751
2752//destroy zoom when mouse on expand btn
2753// Only run hover zoom disable on non-touch devices
2754if (!("ontouchstart" in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0)) {
2755    $(document).on("mouseenter", ".wd-show-product-gallery-wrap a", function(e){
2756        $(".img-zoom").trigger("zoom.destroy");
2757    }).on("mouseleave", ".wd-show-product-gallery-wrap a", function(e){
2758        $(".img-zoom").zoom({ magnify: 1.5 });
2759    });
2760}
2761
2762
2763//for custom x logo
2764document.addEventListener("DOMContentLoaded", function () {
2765    const xLogo = `
2766      <svg viewBox="0 0 1200 1227" xmlns="http://www.w3.org/2000/svg">
2767        <path d="M714.2 529.5 1160 0H1050.9L666.4
2768          450.9 357.2 0H0l468.9 681.4L0 1226.9h109.1l409-493.3
2769          330.2 493.3H1200L714.2 529.5zm-144.5
2770          170.9-47.4-68.1L160 79.8h154.6l304.9
2771          438.8 47.4 68.1 395.2 568.5H907.5L569.7
2772          700.4z" />
2773      </svg>
2774    `;
2775
2776    document.querySelectorAll('.aiz-custom-x-logo').forEach(el => {
2777      el.outerHTML = xLogo.replace('<svg', '<svg class="aiz-custom-x-logo"');
2778    });
2779});
2780
2781$(".jssocials-share-twitter .jssocials-share-link")
2782  .css("background-color", "#332f2fff")
2783  .hover(
2784    function() {
2785      $(this).css("background-color", "#000");
2786    },
2787    function() {
2788      $(this).css("background-color", "#332f2fff");
2789    }
2790);
2791
2792/* top-banner-scroll-text */
2793function initTopBarScroll() {
2794    const inners = document.querySelectorAll(".top-banner-scroll-inner");
2795    const speed = 80;
2796
2797    inners.forEach(inner => {
2798        const parentWidth = inner.parentElement.offsetWidth;
2799        const textWidth = inner.scrollWidth;
2800
2801        inner.style.animation = "none";
2802        inner.style.transform = "translateX(0)";
2803        inner.style.animationPlayState = "running";
2804
2805        if (textWidth > parentWidth) {
2806            if (!inner.dataset.cloned) {
2807                const clone = inner.innerHTML;
2808                inner.innerHTML += clone;
2809                inner.dataset.cloned = true;
2810            }
2811
2812            const totalWidth = inner.scrollWidth;
2813            const duration = totalWidth / speed;
2814
2815            inner.style.animation = `top-banner-scroll-left ${duration}s linear infinite`;
2816            inner.style.animationPlayState = "running";
2817        } else {
2818            inner.style.display = "flex";
2819            inner.style.justifyContent = "center";
2820        }
2821    });
2822}
2823
2824document.addEventListener("DOMContentLoaded", () => {
2825    const inners = document.querySelectorAll(".top-banner-scroll-inner");
2826
2827    inners.forEach(inner => {
2828        inner.addEventListener("mouseenter", () => {
2829            inner.style.animationPlayState = "paused";
2830        });
2831
2832        inner.addEventListener("mouseleave", () => {
2833            inner.style.animationPlayState = "running";
2834        });
2835    });
2836});
2837
2838document.addEventListener("DOMContentLoaded", initTopBarScroll);
2839window.addEventListener("resize", initTopBarScroll);
2840
2841
2842
2843// Gallery Image vIEWER
2844
2845document.addEventListener("DOMContentLoaded", function() {
2846    const modal = document.getElementById("lightboxModal");
2847    const modalImg = document.getElementById("lightboxImage");
2848    const closeBtn = document.querySelector(".lightbox-close");
2849    const zoomInBtn = document.getElementById("zoomInBtn");
2850    const zoomOutBtn = document.getElementById("zoomOutBtn");
2851    const fullscreenBtn = document.getElementById("fullscreenBtn");
2852    const copyLinkBtn = document.getElementById("copyLinkBtn");
2853    const downloadBtn = document.getElementById("downloadBtn");
2854    const prevBtn = document.getElementById("prevBtn");
2855    const nextBtn = document.getElementById("nextBtn");
2856    const imageCounter = document.getElementById("imageCounter");
2857
2858    const galleryImgs = document.querySelectorAll(".lightbox-item img.lightbox-source");
2859
2860    let currentIndex = 0;
2861    let scale = 1;
2862
2863    function openModal(index, direction = 0) {
2864        if (!modal || !modalImg) return;
2865
2866        currentIndex = index;
2867        modal.style.display = "block";
2868
2869        // Slide animation
2870        modalImg.style.transition = "transform 0.3s ease, opacity 0.3s ease";
2871        modalImg.style.transform = `translate(calc(-50% + ${direction * 100}%), -50%) scale(${scale})`;
2872        modalImg.style.opacity = 0;
2873
2874        setTimeout(() => {
2875            modalImg.src = galleryImgs[index].dataset.src || galleryImgs[index].src;
2876            scale = 1; // reset zoom
2877            modalImg.style.transform = `translate(-50%, -50%) scale(${scale})`;
2878            modalImg.style.opacity = 1;
2879            $('.lightbox-content').css('cursor', 'zoom-in');
2880            updateCounter();
2881        }, 200);
2882    }
2883
2884    function updateCounter() {
2885        if (imageCounter) {
2886            imageCounter.textContent = `${currentIndex + 1} / ${galleryImgs.length}`;
2887        }
2888    }
2889
2890    // Gallery buttons
2891    document.querySelectorAll(".woodmart-show-product-gallery").forEach((btn, i) => {
2892        btn.addEventListener("click", function(e) {
2893            e.preventDefault();
2894            openModal(i);
2895        });
2896    });
2897
2898    // Double click to zoom
2899    if (modalImg) {
2900        modalImg.addEventListener("dblclick", () => {
2901            scale = scale === 1 ? 2 : 1;
2902            modalImg.style.transform = `translate(-50%, -50%) scale(${scale})`;
2903            $('.lightbox-content').css('cursor', scale === 1 ? 'zoom-in' : 'zoom-out');
2904        });
2905    }
2906
2907    // Close modal
2908    if (closeBtn && modal) {
2909        closeBtn.onclick = () => modal.style.display = "none";
2910    }
2911
2912    // Previous image
2913    if (prevBtn) {
2914        prevBtn.onclick = () => {
2915            currentIndex = (currentIndex - 1 + galleryImgs.length) % galleryImgs.length;
2916            openModal(currentIndex, 0);
2917        };
2918    }
2919
2920    // Next image
2921    if (nextBtn) {
2922        nextBtn.onclick = () => {
2923            currentIndex = (currentIndex + 1) % galleryImgs.length;
2924            openModal(currentIndex, 0);
2925        };
2926    }
2927
2928    // Zoom in
2929    if (zoomInBtn && modalImg) {
2930        zoomInBtn.onclick = () => {
2931            scale += 0.2;
2932            modalImg.style.transform = `translate(-50%, -50%) scale(${scale})`;
2933            $('.lightbox-content').css('cursor', 'zoom-out');
2934        };
2935    }
2936
2937    // Zoom out
2938    if (zoomOutBtn && modalImg) {
2939        zoomOutBtn.onclick = () => {
2940            scale = Math.max(0.2, scale - 0.2);
2941            modalImg.style.transform = `translate(-50%, -50%) scale(${scale})`;
2942            $('.lightbox-content').css('cursor', 'zoom-in');
2943        };
2944    }
2945
2946    // Fullscreen toggle
2947    if (fullscreenBtn && modal) {
2948        fullscreenBtn.onclick = () => {
2949            if (!document.fullscreenElement) {
2950                modal.requestFullscreen();
2951            } else {
2952                document.exitFullscreen();
2953            }
2954        };
2955    }
2956
2957    // Copy link
2958    if (copyLinkBtn && modalImg) {
2959        copyLinkBtn.onclick = () => {
2960            navigator.clipboard.writeText(modalImg.src)
2961                .then(() => AIZ.plugins.notify('success', 'Link copied to clipboard'));
2962        };
2963    }
2964
2965    // Download
2966    if (downloadBtn && modalImg) {
2967        downloadBtn.onclick = () => {
2968            const link = document.createElement('a');
2969            link.href = modalImg.src;
2970            link.download = 'image';
2971            link.click();
2972        };
2973    }
2974
2975    // Close modal on outside click
2976    if (modal) {
2977        modal.addEventListener("click", function(e) {
2978            if (e.target === modal) modal.style.display = "none";
2979        });
2980    }
2981
2982    // Arrow keys navigation
2983    document.addEventListener("keydown", function(e) {
2984        if (!modal || modal.style.display !== "block") return;
2985        if (e.key === "ArrowRight" && nextBtn) nextBtn.click();
2986        if (e.key === "ArrowLeft" && prevBtn) prevBtn.click();
2987        if (e.key === "Escape") modal.style.display = "none";
2988    });
2989});
2990
2991// smart bar
2992document.addEventListener("DOMContentLoaded", function () {
2993
2994    const smartBar = document.getElementById('smart-bar');
2995    const trigger = document.getElementById('smart-bar-trigger');
2996
2997    if (!smartBar || !trigger) return;
2998
2999    smartBar.classList.remove('visible');
3000    smartBar.classList.add('hidden');
3001
3002    const showSmartBar = () => {
3003        smartBar.classList.remove('hidden');
3004        smartBar.classList.add('visible');
3005    };
3006
3007    const hideSmartBar = () => {
3008        smartBar.classList.remove('visible');
3009        smartBar.classList.add('hidden');
3010    };
3011
3012    const observer = new IntersectionObserver(
3013        (entries) => {
3014            entries.forEach(entry => {
3015
3016                if (entry.isIntersecting && entry.boundingClientRect.top >= 0) {
3017                    showSmartBar();
3018                }
3019                else if (entry.boundingClientRect.top > 0) {
3020                    hideSmartBar();
3021                }
3022                else {
3023                    showSmartBar();
3024                }
3025
3026            });
3027        },
3028        {
3029            root: null,
3030            threshold: 0
3031        }
3032    );
3033
3034    observer.observe(trigger);
3035
3036    const triggerPosition = trigger.getBoundingClientRect();
3037    if (triggerPosition.top <= window.innerHeight) {
3038        showSmartBar();
3039    } else {
3040        hideSmartBar();
3041    }
3042
3043});
3044
3045
3046function closeSmartBar() {
3047    const bar = document.getElementById('smart-bar');
3048    if (!bar) return;
3049
3050    bar.classList.add('closing');
3051
3052    bar.addEventListener('transitionend', function handler() {
3053        bar.removeEventListener('transitionend', handler);
3054        bar.remove();
3055    });
3056}
3057
3058function scrollToTopSection() {
3059    const topSection = document.querySelector('.product-details > .container');
3060
3061    if(topSection) {
3062        topSection.scrollIntoView({
3063            behavior: 'smooth',
3064            block: 'start'
3065        });
3066    }
3067}
3068
3069
3070
3071//for header-6 gear icon show-hide
3072function hideOptions() {
3073    document.querySelector('.silder-toggle').classList.add('d-none');
3074}
3075
3076function showOptions() {
3077    document.querySelector('.silder-toggle').classList.remove('d-none');
3078}
3079
3080
3081
3082// Product Clone
3083
3084function duplicateProduct(productId = null, type = null) {
3085    let selectedProductId;
3086
3087    if (productId === null) {
3088        var selectedProduct = $('input[name="selected_product_id"]:checked');
3089        selectedProductId = selectedProduct.val();
3090
3091        if (!selectedProductId) {
3092            AIZ.plugins.notify('warning', 'Please select a product');
3093            return;
3094        }
3095
3096        $('#products_select_modal').modal('hide');
3097    } else {
3098        selectedProductId = productId;
3099    }
3100
3101    $('#loading-modal').modal('show', { backdrop: 'static' });
3102
3103    $.ajax({
3104        url: duplicateProductUrl.replace(':id', selectedProductId) + (type ? '?type=' + type : ''),
3105        method: 'GET',
3106        success: function(response) {
3107            $('#loading-modal').modal('hide');
3108           if (response.success) {
3109                AIZ.plugins.notify('success', response.message);
3110            } else {
3111                AIZ.plugins.notify('danger', response.message);
3112                return;
3113            }
3114
3115
3116            if (response.redirect) {
3117                setTimeout(function() {
3118                    window.location.href = response.redirect;
3119                }, 1000);
3120            } else {
3121                setTimeout(function() {
3122                    location.reload();
3123                }, 1000);
3124            }
3125        },
3126        error: function(xhr) {
3127            $('#loading-modal').modal('hide');
3128            AIZ.plugins.notify('danger', 'Something went wrong');
3129        }
3130    });
3131}
3132
3133
3134
3135// Open Bulk Action Modal
3136
3137function showBulkActionModal(){
3138
3139    $('#bulk-action-modal').modal('show');
3140}
3141
3142//Hide BulkActionModal
3143function hideBulkActionModal(){
3144    $('#bulk-action-modal').modal('hide');
3145}
3146
3147function initFooTable() {
3148    generateDetails();
3149    initToggles();
3150    handleResize();
3151    updateToggleVisibility(); // Initial check
3152}
3153
3154/* Build details rows for hidden columns */
3155function generateDetails() {
3156    // Remove old details rows
3157    document.querySelectorAll(".details-row").forEach(el => el.remove());
3158
3159    document.querySelectorAll(".data-row").forEach(row => {
3160        const details = document.createElement("tr");
3161        details.className = "details-row";
3162
3163        // Mark this details row as belonging to its data row
3164        details.dataset.parentId = row.dataset.rowId || row.getAttribute("id") || [...document.querySelectorAll(".data-row")].indexOf(row);
3165
3166        const td = document.createElement("td");
3167        td.colSpan = row.children.length;
3168
3169        let html = "";
3170
3171        [...row.children].forEach(cell => {
3172            if (cell.querySelector(".toggle-plus-minus-btn")) return;
3173
3174            if (window.getComputedStyle(cell).display === "none") {
3175                const label = cell.dataset.label || "";
3176                html += `
3177                    <div class="detail-item py-10px">
3178                        <span class="detail-label d-block text-uppercase fs-12 fw-700 text-secondary mb-2">
3179                            ${label}:
3180                        </span>
3181                        <span class="detail-value d-block">${cell.innerHTML}</span>
3182                    </div>
3183                `;
3184            }
3185        });
3186
3187        td.innerHTML = html;
3188        details.appendChild(td);
3189
3190        // Insert after the data row
3191        row.insertAdjacentElement("afterend", details);
3192
3193        // Preserve open state: check if it was open before rebuild
3194        const toggleBtn = row.querySelector(".toggle-plus-minus-btn");
3195        if (toggleBtn && toggleBtn.textContent === "-") {
3196            details.style.display = "table-row";
3197            toggleBtn.textContent = "-"; // keep minus
3198        } else {
3199            details.style.display = "none";
3200            if (toggleBtn) toggleBtn.textContent = "+";
3201        }
3202    });
3203}
3204
3205/* Toggle button handler */
3206function initToggles() {
3207    document.querySelectorAll(".toggle-plus-minus-btn").forEach(btn => {
3208        btn.onclick = () => {
3209            const row = btn.closest("tr");
3210            const details = row.nextElementSibling;
3211            const isOpen = details.style.display === "table-row";
3212
3213            details.style.display = isOpen ? "none" : "table-row";
3214            btn.textContent = isOpen ? "+" : "-";
3215        };
3216    });
3217}
3218
3219/* Show toggle only if there are hidden columns */
3220function updateToggleVisibility() {
3221    document.querySelectorAll(".data-row").forEach(row => {
3222        const toggleBtn = row.querySelector(".toggle-plus-minus-btn");
3223        if (!toggleBtn) return;
3224
3225        const hasHidden = [...row.children].some(cell =>
3226            cell !== toggleBtn.parentElement && window.getComputedStyle(cell).display === "none"
3227        );
3228
3229        toggleBtn.style.display = hasHidden ? "inline-block" : "none";
3230
3231        // Reset to + if no hidden columns (safety)
3232        if (!hasHidden) {
3233            const details = row.nextElementSibling;
3234            if (details && details.classList.contains("details-row")) {
3235                details.style.display = "none";
3236            }
3237            toggleBtn.textContent = "+";
3238        }
3239    });
3240}
3241
3242/* Handle resize: rebuild but preserve open states */
3243function handleResize() {
3244    // Step 1: Remember which rows were open (by checking button text)
3245    const openStates = new Map();
3246    document.querySelectorAll(".data-row").forEach(row => {
3247        const btn = row.querySelector(".toggle-plus-minus-btn");
3248        const key = row.dataset.rowId || [...document.querySelectorAll(".data-row")].indexOf(row);
3249        if (btn) {
3250            openStates.set(key, btn.textContent === "-");
3251        }
3252    });
3253
3254    // Step 2: Rebuild everything
3255    generateDetails();
3256
3257    // Step 3: Restore open states
3258    document.querySelectorAll(".data-row").forEach(row => {
3259        const btn = row.querySelector(".toggle-plus-minus-btn");
3260        if (!btn) return;
3261
3262        const key = row.dataset.rowId || [...document.querySelectorAll(".data-row")].indexOf(row);
3263        if (openStates.get(key)) {
3264            const details = row.nextElementSibling;
3265            if (details && details.classList.contains("details-row")) {
3266                details.style.display = "table-row";
3267            }
3268            btn.textContent = "-";
3269        }
3270    });
3271
3272    // Step 4: Update toggle visibility (in case breakpoints changed)
3273    updateToggleVisibility();
3274}
3275
3276// Throttle resize for performance
3277let resizeTimeout;
3278window.addEventListener("resize", () => {
3279    clearTimeout(resizeTimeout);
3280    resizeTimeout = setTimeout(handleResize, 100);
3281});
3282//behabiour for Table Nav Tabs Scroll
3283document.addEventListener('DOMContentLoaded', () => {
3284    const tableTabsContainer = document.querySelector('.table-tabs-container');
3285    // If element not found — break
3286    if (!tableTabsContainer) return;
3287    const tableTabs = tableTabsContainer.querySelectorAll('.nav-link');
3288    tableTabs.forEach(tab => {
3289        tab.addEventListener('click', () => {
3290            const offset =
3291                tab.offsetLeft - tableTabsContainer.clientWidth / 2 + tab.clientWidth / 2;
3292
3293            tableTabsContainer.scrollTo({
3294                left: offset,
3295                behavior: "smooth"
3296            });
3297        });
3298    });
3299});

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.