PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 3.1.0
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v3.1.0
3.1.9 3.1.8 3.1.7 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 trunk 1.3.7 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9 2.9.1 2.9.2
folders / assets / js / simpledropit.min.js
folders / assets / js Last commit date
custom.js 1 year ago folders.min.js 1 year ago jquery.overlayscrollbars.min.js 1 year ago jquery.star-rating-svg.min.js 1 year ago jquery.ui.touch-punch.min.js 1 year ago jstree.min.js 1 year ago lottie-player.js 4 years ago lottie-player.json 4 years ago mailcheck.js 1 year ago media.min.js 1 year ago new-media.min.js 1 year ago page-post-media.min.js 1 year ago replace-file-name.js 1 year ago replace-media.min.js 1 year ago select2.min.js 1 year ago simpledropit.min.js 1 year ago slick.min.js 1 year ago spectrum.min.js 2 years ago
simpledropit.min.js
367 lines
1 /**
2 * SimpleDropit.js - v0.1.1
3 * Drag-n-drop files, Simple for modern browsers
4 * https://nishantk02.github.io/SimpleDropit
5 *
6 * Made by Nishant K
7 * Under MIT License
8 */
9
10 /**
11 * SimpleDropit.js - v0.1.1
12 * Drag-n-drop files, Simple for modern browsers
13 * https://nishantk02.github.io/SimpleDropit
14 *
15 * Made by Nishant K
16 * Under MIT License
17 */
18
19 (function (global, factory) {
20 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
21 typeof define === 'function' && define.amd ? define(factory) :
22 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.SimpleDropit = factory());
23 }(this, (function () { 'use strict';
24
25 function _extends() {
26 _extends = Object.assign || function (target) {
27 for (var i = 1; i < arguments.length; i++) {
28 var source = arguments[i];
29
30 for (var key in source) {
31 if (Object.prototype.hasOwnProperty.call(source, key)) {
32 target[key] = source[key];
33 }
34 }
35 }
36
37 return target;
38 };
39
40 return _extends.apply(this, arguments);
41 }
42
43 function _inheritsLoose(subClass, superClass) {
44 subClass.prototype = Object.create(superClass.prototype);
45 subClass.prototype.constructor = subClass;
46
47 _setPrototypeOf(subClass, superClass);
48 }
49
50 function _setPrototypeOf(o, p) {
51 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
52 o.__proto__ = p;
53 return o;
54 };
55
56 return _setPrototypeOf(o, p);
57 }
58
59 function _assertThisInitialized(self) {
60 if (self === void 0) {
61 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
62 }
63
64 return self;
65 }
66
67 // Helper functions
68 function getElementDocument(element) {
69 if (!element || !element.ownerDocument) {
70 return document;
71 }
72
73 return element.ownerDocument;
74 }
75 function hasClass(element, className) {
76 if (element) {
77 return element.classList.contains(className);
78 } else {
79 return null;
80 }
81 }
82 function triggerClick(element) {
83 if (element.click) {
84 element.click();
85 } else if (document.createEvent) {
86 var eventObj = document.createEvent('MouseEvents');
87 eventObj.initEvent('click', true, true);
88 element.dispatchEvent(eventObj);
89 }
90 }
91
92 var SimpleDropitMethods = /*#__PURE__*/function () {
93 function SimpleDropitMethods() {}
94
95 SimpleDropitMethods.isFiles = function isFiles(arg) {
96 var r = false;
97
98 if (arg.types === undefined && arg.files) {
99 for (var _i = 0, _Object$entries = Object.entries(arg.files); _i < _Object$entries.length; _i++) {
100 var _Object$entries$_i = _Object$entries[_i];
101 _Object$entries$_i[0];
102 var file = _Object$entries$_i[1];
103
104 if (file.name !== '') {
105 r = true;
106 }
107 }
108 } else {
109 arg.types.forEach(function (file, index) {
110 if (file === "Files" || file === "application/x-moz-file") {
111 r = true;
112 }
113 });
114 }
115
116 return r;
117 };
118
119 return SimpleDropitMethods;
120 }();
121
122 var SimpleDropit = /*#__PURE__*/function (_SimpleDropitMethods) {
123 _inheritsLoose(SimpleDropit, _SimpleDropitMethods);
124
125 /**
126 * SimpleDropit Object
127 * @param {String} selector Element object
128 * @param {Object} options User options
129 */
130 function SimpleDropit(selector, options) {
131 var _this;
132
133 _this = _SimpleDropitMethods.call(this) || this;
134
135 _this.isAdvancedUpload = function () {
136 var div = document.createElement('div');
137 return ('draggable' in div || 'ondragstart' in div && 'ondrop' in div) && 'FormData' in window && 'FileReader' in window;
138 };
139
140 _this.onChange = function (event) {
141 if (!SimpleDropit.isFiles(event.target)) {
142 return;
143 }
144
145 SimpleDropit.showFiles(_this.filenameEl, event.target.files);
146
147 _this.boxEl.classList.add('is-dropped');
148 };
149
150 _this.dragIn = function (event) {
151 // Check the dragged elements are Files
152 if (!SimpleDropit.isFiles(event.dataTransfer)) {
153 return;
154 }
155
156 if (!hasClass(_this.boxEl, 'is-dragover')) _this.boxEl.classList.add('is-dragover');
157 };
158
159 _this.dragOut = function (event) {
160 // Check the dragged elements are Files
161 if (!SimpleDropit.isFiles(event.dataTransfer)) {
162 return;
163 }
164
165 if (hasClass(_this.boxEl, 'is-dragover')) _this.boxEl.classList.remove('is-dragover');
166 };
167
168 _this.drop = function (event) {
169 // Check the dropped elements are Files
170 if (!SimpleDropit.isFiles(event.dataTransfer)) {
171 return;
172 }
173
174 _this.droppedFiles = event.dataTransfer.files;
175 SimpleDropit.showFiles(_this.filenameEl, _this.droppedFiles);
176
177 _this.boxEl.classList.add('is-dropped');
178 };
179
180 _this.preventEventPropagation = function (event) {
181 event.preventDefault();
182 event.stopPropagation();
183 };
184
185 try {
186 if (typeof selector === 'string') {
187 throw new Error('Invalid Element Object');
188 } else if (typeof selector === 'object' && selector !== null) {
189 _this.el = selector;
190 } else {
191 throw new Error('Element Object does not exists');
192 }
193 } catch (error) {
194 console.error(error.name + ': ' + error.message);
195 return _assertThisInitialized(_this);
196 }
197
198 _this.options = _extends({}, SimpleDropit.defaultOptions, options);
199 _this.classNames = _extends({}, SimpleDropit.defaultOptions.classNames, _this.options.classNames);
200
201 if (SimpleDropit.instances.has(_this.el)) {
202 return _assertThisInitialized(_this);
203 }
204
205 _this.init();
206
207 return _this;
208 }
209
210 var _proto = SimpleDropit.prototype;
211
212 _proto.init = function init() {
213 // Save a reference to the instance, so we know this DOM node has already been instanciated
214 SimpleDropit.instances.set(this.el, this);
215 this.initDom();
216 this.initListeners();
217 };
218
219 _proto.initDom = function initDom() {
220 // Assuring this element doesn't have the wrapper elements yet
221 if (this.el.closest('.' + this.classNames.boxEl) !== null) {
222 // Assume that element has his DOM already initiated
223 this.boxEl = this.el.closest('.' + this.classNames.boxEl);
224 this.boxWrapperEl = this.boxEl.querySelector('.' + this.classNames.boxWrapperEl);
225 this.labelWrapperEl = this.boxEl.querySelector('.' + this.classNames.labelWrapperEl);
226 this.supportedLabelEl = this.boxEl.querySelector('.' + this.classNames.supportedLabelEl);
227 this.filenameEl = this.boxEl.querySelector('.' + this.classNames.filenameEl);
228 this.browseLabelEl = this.boxEl.querySelector('.' + this.classNames.browseLabelEl);
229 } else {
230 // Prepare DOM
231 var elClone = this.el.cloneNode(true);
232 this.boxEl = document.createElement('div');
233 this.boxWrapperEl = document.createElement('div');
234 this.labelWrapperEl = document.createElement('div');
235 this.supportedLabelEl = document.createElement('span');
236 this.filenameEl = document.createElement('span');
237 this.browseLabelEl = document.createElement('label');
238 this.boxEl.classList.add(this.classNames.boxEl);
239 this.boxWrapperEl.classList.add(this.classNames.boxWrapperEl);
240 this.labelWrapperEl.classList.add(this.classNames.labelWrapperEl);
241 this.supportedLabelEl.classList.add(this.classNames.supportedLabelEl);
242 this.filenameEl.classList.add(this.classNames.filenameEl);
243 this.browseLabelEl.classList.add(this.classNames.browseLabelEl);
244 this.el.classList.add('sd-file-input', 'sd-file-input-hide');
245 this.supportedLabelEl.innerHTML = this.options.supportedLabel + '&nbsp;';
246 this.labelWrapperEl.appendChild(this.supportedLabelEl);
247 this.labelWrapperEl.appendChild(this.filenameEl);
248 this.browseLabelEl.innerHTML = '<div class="upload-overlay"><svg width="28" height="24" viewBox="0 0 28 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M2 16.1667V17.6667C2 20.0599 3.9401 22 6.33333 22H21.6667C24.0599 22 26 20.0599 26 17.6667V16.1667M14 17.8333V2M14 2L20.8571 8.66667M14 2L7.14286 8.66667" stroke="#E6386C" stroke-width="2.16667" stroke-linejoin="round"></path> </svg><span class="upload-title">'+replace_settings.drag_file+'</span><span class="upload-size">'+replace_settings.max_size+'</span></div>';
249 this.labelWrapperEl.appendChild(this.browseLabelEl);
250 this.labelWrapperEl.appendChild(elClone);
251 this.boxWrapperEl.appendChild(this.labelWrapperEl);
252 this.boxEl.appendChild(this.boxWrapperEl);
253 this.el.after(this.boxEl);
254 this.el.remove();
255 this.el = elClone;
256 }
257
258 if (this.isAdvancedUpload) {
259 this.boxEl.classList.add('sd-advanced-upload');
260 }
261 };
262
263 _proto.initListeners = function initListeners() {
264 var _this2 = this;
265
266 ['drag', 'dragstart', 'dragend', 'dragover', 'dragenter', 'dragleave', 'drop'].forEach(function (e) {
267 getElementDocument(_this2.boxEl).addEventListener(e, _this2.preventEventPropagation, false);
268
269 _this2.boxEl.addEventListener(e, _this2.preventEventPropagation, false);
270 });
271 ['dragenter', 'dragover'].forEach(function (e) {
272 getElementDocument(_this2.boxEl).addEventListener(e, _this2.dragIn, true);
273 });
274 ['dragleave', 'drop'].forEach(function (e) {
275 getElementDocument(_this2.boxEl).addEventListener(e, _this2.dragOut, true);
276 });
277 this.boxEl.addEventListener('drop', this.drop, true);
278 this.el.addEventListener('change', this.onChange, true);
279 this.browseLabelEl.addEventListener('click', function (event) {
280 triggerClick(_this2.el);
281 });
282 };
283
284 SimpleDropit.showFiles = function showFiles(el, files) {
285 var fileName = files[0].name;
286
287 if (fileName !== '' && fileName !== undefined) {
288 el.innerText = ""; //files.length > 1 ? files.length + ' files selected / ' : fileName;
289
290 jQuery(".sd-label-wrapper .img-overlay").remove();
291 jQuery(".sd-label-wrapper").append("<div class='img-overlay'></div>");
292 jQuery(".sd-label-wrapper .img-overlay").append("<span class='file-name'>"+replace_settings.file_name+": "+fileName+"</span>");
293
294 fileName = fileName.toLowerCase();
295 fileName = fileName.split(".");
296 var fileExt = fileName[fileName.length - 1];
297 jQuery(".new-image-box .image-size").remove();
298 if(fileExt == "jpg" || fileExt == "png" || fileExt == "jpeg" || fileExt == "gif" || fileExt == "svg" || fileExt == "webp") {
299 if (files && files[0]) {
300 var reader = new FileReader();
301 jQuery(".sd-label-wrapper .img-overlay").append("<span class='file-size'>"+replace_settings.file_type+": "+ files[0].type +"</span>");
302 reader.onload = function (e) {
303 var fileSize = getFileSize(e.total);
304 jQuery(".upload-overlay").html("<img class='pre-image' id='pre-image' >");
305 jQuery('#pre-image').attr('src', e.target.result);
306
307 var image = new Image();
308 image.src = e.target.result;
309 image.onload = function () {
310 jQuery(".sd-label-wrapper .img-overlay").append("<span class='file-size'>"+replace_settings.dimension+": "+this.width + " x " + this.height +"</span>");
311 jQuery(".sd-label-wrapper .img-overlay").append("<span class='file-size'>"+replace_settings.file_size+": "+ fileSize +"</span>");
312 };
313 }
314 reader.readAsDataURL(files[0]); // convert to base64 string
315 }
316 } else {
317 jQuery(".upload-overlay").html('<span class="dashicons dashicons-media-document"></span>');
318 if (files && files[0]) {
319 var fileSize = getFileSize(files[0].size);
320 jQuery(".sd-label-wrapper .img-overlay").append("<span class='file-size'>"+replace_settings.file_type+": "+ files[0].type +"</span>");
321 jQuery(".sd-label-wrapper .img-overlay").append("<span class='file-size'>"+replace_settings.file_size+": "+ fileSize +"</span>");
322 }
323 }
324
325 jQuery(".file-type").removeClass("active");
326 if(fileExt.toLowerCase() != (jQuery("#file_ext").val()).toLowerCase()) {
327 jQuery(".file-type").addClass("active");
328 }
329 jQuery(".button-primary").prop("disabled", false);
330 return true;
331 } else {
332 return false;
333 }
334 };
335
336 return SimpleDropit;
337 }(SimpleDropitMethods);
338
339 function getFileSize(fileSize) {
340 fileSize = parseInt(fileSize);
341 if(fileSize > 1000000) {
342 fileSize = parseFloat(fileSize/1000000).toFixed(2)+" MB";
343 } else if(fileSize > 1000) {
344 fileSize = parseFloat(fileSize/1000).toFixed(2)+" KB";
345 } else {
346 fileSize = fileSize+" B";
347 }
348 return fileSize;
349 }
350
351 SimpleDropit.instances = new WeakMap();
352 SimpleDropit.defaultOptions = {
353 classNames: {
354 boxEl: 'sd-box',
355 boxWrapperEl: 'sd-box-wrapper',
356 browseLabelEl: 'sd-label',
357 filenameEl: 'sd-box-file-name',
358 labelWrapperEl: 'sd-label-wrapper',
359 supportedLabelEl: 'sd-box-dragndrop'
360 },
361 supportedLabel: ''
362 };
363
364 return SimpleDropit;
365
366 })));
367