Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:29:06+00:00 2026-06-15T22:29:06+00:00

In my app I use the below code to give expand/collapse capabilities. In one

  • 0

In my app I use the below code to give expand/collapse capabilities.

In one of my .js files:

$(document).ready(function(){

    $('.row .bundle').on('click', function(e) {
        e.preventDefault();
        var $this = $(this);
        var $collapse = $this.closest('.collapse-group').find('.collapse');
        $collapse.collapse('toggle');
    });

});

In the view, surrounding whatever I want to expand:

<div class="row" style="text-align:center">
 <div class="collapse-group">
    <h4 class="normal_links">
        <a class="bundle" href='#'>(Expand)</a>
    </h4><br>
  <div class="collapse normal_links" >
    # Code to expand/collapse here
  </div>
 </div>
</div>

Worked like a charm until I started using the morris.js library to introduce some charts to my app, at which point the expand/collapse (henceforce EC) functionality stopped working on every page OTHER than the one on which my charts show. When I say EC doesn’t work, I mean that when I click the expand link, it just follows it to ‘#’.

My morris.js code, in the animal.js.coffee file of the model to which the charts belong:

jQuery ->
Morris.Donut
  element: 'weight_chart'
  data: [
    {label: "Pounds Sold", value: $('#weight_chart').data('sold')}
    {label: "Pounds Left", value: $('#weight_chart').data('left')}
  ]
  colors: ['#0066CC', "#880000"]

Morris.Donut
  element: 'sales_chart'
  data: [
    {label: "Revenue Made", value: $('#sales_chart').data('sold')}
    {label: "Est. Revenue Left", value: $('#sales_chart').data('left')}
  ]
  colors: ["#336633", "#880000"]

Morris.Donut
    element: 'status_chart'
    data: [
        {label: "Incomplete", value: $('#status_chart').data('zero')}
        {label: "Downpaid", value: $('#status_chart').data('one')}
        {label: "Fully Paid", value: $('#status_chart').data('two')}
        {label: "Received", value: $('#status_chart').data('three')}
    ]
    colors: ["#880000", '#E09050', '#989898', '#000000' ]

An example of how I actually call the chart in the view:

 <%= content_tag :div, "", id: "sales_chart", 
       data: {sold: @animal.rev.round(2), 
              left: @animal.rev_left.round(2)}, 
       class: "morris_chart" %>

The charts display perfectly, as does the EC on the page with the charts. On seemingly every other page, not. And when I delete the animal.js.coffee file with the morris code (temporarily), the problem goes away. I’ve triple checked my view code, and it’s all good (or at least identical to the code that is working).

Possibly of additional interest is that back when this worked there used to be an empty animal.js file, and I replaced it with a animal.js.coffee file with the morris-relevant code. The actual morris.js and raphael.js code is in vendors/javascripts. The EC javascript code is in the .js file of another model entirely, but that hasn’t been a problem up to this point.

Any ideas? I’ll be away from my computer for a few hours, but when I’m back I’ll post any additional code anybody wants.

EDIT — Figured my application.js file might also be relevant:

// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require raphael
//= require morris
//= require_tree .
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:29:07+00:00Added an answer on June 15, 2026 at 10:29 pm

    The problem appears to have been that the Coffeescript was looking for the elements (“sales_chart”, etc) on pages where it did not appear. When that happened, things went wrong, and none of my other Javascript worked. To fix this, all I had to do was check for the element before calling Morris on it. So:

    jQuery ->
    
        if $('#weight_chart').length
          Morris.Donut
            element: 'weight_chart'
            data: [
              {label: "Pounds Sold", value: $('#weight_chart').data('sold')}
              {label: "Pounds Left", value: $('#weight_chart').data('left')}
            ]
            colors: ['#0066CC', "#880000"]
    
        if $('#sales_chart').length
          Morris.Donut
            element: 'sales_chart'
            data: [
              {label: "Revenue Made", value: $('#sales_chart').data('sold')}
              {label: "Est. Revenue Left", value: $('#sales_chart').data('left')}
            ]
            colors: ["#336633", "#880000"]
    
        if $('#status_chart').length
          Morris.Donut
            element: 'status_chart'
            data: [
              {label: "Incomplete", value: $('#status_chart').data('zero')}
              {label: "Downpaid", value: $('#status_chart').data('one')}
              {label: "Fully Paid", value: $('#status_chart').data('two')}
              {label: "Received", value: $('#status_chart').data('three')}
            ]
            colors: ["#880000", '#E09050', '#989898', '#000000']
    

    Problem solved. Thanks for the help, and the excuse to learn Coffeescript!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the below code to create and read my database in the app
I use tabhost in my app. I use below code to add intent: TabHost
I would like to use the code below as a helper function, since it
I use the line below in my C# winform app, this works great but
My configuration: app.configure(function(){ app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.bodyParser()); app.use(express.cookieParser()); app.use(express.session({ secret:
I'm using Xcode 4.3.1 I use the below code to get the Facebook access
I am developing an android email client app with the use of one email
I try use below code to load an URL. URL url = new URL(urlstr);
I'm using the below code to transfer an image from one folder on external
I use below code to post a photo on wall usually $attachments = array(

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.