twitter_post.js 1002 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * Attach handlers to toggle the twitter message field and inform the number
  3. * of characters remaining to achieve the max length
  4. */
  5. (function ($) {
  6. Drupal.behaviors.twitter_post = {
  7. attach: function (context, settings) {
  8. $("#twitter-textfield", context).keyup(function() {
  9. var charsLeft = (140 - $(this).val().length);
  10. var descDiv = $(this).next();
  11. $(descDiv).html("<strong>" + charsLeft + "</strong> characters remaining");
  12. if (charsLeft < 0) {
  13. $(descDiv).addClass("negative");
  14. } else {
  15. $(descDiv).removeClass("negative");
  16. }
  17. });
  18. if (!$("#twitter-toggle").attr("checked")) {
  19. $(".form-item-twitter-status").hide();
  20. }
  21. $("#twitter-toggle").bind("click", function() {
  22. if ($("#twitter-toggle").attr("checked")) {
  23. $(".form-item-twitter-status").show();
  24. }
  25. else {
  26. $(".form-item-twitter-status").hide();
  27. }
  28. });
  29. }
  30. };
  31. }(jQuery));