[development] Passing a client value back to Drupal
Earl Miles
merlin at logrus.com
Wed Mar 30 05:43:30 UTC 2011
On 3/29/2011 5:12 PM, jeff at ayendesigns.com wrote:
> That's the clean way to do it, and I would if I were in control of the
> handshaking, but because Ctools is doing the handling of the link click
> and the construction of the AJAX handshaking, I can't just package it up
> and send it...I need to find the right 'box and forms' to get it to
> accept, carry and deliver my package for me.
This is how CTools binds to links, normally: (There's a couple of other
methods as well, but they're all similar).
$('a.ctools-use-ajax:not(.ctools-use-ajax-processed)', context)
.addClass('ctools-use-ajax-processed')
.click(Drupal.CTools.AJAX.clickAJAXLink);
If you need special handling of the link, what you probably need to do
is bind yourself, and then use your own version of clickAJAXLink that
gets your data and does what it needs.
That function isn't very long:
/**
* Generic replacement click handler to open the modal with the
destination
* specified by the href of the link.
*/
Drupal.CTools.AJAX.clickAJAXLink = function() {
if ($(this).hasClass('ctools-ajaxing')) {
return false;
}
var url = $(this).attr('href');
var object = $(this);
$(this).addClass('ctools-ajaxing');
try {
url = url.replace(/\/nojs(\/|$)/g, '/ajax$1');
$.ajax({
type: "POST",
url: url,
data: { 'js': 1, 'ctools_ajax': 1},
global: true,
success: Drupal.CTools.AJAX.respond,
error: function(xhr) {
Drupal.CTools.AJAX.handleErrors(xhr, url);
},
complete: function() {
$('.ctools-ajaxing').removeClass('ctools-ajaxing');
},
dataType: 'json'
});
}
catch (err) {
alert("An error occurred while attempting to process " + url);
$('.ctools-ajaxing').removeClass('ctools-ajaxing');
return false;
}
return false;
};
You can either modify the href and then call through to it, or just
replace it as you need.
More information about the development
mailing list