jquery - Character limitation for WordPress WYSIWYG editor -
i limited number of characters can added content special page (event submission page). works fine in text or code mode in wordpress not when use wysiwyg editor.
any idea how change works using wordpress editor?
thank much!
here js using.
// set character limit var count_limit = 1000; // set initial symbol count on page load $('#tcepostcontent-wc span').html($('#tcepostcontent').val()); $('#tcepostcontent').on('keyup', function () { var char_count = $(this).val().length; var tcepostcontent = $(this).val(); var text_remaining = count_limit - char_count; // update character count on every key $('#tcepostcontent-wc span').html(text_remaining); if (char_count >= count_limit) { $('#tcepostcontent-wc').css('color', 'red'); $(this).val(tcepostcontent.substr(1, count_limit)); } else { $('#tcepostcontent-wc').css('color', null); } }).after('<p id="tcepostcontent-wc">max 1000 available <span>1000</span></p>');
the visual editor of wordpress tinymce , implement custom api there can use solve topic. should use follow source, add in small custom plugin, change id tinymce.activeeditor.editorid of editor, activate it, , done.
add_filter( 'tiny_mce_before_init', 'wpse24113_tiny_mce_before_init' ); function wpse24113_tiny_mce_before_init( $initarray ) { $initarray['setup'] = <<<js [function( ed ) { ed.onkeydown.add( function( ed, e ) { if ( tinymce.activeeditor.editorid == 'content-id' ) { var content = tinymce.activeeditor.getcontent(); var max = 300; var len = content.length; if (len >= max) { $( '#charnum' ).html( '<span class="text-error">you've got more '+max+' characters!</span>' ); } else { var charcount = max - len; $( '#charnum').html( charcount + ' characters left' ); } } }); }][0] js; return $initarray; } the source this answer in se forum wordpress topics.
Comments
Post a Comment