Skip to content

Instantly share code, notes, and snippets.

@MrVibe
Last active August 29, 2019 12:55
Show Gist options
  • Save MrVibe/10b18d03d81090ba5a3fb45ea6575c2d to your computer and use it in GitHub Desktop.
Save MrVibe/10b18d03d81090ba5a3fb45ea6575c2d to your computer and use it in GitHub Desktop.
Record number of Words in tinyMCE editor in Units, shows alert when limit exceeds.
add_action('wp_footer',function(){
if(!is_page(vibe_get_option('create_course'))){
return;
}
?>
<script>
jQuery(document).ready(function($){
var word_limit = 200;
$('#course_curriculum').on('active',function(){
tinymce.activeEditor.on('KeyUp',function(){
var body = tinymce.activeEditor.getBody();
var content = tinymce.trim(body.innerText || body.textContent);
content = $.trim(content.replace( /[^\w ]/g, " "));
var word_count = content == "" ? 0 : content.split( /\s+/ ).length;
if(word_count > word_limit){
//Show some message etc.
alert('word limit exceeded by '+(word_count - word_limit));
}
});
});
});
</script>
<?php
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment