upfiles.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>upfile</title>
  6. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
  7. <meta name="apple-mobile-web-app-capable" content="yes" />
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  9. <meta name="format-detection" content="telephone=no">
  10. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  11. <style>
  12. html,body{height:100%;margin:0;padding:0;background:#fff;}
  13. ul{margin:0;padding:0;list-style:none;}
  14. #wrap{padding:10px;}
  15. #topbar{padding:10px 0;border-bottom:1px solid #ccc;text-align:right;}
  16. .tox *:not(svg):not(rect) {
  17. box-sizing: inherit;
  18. color: inherit;
  19. cursor: inherit;
  20. direction: inherit;
  21. font-family: inherit;
  22. font-size: inherit;
  23. font-style: inherit;
  24. font-weight: inherit;
  25. line-height: inherit;
  26. -webkit-tap-highlight-color: inherit;
  27. text-align: inherit;
  28. text-decoration: inherit;
  29. text-shadow: inherit;
  30. text-transform: inherit;
  31. vertical-align: inherit;
  32. white-space: inherit;
  33. }
  34. .tox *:not(svg):not(rect) {
  35. /* stylelint-disable-line no-duplicate-selectors */
  36. background: transparent;
  37. border: 0;
  38. float: none;
  39. height: auto;
  40. margin: 0;
  41. max-width: none;
  42. outline: 0;
  43. padding: 0;
  44. position: static;
  45. width: auto;
  46. }
  47. .tox .tox-form__group {
  48. box-sizing: border-box;
  49. margin-bottom: 4px;
  50. }
  51. .tox .tox-label, .tox .tox-toolbar-label {
  52. color: rgba(34,47,62,.7);
  53. display: block;
  54. font-size: 14px;
  55. font-style: normal;
  56. font-weight: 400;
  57. line-height: 1.3;
  58. padding: 0 8px 0 0;
  59. text-transform: none;
  60. white-space: nowrap;
  61. }
  62. .tox .tox-selectfield select, .tox .tox-textarea, .tox .tox-textfield, .tox .tox-toolbar-textfield {
  63. -webkit-appearance: none;
  64. -moz-appearance: none;
  65. appearance: none;
  66. background-color: #fff;
  67. border-color: #ccc;
  68. border-radius: 3px;
  69. border-style: solid;
  70. border-width: 1px;
  71. box-shadow: none;
  72. box-sizing: border-box;
  73. color: #222f3e;
  74. font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
  75. font-size: 16px;
  76. line-height: 24px;
  77. margin: 0;
  78. min-height: 34px;
  79. outline: 0;
  80. padding: 5px 4.75px;
  81. resize: none;
  82. width: 100%;
  83. }
  84. .tox .tox-dialog__body-content {
  85. box-sizing: border-box;
  86. display: flex;
  87. flex: 1;
  88. flex-direction: column;
  89. -ms-flex-preferred-size: auto;
  90. max-height: 650px;
  91. overflow: auto;
  92. -webkit-overflow-scrolling: touch;
  93. padding: 16px 16px;
  94. }
  95. .tox .tox-dialog__body-content {
  96. box-sizing: border-box;
  97. display: flex;
  98. flex: 1;
  99. flex-direction: column;
  100. -ms-flex-preferred-size: auto;
  101. max-height: 650px;
  102. overflow: auto;
  103. -webkit-overflow-scrolling: touch;
  104. padding: 16px 16px;
  105. }
  106. .tox .tox-dialog__body-content > * {
  107. margin-bottom: 0;
  108. margin-top: 16px;
  109. }
  110. .tox .tox-dialog__body-content > *:first-child {
  111. margin-top: 0;
  112. }
  113. .tox .tox-dialog__body-content > *:last-child {
  114. margin-bottom: 0;
  115. }
  116. .tox .tox-dialog__body-content > *:only-child {
  117. margin-bottom: 0;
  118. margin-top: 0;
  119. }
  120. .tox .tox-dialog__body-content a {
  121. color: #207ab7;
  122. cursor: pointer;
  123. text-decoration: none;
  124. }
  125. .tox .tox-dialog__body-content a:hover,
  126. .tox .tox-dialog__body-content a:focus {
  127. color: #185d8c;
  128. text-decoration: none;
  129. }
  130. .tox .tox-dialog__body-content a:active {
  131. color: #185d8c;
  132. text-decoration: none;
  133. }
  134. .tox .tox-dialog__body-content svg {
  135. fill: #222f3e;
  136. }
  137. .tox .tox-form__group--stretched {
  138. display: flex;
  139. flex: 1;
  140. flex-direction: column;
  141. -ms-flex-preferred-size: auto;
  142. }
  143. .tox .tox-form__group {
  144. box-sizing: border-box;
  145. margin-bottom: 4px;
  146. }
  147. .tox .tox-dropzone-container {
  148. display: flex;
  149. flex: 1;
  150. }
  151. element.style {
  152. }
  153. .tox .tox-dropzone {
  154. cursor: pointer;
  155. align-items: center;
  156. background: #fff;
  157. border: 2px dashed #ccc;
  158. box-sizing: border-box;
  159. display: flex;
  160. flex-direction: column;
  161. flex-grow: 1;
  162. justify-content: center;
  163. min-height: 100px;
  164. padding: 10px;
  165. }
  166. .tox .tox-button {
  167. background-color: #207ab7;
  168. background-image: none;
  169. background-position: 0 0;
  170. background-repeat: repeat;
  171. border-color: #207ab7;
  172. border-radius: 3px;
  173. border-style: solid;
  174. border-width: 1px;
  175. box-shadow: none;
  176. box-sizing: border-box;
  177. color: #fff;
  178. cursor: pointer;
  179. display: inline-block;
  180. font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
  181. font-size: 14px;
  182. font-weight: 700;
  183. letter-spacing: normal;
  184. line-height: 24px;
  185. margin: 0;
  186. outline: 0;
  187. padding: 4px 16px;
  188. text-align: center;
  189. text-decoration: none;
  190. text-transform: capitalize;
  191. white-space: nowrap;
  192. }
  193. .tox .tox-button[disabled] {
  194. background-color: #207ab7;
  195. background-image: none;
  196. border-color: #207ab7;
  197. box-shadow: none;
  198. color: rgba(255, 255, 255, 0.5);
  199. cursor: not-allowed;
  200. }
  201. .tox .tox-button:focus:not(:disabled) {
  202. background-color: #1c6ca1;
  203. background-image: none;
  204. border-color: #1c6ca1;
  205. box-shadow: none;
  206. color: #fff;
  207. }
  208. .tox .tox-button:hover:not(:disabled) {
  209. background-color: #1c6ca1;
  210. background-image: none;
  211. border-color: #1c6ca1;
  212. box-shadow: none;
  213. color: #fff;
  214. }
  215. .tox .tox-button:active:not(:disabled) {
  216. background-color: #185d8c;
  217. background-image: none;
  218. border-color: #185d8c;
  219. box-shadow: none;
  220. color: #fff;
  221. }
  222. .tox .tox-button--secondary {
  223. background-color: #f0f0f0;
  224. background-image: none;
  225. background-position: 0 0;
  226. background-repeat: repeat;
  227. border-color: #f0f0f0;
  228. border-radius: 3px;
  229. border-style: solid;
  230. border-width: 1px;
  231. box-shadow: none;
  232. color: #222f3e;
  233. outline: 0;
  234. padding: 4px 16px;
  235. text-decoration: none;
  236. text-transform: capitalize;
  237. }
  238. .tox .tox-button--secondary[disabled] {
  239. background-color: #f0f0f0;
  240. background-image: none;
  241. border-color: #f0f0f0;
  242. box-shadow: none;
  243. cursor: pointer;
  244. color: rgba(34, 47, 62, 0.5);
  245. }
  246. .tox .tox-button--secondary:focus:not(:disabled) {
  247. background-color: #e3e3e3;
  248. background-image: none;
  249. border-color: #e3e3e3;
  250. box-shadow: none;
  251. color: #222f3e;
  252. }
  253. .tox .tox-button--secondary:hover:not(:disabled) {
  254. background-color: #e3e3e3;
  255. background-image: none;
  256. border-color: #e3e3e3;
  257. box-shadow: none;
  258. color: #222f3e;
  259. }
  260. .tox .tox-button--secondary:active:not(:disabled) {
  261. background-color: #d6d6d6;
  262. background-image: none;
  263. border-color: #d6d6d6;
  264. box-shadow: none;
  265. color: #222f3e;
  266. }
  267. </style>
  268. </head>
  269. <body>
  270. <div id="wrap">
  271. <!-- <div id="topbar"><button class="addfile primary">+ 添加文件</button> -->
  272. <!-- <button class="upall primary">全部上传</button>
  273. <button class="removeall">清空列表</button></div> -->
  274. <ul id="file_list" class="tox">
  275. <div role="tabpanel" class="tox-dialog__body-content" style="height: 336px; flex-basis: 210px;" aria-labelledby="aria_5965197812761603939544315">
  276. <div class="tox-form">
  277. <div class="tox-form__group">
  278. <label class="tox-label" for="form-field_8471486645261603941857554">链接</label>
  279. <div class="tox-form__controls-h-stack">
  280. <div class="tox-control-wrap">
  281. <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">
  282. </div>
  283. </div>
  284. </div>
  285. <div class="tox-form__group">
  286. <label class="tox-label" for="form-field_2497330145271603941857555">显示文字</label>
  287. <input type="text" tabindex="-1" data-alloy-tabstop="true" class="tox-textfield" id="upFileTextID">
  288. </div>
  289. <div style="height: 10px;"></div>
  290. <div class="tox-form__group tox-form__group--stretched">
  291. <div class="tox-dropzone-container">
  292. <div class="tox-dropzone">
  293. <p style="margin: 10px auto;color:rgba(34,47,62,.7)">拖放一张文件至此</p>
  294. <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;">浏览文件<input type="file" accept="image/*" style="display: none;"></button>
  295. <input id="upfileNameID" style="margin: 5px auto;font-size: 12px; color:rgba(34,47,62,.7); width: 300px; text-align: center;" type="text" value="">
  296. </div>
  297. </div>
  298. </div>
  299. </div>
  300. <button title="上传文件" type="button" onclick="sendUpFile()" style="width: 80%;position: absolute;bottom:10px;left: 55px; 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;">开始上传</span></button>
  301. </div>
  302. </ul>
  303. </div>
  304. <script>
  305. var editor=parent.tinymce.activeEditor;
  306. var upfile=parent.upfile;
  307. var upload_handler = upfile.file_callback;
  308. var upfileData = ""
  309. var upfileUrl = null
  310. function addFile(file){
  311. upfileData = file[0];
  312. document.getElementById('upfileNameID').value=file[0].name;
  313. }
  314. let inputUrl = document.getElementById('upFileUrlID');
  315. let inputText = document.getElementById('upFileTextID');
  316. function sendUpFile(){
  317. upload_handler(upfileData,function(url,_obj){
  318. inputUrl.value = url;
  319. inputText.value ?'': inputText.value = url;
  320. _obj&&_obj.text?inputText.value=_obj.text:'';
  321. upfile.res.url = upfileUrl = url;
  322. upfile.res.text = inputText.value;
  323. })
  324. }
  325. inputUrl.oninput = function(){upfile.res.url = inputUrl.value; upfileUrl=== null?inputText.value=inputUrl.value:'' }
  326. inputText.oninput = function(){upfile.res.text=inputText.value;upfileUrl="123";}
  327. //拖拽添加
  328. document.addEventListener('dragover', function(e){
  329. e.stopPropagation();
  330. e.preventDefault();
  331. e.dataTransfer.dropEffect = 'copy';
  332. });
  333. document.addEventListener('drop', function(e){
  334. e.stopPropagation();
  335. e.preventDefault();
  336. if(!e.dataTransfer.files){return false;}
  337. var dropfiles = e.dataTransfer.files;
  338. if(!(dropfiles.length>0)){return false;}
  339. addFile(dropfiles);
  340. });
  341. 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');
  342. 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()})};
  343. function getFile(){
  344. pickFile(editor).then(function (files){
  345. addFile(files);
  346. })
  347. }
  348. </script>
  349. </body>
  350. </html>