custom.js
5 years ago
folders.js
5 years ago
folders.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-media.js
5 years ago
select2.min.js
6 years ago
spectrum.min.js
6 years ago
replace-media.js
80 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 | $("#upload-file").click(function(){ |
| 16 | $("#media_file").click(); |
| 17 | }); |
| 18 | |
| 19 | // file selected |
| 20 | $("#media_file").change(function(){ |
| 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 | |
| 31 | function uploadData(input) { |
| 32 | if($("#media_file").val() != "") { |
| 33 | |
| 34 | var fileName = $("#media_file").val(); |
| 35 | fileName = fileName.toLowerCase(); |
| 36 | fileName = fileName.split("."); |
| 37 | var fileExt = fileName[fileName.length - 1]; |
| 38 | if(fileExt == "jpg" || fileExt == "png" || fileExt == "jpeg" || fileExt == "gif") { |
| 39 | if (input.files && input.files[0]) { |
| 40 | var reader = new FileReader(); |
| 41 | |
| 42 | reader.onload = function (e) { |
| 43 | $(".drag-and-drop-title").html("<img class='pre-image' id='pre-image' >"); |
| 44 | $('#pre-image').attr('src', e.target.result); |
| 45 | } |
| 46 | |
| 47 | reader.readAsDataURL(input.files[0]); // convert to base64 string |
| 48 | } |
| 49 | } else { |
| 50 | $(".drag-and-drop-title").html('<span class="dashicons dashicons-media-document"></span>'); |
| 51 | } |
| 52 | |
| 53 | setFileSize(input.files[0].size); |
| 54 | |
| 55 | $(".replace-message").removeClass("active"); |
| 56 | if(fileExt != $("#file_ext").val()) { |
| 57 | $(".file-type").addClass("active"); |
| 58 | $("#rename-file").prop("checked", true); |
| 59 | } else { |
| 60 | $("#replace-file").prop("checked", true); |
| 61 | } |
| 62 | $(".button-primary").prop("disabled", false); |
| 63 | } else { |
| 64 | $(".button-primary").prop("disabled", true); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | function setFileSize(fileSize) { |
| 69 | fileSize = parseInt(fileSize); |
| 70 | if(fileSize > 1000000) { |
| 71 | fileSize = parseFloat(fileSize/1000000).toFixed(2)+" MB"; |
| 72 | } else if(fileSize > 1000) { |
| 73 | fileSize = parseFloat(fileSize/1000).toFixed(2)+" KB"; |
| 74 | } else { |
| 75 | fileSize = fileSize+" B"; |
| 76 | } |
| 77 | $(".new-image-box .file-size").html(fileSize); |
| 78 | } |
| 79 | |
| 80 | })); |