diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index ec7a2138f..e680179c4 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -157,6 +157,7 @@ if ( ( 'edit' == $action) && current_user_can('delete_post', $post_ID) )
+

diff --git a/wp-admin/edit-page-form.php b/wp-admin/edit-page-form.php index e800a4679..f2eeab7d6 100644 --- a/wp-admin/edit-page-form.php +++ b/wp-admin/edit-page-form.php @@ -140,6 +140,7 @@ if ( ('edit' == $action) && current_user_can('delete_page', $post_ID) )
+

diff --git a/wp-admin/js/word-count.js b/wp-admin/js/word-count.js new file mode 100644 index 000000000..6be48ba50 --- /dev/null +++ b/wp-admin/js/word-count.js @@ -0,0 +1,39 @@ +// Word count +(function(JQ) { + wpWordCount = { + + init : function() { + var t = this, last = 0, co = JQ('#content'); + + JQ('#wp-word-count').html( wordCountL10n.count.replace( /%d/, '0' ) ); + t.block = 0; + t.wc(co.val()); + co.keyup( function(e) { + if ( e.keyCode == last ) return true; + if ( 13 == e.keyCode || 8 == last || 46 == last ) t.wc(co.val()); + last = e.keyCode; + return true; + }); + }, + + wc : function(tx) { + var t = this, w = JQ('#word-count'), tc = 0; + + if ( t.block ) return; + t.block = 1; + tx = tx.replace( /^\s*|\s*$/g, '' ); + setTimeout( function() { + if ( tx ) { + tx = tx.replace( /<.[^<>]*?>/g, ' ' ).replace( / /gi, ' ' ); + tx = tx.replace( /[0-9.(),;:!?%#$¿'"_+=\\/-]*/g, '' ); + tx.replace( /\S\s+/g, function(){tc++;} ); + } + w.html(tc.toString()); + + setTimeout( function() { t.block = 0; }, 2000 ); + }, 1 ); + } + } +}(jQuery)); + +jQuery(document).ready( function(){ wpWordCount.init(); } ); diff --git a/wp-admin/page-new.php b/wp-admin/page-new.php index f09d65784..95d49073e 100644 --- a/wp-admin/page-new.php +++ b/wp-admin/page-new.php @@ -9,6 +9,7 @@ if ( user_can_richedit() ) wp_enqueue_script('editor'); wp_enqueue_script('thickbox'); wp_enqueue_script('media-upload'); +wp_enqueue_script('word-count'); require_once('admin-header.php'); ?> diff --git a/wp-admin/page.php b/wp-admin/page.php index 1b4dc2825..b6eef5f47 100644 --- a/wp-admin/page.php +++ b/wp-admin/page.php @@ -83,6 +83,7 @@ case 'edit': wp_enqueue_script('editor'); wp_enqueue_script('thickbox'); wp_enqueue_script('media-upload'); + wp_enqueue_script('word-count'); if ( current_user_can('edit_page', $page_ID) ) { if ( $last = wp_check_post_lock( $post->ID ) ) { diff --git a/wp-admin/post-new.php b/wp-admin/post-new.php index 263783a39..7d32c8aa7 100644 --- a/wp-admin/post-new.php +++ b/wp-admin/post-new.php @@ -9,6 +9,7 @@ if ( user_can_richedit() ) wp_enqueue_script('editor'); wp_enqueue_script('thickbox'); wp_enqueue_script('media-upload'); +wp_enqueue_script('word-count'); require_once ('./admin-header.php'); diff --git a/wp-admin/post.php b/wp-admin/post.php index bcbad6284..bbc214bbf 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -90,6 +90,7 @@ case 'edit': wp_enqueue_script('editor'); wp_enqueue_script('thickbox'); wp_enqueue_script('media-upload'); + wp_enqueue_script('word-count'); if ( current_user_can('edit_post', $post_ID) ) { if ( $last = wp_check_post_lock( $post->ID ) ) { diff --git a/wp-admin/wp-admin.css b/wp-admin/wp-admin.css index c29a81ec3..8dc04a915 100644 --- a/wp-admin/wp-admin.css +++ b/wp-admin/wp-admin.css @@ -1503,3 +1503,7 @@ table.diff td, table.diff th { table.diff .diff-deletedline del, table.diff .diff-addedline ins { text-decoration: none; } + +#wp-word-count { + display: block; +} diff --git a/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js b/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js index 28144579a..fce360525 100644 --- a/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js +++ b/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js @@ -132,7 +132,17 @@ } }); - // Add listeners to handle more break + // Word count if script is loaded + if ( 'undefined' != wpWordCount ) { + var last = 0; + ed.onKeyUp.add(function(ed, e) { + if ( e.keyCode == last ) return; + if ( 13 == e.keyCode || 8 == last || 46 == last ) wpWordCount.wc( ed.getContent({format : 'raw'}) ); + last = e.keyCode; + }); + }; + + // Add listeners to handle more break t._handleMoreBreak(ed, url); // Add custom shortcuts diff --git a/wp-includes/js/tinymce/tiny_mce_config.php b/wp-includes/js/tinymce/tiny_mce_config.php index 34c0f1990..3d5e47af5 100644 --- a/wp-includes/js/tinymce/tiny_mce_config.php +++ b/wp-includes/js/tinymce/tiny_mce_config.php @@ -226,7 +226,7 @@ if ( $compress && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) { // Setup cache info if ( $disk_cache ) { - $cacheKey = apply_filters('tiny_mce_version', '20080414'); + $cacheKey = apply_filters('tiny_mce_version', '20080423'); foreach ( $initArray as $v ) $cacheKey .= $v; diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index ef4488006..ccb73c42d 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -36,7 +36,7 @@ class WP_Scripts { $this->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080325' ); // Modify this version when tinyMCE plugins are changed. - $mce_version = apply_filters('tiny_mce_version', '20080414'); + $mce_version = apply_filters('tiny_mce_version', '20080423'); $this->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version ); $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6'); @@ -193,7 +193,11 @@ class WP_Scripts { 'edit' => __('Edit'), 'cancel' => __('Cancel'), )); - $this->add( 'editor', '/wp-admin/js/editor.js', array('tiny_mce'), '20080221' ); + + $this->add( 'word-count', '/wp-admin/js/word-count.js', array( 'jquery' ), '20080423' ); + $this->localize( 'word-count', 'wordCountL10n', array( + 'count' => __('Word count: %d') + )); } }