Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

afterCloudRender not recognizing the spans #38

Open
dietah opened this issue Apr 23, 2013 · 2 comments
Open

afterCloudRender not recognizing the spans #38

dietah opened this issue Apr 23, 2013 · 2 comments

Comments

@dietah
Copy link

dietah commented Apr 23, 2013

In a tool I'm developing we need to be able to trigger some actions for each word in the generated cloud.

When using the afterCloudRender the correct callback is triggered but none of the words are found.

var _MakeWordsClickable = function () {
        console.log('callback start');
        console.log($('div#wordcloud span').size());

        $('div#wordcloud span').each(function () {
            $(this).click(function () {
                console.log($(this).text());
            });
        });

        console.log('callback end');
    }

The console shows 'callback start' and 'callback end' but the size of the spans is 0.

When I execute the code with a timeout of 200 miliseconds everything works.

$("#wordcloud").jQCloud(objCloud, { afterCloudRender: setTimeout('_MakeWordsClickable()',200) });

I tried to circumvent the timeout by using the afterWordRender at each word, but the same problems exists.

So in essence, jQCloud is not waiting until the cloud is completely rendered.

Thanks for looking into this.

@descl
Copy link

descl commented Jan 2, 2014

same problem here, is there a better fix than using timeout?
thanks, chris

@dietah
Copy link
Author

dietah commented Jan 9, 2014

Hi Chris,

In _MakeWordsClickable() I used the jQuery .on() command which is like a live bind, so as each word is added to the cloud it automatically gets that code.

For example:

var _MakeWordsClickable = function(){   
        $('div#wordcloud').on('click', 'span', function(){
            // do something
        });             
}

This way there is no need for a timeout, which would be subject to the amount of words loaded.

Hope this helps.

Thanks,
Dieter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants