| 1 |
// $Id: fasttoggle.js,v 1.4 2007/10/07 10:37:38 timcn Exp $ |
// $Id: fasttoggle.js,v 1.5 2007/10/07 12:27:53 timcn Exp $ |
| 2 |
|
|
| 3 |
Drupal.fasttoggle = { |
Drupal.fasttoggle = { |
| 4 |
|
'className': function(data) { |
| 5 |
|
$(this) |
| 6 |
|
.attr('class', $(this).attr('class').replace(/\bfasttoggle-status-[^\s]+/, '')) |
| 7 |
|
.addClass(data.className); |
| 8 |
|
}, |
| 9 |
|
|
| 10 |
'comment': function(data) { |
'comment': function(data) { |
| 11 |
if (data.option == 'status') { |
if (data.option == 'status') { |
| 12 |
$(this).parents('.comment')[data.status ? 'addClass' : 'removeClass']('comment-unpublished'); |
$(this).parents('.comment')[data.status ? 'addClass' : 'removeClass']('comment-unpublished'); |
| 26 |
}; |
}; |
| 27 |
|
|
| 28 |
Drupal.behaviors.fasttoggle = function(context) { |
Drupal.behaviors.fasttoggle = function(context) { |
| 29 |
|
// Unbind is used to prevent dblclick module from interfering. |
| 30 |
$('a.fasttoggle', context).unbind('click').click(function() { |
$('a.fasttoggle', context).unbind('click').click(function() { |
| 31 |
// Add the throbber |
// Add the throbber |
| 32 |
var link = $(this).addClass('throbbing'); |
var link = $(this).addClass('throbbing'); |
| 40 |
'dataType': 'json', |
'dataType': 'json', |
| 41 |
'success': function(data) { |
'success': function(data) { |
| 42 |
// Remove the throbber |
// Remove the throbber |
| 43 |
link.html(data.text).removeClass('throbbing'); |
link.text(data.text).removeClass('throbbing'); |
| 44 |
|
|
| 45 |
|
// Change the class name of the link after toggling it. |
| 46 |
|
if (data.className) { |
| 47 |
|
Drupal.fasttoggle.className.call(link[0], data); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
// Call the callback function for altering the display of other elements |
// Call the callback function for altering the display of other elements |
| 51 |
if (data.callback && Drupal.fasttoggle[data.callback]) { |
if (data.callback && Drupal.fasttoggle[data.callback]) { |
| 52 |
Drupal.fasttoggle[data.callback].call(link[0], data); |
Drupal.fasttoggle[data.callback].call(link[0], data); |