Closed (works as designed)
Project:
Colorbox Node
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
30 Aug 2013 at 04:37 UTC
Updated:
10 Feb 2014 at 22:37 UTC
Jump to comment: Most recent
Comments
Comment #1
dustinbrunson commentedI know that when the colorbox node is closed out that the javascript is still loaded, and therefore when the node is opened again there is not onload event fired for some reason.
I can't find a way to clear the javascript or know when the page is loaded to call a function to set things up again within the colorbox node window.
Comment #2
iLLin commentedYou need to setup your javascript as a behavior.
Comment #3
dustinbrunson commentedOkay I am able to get the jquery into the colorbox with this code within my js file, however it is firing the doit() 3 times when the colorbox node opens.
(function($) {
Drupal.behaviors.module = {
attach: function (context, settings) {
doit();
}
};
})(jQuery);
Comment #4
iLLin commentedThat is why you need to use .once() in your calls. It will prevent that.
Where your "myevent" is w/e you want to call it. This will allow you to setup multiple instances on a dom object if you need to by changing the myevent to a different one each time.
Comment #5
dustinbrunson commentedThank you iLLin,
.once works except that I had more robust scripting going and could not use that for everything.
I was able to get it working with this implementation
Drupal.behaviors.mybehavior = {
attach: function (context, settings) {
$('#mybehavior', context).once('#mybehavior', function () {
// Apply the MyBehaviour effect to the elements only once.
dothefunction();
});
}
};
This way I could put all of my jquery within the dothefunction() and not it all works perfectly everytime. very cool, thanks for all your hard work and help.
Comment #6
iLLin commentedNo prob!
Comment #7
cancerian7 commentedHi Dennis,
Thanks for creating this module. I like it, but I am having the same issue with fb_social module.
I get the facebook comments box on the first view of colorbox node but on the second view it doesn't render. After, I refresh parent window it appears again on the colorbox node. Can you please tell me how to get rid of this issue? or make it compatible with fb_social module?
Thanks.
Comment #8
dustinbrunson commentedHey Cancerian7, this is the code I use for custom javascript in my module. From the module I load this javascript file and then execute any code from within the doit function. since I don't know your specific problem, this is the best I can do to help. This is how I do it. It seems to attach the javascript directly to the module block so that it gets loaded again each time. not sure exactly why it works but it does :)
change our module-name for the name of your module - if its the fb_social module that is having problems you may need to look into its javascript file and change it to match this.
(function($) {
Drupal.behaviors.module-name = {
'attach': function(context) {
keystatus='no';
$('.block-module-name', context).once('block-module-name', function () {
// Apply the MyBehaviour effect to the elements only once.
doit();
});
}
}
function doit() {
// put your code here
}
})(jQuery);
Comment #9
cancerian7 commentedHi Dustin,
Thank you so much for looking into this. Here is the javascript which I found in the fb_social.module
Here is the link to the module source code http://drupalcode.org/project/fb_social.git/blob/HEAD:/fb_social.module
Please help. Thanks
Comment #10
dustinbrunson commentedThis is definitely beyond my expertise, but this may work for you
you need to make sure that there is a class name on the module that matches the name in this line
$('.fb_social', context).once('fb_social', function ()
or change the code below to match the classname on your module - for example if the module is #fb_social
then use this: $('#fb_social', context).once('fb_social', function ()
change the code in your file to this:
$output = '
';
(function($) { Drupal.behaviors.fb_social = { 'attach': function(context) { $('.fb_social', context).once('fb_social', function () { // Apply the MyBehaviour effect to the elements only once. doit(); }); } } function doit() { window.fbAsyncInit = function() { FB.init({ appId: " . drupal_to_js($appid) . ", status: true, cookie: true, xfbml: true}); jQuery.event.trigger('fb:init'); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/" . $fb_locale . "/all.js'; document.getElementById('fb-root').appendChild(e); }()); } })(jQuery)$output .= "
";
if this doesn't work I am not sure I can be of anymore help.
Comment #11
cancerian7 commentedThanks for this, I guess you are getting close in solving this problem. Everything goes well after applying your code but it's printing the code with correct FB app id on the colorbox node and not rendering it.
I found another javascript in the source code of fb_social module.
Comment #12
iLLin commentedIt might be better to take this to the Facebook Social module page as they need to setup their stuff as behaviors so it gets reattached on each page load.
Comment #13
cancerian7 commentedOk sorry, I guess I have to run colorbox in an iframe now. Because your module is not working with many other modules like addtoany, sharethis, addthis etc. So, it's best to not create issues with other modules rather than just one.
Thanks for your time Dustin.