* Move all Diaspora-specific javascripts to app/assets/javascripts * Move all vendored javascripts to vendor/assets/javascripts * Add the appropriate Sprockets require directives to make sure everything gets included in the right order * Remove Jammit dependencies * Fix all templates that were using Jammit's include_javascripts helper * Add handlebars_assets gem for compiling Handlebars templates * Move all Handlebars templates to app/assets/templates and rename from .handlebars to .jst.hbs (this is to keep them in the same global JST namespace that they were in under Jammit) * Add public/assets to .gitignore since these files can and should be re-generated by Heroku or Capistrano during each deploy * Fix a few Handlebars templates that were looking for images in the wrong location (I'm sure there are others, but it's late) * Configure application.rb to precompile all javascript and css assets that were compiled by Jammit in the Rails 3.0 code
58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
/*
|
|
* Character Count Plugin - jQuery plugin
|
|
* Dynamic character count for text areas and input fields
|
|
* written by Alen Grakalic
|
|
* http://cssglobe.com/post/7161/jquery-plugin-simplest-twitterlike-dynamic-character-count-for-textareas
|
|
*
|
|
* Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
|
|
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
|
* and GPL (GPL-LICENSE.txt) licenses.
|
|
*
|
|
* Built for jQuery library
|
|
* http://jquery.com
|
|
*
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
$.fn.charCount = function(options){
|
|
|
|
// default configuration properties
|
|
var defaults = {
|
|
allowed: 140,
|
|
warning: 25,
|
|
css: 'counter',
|
|
counterElement: 'span',
|
|
cssWarning: 'warning',
|
|
cssExceeded: 'exceeded',
|
|
counterText: ''
|
|
};
|
|
|
|
var options = $.extend(defaults, options);
|
|
|
|
function calculate(obj){
|
|
var count = $(obj).val().length;
|
|
var available = options.allowed - count;
|
|
if(available <= options.warning && available >= 0){
|
|
$(obj).next().addClass(options.cssWarning);
|
|
} else {
|
|
$(obj).next().removeClass(options.cssWarning);
|
|
}
|
|
if(available < 0){
|
|
$(obj).next().addClass(options.cssExceeded);
|
|
} else {
|
|
$(obj).next().removeClass(options.cssExceeded);
|
|
}
|
|
$(obj).next().html(options.counterText + available);
|
|
};
|
|
|
|
this.each(function() {
|
|
$(this).after('<'+ options.counterElement +' class="' + options.css + '">'+ options.counterText +'</'+ options.counterElement +'>');
|
|
calculate(this);
|
|
$(this).keyup(function(){calculate(this)});
|
|
$(this).change(function(){calculate(this)});
|
|
});
|
|
|
|
};
|
|
|
|
})(jQuery);
|