Flot, UI Slider, Renders in Chrome and Safari, but not in FF 3.6.2

Flot, UI Slider, Renders in Chrome and Safari, but not in FF 3.6.2

Hi All,

I am being slowly driven mad by this problem. The page renders fine in Chrome and Safari, and it renders fine in Firefox when I have Firebug on. But if I turn off Firebug, the Flot plot will not render in Firefox. I had it in a simpler HTML file also, and was able to solve it by adding the $(document).ready() function. But it has not solved the problem for the present file. I'm pretty sure that it's got to do with the loop which populates the data array, but I'm not getting any error messages from any browser... Is there something I should be looking for? Is there something about Firefox's handling of the queue that would cause this? 

Thanks for any help,
brokenindex

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
  6. <title>
  7. Mouseover Plot, see x and y values, plot line equation which changes as sliders are dragged
  8. </title>
  9. <!-- Generic CSS for all jQuery elements in this course -->
  10. <link type="text/css" href="css/generic.css" rel="stylesheet" />
  11. <!-- CSS for jQuery UI -->
  12. <link type="text/css" href="css/custom-theme/jquery-ui.custom.css" rel="stylesheet" />
  13. <!--[if IE]><script language="javascript" type="text/javascript" src="flot/excanvas.min.js"></script><![endif]-->
  14. <link href="flot/layout.css" rel="stylesheet" type="text/css" />
  15. <script type="text/javascript" src="js/jquery.min.js">
  16. </script>
  17. <script language="javascript" type="text/javascript" src="flot/jquery.flot.min.js">
  18. </script>
  19. <script type="text/javascript" src="js/jquery-ui.custom.min.js">
  20. </script>
  21. <style type="text/css">
  22. p, h3 {
  23. position: relative;
  24. padding-bottom: 20px;
  25. text-align:justify;
  26. margin-left: auto;
  27. margin: auto;
  28. }
  29. #placeholder {
  30. position: relative;
  31. width:350px;
  32. height:350px;
  33. margin-left: 10%;
  34. margin-right: auto;
  35. }
  36. #slopeDiv{
  37. position: relative;
  38. top: -350px;
  39. margin-left: 60%;
  40. }
  41. #yintDiv{
  42. position: relative;
  43. top: -690px;
  44. margin-left: 70%;
  45. }
  46. #startForm {
  47. position: relative;
  48. margin-left: 20%;
  49. margin-bottom: 20px;
  50. width: 60%;
  51. border-style:solid;
  52. border-width:1px;
  53. text-align: center;
  54. padding-top: 10px;
  55. padding-bottom: 10px;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <h3>
  61. What's your <i>f(x)</i>?
  62. </h3>
  63. <div id="startForm"> 
  64. <i>y</i> = <i>x</i>3 + 2
  65. </div>
  66. <p>The formula above is your starting point. Drag the sliders below to adjust the slope and y-intercept to adjust the line. Mouse over the plot to see the exact <i>x</i> and <i>y</i> coordinates of the cursor.
  67. </p>
  68. <div id="placeholder"></div>
  69. <div id="formElements">
  70. <div id="xTxt">
  71. <p>
  72. <i>x</i> =
  73. </p>
  74. </div>
  75. <div id="yTxt">
  76. <p>
  77. <i>y</i> =
  78. </p>
  79. </div>
  80. </div>
  81. <div id="slopeDiv">
  82. <p>
  83. <label for="slope">Slope:</label>
  84. <input type="text" id="slope" style="border:0; color:#f6931f; font-weight:bold;" />
  85. </p>

  86. <div id="slider-slope" style="height:300px;"></div>
  87. </div>
  88. <div id="yintDiv">
  89. <p>
  90. <label for="yint"><i>y</i>-Intercept:</label>
  91. <input type="text" id="yint" style="border:0; color:#f6931f; font-weight:bold;" />
  92. </p>

  93. <div id="slider-yint" style="height:300px;"></div>
  94. </div>
  95. <script id="source" language="javascript" type="text/javascript">
  96. /* <![CDATA[ */
  97. alert('in script');
  98. var j = jQuery.noConflict();

  99. var mySlope;
  100. var myYint;

  101. j(document).ready(function() {
  102.     alert('document ready');
  103.     

  104.     function resetPlot() {

  105.         d1 = [];

  106.         console.log('reset plot');

  107.         for (var i = -20; i < 20; i++) {

  108.             //var mySlope = j('#slope').val();
  109.             //var myYint = j('#yint').val();

  110.         mySlope = j("#slider-slope").slider('value'); //j('#slope').val();
  111.         myYint = j("#slider-yint").slider('value'); //j('#yint').val();

  112.             var myY = (i * mySlope) + myYint;

  113.             d1.push([i, myY]);

  114.         };

  115.         plotThis();

  116.     }

  117.     function placeTxt() {

  118.         var pOff = j('#placeholder').offset();
  119.         //console.log(pOff);
  120.         j('#formElements').css({
  121.             position: 'absolute',
  122.             left: pOff.left + 365,
  123.             top: pOff.top + 10
  124.         });
  125.     }
  126.     placeTxt();

  127.     // Reposition the click target any time the window is resized.
  128.     j(window).resize(function() {
  129.         placeTxt();
  130.     });

  131.     j('#placeholder').bind("plothover",
  132.     function(event, pos, item) {
  133.         j('#xTxt').html('<p><i>x</i> = ' + pos.x.toFixed(2) + '</p>');
  134.         j('#yTxt').html('<p><i>y</i> = ' + pos.y.toFixed(2) + '</p>');

  135.         j('#placeholder').mouseleave(
  136.         function() {
  137.             j('#xTxt').html('<p><i>x</i> = </p>');
  138.             j('#yTxt').html('<p><i>y</i> = </p>');

  139.         }
  140.         );

  141.     });

  142.     function plotThis() {

  143.         //console.log('plotThis()');
  144.         //alert('plotThis()');

  145.         j.plot(j("#placeholder"), [
  146.         {
  147.             data: d1,
  148.             points: {
  149.                 show: false,
  150. hoverable: false
  151.             },
  152.             lines: {
  153.                 show: true,
  154.                 fill: false,
  155. hoverable: false
  156.             },
  157.             color: "#F88017"
  158.         }

  159.         ], {
  160.             xaxis: {
  161.                 ticks: 15,
  162.                 min: -15,
  163.                 max: 15
  164.             },
  165.             yaxis: {
  166.                 ticks: 15,
  167.                 min: -15,
  168.                 max: 15
  169.             },
  170.             grid: {
  171.                 backgroundColor: {
  172.                     colors: ["#fff", "#eee"]
  173.                 },
  174.                 markings: [{
  175.                     xaxis: {
  176.                         from: 0,
  177.                         to: 0
  178.                     },
  179.                     yaxis: {
  180.                         from: -14,
  181.                         to: 14
  182.                     },
  183.                     color: "#C0C0C0"
  184.                 },
  185.                 {
  186.                     xaxis: {
  187.                         from: -14,
  188.                         to: 14
  189.                     },
  190.                     yaxis: {
  191.                         from: 0,
  192.                         to: 0
  193.                     },
  194.                     color: "#C0C0C0"
  195.                 }],
  196.                 hoverable: true,
  197. autoHighlight: false
  198.             }
  199.         });

  200.     }


  201.     j("#slider-slope").slider({
  202.         orientation: "vertical",
  203.         range: "min",
  204.         min: -15,
  205.         max: 15,
  206.         value: 3,
  207.         step: 0.25,
  208.         slide: function(event, ui) {
  209.             j("#slope").val(ui.value);
  210.             resetPlot();
  211.         }
  212.     });
  213.     j("#slope").val(j("#slider-slope").slider("value"));

  214.     j("#slider-yint").slider({
  215.         orientation: "vertical",
  216.         range: "min",
  217.         min: -15,
  218.         max: 15,
  219.         value: 2,
  220.         slide: function(event, ui) {
  221. //alert('slide');
  222.             j("#yint").val(ui.value);
  223.             resetPlot();
  224.         }

  225.     });
  226.     j("#yint").val(j("#slider-yint").slider("value"));

  227. var d1 = [];

  228.     for (var i = -20; i < 20; i++) {

  229.         //alert('looping');
  230.          mySlope = j("#slider-slope").slider('value'); //j('#slope').val();
  231.          myYint = j("#slider-yint").slider('value'); //j('#yint').val();

  232.         var myY = (i * mySlope) + myYint;

  233.         d1.push([i, myY]);

  234. console.log(d1);

  235.     };

  236.     plotThis();
  237. });
  238. /* ]]> */

  239. </script>
  240. </body>
  241. </html>