forked from NMAI-lab/moodle-mod_socialwiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.js
65 lines (61 loc) · 2.18 KB
/
view.js
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
65
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Script for the like button.
*
* @package mod_socialwiki
* @copyright 2015 NMAI-lab
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$("#socialwiki-like").on('click', function (e) {
e.preventDefault();
var $like = $(this);
if ($like.attr('href') === '') {
return;
}
$.get("like.ajax.php" + options, function (data) {
if (data !== 'error') {
var $btnimg = $like.find("img");
$btnimg.attr({
'other': $btnimg.attr('src'),
'src': $btnimg.attr('other')
});
$like.toggleClass('liked');
$like.find("span").text(data);
}
}).fail(function() {
alert("Could not send like.");
});
});
$("#navigator").on('change', function() {
$(this).find('option[value=' + this.value + ']').insertAfter($(this).find('option:eq(1)'));
$(".wikipage").fadeTo("fast", 0.3);
$.get("like.ajax.php" + options + "&navi=" + this.value, function (data) {
if (data !== 'error') {
$(".socialwiki-contributors").remove();
$(".wikipage").replaceWith(data);
}
}).fail(function() {
alert("Could not load updated content.");
$(".wikipage").stop(true).fadeTo("fast", 1);
});
});
$("#socialwiki-comdirection").on('click', function () {
var $this = $(this);
var swap = $this.attr("other");
$this.attr("other", $this.text());
$this.text(swap);
$(".socialwiki-commentlist").toggleClass('reversed');
}).show();