From 123a6091fbd7ff80274f6b9187fcd4cda3d989f1 Mon Sep 17 00:00:00 2001
From: ryan
Date: Tue, 29 Apr 2008 19:17:23 +0000
Subject: [PATCH] Word count from azaozz. see #4807
git-svn-id: http://svn.automattic.com/wordpress/trunk@7854 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
wp-admin/edit-form-advanced.php | 1 +
wp-admin/edit-page-form.php | 1 +
wp-admin/js/word-count.js | 39 +++++++++++++++++++
wp-admin/page-new.php | 1 +
wp-admin/page.php | 1 +
wp-admin/post-new.php | 1 +
wp-admin/post.php | 1 +
wp-admin/wp-admin.css | 4 ++
.../plugins/wordpress/editor_plugin.js | 12 +++++-
wp-includes/js/tinymce/tiny_mce_config.php | 2 +-
wp-includes/script-loader.php | 8 +++-
11 files changed, 67 insertions(+), 4 deletions(-)
create mode 100644 wp-admin/js/word-count.js
diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php
index ec7a2138f8..e680179c40 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 e800a46795..f2eeab7d69 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 0000000000..6be48ba506
--- /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 f09d657841..95d49073e8 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 1b4dc28253..b6eef5f47b 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 263783a39d..7d32c8aa70 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 bcbad62847..bbc214bbfe 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 c29a81ec3d..8dc04a9158 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 28144579a3..fce3605253 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 34c0f19908..3d5e47af5e 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 ef4488006d..ccb73c42d2 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')
+ ));
}
}