0

I am using a third party package. When I use a code the code functions as it should.

<template name ="gamePage">

        <h2>Counting down 15 minutes (900 seconds)</h2>
        <div id="CountDownTimer" data-timer="900" style="width: 1000px; height: 250px;"></div>

    <script>

        $("#CountDownTimer").TimeCircles({ time: { Days: { show: false }, Hours: { show: false }}});

    </script>

</template>

However, when I try to remove the and instead have the javascript function be in the page it does not work.

Template.gamePage.test123 = function() {
    $("#CountDownTimer").TimeCircles({ time: { Days: { show: false }, Hours: { show: false }}});

};

<template name ="gamePage">

        <h2>Counting down 15 minutes (900 seconds)</h2>
        <div id="CountDownTimer" data-timer="900" style="width: 1000px; height: 250px;"></div>

        {{test123}}

</template>

What is the proper way of doing this?

1
  • In your script declarations (<head>...</head>), are you loading jQuery or Meteor first? Commented Oct 11, 2014 at 23:12

1 Answer 1

1

Remove {{test123}} from your template and use the rendered callback:

Template.gamePage.rendered = function() {
  $("#CountDownTimer").TimeCircles(
    {time: {Days: {show: false}, Hours: {show: false}}}
  );
};

rendered is the proper place to do things like jQuery plugin initialization and anything else that requires DOM elements to first be on the page.

Sign up to request clarification or add additional context in comments.

5 Comments

This logically makes sense to me, but unfortunately still does not work. If I call $("#CountDownTimer").TimeCircles( {time: {Days: {show: false}, Hours: {show: false}}} ); from the console it works. I tried wrapping it in rendered = function() {Meteor.startup( and also does not work
That's interesting. Does it give you any errors in the console? What version of meteor are you using?
Meteor 0.9.3.1, no errors in the console. The package TimeCircles is my first package that I have created. I am wondering if I did all the necessary requirements right, as it may be something with the load order. I am adding the package.js file code. I am stumped, but truly appreciate your help.
Yeah I'm not sure. The path looks a little weird for the api.addFiles - that's relative to the root of the package or the project? I could probably diagnose this in a couple of minutes if I could see the source. Any chance you could create a repo with the bare minimum code do demonstrate the problem?
I believe since I had a {{#if}} in there to manage when the code was displayed was the problem. Once I put the code in a new template, such as {{#if xyz}} {{> timeCircle}} the timeCircle.rendered = function worked. I appreciate your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.