Last active
August 29, 2019 12:55
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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