/[drupal]/contributions/modules/vote_up_down/ajax_vote_up_down.js
ViewVC logotype

Contents of /contributions/modules/vote_up_down/ajax_vote_up_down.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Mon Nov 19 07:32:27 2007 UTC (2 years ago) by frjo
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.5: +11 -10 lines
File MIME type: text/javascript
THis is for Drupal 5
1 // $Id: ajax_vote_up_down.js,v 1.5 2006/11/24 13:18:35 frjo Exp $
2
3 Drupal.voteUpDownAutoAttach = function() {
4 var vdb = [];
5 $('span.vote-up-inact, span.vote-down-inact, span.vote-up-act, span.vote-down-act').each(function () {
6 // Read in the path to the PHP handler
7 var uri = $(this).attr('title');
8 // Get title from a tag.
9 var atitle = $(this).children('a').attr('title');
10 $(this).attr('title', atitle);
11 // remove href link
12 $(this).html('');
13 // Create an object with this uri. Because
14 // we feed in the span as an argument, we'll be able
15 // to attach events to this element.
16 if (!vdb[uri]) {
17 vdb[uri] = new Drupal.VDB(this, uri);
18 }
19 });
20 }
21
22 /**
23 * A Vote DataBase object
24 */
25 Drupal.VDB = function(elt, uri) {
26 var db = this;
27 // By making the span element a property of this object,
28 // we get the ability to attach behaviours to that element.
29 this.elt = elt;
30 this.uri = uri;
31 this.id = $(elt).attr('id');
32 this.type = this.id.indexOf('node') > -1 ? 'node' : 'comment';
33 this.dir1 = this.id.indexOf('vote_up') > -1 ? 'up' : 'down';
34 this.dir2 = this.dir1 == 'up' ? 'down' : 'up';
35 // Extract the cid so we can change other elements for the same cid
36 this.cid = db.id.match(/[0-9]+$/);
37 $(elt).click(function() {
38 // Ajax GET request for vote data
39 $.ajax({
40 type: "GET",
41 url: db.uri,
42 success: function (data) {
43 //update the voting arrows
44 $('#' + db.id + '.vote-' + db.dir1 + '-inact')
45 .removeClass('vote-' + db.dir1 + '-inact')
46 .addClass('vote-' + db.dir1 + '-act');
47 $('#vote_' + db.dir2 + '_' + db.type + '_' + db.cid)
48 .removeClass('vote-' + db.dir2 + '-act')
49 .addClass('vote-' + db.dir2 + '-inact');
50 // update the points
51 $('#vote_points_' + db.type + '_' + db.cid).html(data);
52 },
53 error: function (xmlhttp) {
54 alert('An HTTP error '+ xmlhttp.status +' occured.\n'+ db.uri);
55 }
56 });
57 });
58 }
59
60 // Global killswitch
61 if (Drupal.jsEnabled) {
62 $(document).ready(Drupal.voteUpDownAutoAttach);
63 }

  ViewVC Help
Powered by ViewVC 1.1.2