[development] Passing a client value back to Drupal
jeff at ayendesigns.com
jeff at ayendesigns.com
Thu Mar 31 01:40:04 UTC 2011
Getting warm. Since I'm replacing the click handler, I decided not to
mess with url at all and to just add another data pair to the data being
passed, and treat it as 3 parms in the module.
I note that both 'modal' and 'ajax' are being loaded, and that the
binding is actually do modal (from what I see in firebug). Looking at
the code, modal link click is just a small lead-in to ajax link click,
so I think I need to unbind the modal click handler and bind my own,
having it call my own ajax link click function.
The unbind works. The bind does not. I start the bind with an alert, and
when I actually click the link, it attempts to make a page change (no
ajax bind, and no alert). Here is what I have:
/**
* Unbind the CTools click event handler then add our own
*/
$(document).ready(function() {
$('a.ctools-use-modal').unbind('click');
$('a.ctools-use-modal-processed').unbind('click');
$('a.ctools-use-modal:not(.ctools-use-modal-processed-My)', context)
.addClass('ctools-use-modal-processed-My')
.click(Drupal.CTools.Modal.clickAjaxMyLink);
});
Drupal.CTools.Modal.clickAjaxMyLink = function () {
// show the empty dialog right away.
Drupal.CTools.Modal.show(Drupal.CTools.Modal.getSettings(this));
Drupal.CTools.AJAX.clickAJAXMyLink.apply(this);
if (!$(this).hasClass('ctools-ajaxing')) {
Drupal.CTools.Modal.dismiss();
}
return false;
};
/**
* Generic replacement click handler to open the modal with the
destination
* specified by the href of the link.
*/
Drupal.CTools.AJAX.clickAJAXMyLink = function() {
alert('made it');
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, 'body':
CKEDITOR.instances['edit-body'].getData()},
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;
};
On 03/30/2011 01:43 AM, Earl Miles wrote:
>
> 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.
>
> 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