// $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) { } }); }); } /* playback timings (ms): LoadShardBlock: 61.695 (3) esindex: 0.017 captures_list: 75.335 CDXLines.iter: 8.325 (3) PetaboxLoader3.datanode: 53.811 (5) exclusion.robots: 0.213 exclusion.robots.policy: 0.203 RedisCDXSource: 3.301 PetaboxLoader3.resolve: 51.362 (2) load_resource: 98.522 */