I think that there is a better way of content area update. Current method is to temporary inject hidden new content into page body, change old content with new one and then remove hidden content. That works buts its ugly like comment in code already says it.
Better is to create jQuery object from new content on the fly and then query that object and not all page, something like this:
if (isset(options.targetSelectors)) { // Pick and choose what returned content goes where.
var ajaxRes = $('<div id="popups-temp" style="display:none">'+ data.content.replace(/\n/g, '') + '</div>');
jQuery.each(options.targetSelectors, function(t_new, t_old) {
if(!isNaN(t_new)) {
t_new = t_old; // handle case where targetSelectors is an array, not a hash.
}
// Instead of injecting temp content, just query ajaxRes for new content.
var new_content = $(t_new, ajaxRes).html();
// inject the untrimmed new content into the page, but hidden - ugly hack!
//$('body').prepend('<div id="popups-temp" style="display:none">'+ data.content.replace(/\n/g, '') + '</div>');
//var new_content = $(t_new).html();
//$('#popups-temp').remove();
var $c = $(t_old).html(new_content); // Inject the trimmed new content into the original page.
Drupal.popups.attachBehaviors($c, options);
});
}This is cleaner and faster. Tested with 5.x-1.0-beta1 and its working fine.
Comments
Comment #1
starbow commentedWhat version of jQuery are you using?
Comment #2
pivica commentedYes you were right I had installed jQuery update. Sorry.
Comment #3
borntodeal commentedI am a total newbie to Drupal and a lay-person not a programmer so bear with me...
I want to add content to a Drupal page with a link within that content that when moused-over will bring up an "informer" window that has content (e.g. links to other pages/nodes) and then the pop-up links can be clicked to link to those sites...
Is this making sense and can this be done easily without back-end programming?
Comment #4
asak commentedPopups on mouseover... mighty useful... is this just a matter of changing a line of code?