Advertisement
Guest User

Golos Redactor

a guest
Feb 18th, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 6.15 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="ru">
  3. <head>
  4. <meta charset="utf-8"/>
  5. <title>Golos.io Редактор</title>
  6. <style>
  7. .drdrop {
  8.     padding: 10px 0;
  9.     border-radius: 5px;
  10. }
  11. body { font-family: Arial, Helvetica, sans-serif;color: grey; }
  12. input,#text-editor {
  13.     background: #f7f7f7;
  14.     border: 0;
  15.     box-shadow: inset 0 0 10px -5px black;
  16.     color:black;
  17.         padding: 5px;
  18.     border-radius: 5px;
  19. }
  20. input#permlink {
  21.     font-size: 15px;
  22.     padding: 0 10px;
  23.     height: 18px;
  24.     border-radius: 30px 0 30px 0;
  25.     margin-right: 10px;
  26. }
  27.  
  28. #addimg.loading{
  29. background:url(https://s3.postimg.org/ejg32n7er/loading.gif);
  30. transition:2s all ease;
  31. height:50px;
  32. }
  33. #addimg.loading.hasload{
  34. background:#36c77f;
  35. height:auto;
  36. }
  37.  
  38. .drdrop span { background: #7aa8ff; border: 0; padding: 10px; color: white; border-radius: 3px; box-shadow: 0 0 16px -7px black; cursor: pointer; }
  39. #text-editor img { max-width: 100%; height: auto; }#text-editor { background: #f7f7f7; min-height: 200px; border-radius: 5px; padding: 1px 10px; }.golos-form { padding:5%; }#alerts { background: #ff8282; color: white; font-size:18px; border-radius: 3px; }input#post-golos-title{width:100%;margin:10px auto;padding:5px;border-radius:5px;font-size:1rem}.golos-form .mce-panel{border-radius:3px;margin:10px auto}.golos-form input[type=submit]{cursor:pointer;background:#248eff;border:0;display:block;margin:20px auto;padding:10px;width:160px;border-radius:3px;color:#fff;box-shadow:0 0 10px -5px #000}</style>
  40. <meta name="Description" content="Удобный редактор с хостингом фото для голоса">
  41. <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
  42. <link rel="icon" type="image/x-icon" href="https://golos.io/images/favicons/favicon.ico"/>
  43. <script async src="https://golos.rubtc.info/wp-content/plugins/golos/golos.js"></script>
  44. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script>
  45. <script src="https://cdn.tinymce.com/4/tinymce.min.js"></script>
  46.  
  47. </head>
  48. <body>
  49. <div class="golos-form">
  50.  
  51.  
  52. <form id="post-golos-form" enctype="multipart/form-data">
  53.             <h2><label for="post-golos-title">golos.io редактор + хостинг фотографий</label></h2>
  54.             <input type="text" name="post-golos-title" id="post-golos-title" required aria-required="true" placeholder="Заголовок">
  55.             <p>golos.io/топик/@имя/... <input type="text" id="permlink" name="permlink" required aria-required="true"/> <label for="permlink">Вы можете задать ссылку для своего поста</label></p>
  56.        
  57.            
  58.  
  59. <div class="drdrop"><span id="addimg" onclick="document.querySelector('#loadinp').click()">Добавить фото</span></div><input id="loadinp" style="visibility: collapse; width: 0px;" type="file" onchange="upload(this.files[0])">
  60. <div id="text-editor"></div>
  61. <p><input type="text" id="topic" name="topic" required aria-required="true" placeholder="Главный Топик"/>  <input type="text" id="tags" name="tags" required aria-required="true" placeholder="Теги через запятую"/>
  62. <input type="text" id="username" name="username" required aria-required="true"/ placeholder="Логин">
  63. <input type="password" id="postingkey" name="postingkey" required aria-required="true" placeholder="Постинг ключ"/>
  64. <input type="submit" value="Отправить"></p>
  65. </form>
  66. <div id="alerts"></div>
  67. </div>
  68.  
  69. <script>
  70. jQuery(document).ready( function( $ ) {
  71.     tinymce.init( {
  72.         selector:'#text-editor',      
  73.        theme: 'inlite',
  74.   plugins: 'table link paste contextmenu textpattern autolink fullscreen',
  75.   selection_toolbar: 'bold italic | quicklink h2 h3 blockquote',
  76.   inline: true,
  77.   paste_data_images: true
  78.  
  79.     } );
  80. });
  81.  
  82.  
  83. window.ondragover = function(e) {e.preventDefault()}
  84.     window.ondrop = function(e) {e.preventDefault(); upload(e.dataTransfer.files[0]); }
  85.     function upload(file) {
  86.         if (!file || !file.type.match(/image.*/)) return;
  87.         document.getElementById("addimg").classList.add('loading');
  88.         var fd = new FormData();
  89.         fd.append("image", file);
  90.         var xhr = new XMLHttpRequest();
  91.         xhr.open("POST", "https://api.imgur.com/3/image.json");
  92.         xhr.onload = function() {
  93.             var imgurl = JSON.parse(xhr.responseText).data.link;
  94.             var ed = tinyMCE.get('text-editor');                // get editor instance
  95.             var newNode = ed.getDoc().createElement ( "img" );  // create img node
  96.             newNode.src=imgurl;                           // add src attribute
  97.             ed.execCommand('mceInsertContent', false, newNode.outerHTML)
  98.             document.getElementById("addimg").classList.add('hasload');
  99.            
  100.            
  101.         }
  102.         xhr.setRequestHeader('Authorization', 'Client-ID 28aaa2e823b03b1');
  103.         xhr.send(fd);
  104.     }
  105.  
  106. // Запускаем функцию нажатием submit в форме #post-golos-form
  107. jQuery( '#post-golos-form' ).on( 'submit', function(e) {
  108.         e.preventDefault();
  109.         // Записываем в переменные содержимое полей
  110.          var t = document.getElementById("post-golos-title").value,
  111.              // Вытаскиваем наш контент из редактора в переменную post_body
  112.              post_body = tinyMCE.activeEditor.getContent(),
  113.              k = document.getElementById("postingkey").value,
  114.              u = document.getElementById("username").value,
  115.              permlink = document.getElementById("permlink").value,
  116.              topic = document.getElementById("topic").value,
  117.              tags = document.getElementById("tags").value,
  118.              
  119.              jsonMetadata =  '{"tags":['+tags+']}',
  120.              parentAuthor = '',
  121.              parentPermlink = topic;
  122.              
  123.              console.log();
  124.            
  125.              steem.broadcast.comment(
  126.                     k,
  127.                         parentAuthor,
  128.                         parentPermlink,
  129.                         u,
  130.                         permlink,
  131.                         t,
  132.                         post_body,
  133.                         jsonMetadata,
  134.                     function(err, result) {
  135.                       console.log(err,result);
  136.                       // В случае ошибок - отразим их под формой
  137.                       if(err != null){
  138.                       document.getElementById('alerts').innerHTML = ('<blockquote>'+err+'</blockquote>');
  139.                       }
  140.                     });
  141.                    
  142. });
  143.  
  144.    
  145. </script>
  146. </body>
  147. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement