-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathajax_vud.js
52 lines (50 loc) · 1.75 KB
/
ajax_vud.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
// $Id: ajax_vote_up_down.js,v 1.6.2.5 2009/01/29 19:44:05 lut4rp Exp $
/**
* Pre-processing for the vote database object creation.
*/
Drupal.behaviors.voteUpDownAutoAttach = function () {
var vdb = [];
$('span.vote-up-inact, span.vote-down-inact, span.vote-up-act, span.vote-down-act').each(function () {
// Read in the path to the PHP handler.
var uri = $(this).attr('title');
// Remove the title, so no tooltip will displayed.
$(this).removeAttr('title');
// Remove the href link.
$(this).html('');
// Create an object with this uri, so that we can attach events to it.
if (!vdb[uri]) {
vdb[uri] = new Drupal.VDB(this, uri);
}
});
}
/**
* The Vote database object
*/
Drupal.VDB = function (elt, uri) {
var db = this;
this.elt = elt;
this.uri = uri;
this.id = $(elt).attr('id');
this.dir1 = this.id.indexOf('vote_up') > -1 ? 'up' : 'down';
this.dir2 = this.dir1 == 'up' ? 'down' : 'up';
$(elt).click(function () {
// Ajax POST request for the voting data
$.ajax({
type: 'GET',
url: db.uri,
success: function (data) {
// Extract the cid so we can change other elements for the same cid
var cid = db.id.match(/[0-9]+$/);
var pid = 'vote_points_' + cid;
// Update the voting arrows
$('#' + db.id + '.vote-' + db.dir1 + '-inact').removeClass('vote-' + db.dir1 + '-inact').addClass('vote-' + db.dir1 + '-act');
$('#' + 'vote_' + db.dir2 + '_' + cid).removeClass('vote-' + db.dir2 + '-act').addClass('vote-' + db.dir2 + '-inact');
// Update the points
$('#' + pid).html(data);
},
error: function (xmlhttp) {
alert('An HTTP '+ xmlhttp.status +' error occured. Your vote was not submitted!\n');
}
});
});
}