custom.js
5 years ago
folders.js
5 years ago
folders.min.js
5 years ago
jquery.mcustomscrollbar.min.js
5 years ago
jquery.mousewheel.min.js
5 years ago
jquery.ui.touch-punch.min.js
5 years ago
jstree.js
5 years ago
jstree.min.js
5 years ago
media.js
5 years ago
new-media.js
5 years ago
page-post-media.js
5 years ago
page-post-media.min.js
5 years ago
replace-file-name.js
5 years ago
replace-media.js
5 years ago
select2.min.js
6 years ago
spectrum.min.js
6 years ago
replace-media.js
95 lines
| 1 | (function (factory) { |
| 2 | "use strict"; |
| 3 | if (typeof define === 'function' && define.amd) { |
| 4 | define(['jquery'], factory); |
| 5 | } |
| 6 | else if(typeof module !== 'undefined' && module.exports) { |
| 7 | module.exports = factory(require('jquery')); |
| 8 | } |
| 9 | else { |
| 10 | factory(jQuery); |
| 11 | } |
| 12 | }(function ($, undefined) { |
| 13 | $(document).ready(function (){ |
| 14 | // Open file selector on div click |
| 15 | $(document).on("click", "#upload-file", function(e){ |
| 16 | $("#media_file").click(); |
| 17 | }); |
| 18 | |
| 19 | // file selected |
| 20 | $(document).on("change", "#media_file", function(e){ |
| 21 | var fd = new FormData(); |
| 22 | |
| 23 | var files = $('#media_file')[0].files[0]; |
| 24 | |
| 25 | fd.append('media_file',files); |
| 26 | |
| 27 | uploadData(this); |
| 28 | }); |
| 29 | |
| 30 | $(document).on("click", ".upgrade-btn-box a", function(e){ |
| 31 | e.stopPropagation(); |
| 32 | e.stopImmediatePropagation(); |
| 33 | }); |
| 34 | }); |
| 35 | |
| 36 | function uploadData(input) { |
| 37 | if($("#media_file").val() != "") { |
| 38 | $(".new-image-box .file-size").addClass("hide-it"); |
| 39 | $("#upload-file").removeClass("active"); |
| 40 | |
| 41 | var fileName = $("#media_file").val(); |
| 42 | fileName = fileName.toLowerCase(); |
| 43 | fileName = fileName.split("."); |
| 44 | var fileExt = fileName[fileName.length - 1]; |
| 45 | $(".new-image-box .image-size").remove(); |
| 46 | if(fileExt == "jpg" || fileExt == "png" || fileExt == "jpeg" || fileExt == "gif") { |
| 47 | if (input.files && input.files[0]) { |
| 48 | var reader = new FileReader(); |
| 49 | |
| 50 | reader.onload = function (e) { |
| 51 | $(".drag-and-drop-title").html("<img class='pre-image' id='pre-image' >"); |
| 52 | $('#pre-image').attr('src', e.target.result); |
| 53 | |
| 54 | var image = new Image(); |
| 55 | image.src = e.target.result; |
| 56 | image.onload = function () { |
| 57 | $(".new-image-box img").after('<span class="image-size">Height x Width</span>').show(); |
| 58 | }; |
| 59 | } |
| 60 | |
| 61 | reader.readAsDataURL(input.files[0]); // convert to base64 string |
| 62 | } |
| 63 | } else { |
| 64 | $(".drag-and-drop-title").html('<span class="dashicons dashicons-media-document"></span>'); |
| 65 | } |
| 66 | |
| 67 | setFileSize(input.files[0].size); |
| 68 | |
| 69 | $(".replace-message").removeClass("active"); |
| 70 | if(fileExt != $("#file_ext").val()) { |
| 71 | $(".file-type").addClass("active"); |
| 72 | $("#rename-file").prop("checked", true); |
| 73 | } else { |
| 74 | $("#replace-file").prop("checked", true); |
| 75 | } |
| 76 | $(".button-primary").prop("disabled", false); |
| 77 | } else { |
| 78 | $(".button-primary").prop("disabled", true); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | function setFileSize(fileSize) { |
| 83 | fileSize = parseInt(fileSize); |
| 84 | if(fileSize > 1000000) { |
| 85 | fileSize = parseFloat(fileSize/1000000).toFixed(2)+" MB"; |
| 86 | } else if(fileSize > 1000) { |
| 87 | fileSize = parseFloat(fileSize/1000).toFixed(2)+" KB"; |
| 88 | } else { |
| 89 | fileSize = fileSize+" B"; |
| 90 | } |
| 91 | $(".new-image-box .file-size").removeClass("hide-it"); |
| 92 | $("#upload-file").addClass("active"); |
| 93 | } |
| 94 | |
| 95 | })); |