I think the handbook page describes exactly what I need, but I haven't understood it. I'm using panels 3 and want the flag-view-block in my right column to refresh, when the flag link in my left column is clicked.
1. Do I have to install the component module?
2. What do I have to change in this code on the handbook page?
$(document).bind('flagGlobalAfterLinkUpdate', function(event, data) {
function blockExistsOnPage(module_name, block_id) {
var dom_id = 'block-' + module_name + '-' + block_id;
return $('#'+dom_id).length != 0;
}
function refreshBlock(module_name, block_id) {
var dom_id = 'block-' + module_name + '-' + block_id;
$.get(base_url + '?q=component/block/' + module_name + '/' + block_id, null, function(newHtml) {
// Replace the old block with the new one.
$('#'+dom_id).after(newHtml).remove();
});
}
if (data.flagName == 'bookmarks') {
if (blockExistsOnPage('views', 'flag_bookmarks-block_1')) {
refreshBlock('views', 'flag_bookmarks-block_1');
}
}
});
Which block ID, module name and dom ID do I have to replace? In my css I found for my block in my panel the classes "view-display-id-block_1" "view-dom-id-1".
You see, I haven't really understood the code, but i'd like to get it working and i'd be thankful about your help.
Comments
Comment #1
Andrew Gorokhovets commentedhttp://drupal.org/node/369693#comment-2350262
Comment #2
Andrew Gorokhovets commentedUnfortunately this code non-working :-(
The same problem.
Comment #3
Andrew Gorokhovets commentedI think this code on book page (http://drupal.org/node/336122 Example: Refreshing a block on the page, via AJAX) precisely contains errors.
For example
$.get(base_url + '?q=component/block/' + module_name + '/' + block_id, null, function(newHtml) {Will return
http://localhosT?q=component/block/module_name/block_id
The slash after base_url is passed.
But here is not one error
Comment #4
Andrew Gorokhovets commentedcomponent.module must be enable.
In Flag.tpl.php To press id="flag-checkbox"
Now other problem...
Block Update becomes earlier than content flaged
Comment #5
Andrew Gorokhovets commentedExcellent working examples here:
http://ucenter.googllers.com/home/space.php?uid=4&do=blog&id=54
Comment #6
Michelangelo commentedIf the unflag link is within the block being refreshed, after the first block refresh, click an unflag link again causes the whole page to be reloaded with the contents of the block. The url becomes that of the component.
The 'destination' url parameter in the unflag links is modified after the block refresh. Could this be the cause?
Comment #7
Andrew Gorokhovets commentedYes I cnow about this problem.I Still working.
Comment #8
YK85 commented+1 subscribing
Comment #9
ariedels commentedI too am having the problem with internal flags.
I am not well versed in jquery, but it would seem that one could do a find and replace on the output from the component module so that the flags were restored to their original.
i.e.
the original flag: ..../flag/flag/bookmark/234?destination=node&token=....
the script above in #3 changes it to:
.../flag/flag/remove/210?destination=component%2Fblock%2Fviews%2Fbookmark-block&token=....
If there a way to replace "component%2Fblock%2Fviews%2Fbookmark-block" with "node" in the jQuery functions before the new block gets updated?
Comment #10
henrijs.seso commentedthere is a bug in code. use
var base_url = (Drupal.settings && Drupal.settings.basePath) || '/';in stead ofvar base_url = (Drupal.setting && Drupal.setting.basePath) || '/';Comment #11
quicksketchI've updated the documentation at http://drupal.org/node/336122 to use
Drupal.settings(plural) instead ofDrupal.setting(singular). I've also updated the documentation to use Drupal.attachBehaviors() on the new HTML, making it so that the refreshed block will continue to operate if it contains JavaScript behaviors.Comment #13
ceerwk commentedAs per comment #9. I am also having this problem. Anyone have any ideas how to solve it? Thanks.
Comment #14
sambaynham commentedI can say that the code at http://ucenter.googllers.com/home/space.php?uid=4&do=blog&id=54 works flawlessly for me.
Comment #15
cpliakas commentedFor Views at least, check out Views Flag Refresh for another possible solution to the problem.
Thanks,
Chris
Comment #16
gynekolog commentedAnd so when I have non-views block and Flag 7.x-3.2?
I have classic block with name of actual logged user and with number flagged contents (own code). How can I refresh the block after flagging content?
excuse my english please
Comment #17
ivnishClosed as outdated because Drupal 7 is EOL