| 1 |
|
| 2 |
Drupal.behaviors.relevanceImage = function (context) {
|
| 3 |
$('.node-results img.relevance:not(.relevanceImage-processed)', context).
|
| 4 |
addClass('relevanceImage-processed').
|
| 5 |
css('cursor', 'pointer').
|
| 6 |
click( function(e){
|
| 7 |
var nid = $(this).parent().get(0).id.substr(19);
|
| 8 |
var type = this.src.match(/up/) ? true : false;
|
| 9 |
if (relevance.getStatus(nid) === type)
|
| 10 |
relevance.setStatus(nid, null);
|
| 11 |
else
|
| 12 |
relevance.setStatus(nid, type);
|
| 13 |
|
| 14 |
});
|
| 15 |
|
| 16 |
};
|
| 17 |
|
| 18 |
|
| 19 |
Drupal.relevanceFeedback = function () {
|
| 20 |
this.status = {};
|
| 21 |
}
|
| 22 |
|
| 23 |
Drupal.relevanceFeedback.prototype.setStatus = function(nid, on) {
|
| 24 |
this.status[nid] = on;
|
| 25 |
|
| 26 |
var keys = $("form input[name='keys']").attr('value');
|
| 27 |
var type = on ? 'rel' : (on == null ? 'undef' : 'nonrel');
|
| 28 |
|
| 29 |
$.get("/relevance_feedback/js/", { nid: nid, keys: keys, type: type}, function(data){
|
| 30 |
if ( data == 1 )
|
| 31 |
location.reload();
|
| 32 |
}
|
| 33 |
);
|
| 34 |
|
| 35 |
//change image accordingly
|
| 36 |
$("span[id='relevance_feedback_" + nid + "'] img.up").each( function(e) {
|
| 37 |
var base = this.src.replace(/_on/, "").replace(/up\.gif/, "");
|
| 38 |
this.src = on ? base + "up_on.gif" : base + "up.gif";
|
| 39 |
});
|
| 40 |
$("span[id='relevance_feedback_" + nid + "'] img.down").each( function(e) {
|
| 41 |
var base = this.src.replace(/_on/, "").replace(/down\.gif/, "");
|
| 42 |
this.src = on === false ? base + "down_on.gif" : base + "down.gif";
|
| 43 |
});
|
| 44 |
}
|
| 45 |
|
| 46 |
Drupal.relevanceFeedback.prototype.getStatus = function(nid) {
|
| 47 |
return this.status[nid];
|
| 48 |
}
|
| 49 |
|
| 50 |
|
| 51 |
$(document).ready(function() {
|
| 52 |
relevance = new Drupal.relevanceFeedback;
|
| 53 |
|
| 54 |
//parse the inital status
|
| 55 |
$("span.relevance_feedback").each( function(e) {
|
| 56 |
if ($(this).attr('rf_status') != null) {
|
| 57 |
var nid = this.id.substr(19);
|
| 58 |
relevance.setStatus(nid, $(this).attr('rf_status') == "1" ? true : false);
|
| 59 |
}
|
| 60 |
});
|
| 61 |
});
|
| 62 |
|