aboutsummaryrefslogtreecommitdiff
path: root/mod/riverdashboard/views/default/riverdashboard/js.php
blob: edb041e4ffe6fc8f44bc971525fcd94a04be57f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<script type="text/javascript">
	$(document).ready(function() {
		$('.river_comment_form_button').click(function() {
			elgg_slide_toggle(this, '.river_item', '.river_comment_form');
		});

		$('.likes_user_list_button').click(function() {
			var myParent = $(this).closest('.river_item');
			var likesList = myParent.find('.likes_list');

			if (likesList.css('display') == 'none') {
				// pull in likes via ajax to save on loading many avatars
				var riverItem = $(this).closest('.river_item');
				var guid = riverItem.attr('id').replace('river_entity_', '');

				var params = {
					'entity_guid': guid
				}

				$(likesList).load('<?php echo $vars['url'];?>mod/riverdashboard/endpoint/get_likes.php', params, function(data) {
					console.log(data);
					// hide comments
					myParent.find('.comments_container').animate({"height": "toggle", "opacity": "toggle"}, { duration: 400 });
					// change selected tab
					myParent.find('.show_comments_button').addClass('off');
					myParent.find('.likes_user_list_button').removeClass('off');
					// show users that liked object
					elgg_slide_toggle(this, '.river_item', '.likes_list');
				});
			}
		});

		$('.show_comments_button').click(function() {
			var myParent = $(this).closest('.river_item');
			if (myParent.find('.comments_container').css('display') == 'none') {
				// hide likes
				myParent.find('.likes_list').animate({"height": "toggle", "opacity": "toggle"}, { duration: 400 });
				// change selected tab
				myParent.find('.show_comments_button').removeClass('off');
				myParent.find('.likes_user_list_button').addClass('off');
				// show users that liked object
				elgg_slide_toggle(this, '.river_item', '.comments_container');
			}
		});

		// grab more comments
		$('.river_show_more_comments').click(function() {
			var riverItem = $(this).closest('.river_item');
			var guid = riverItem.attr('id').replace('river_entity_', '');
			var commentsList = riverItem.find('.comments_list');
			var numComments = riverItem.find('.river_comment').length;

			var params = {
				'entity_guid': guid,
				'offset': numComments
			}

			$.post('<?php echo $vars['url'];?>mod/riverdashboard/endpoint/get_comments.php', params, function(data) {
				commentsList.prepend(data);
				commentsList.prev('.river_show_more_comments').hide();
			});
		});
	});
</script>