Advertisement
Guest User

character counter for text content field & excerpt field

a guest
Jun 11th, 2014
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1.     public function excerpt_count_js(){
  2.         echo '<script>jQuery(document).ready(function(){
  3.  
  4.                 if( jQuery("#excerpt").length ) {
  5.                     jQuery("#postexcerpt .handlediv").after("<input type=\'text\' value=\'0\' maxlength=\'3\' size=\'3\' id=\'excerpt_counter\' readonly=\'\' style=\'background:#fff; position:absolute;top:0.2em;right:2em; color:#666;\'>");
  6.                     jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length);
  7.                     jQuery("#excerpt").keyup( function() {
  8.                         jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length);
  9.                     });
  10.                 }
  11.  
  12.                 if( jQuery("#wp-word-count").length ) {
  13.                     jQuery("#wp-word-count").after("<td id=\'wp-character-count\'>'. __( 'Character (text only) count:' ) .'<span class=\'character-count\'>0</span></td>");
  14.                 }
  15.  
  16.                 if ( jQuery("#content_ifr") ) {
  17.  
  18.                     $update = function() {
  19.                         tinyMCE.triggerSave();
  20.                         jQuery("#wp-character-count .character-count").html(jQuery("#content").val().length);
  21.                     }
  22.  
  23.                     setInterval(function() { $update(); }, 1000);
  24.  
  25.                 }
  26.                 else {
  27.                     jQuery("#wp-character-count .character-count").html(jQuery("#wp-content-wrap .wp-editor-area").val().length);
  28.  
  29.                     jQuery("#wp-content-wrap .wp-editor-area").keyup( function() {
  30.                         jQuery("#wp-character-count .character-count").html(jQuery("#wp-content-wrap .wp-editor-area").val().length);
  31.                     });
  32.                 }
  33.  
  34.         });</script>';
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement