PageSourceSearch

https://texacopuertorico.com/wp-content/plugins/listeo-core/assets/js/uploads.min.js?ver=2.0.52

js texacopuertorico.com collected 2026-10-08 17:11:37 UTC 7,189 bytes, 203 lines download raw bytes

1/* ----------------- Start Document ----------------- */
2(function ($) {
3  "use strict";
4
5  if ($("#media-uploader._gallery").length > 0) {
6    var gallery_limit = $("#media-uploader._gallery").data("maxfiles");
7    if (!gallery_limit) {
8      gallery_limit = listeo_core.maxFiles;
9    }
10
11    /* Upload using dropzone */
12    Dropzone.autoDiscover = false;
13
14    var galleryDropzone = new Dropzone("#media-uploader._gallery", {
15      url: listeo_core.upload,
16      timeout: 999999,
17      maxFiles: gallery_limit,
18      acceptedFiles: "image/*",
19      maxFilesize: listeo_core.maxFilesize,
20      dictMaxFilesExceeded: listeo_core.dictMaxFilesExceeded,
21      dictDefaultMessage: listeo_core.dictDefaultMessage,
22      dictFallbackMessage: listeo_core.dictFallbackMessage,
23      dictFallbackText: listeo_core.dictFallbackText,
24      dictFileTooBig: listeo_core.dictFileTooBig,
25      dictInvalidFileType: listeo_core.dictInvalidFileType,
26      dictResponseError: listeo_core.dictResponseError,
27      dictCancelUpload: listeo_core.dictCancelUpload,
28      dictCancelUploadConfirmation: listeo_core.dictCancelUploadConfirmation,
29      dictRemoveFile: listeo_core.dictRemoveFile,
30      init: function () {
31        var myDropzone = this;
32
33        this.on("sending", function (file, xhr, formData) {
34          var id = $("input[name=property_id]").val();
35          formData.append("data", id);
36          formData.append("nonce", listeo_core.upload_nonce);
37        });
38
39        this.on("addedfile", function (file) {
40          /* Set active thumb class to preview that is used as thumbnail*/
41          if (file["attachment_id"] === parseInt($("#_thumbnail_id").val())) {
42            file.previewElement.className +=
43              " active-thumb _gallery" + file["attachment_id"];
44          } else {
45            file.previewElement.className +=
46              " _gallery" + parseInt(file["attachment_id"]);
47          }
48
49          file.previewElement.addEventListener("click", function () {
50            $(".dz-preview").removeClass("active-thumb");
51            $(this).addClass("active-thumb");
52            var id = file["attachment_id"];
53            $("#_thumbnail_id").val(id);
54          });
55        });
56
57        this.on("complete", function (file) {
58          file.previewElement.className += " _gallery" + file.attachment_id;
59        });
60
61        this.on("queuecomplete", function (file) {
62          $(".dz-image-preview:first").trigger("click");
63        });
64
65        // Critical - this tells Dropzone how many more files we can accept
66        this.on("maxfilesexceeded", function (file) {
67          console.log("Max files exceeded. Removing:", file.name);
68          this.removeFile(file);
69        });
70      },
71
72      success: function (file, response) {
73        file.previewElement.classList.add("dz-success");
74        response = response.replace(/(\r\n|\n|\r)/gm, "");
75        file["attachment_id"] = response; // push the id for future reference
76        $("#media-uploader-ids").append(
77          '<input id="_gallery' +
78            file["attachment_id"] +
79            '" type="hidden" name="_gallery[' +
80            file["attachment_id"] +
81            ']"  value="' +
82            file["name"] +
83            '">'
84        );
85      },
86
87      error: function (file, response) {
88        file.previewElement.classList.add("dz-error");
89        $(file.previewElement).find(".dz-error-message").text(response);
90      },
91
92      // update the following section is for removing image from library
93      addRemoveLinks: true,
94      removedfile: function (file) {
95        var attachment_id = file["attachment_id"];
96        $("input#_gallery" + attachment_id).remove();
97
98        /*remove thumbnail if the image was set as it*/
99        if ($("#_thumbnail_id").val() == attachment_id) {
100          $("#_thumbnail_id").val("");
101        }
102
103        // Remove the file from the Dropzone instance's files array
104        var _ref;
105        if ((_ref = file.previewElement) != null) {
106          _ref.parentNode.removeChild(file.previewElement);
107        }
108
109        // Find and remove file from internal files array
110        for (var i = 0; i < this.files.length; i++) {
111          if (this.files[i] === file) {
112            this.files.splice(i, 1);
113            break;
114          }
115        }
116
117        // Send the AJAX request to delete the file
118        $.ajax({
119          type: "POST",
120          url: listeo_core.delete,
121          data: {
122            media_id: attachment_id,
123            nonce: listeo_core.upload_nonce,
124          },
125          success: function (result) {
126            console.log("File deleted successfully:", result);
127          },
128          error: function () {
129            console.log("delete error");
130          },
131        });
132
133        // IMPORTANT: Reset Dropzone's internal maxFiles counter
134        // This is what allows new uploads after removal
135        this.options.maxFiles = gallery_limit;
136
137        console.log("File removed. Remaining gallery limit:", gallery_limit);
138        console.log("Current file count:", this.files.length);
139        console.log("Available slots:", gallery_limit - this.files.length);
140
141        return file;
142      },
143    });
144
145    if (typeof images !== typeof undefined && images !== false) {
146      var uploaded_media = jQuery.parseJSON(images);
147
148      for (var i = 0; i < uploaded_media.length; ++i) {
149        var mockFile = {
150          name: uploaded_media[i].name,
151          size: uploaded_media[i].size,
152          attachment_id: uploaded_media[i].attachment_id,
153          status: Dropzone.ADDED,
154          accepted: true,
155        };
156        galleryDropzone.emit("addedfile", mockFile);
157        galleryDropzone.emit("thumbnail", mockFile, uploaded_media[i].thumb);
158        galleryDropzone.emit("complete", mockFile);
159        galleryDropzone.files.push(mockFile);
160      }
161
162      // Log the initial state
163      console.log("Total gallery limit:", gallery_limit);
164      console.log("Existing files:", galleryDropzone.files.length);
165      console.log(
166        "Available slots:",
167        gallery_limit - galleryDropzone.files.length
168      );
169    }
170
171    $(".dropzone")
172      .sortable({
173        items: ".dz-preview",
174        cursor: "move",
175        opacity: 0.5,
176        containment: ".dropzone",
177        distance: 20,
178        tolerance: "pointer",
179        update: sortinputs,
180      })
181      .disableSelection();
182
183    function sortinputs() {
184      $(".dropzone .dz-preview").each(function (i, el) {
185        var p = $(el).attr("class").match(/\d+/g);
186        $("#media-uploader-ids input#_gallery" + p)
187          .remove()
188          .appendTo($("#media-uploader-ids"));
189      });
190    }
191  }
192
193  $(document).ready(function () {
194    $(document).on("click", ".listeo_core-submit-image-preview", function () {
195      $(".listeo_core-submit-image-preview").removeClass("active-thumb");
196      $(this).addClass("active-thumb");
197      var id = $(this).data("thumb");
198      $("#_thumbnail_id").val(id);
199    });
200
201    // ------------------ End Document ------------------ //
202  });
203})(this.jQuery);

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.