Fork自 GitCode / 1024程序员开源挑战赛(10.23-11.14)
/** * upfile 1.1v * The tinymce-plugins is used to upfile * * https://github.com/Five-great/tinymce-plugins * * Copyright 2020, Five(Li Hailong) The Chengdu, China https://www.fivecc.cn/ * * Licensed under MIT */ var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.createTemplateTagFirstArg=function(a){return a.raw=a};$jscomp.createTemplateTagFirstArgWithRaw=function(a,c){a.raw=c;return a}; tinymce.PluginManager.add("upfile",function(a,c){window.upfile={};window.upfile.file_callback=a.getParam("file_callback",void 0,"function");window.upfile.tinymce=tinymce;window.upfile.res={};var d=function(){return a.windowManager.open({title:"\u4e0a\u4f20\u6587\u4ef6",body:{type:"panel",items:[{type:"iframe",name:"iframe2",label:" ",sandboxed:!0}]},initialData:{iframe2:'<!doctype html>\n <html>\n <head>\n <meta charset="utf-8" />\n <title>upfile</title>\n <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>\n <meta name="apple-mobile-web-app-capable" content="yes" />\n <meta name="apple-mobile-web-app-status-bar-style" content="black" />\n <meta name="format-detection" content="telephone=no">\n <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />\n <style>\n html,body{height:100%;margin:0;padding:0;background:#fff;}\n ul{margin:0;padding:0;list-style:none;}\n #wrap{padding:10px;}\n #topbar{padding:10px 0;border-bottom:1px solid #ccc;text-align:right;}\n .tox *:not(svg):not(rect) {\n box-sizing: inherit;\n color: inherit;\n cursor: inherit;\n direction: inherit;\n font-family: inherit;\n font-size: inherit;\n font-style: inherit;\n font-weight: inherit;\n line-height: inherit;\n -webkit-tap-highlight-color: inherit;\n text-align: inherit;\n text-decoration: inherit;\n text-shadow: inherit;\n text-transform: inherit;\n vertical-align: inherit;\n white-space: inherit;\n }\n \n .tox *:not(svg):not(rect) {\n /* stylelint-disable-line no-duplicate-selectors */\n background: transparent;\n border: 0;\n float: none;\n height: auto;\n margin: 0;\n max-width: none;\n outline: 0;\n padding: 0;\n position: static;\n width: auto;\n }\n \n .tox .tox-form__group {\n box-sizing: border-box;\n margin-bottom: 4px;\n }\n .tox .tox-label, .tox .tox-toolbar-label {\n color: rgba(34,47,62,.7);\n display: block;\n font-size: 14px;\n font-style: normal;\n font-weight: 400;\n line-height: 1.3;\n padding: 0 8px 0 0;\n text-transform: none;\n white-space: nowrap;\n }\n .tox .tox-selectfield select, .tox .tox-textarea, .tox .tox-textfield, .tox .tox-toolbar-textfield {\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n background-color: #fff;\n border-color: #ccc;\n border-radius: 3px;\n border-style: solid;\n border-width: 1px;\n box-shadow: none;\n box-sizing: border-box;\n color: #222f3e;\n font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;\n font-size: 16px;\n line-height: 24px;\n margin: 0;\n min-height: 34px;\n outline: 0;\n padding: 5px 4.75px;\n resize: none;\n width: 100%;\n }\n .tox .tox-dialog__body-content {\n box-sizing: border-box;\n display: flex;\n flex: 1;\n flex-direction: column;\n -ms-flex-preferred-size: auto;\n max-height: 650px;\n overflow: auto;\n -webkit-overflow-scrolling: touch;\n padding: 16px 16px;\n }\n .tox .tox-dialog__body-content {\n box-sizing: border-box;\n display: flex;\n flex: 1;\n flex-direction: column;\n -ms-flex-preferred-size: auto;\n max-height: 650px;\n overflow: auto;\n -webkit-overflow-scrolling: touch;\n padding: 16px 16px;\n }\n .tox .tox-dialog__body-content > * {\n margin-bottom: 0;\n margin-top: 16px;\n }\n .tox .tox-dialog__body-content > *:first-child {\n margin-top: 0;\n }\n .tox .tox-dialog__body-content > *:last-child {\n margin-bottom: 0;\n }\n .tox .tox-dialog__body-content > *:only-child {\n margin-bottom: 0;\n margin-top: 0;\n }\n .tox .tox-dialog__body-content a {\n color: #207ab7;\n cursor: pointer;\n text-decoration: none;\n }\n .tox .tox-dialog__body-content a:hover,\n .tox .tox-dialog__body-content a:focus {\n color: #185d8c;\n text-decoration: none;\n }\n .tox .tox-dialog__body-content a:active {\n color: #185d8c;\n text-decoration: none;\n }\n .tox .tox-dialog__body-content svg {\n fill: #222f3e;\n }\n \n .tox .tox-form__group--stretched {\n display: flex;\n flex: 1;\n flex-direction: column;\n -ms-flex-preferred-size: auto;\n }\n .tox .tox-form__group {\n box-sizing: border-box;\n margin-bottom: 4px;\n }\n .tox .tox-dropzone-container {\n display: flex;\n flex: 1;\n }\n \n element.style {\n }\n .tox .tox-dropzone {\n cursor: pointer;\n align-items: center;\n background: #fff;\n border: 2px dashed #ccc;\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n flex-grow: 1;\n justify-content: center;\n min-height: 100px;\n padding: 10px;\n }\n \n .tox .tox-button {\n background-color: #207ab7;\n background-image: none;\n background-position: 0 0;\n background-repeat: repeat;\n border-color: #207ab7;\n border-radius: 3px;\n border-style: solid;\n border-width: 1px;\n box-shadow: none;\n box-sizing: border-box;\n color: #fff;\n cursor: pointer;\n display: inline-block;\n font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;\n font-size: 14px;\n font-weight: 700;\n letter-spacing: normal;\n line-height: 24px;\n margin: 0;\n outline: 0;\n padding: 4px 16px;\n text-align: center;\n text-decoration: none;\n text-transform: capitalize;\n white-space: nowrap;\n }\n .tox .tox-button[disabled] {\n background-color: #207ab7;\n background-image: none;\n border-color: #207ab7;\n box-shadow: none;\n color: rgba(255, 255, 255, 0.5);\n cursor: not-allowed;\n }\n .tox .tox-button:focus:not(:disabled) {\n background-color: #1c6ca1;\n background-image: none;\n border-color: #1c6ca1;\n box-shadow: none;\n color: #fff;\n }\n .tox .tox-button:hover:not(:disabled) {\n background-color: #1c6ca1;\n background-image: none;\n border-color: #1c6ca1;\n box-shadow: none;\n color: #fff;\n }\n .tox .tox-button:active:not(:disabled) {\n background-color: #185d8c;\n background-image: none;\n border-color: #185d8c;\n box-shadow: none;\n color: #fff;\n }\n \n .tox .tox-button--secondary {\n background-color: #f0f0f0;\n background-image: none;\n background-position: 0 0;\n background-repeat: repeat;\n border-color: #f0f0f0;\n border-radius: 3px;\n border-style: solid;\n border-width: 1px;\n box-shadow: none;\n color: #222f3e;\n outline: 0;\n padding: 4px 16px;\n text-decoration: none;\n text-transform: capitalize;\n }\n .tox .tox-button--secondary[disabled] {\n background-color: #f0f0f0;\n background-image: none;\n border-color: #f0f0f0;\n box-shadow: none;\n cursor: pointer;\n color: rgba(34, 47, 62, 0.5);\n }\n .tox .tox-button--secondary:focus:not(:disabled) {\n background-color: #e3e3e3;\n background-image: none;\n border-color: #e3e3e3;\n box-shadow: none;\n color: #222f3e;\n }\n .tox .tox-button--secondary:hover:not(:disabled) {\n background-color: #e3e3e3;\n background-image: none;\n border-color: #e3e3e3;\n box-shadow: none;\n color: #222f3e;\n }\n .tox .tox-button--secondary:active:not(:disabled) {\n background-color: #d6d6d6;\n background-image: none;\n border-color: #d6d6d6;\n box-shadow: none;\n color: #222f3e;\n }\n </style>\n \n </head>\n <body>\n <div id="wrap">\n <ul id="file_list" class="tox">\n <div role="tabpanel" class="tox-dialog__body-content" style="height: 336px; flex-basis: 210px;" aria-labelledby="aria_5965197812761603939544315">\n <div class="tox-form">\n <div class="tox-form__group">\n <label class="tox-label" for="form-field_8471486645261603941857554">\u94fe\u63a5</label>\n <div class="tox-form__controls-h-stack">\n <div class="tox-control-wrap">\n <input type="url" aria-errormessage="aria-invalid_348682591591603941621447" role="combobox" aria-autocomplete="list" aria-haspopup="true" tabindex="-1" data-alloy-tabstop="true" class="tox-textfield" aria-expanded="false" id="upFileUrlID">\n </div>\n </div>\n </div>\n <div class="tox-form__group">\n <label class="tox-label" for="form-field_2497330145271603941857555">\u663e\u793a\u6587\u5b57</label>\n <input type="text" tabindex="-1" data-alloy-tabstop="true" class="tox-textfield" id="upFileTextID">\n </div>\n <div style="height: 10px;"></div>\n <div class="tox-form__group tox-form__group--stretched">\n <div class="tox-dropzone-container">\n <div class="tox-dropzone">\n <p style="margin: 10px auto;color:rgba(34,47,62,.7)">\u62d6\u653e\u4e00\u5f20\u6587\u4ef6\u81f3\u6b64</p>\n <button id="upfileID" type="button" onclick="getFile()" data-alloy-tabstop="true" tabindex="-1" class="tox-button tox-button--secondary" style="position: relative; min-height: 30px; overflow: visible;">\u6d4f\u89c8\u6587\u4ef6<input type="file" accept="image/*" style="display: none;"></button>\n <input id="upfileNameID" style="margin: 5px auto;font-size: 12px; color:rgba(34,47,62,.7); width: 300px; text-align: center;" type="text" value="">\n </div>\n </div>\n </div>\n </div>\n <button title="\u4e0a\u4f20\u6587\u4ef6" type="button" onclick="sendUpFile()" style="width: 80%;position: absolute;bottom:10px;left: 43px; margin: 0 auto;letter-spacing: 2px; display: block;" class="tox-button"><svg width="24" height="24" style="margin-top:5px;" ><path fill="#fff" d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-4v-2h4V8H5v10h4v2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zm-8 9.4l-2.3 2.3a1 1 0 1 1-1.4-1.4l4-4a1 1 0 0 1 1.4 0l4 4a1 1 0 0 1-1.4 1.4L13 13.4V20a1 1 0 0 1-2 0v-6.6z" fill-rule="nonzero"></path></svg><span style="top:-6px; position: relative; margin-left:5px;">\u5f00\u59cb\u4e0a\u4f20</span></button>\n </div>\n </ul>\n </div>\n <script>\n var editor=parent.upfile.tinymce.activeEditor;\n var upfile=parent.upfile;\n var upload_handler = upfile.file_callback;\n typeof upload_handler == \'function\'?\'\': editor \n var upfileData = ""\n var upfileUrl = null\n function addFile(file){\n upfileData = file[0];\n document.getElementById(\'upfileNameID\').value=file[0].name;\n }\n let inputUrl = document.getElementById(\'upFileUrlID\');\n let inputText = document.getElementById(\'upFileTextID\');\n function sendUpFile(){\n upload_handler(upfileData,function(url,_obj){\n inputUrl.value = url;\n inputText.value ?\'\': inputText.value = url;\n _obj&&_obj.text?inputText.value=_obj.text:\'\';\n upfile.res.url = upfileUrl = url;\n upfile.res.text = inputText.value;\n \n })\n }\n \n inputUrl.oninput = function(){upfile.res.url = inputUrl.value; upfileUrl=== null?inputText.value=inputUrl.value:\'\' }\n inputText.oninput = function(){upfile.res.text=inputText.value;upfileUrl="123";}\n //\u62d6\u62fd\u6dfb\u52a0\n document.addEventListener(\'dragover\', function(e){\n e.stopPropagation();\n e.preventDefault();\n e.dataTransfer.dropEffect = \'copy\';\n });\n document.addEventListener(\'drop\', function(e){\n e.stopPropagation();\n e.preventDefault();\n if(!e.dataTransfer.files){return false;}\n var dropfiles = e.dataTransfer.files;\n if(!(dropfiles.length>0)){return false;}\n addFile(dropfiles);\n });\n \n var global$1 = upfile.tinymce.util.Tools.resolve(\'tinymce.util.Promise\');var global$2 = upfile.tinymce.util.Tools.resolve(\'tinymce.Env\');var global$3 = upfile.tinymce.util.Tools.resolve(\'tinymce.util.Delay\');\n var pickFile=function(a){return new global$1(function(e){var c=document.createElement("input");c.type="file";c.style.position="fixed";c.style.left="0";c.style.top="0";c.style.opacity="0.001";document.body.appendChild(c);var b=function(f){e(Array.prototype.slice.call(f.target.files))};c.addEventListener("change",b);var d=function(g){var f=function(){e([]);c.parentNode.removeChild(c)};if(global$2.os.isAndroid()&&g.type!=="remove"){global$3.setEditorTimeout(a,f,0)}else{f()}a.off("focusin remove",d)};a.on("focusin remove",d);c.click()})};\n function getFile(){\n \n pickFile(editor).then(function (files){\n addFile(files);\n }) \n }\n \x3c/script>\n </body>\n </html>\n '}, buttons:[{type:"cancel",text:"Close"},{type:"custom",text:"Save",name:"save",primary:!0}],onAction:function(e,b){switch(b.name){case "save":b=upfile.res,a.insertContent('<span class="attachment" contenteditable="false"><a href="'+b.url+'" target="_blank" title="'+b.text+'" >'+b.text+"<a></span>"),upfile.res={},e.close()}}})};a.ui.registry.addIcon("upfileicon",'<svg viewBox="0 0 1280 1024" xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M1126.2,779.8V87.6c0-24-22.6-86.9-83.5-86.9H83.5C14.7,0.7,0,63.7,0,87.7v692c0,36.2,29.2,89.7,83.5,89.7l959.3-1.3c51.7,0,83.5-42.5,83.5-88.3zm-1044,4V86.3h961.6V783.7H82.2v0.1z" fill="#53565A"/><path d="M603,461.6L521.1,366.3,313,629.8,227.2,546.8,102.4,716.8H972.8v-170L768.2,235.2,603.1,461.6zM284.6,358.4a105.4,105.4,0,0,0,73.5-30c19.5-19.1,30.3-45,30.2-71.8,0-56.8-45.9-103-102.4-103-56.6,0-102.4,46.1-102.4,103C183.4,313.5,228,358.4,284.6,358.4z" fill="#9598A0"/><path d="M1197.7,153.6l-0.3,669.3s13.5,113.9-67.4,113.9H153.6c0,24.1,23.9,87.2,83.5,87.2h959.3c58.3,0,83.6-49.5,83.6-89.9V240.8c-0.1-41.8-44.9-87.2-82.3-87.2z" fill="#53565A"/></svg>'); a.ui.registry.addButton("upfile",{icon:"upfile",tooltip:"\u4e0a\u4f20\u6587\u4ef6",onAction:function(){d();document.querySelector("iframe[srcdoc]").style.height="360px"}});a.ui.registry.addMenuItem("upfile",{icon:"upfileicon",text:"\u56fe\u7247\u4e0a\u4f20...",onAction:function(){d();document.querySelector("iframe[srcdoc]").style.height="360px"}});return{getMetadata:function(){return{name:"\u4e0a\u4f20\u6587\u4ef6",url:"https://github.com/Five-great/tinymce-plugins"}}}});