Skip to content

Instantly share code, notes, and snippets.

@thefrosty
Created September 29, 2010 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefrosty/602228 to your computer and use it in GitHub Desktop.
Save thefrosty/602228 to your computer and use it in GitHub Desktop.
I'm going to set an option in the settings page to opt into this. So if users wanted to tweet from the admin a longer script, like tweet-longer then can.
jQuery(document).ready( function($) {
/* jQuery jqEasyCharCounter plugin
* Examples and documentation at: http://www.jqeasy.com/
* Version: 1.0 (05/07/2010)
* No license. Use it however you want. Just keep this notice included.
* Requires: jQuery v1.3+
*
* Modified by: Austin Passy 09/29/2010
* @link http://austinpassy.com
*/
(function(a){a.fn.extend({jqEasyCounter:function(b){return this.each(function(){var f=a(this),e=a.extend({maxChars:100,maxCharsWarning:80,msgFontSize:"12px",msgFontColor:"#000000",msgFontFamily:"Arial",msgTextAlign:"right",msgWarningColor:"#F00",msgAppendMethod:"insertAfter"},b);if(e.maxChars<=0){return}var d=a('<div class="jqEasyCounterMsg" style="padding:2px 7px;">&nbsp;</div>');var c={"font-size":e.msgFontSize,"font-family":e.msgFontFamily,color:e.msgFontColor,"text-align":e.msgTextAlign,width:f.width(),opacity:0};d.css(c);d[e.msgAppendMethod](f);f.bind("keydown keyup keypress",g).bind("focus paste",function(){setTimeout(g,10)}).bind("blur",function(){d.stop().fadeTo("fast",0);return false});function g(){var i=f.val(),h=i.length;if(h>=e.maxChars){i=i.substring(0,e.maxChars)}if(h>e.maxChars){var j=f.scrollTop();f.val(i.substring(0,e.maxChars));f.scrollTop(j);$('input#publish').attr('disabled','disabled')}else{$('input#publish').removeAttr('disabled')}if(h>=e.maxCharsWarning){d.css({color:e.msgWarningColor});$(this).css({"backgroundColor":"#ffcccc"})}else{d.css({color:e.msgFontColor});$(this).css({"backgroundColor":"#fff"})}d.html("Characters: "+f.val().length+"/"+e.maxChars);d.stop().fadeTo("fast",1)}})}})})(jQuery);
/*
$('#content').keydown(function(e){
var words = $.trim($(this).val()).split(' ').length;
if ( words > 10 && e.keyCode > 65 ) { return false; }
});
$('#wp-word-count').html('Characters:' + words +);
*/
$('#content').jqEasyCounter({
'maxChars': 140,
'maxCharsWarning': 130,
'msgFontSize': '11px',
'msgFontColor': '#333',
'msgFontFamily': '"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif',
'msgTextAlign': 'left',
'msgWarningColor': '#F00',
'msgAppendMethod': 'insertAfter'
});
@thefrosty
Copy link
Author

//This is the else statement I've created if a user opts out of limiting the content to just 140 characters.
//It's a stripped down version, that allows more than 140 characters, but warns the user and still counts characters.

        (function(a){a.fn.extend({jqEasyCounter:function(b){return this.each(function(){var f=a(this),e=a.extend({maxChars:100,maxCharsWarning:80,msgFontSize:"12px",msgFontColor:"#000000",msgFontFamily:"Arial",msgTextAlign:"right",msgWarningColor:"#F00",msgAppendMethod:"insertAfter"},b);if(e.maxChars<=0){return}var d=a('<div class="jqEasyCounterMsg" style="padding:2px 7px;">&nbsp;</div>');var c={"font-size":e.msgFontSize,"font-family":e.msgFontFamily,color:e.msgFontColor,"text-align":e.msgTextAlign,width:f.width(),opacity:0};d.css(c);d[e.msgAppendMethod](f);f.bind("keydown keyup keypress",g).bind("focus paste",function(){setTimeout(g,10)}).bind("blur",function(){d.stop().fadeTo("fast",0);return false});function g(){var i=f.val(),h=i.length;/_if(h>=e.maxChars){i=i.substring(0,e.maxChars)}if(h>e.maxChars){var j=f.scrollTop();f.val(i.substring(0,e.maxChars));f.scrollTop(j);$('input#publish').attr('disabled','disabled')}else{$('input#publish').removeAttr('disabled')}_/if(h>=e.maxCharsWarning){d.css({color:e.msgWarningColor});$(this).css({"backgroundColor":"#ffcccc"})}else{d.css({color:e.msgFontColor});$(this).css({"backgroundColor":"#fff"})}d.html("Characters: "+f.val().length+"/"+e.maxChars);/_added_/if(h>=e.maxCharsWarning){d.html("This post will auto trim itself to<br />140 character or less with a link back to itself.");}/_end_/d.stop().fadeTo("fast",1)}})}})})(jQuery);
        $('#content').jqEasyCounter({
            'maxChars': 140,
            'maxCharsWarning': 140,
            'msgFontSize': '11px',
            'msgFontColor': '#333',
            'msgFontFamily': '"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif',
            'msgTextAlign': 'left',
            'msgWarningColor': '#F00',
            'msgAppendMethod': 'insertAfter'              
        });
    <?php } ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment