Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Count characters left in status

  • Loading branch information...
commit 01f423fdfee5793c44f7e1c6dd60a1379705221c 1 parent e3e5037
@jdubois jdubois authored
View
1  src/main/webapp/WEB-INF/messages/messages_en.properties
@@ -70,6 +70,7 @@ tatami.follow.suggestions=Who to follow?
tatami.follow.nobody=No new user to follow today.
tatami.new.status=Update
+tatami.status.characters.left=Characters left:
tatami.timeline=Timeline
tatami.user.picture=Picture
View
1  src/main/webapp/WEB-INF/messages/messages_fr.properties
@@ -70,6 +70,7 @@ tatami.follow.suggestions=Qui suivre ?
tatami.follow.nobody=Personne à suivre aujourd'hui.
tatami.new.status=Nouveau
+tatami.status.characters.left=Caractères restant :
tatami.timeline=Timeline
tatami.user.picture=Photo
View
2  src/main/webapp/WEB-INF/pages/home.jsp
@@ -72,6 +72,8 @@
var searchQuery = "${search}";
var page = "home";
+ var text_characters_left="<fmt:message key="tatami.status.characters.left"/>";
+
if(tag !== '')
$('a[href="#tags"]').tab('show');
else if(searchQuery !== '')
View
1  src/main/webapp/WEB-INF/pages/includes/footer.jsp
@@ -12,6 +12,7 @@
<script src="/js/bootstrap-min.js"></script>
<script src="/js/underscore-min.js"></script>
<script src="/js/backbone-min.js"></script>
+ <script src="/js/jquery-charcount.js"></script>
<script src="/js/jquery-tatami-tagLinker.js"></script>
<script src="/js/jquery-tatami-usernameLinker.js"></script>
<script src="/js/jquery-raphael-tatami-pie.js"></script>
View
2  src/main/webapp/WEB-INF/pages/includes/templates-home.jsp
@@ -64,7 +64,7 @@
<script type="text/template" id="update-template">
<fieldset class="span12">
<div class="control-group">
- <textarea class="span12" required="required" placeholder="<fmt:message key="tatami.status.update"/>..." maxlength="500" name="content"></textarea>
+ <textarea id="updateStatusContent" class="span12" required="required" placeholder="<fmt:message key="tatami.status.update"/>..." maxlength="500" name="content"></textarea>
</div>
<div>
<button type='submit' class="btn btn-primary btn-block"><fmt:message key="tatami.status.update"/></button>
View
1  src/main/webapp/WEB-INF/wro.xml
@@ -10,6 +10,7 @@
<js>/js/bootstrap-min.js</js>
<js>/js/underscore-min.js</js>
<js>/js/backbone-min.js</js>
+ <js>/js/jquery-charcount.js</js>
<js>/js/jquery-tatami-infinitiScroll.js</js>
<js>/js/jquery-tatami-tagLinker.js</js>
<js>/js/jquery-tatami-usernameLinker.js</js>
View
7 src/main/webapp/css/tatami.css
@@ -62,6 +62,13 @@ form {
padding-right: 14px;
}
+.counter{
+ font-size:80%;
+ font-style: italic;
+}
+.counter_warning{color: #ff7f00;}
+.counter_exceeded{color: #ee0014;}
+
.alert-discuss {
color: #3a5fad;
background-color: #d9e0f7;
View
58 src/main/webapp/js/jquery-charcount.js
@@ -0,0 +1,58 @@
+/*
+ * 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);
View
8 src/main/webapp/js/tatami-home.js
@@ -808,6 +808,14 @@ app.Router.HomeRouter = Backbone.Router.extend({
model : new app.Model.ProfileModel()
});
$('#profileContent').html(profile.render());
+ $("#updateStatusContent").charCount({
+ css: 'counter',
+ cssWarning: 'counter_warning',
+ cssExceeded: 'counter_exceeded',
+ allowed: 500,
+ warning: 20,
+ counterText: text_characters_left
+ });
var follow = app.views.follow = new app.View.FollowView();
$('#profileFollow').html(follow.render());
Please sign in to comment.
Something went wrong with that request. Please try again.