mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Word count from azaozz. see #4807
git-svn-id: http://svn.automattic.com/wordpress/trunk@7854 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ca284189fb
commit
123a6091fb
@ -157,6 +157,7 @@ if ( ( 'edit' == $action) && current_user_can('delete_post', $post_ID) )
|
||||
<br class="clear" />
|
||||
<?php endif; ?>
|
||||
<span id="autosave"></span>
|
||||
<span id="wp-word-count"></span>
|
||||
</p>
|
||||
|
||||
<div class="side-info">
|
||||
|
@ -140,6 +140,7 @@ if ( ('edit' == $action) && current_user_can('delete_page', $post_ID) )
|
||||
<br class="clear" />
|
||||
<?php endif; ?>
|
||||
<span id="autosave"></span>
|
||||
<span id="wp-word-count"></span>
|
||||
</p>
|
||||
|
||||
<div class="side-info">
|
||||
|
39
wp-admin/js/word-count.js
Normal file
39
wp-admin/js/word-count.js
Normal file
@ -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/, '<span id="word-count">0</span>' ) );
|
||||
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(); } );
|
@ -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');
|
||||
?>
|
||||
|
@ -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 ) ) {
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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 ) ) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user