aboutsummaryrefslogtreecommitdiff
path: root/mod/thewire/views/default/js
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-03-30 02:07:59 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-03-30 02:07:59 +0000
commitb472188b1e3fe4ff8a0da791910d12496b1de348 (patch)
tree63cc52ab126372ba532e7c246fe06b5e1364f764 /mod/thewire/views/default/js
parent030f72d81b76823e4f3b85675beb896b00b6af5d (diff)
downloadelgg-b472188b1e3fe4ff8a0da791910d12496b1de348.tar.gz
elgg-b472188b1e3fe4ff8a0da791910d12496b1de348.tar.bz2
Fixes #3200 ajax-based view previous link works for the wire
git-svn-id: http://code.elgg.org/elgg/trunk@8882 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/thewire/views/default/js')
-rw-r--r--mod/thewire/views/default/js/thewire.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/mod/thewire/views/default/js/thewire.php b/mod/thewire/views/default/js/thewire.php
new file mode 100644
index 000000000..1eda90bee
--- /dev/null
+++ b/mod/thewire/views/default/js/thewire.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ * The wire's JavaScript
+ */
+
+$site_url = elgg_get_site_url();
+
+?>
+
+elgg.provide('elgg.thewire');
+
+elgg.thewire.init = function() {
+ $("#thewire-textarea").live('keydown', function() {
+ elgg.thewire.textCounter(this, $("#thewire-characters-remaining span"), 140);
+ });
+ $("#thewire-textarea").live('keyup', function() {
+ elgg.thewire.textCounter(this, $("#thewire-characters-remaining span"), 140);
+ });
+
+ $(".thewire-previous").live('click', elgg.thewire.viewPrevious);
+}
+
+/**
+ * Update the number of characters left with every keystroke
+ *
+ * @param {Object} textarea
+ * @param {Object} status
+ * @param {integer} limit
+ * @return void
+ */
+elgg.thewire.textCounter = function(textarea, status, limit) {
+
+ var remaining_chars = limit - textarea.value.length;
+ status.html(remaining_chars);
+
+ if (remaining_chars < 0) {
+ status.parent().css("color", "#D40D12");
+ $("#thewire-submit-button").attr('disabled', 'disabled');
+ $("#thewire-submit-button").addClass('elgg-state-disabled');
+ } else {
+ status.parent().css("color", "");
+ $("#thewire-submit-button").removeAttr('disabled', 'disabled');
+ $("#thewire-submit-button").removeClass('elgg-state-disabled');
+ }
+}
+
+/**
+ * Display the previous wire post
+ *
+ * Makes Ajax call to load the html and handles changing the previous link
+ *
+ * @param {Object} event
+ * @return void
+ */
+elgg.thewire.viewPrevious = function(event) {
+ var $link = $(this);
+ var postGuid = $link.attr("href").split("/").pop();
+ var $previousDiv = $("#thewire-previous-" + postGuid);
+
+ if ($link.html() == "<?php echo elgg_echo('thewire:hide'); ?>") {
+ $link.html("<?php echo elgg_echo('thewire:previous'); ?>");
+ $link.attr("title", "<?php echo elgg_echo('thewire:previous:help'); ?>");
+ $previousDiv.slideUp(400);
+ } else {
+ $link.html("<?php echo elgg_echo('thewire:hide'); ?>");
+ $link.attr("title", "<?php echo elgg_echo('thewire:hide:help'); ?>");
+
+ $.ajax({type: "GET",
+ url: "<?php echo $site_url . "ajax/view/thewire/previous"; ?>",
+ dataType: "html",
+ cache: false,
+ data: {guid: postGuid},
+ success: function(htmlData) {
+ if (htmlData.length > 0) {
+ $previousDiv.html(htmlData);
+ $previousDiv.slideDown(600);
+ }
+ }
+ });
+
+ }
+
+ event.preventDefault();
+}
+
+elgg.register_hook_handler('init', 'system', elgg.thewire.init); \ No newline at end of file