Changeset 1804849
- Timestamp:
- 01/17/2018 11:19:04 PM (8 years ago)
- Location:
- wp-mastodon-share/trunk
- Files:
-
- 2 added
- 2 deleted
- 3 edited
-
README.txt (modified) (2 diffs)
-
js/toot_editor.js (modified) (2 diffs)
-
languages/mastoshare-fr_FR.mo (deleted)
-
languages/mastoshare-fr_FR.po (deleted)
-
languages/wp-mastodon-share-de_DE.mo (added)
-
languages/wp-mastodon-share-de_DE.po (added)
-
wp-mastodon-share.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-mastodon-share/trunk/README.txt
r1768755 r1804849 1 1 === Mastodon Share === 2 Tested up to: 4.9 2 Tested up to: 4.9.2 3 3 Donate link: https://liberapay.com/hellexis/donate 4 4 Tags: posts, mastodon, share … … 16 16 == Changelog == 17 17 18 = 0.9 = 19 * Fix permalink bug on toot editor 20 18 21 = 0.8 = 19 Add toot editor 20 Fix the splitted words bug 21 Fix small picture on toot bug 22 * Add toot editor 23 * Fix the splitted words bug 22 24 23 25 = 0.7 = -
wp-mastodon-share/trunk/js/toot_editor.js
r1768755 r1804849 1 1 var $ = jQuery; 2 2 3 $(document).ready(function(){ 3 $(function(){ 4 5 var message = ''; 4 6 5 7 var template = $('#mastoshare_toot_template'); 6 8 var toot = $('#mastoshare_toot'); 7 var post_type = $('#post_type').val();9 var title = $('#title'); 8 10 9 var title = $('#title');10 11 var tags = $('#post_tag .tagchecklist span'); 11 var content = '';12 12 var excerpt = $('#excerpt'); 13 var permalink = $('#sample-permalink'); 14 var final_permalink = permalink.text(); 15 var slug = $('#editable-post-name').text(); 16 var message = ''; 13 17 14 var toot_limit_size = toot.attr('maxlength'); 18 15 var toot_limit_size_span = $('#toot_limit_size'); 19 16 var toot_current_size_span = $('#toot_current_size'); 20 17 var final_excerpt = ''; 21 22 18 toot_limit_size_span.text(toot_limit_size); 23 19 24 function generate_ hashtags() {20 function generate_toot(reduce_of = 0) { 25 21 22 message = template.val(); 23 24 var excerpt = get_excerpt(); 25 var permalink = get_permalink(); 26 var hashtags = get_hashtags(); 27 28 //If toot reduce needed 29 if(reduce_of !== 0) { 30 var words = excerpt.split(' '); 31 words = words.slice(0, reduce_of); 32 excerpt = words.join(' '); 33 } 34 35 var metas = [ 36 {name: 'title', value: title.val()}, 37 {name: 'excerpt', value: excerpt}, 38 {name: 'permalink', value: permalink}, 39 {name: 'tags', value: hashtags} 40 ]; 41 42 for(i in metas) { 43 var item = metas[i]; 44 message = message.replace('[' + item.name + ']', item.value); 45 } 46 47 //If message is too long 48 if (message.length > toot_limit_size) { 49 50 if(reduce_of == 0){ 51 reduce_of = -1; 52 } else { 53 reduce_of = reduce_of -1; 54 } 55 56 generate_toot(reduce_of); 57 58 } else { 59 toot_current_size_span.text(message.length); 60 toot.val(message); 61 } 62 } 63 64 function get_permalink() { 65 66 var current_path = window.location.href; 67 68 var sample_permalink = $('#sample-permalink').text(); 69 var editable_post_name =$('#editable-post-name').text(); 70 var editable_post_name_full = $('#editable-post-name-full').text(); 71 72 var permalink = sample_permalink.replace(editable_post_name, editable_post_name_full); 73 74 return permalink; 75 } 76 77 function get_excerpt() { 78 79 var content = tinymce.editors.content.getContent({format : 'text'}); 80 81 if(typenow != 'page'){ 82 83 if(excerpt.val().length != 0) { 84 return excerpt.val().replace(/<(?!\/?>)[^>]*>/gm, ''); 85 } 86 } 87 88 return content; 89 } 90 91 function get_hashtags() { 26 92 var tags = $('#tagsdiv-post_tag .tagchecklist span.screen-reader-text'); 27 93 var hashtags = ''; 94 28 95 tags.each(function(index, item){ 29 96 hashtags+='#' + $(item).text().split(':')[1].trim() + ' '; … … 33 100 } 34 101 35 function generate_toot(reduce_of = 0) {36 37 message = template.val();38 content = tinymce.editors.content.getContent({format : 'text'});39 40 if(post_type == 'page'){41 final_excerpt = content;42 } else {43 44 if(excerpt.val().length != 0) {45 final_excerpt = excerpt.val();46 } else {47 final_excerpt = content;48 }49 }50 51 52 var new_slug = $('#editable-post-name').text();53 54 if(new_slug.length > 0) {55 final_permalink = final_permalink.replace(slug, new_slug);56 slug = new_slug;57 }58 59 //If toot reduce needed60 if(reduce_of !== 0) {61 var words = final_excerpt.split(' ');62 words = words.slice(0, reduce_of);63 final_excerpt = words.join(' ');64 }65 66 var metas = [67 {name: 'title', value: title.val()},68 {name: 'excerpt', value: final_excerpt},69 {name: 'permalink', value: final_permalink},70 {name: 'tags', value: generate_hashtags()}71 ];72 73 for(i in metas) {74 var item = metas[i];75 76 message = message.replace('[' + item.name + ']', item.value);77 }78 79 if (message.length > toot_limit_size) {80 81 if(reduce_of == 0){82 reduce_of = -1;83 } else {84 reduce_of = reduce_of -1;85 }86 generate_toot(reduce_of);87 } else {88 toot_current_size_span.text(message.length);89 toot.val(message);90 91 }92 93 };94 95 102 toot.bind('input propertychange', function() { 96 103 toot_current_size_span.text(toot.val().length); 97 104 }); 98 105 99 title.on('keyup', function(){ 106 //Regenerate the toot when title changed 107 title.on('keyup', function() { 100 108 generate_toot(); 101 109 }); 102 110 103 excerpt.on('keyup', function(){ 111 //Regenerate the toot when excerpt changed 112 excerpt.on('keyup', function() { 104 113 generate_toot(); 105 114 }); 106 107 var watcher = setInterval(function() {108 109 if(tinymce.editors.length > 0) {110 var contentEditor = tinymce.editors.content;111 115 112 var tagsListReady = $('#tagsdiv-post_tag .tagchecklist span.screen-reader-text').length > 0; 113 114 //Force tagsListReady to true for page 115 if(post_type == 'page') { 116 tagsListReady = true; 117 } 116 //Regenerate the toot when tags changed 117 $('ul.tagchecklist').on('DOMSubtreeModified', function() { 118 generate_toot(); 119 }); 118 120 119 if( contentEditor != undefined && tagsListReady) { 120 121 tinymce.editors.content.on('keyup', function() { 122 generate_toot(); 123 }); 121 $('#edit-slug-box').on('DOMSubtreeModified', function() { 122 generate_toot(); 123 }); 124 124 125 if(post_type == 'post') { 126 $('#tagsdiv-post_tag').on('DOMSubtreeModified', function() { 127 generate_toot(); 128 }); 129 } 125 var watcher = setInterval(function(){ 130 126 131 $('#edit-slug-box').on('DOMSubtreeModified', function(event) { 132 generate_toot(); 133 }); 127 if(tinymce.activeEditor){ 134 128 135 generate_toot(); 136 clearInterval(watcher); 137 } 129 //Stop the watcher when activeEditor catched 130 clearInterval(watcher); 131 132 //First generation of the toot 133 generate_toot(); 134 135 //Regenerate the toot when content changed 136 tinymce.activeEditor.on('keyup', function(){ 137 generate_toot(); 138 }); 138 139 } 139 }, 500);140 140 },1000); 141 141 142 }); -
wp-mastodon-share/trunk/wp-mastodon-share.php
r1768755 r1804849 5 5 * Plugin URI: https://github.com/kernox/mastoshare-wp 6 6 * Description: Share WordPress posts on a mastodon instance. 7 * Version: 0. 87 * Version: 0.9 8 8 * Author: Hellexis 9 9 * Author URI: https://github.com/kernox … … 205 205 206 206 update_post_meta( $post->ID, 'mastoshare-post-status', 'off' ); 207 208 add_action('admin_notices', 'mastoshare_notice_toot_success'); 207 209 208 210 if ( isset( $toot['error'] ) ) { … … 270 272 $message = get_option( 'mastoshare-message' ); 271 273 272 echo '<textarea id="mastoshare_toot" name="mastoshare_toot" maxlength="' . $toot_size . '" style="width:100%; min-height:320px; resize:none"> </textarea>'.274 echo '<textarea id="mastoshare_toot" name="mastoshare_toot" maxlength="' . $toot_size . '" style="width:100%; min-height:320px; resize:none">Loading, please wait ...</textarea>'. 273 275 '<textarea id="mastoshare_toot_template" style="display:none">' . $message . '</textarea>' . 274 '<p>' . __( 'Chars', 'wp-mastodon-share' ) . ': <span id="toot_current_size">?</span> / <span id="toot_limit_size">?</p>' . 275 '<input type="hidden" id="post_type" value="'.$post->post_type.'">'; 276 } 276 '<p>' . __( 'Chars', 'wp-mastodon-share' ) . ': <span id="toot_current_size">?</span> / <span id="toot_limit_size">?</p>'; 277 }
Note: See TracChangeset
for help on using the changeset viewer.