thewire.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * The wire's JavaScript
  4. */
  5. $site_url = elgg_get_site_url();
  6. ?>
  7. elgg.provide('elgg.thewire');
  8. elgg.thewire.init = function() {
  9. $("#thewire-textarea").live('keydown', function() {
  10. elgg.thewire.textCounter(this, $("#thewire-characters-remaining span"), 140);
  11. });
  12. $("#thewire-textarea").live('keyup', function() {
  13. elgg.thewire.textCounter(this, $("#thewire-characters-remaining span"), 140);
  14. });
  15. $(".thewire-previous").live('click', elgg.thewire.viewPrevious);
  16. };
  17. /**
  18. * Update the number of characters left with every keystroke
  19. *
  20. * @param {Object} textarea
  21. * @param {Object} status
  22. * @param {integer} limit
  23. * @return void
  24. */
  25. elgg.thewire.textCounter = function(textarea, status, limit) {
  26. var remaining_chars = limit - $(textarea).val().length;
  27. status.html(remaining_chars);
  28. if (remaining_chars < 0) {
  29. status.parent().addClass("thewire-characters-remaining-warning");
  30. $("#thewire-submit-button").attr('disabled', 'disabled');
  31. $("#thewire-submit-button").addClass('elgg-state-disabled');
  32. } else {
  33. status.parent().removeClass("thewire-characters-remaining-warning");
  34. $("#thewire-submit-button").removeAttr('disabled', 'disabled');
  35. $("#thewire-submit-button").removeClass('elgg-state-disabled');
  36. }
  37. };
  38. /**
  39. * Display the previous wire post
  40. *
  41. * Makes Ajax call to load the html and handles changing the previous link
  42. *
  43. * @param {Object} event
  44. * @return void
  45. */
  46. elgg.thewire.viewPrevious = function(event) {
  47. var $link = $(this);
  48. var postGuid = $link.attr("href").split("/").pop();
  49. var $previousDiv = $("#thewire-previous-" + postGuid);
  50. if ($link.html() == elgg.echo('thewire:hide')) {
  51. $link.html(elgg.echo('thewire:previous'));
  52. $link.attr("title", elgg.echo('thewire:previous:help'));
  53. $previousDiv.slideUp(400);
  54. } else {
  55. $link.html(elgg.echo('thewire:hide'));
  56. $link.attr("title", elgg.echo('thewire:hide:help'));
  57. $.ajax({type: "GET",
  58. url: elgg.config.wwwroot + "ajax/view/thewire/previous",
  59. dataType: "html",
  60. cache: false,
  61. data: {guid: postGuid},
  62. success: function(htmlData) {
  63. if (htmlData.length > 0) {
  64. $previousDiv.html(htmlData);
  65. $previousDiv.slideDown(600);
  66. }
  67. }
  68. });
  69. }
  70. event.preventDefault();
  71. };
  72. elgg.register_hook_handler('init', 'system', elgg.thewire.init);