%PDF- %PDF-
Direktori : /var/www/projetos/suporte.iigd.com.br/js/ |
Current File : //var/www/projetos/suporte.iigd.com.br/js/fileupload.min.js |
/** * --------------------------------------------------------------------- * * GLPI - Gestionnaire Libre de Parc Informatique * * http://glpi-project.org * * @copyright 2015-2024 Teclib' and contributors. * @copyright 2003-2014 by the INDEPNET Development Team. * @licence https://www.gnu.org/licenses/gpl-3.0.html * * --------------------------------------------------------------------- * * LICENSE * * This file is part of GLPI. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. * * --------------------------------------------------------------------- */ var insertIntoEditor=[];var uploaded_images=[];function uploadFile(e,t){insertIntoEditor[e.name]=isImage(e);var n=$('[data-uploader-name="'+t.getElement().name+'"]');if(n.length===0){n=$(t.getElement()).closest("form").find('[data-uploader-name="filename"]')}if(n.length===0){n=$(t.getElement()).closest("form").find("[data-uploader-name=]").first()}n.fileupload("add",{files:[e]})}var handleUploadedFile=function(e,t,n,a,i){$.ajax({type:"POST",url:CFG_GLPI.root_doc+"/ajax/getFileTag.php",data:{data:t},dataType:"JSON",success:function(r){$.each(e,(function(e,o){if(t[e].error!==undefined){a.parent().find(".uploadbar").text(t[e].error).css("width","100%");return}var d=r[e];var l=null;if(i){l=tinyMCE.get(i);const e=uploaded_images.find((function(e){return e.filename===o.name}));const t=e!==undefined?l.dom.select('img[data-upload_id="'+e.upload_id+'"]'):[];if(t.length>0){l.dom.setAttrib(t,"id",d.tag.replace(/#/g,""))}else if(Object.prototype.hasOwnProperty.call(insertIntoEditor,o.name)&&insertIntoEditor[o.name]){insertImgFromFile(l,o,d.tag);n=l.targetElm.name}}displayUploadedFile(t[e],d,l,n,a);a.parent().find(".uploadbar").text(__("Upload successful")).css("width","100%").delay(2e3).fadeOut("slow")}))},error:function(e){console.warn(e.responseText)},complete:function(){$.each(e,(function(e,t){delete insertIntoEditor[t.name]}))}})};var displayUploadedFile=function(e,t,n,a,i){var r=$('input[name^="_'+a+'["]').length;var o=e.name.split(".").pop();var d=$("<p></p>").attr("id",e.id).html(getExtIcon(o)+" "+"<b>"+e.display+"</b>"+" ("+getSize(e.size)+") ").appendTo(i);$("<input/>").attr("type","hidden").attr("name","_"+a+"["+r+"]").attr("value",e.name).appendTo(d);$("<input/>").attr("type","hidden").attr("name","_prefix_"+a+"["+r+"]").attr("value",e.prefix).appendTo(d);$("<input/>").attr("type","hidden").attr("name","_tag_"+a+"["+r+"]").attr("value",t.name).appendTo(d);var l={0:e.id,1:e.id+"2"};$('<span class="ti ti-circle-x pointer"></span>').click((function(){deleteImagePasted(l,t.tag,n)})).appendTo(d)};var deleteImagePasted=function(e,t,n){$.each(e,(function(e,t){$("#"+t).remove()}));if(typeof n!=="undefined"&&typeof n.dom!=="undefined"){var a=new RegExp("#","g");n.dom.remove(t.replace(a,""))}};var insertImgFromFile=function(e,t,n){var a=window.URL||window.webkitURL;var i=a.createObjectURL(t);var r=new RegExp("#","g");var o=$(tinyMCE.activeEditor.getContainer()).height()-60;var d=$(tinyMCE.activeEditor.getContainer()).width()-120;if(window.FileReader&&window.File&&window.FileList&&window.Blob){e.setProgressState(true);var l=new FileReader;l.onload=function(t){var a=new Image;a.src=t.target.result;a.onload=function(){var t=this.width;var a=this.height;var l=0;if(t>d){l=d/t;a=a*l;t=t*l}if(a>o){l=o/a;t=t*l;a=a*l}e.execCommand("mceInsertContent",false,"<img width='"+t+"' height='"+a+"' id='"+n.replace(r,"")+"' src='"+i+"'>");e.setProgressState(false)}};l.readAsDataURL(t)}else{console.warn("thanks to update your browser to get preview of image")}};var dataURItoBlob=function(e){var t;if(e.split(",")[0].indexOf("base64")>=0){t=atob(e.split(",")[1])}else{t=unescape(e.split(",")[1])}var n=e.split(",")[0].split(":")[1].split(";")[0];var a=n.split("/")[1];var i=new Uint8Array(t.length);for(var r=0;r<t.length;r++){i[r]=t.charCodeAt(r)}var o=new Blob([i],{type:n});o.name="image_paste"+Math.floor(Math.random()*1e7+1)+"."+a;return o};var isImageFromPaste=function(e){return e.match(new RegExp("<img.*data:image/"))!==null};var isImageBlobFromPaste=function(e){return e.match(new RegExp("<img.*src=['\"]blob:"))!==null};var extractSrcFromImgTag=function(e){var t=$("<div></div>").append(e).find("img");if(t.length>0){return t.attr("src")}return""};var insertImageInTinyMCE=function(e,t){uploadFile(t,e)};const setRichTextEditorContent=function(e,t){if(typeof tinyMCE==="undefined"){return}const n=tinyMCE.get(e);if(n){n.setContent("");n.execCommand("mceInsertClipboardContent",false,{html:t,internal:true});n.fire("keyup")}};if(typeof tinyMCE!="undefined"){tinyMCE.PluginManager.add("glpi_upload_doc",(function(e){let t=null;const n={pngblip:"image/png",jpegblip:"image/jpeg"};e.on("paste",(e=>{t=e.clipboardData}));e.on("PastePreProcess",(function(a){const i=[];if(t!==null&&t.types.includes("text/rtf")){const e=t.getData("text/rtf");const a=e.replace(/(\r\n|\n|\r)/gm,"");const r=a.matchAll(/\\(pngblip|jpegblip)([a-z0-9]*)}/g);for(const e of r){const t=e[1];const a=e[2];const r=function(e){return btoa(e.match(/\w{2}/g).map((function(e){return String.fromCharCode(parseInt(e,16))})).join(""))};i.push({type:n[t],content:r(a)})}}var r=$("<div></div>");r.append(a.content);r.find("img").each((function(){const t=$(this);let n=t.attr("src");const a="^file://";if(n.match(a)!==null&&i.length>0){const e=i.shift();n=`data:${e["type"]};base64,`+e["content"];t.attr("src",n)}if(n.match(new RegExp("^(data|blob):"))!==null){const a=Math.random().toString();t.attr("data-upload_id",a);fetch(n).then((function(e){return e.blob()})).then((function(t){if(/^image\/.+/.test(t.type)===false){return}if(t instanceof File){t=new Blob([t],{type:t.type})}const n=t.type.replace("image/","");t.name="image_paste"+Math.floor(Math.random()*1e7+1)+"."+n;uploaded_images.push({upload_id:a,filename:t.name});uploadFile(t,e)}))}}));a.content=r.html()}))}))}$((function(){$(document).bind("dragover",(function(e){e.preventDefault();var t=$(".dropzone");var n;var a=window.dropZoneTimeout;if(!a){t.addClass("dragin")}else{clearTimeout(a)}var i=false;var r=e.target;do{if($(r).hasClass("draghoverable")){i=true;n=$(r);break}r=r.parentNode}while(r!==null);t.removeClass("dragin draghover");if(i){n.addClass("draghover")}}));$(document).bind("drop",(function(e){e.preventDefault();$(".draghoverable").removeClass("draghover")}))}));