SHARE
TWEET

Page Timeframe Default

sweenig Jan 14th, 2014 431 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. This widget overrides the timerange of this page whenever one hasn't been manually specified.<div id="help"></div>
  2. <script>
  3. var passedtimerange = 0;
  4. var parenttimerange = 0;
  5. var ispageexplicit=false;
  6. var helpdiv = document.getElementById("help");
  7.  
  8. //get the iframe url timerange value and store in timerange (if passed)
  9. var iframeurl=location.search;
  10. iframeurl=iframeurl.replace('?','');
  11. var iframeargsarray=iframeurl.split('&');
  12. var iframeargsmatrix = new Array(iframeargsarray.length);
  13. for (var i = 0; i < iframeargsarray.length; i++){
  14.         iframeargsmatrix[i] = new Array(2);iframeargsmatrix[i] = iframeargsarray[i].split('=');}
  15. for (var j=0; j < iframeargsmatrix.length; j++){
  16.         if(iframeargsmatrix[j][0] == 'timeRange'){passedtimerange = iframeargsmatrix[j][1];break;}}
  17. //passedtimerange contains the iframe's timerange.  If 0, no timerange was passed.
  18. //get the parent url parameters
  19. var parenturl=parent.document.location.search;
  20. parenturl=parenturl.replace('?','');
  21. var argsarray=parenturl.split('&');
  22. var argsmatrix = new Array(argsarray.length);
  23. for (var i = 0; i < argsarray.length; i++){
  24.         argsmatrix[i] = new Array(2);argsmatrix[i] = argsarray[i].split('=');}
  25. for (var j = 0; j < argsmatrix.length; j++){
  26.         if (argsmatrix[j][0] == 'pg'){ispageexplicit=true;}
  27.         if (argsmatrix[j][0] == 'timeRange'){parenttimerange = argsmatrix[j][1];}}
  28. //parenttimerange contains the parent url's timerange.  If 0, no timerange was specified.
  29.  
  30. if(ispageexplicit){
  31. if(passedtimerange != 0){
  32.         helpdiv.innerHTML = 'You have specified the timeRange ' + passedtimerange + '. <br />Now edit this view and set the height to 0 to maximize available screen real estate. You should probably change the title of the browser view so that it indicates the new timeRange.';
  33.         if (parenttimerange == 0){parent.document.location=parent.document.location.href + '&timeRange=' + passedtimerange;}}
  34. else {
  35.         var helptext = 'You have not specified a timeRange within the browser view\'s target URL.'
  36.         if (parenttimerange == 0){helptext = helptext + ' If you don\'t know what timeRange to use, select a timeRange from the main time controls on this page.  When the page refreshes, you\'ll see updated instructions.';}
  37.         else {helptext += ' If you would like to set the currently selected timeRange as the default for this page, change the browser view\'s target URL to the following:<br /><b>../content/defaulttime.html?timeRange=' + parenttimerange + '</b>' ;}
  38.         helptext += '<br />Otherwise, refer to the following table:<br />';
  39.         helptext += '<table border=1><tr><th>timeRange</th><th>Value</th></tr>';
  40.         helptext += '<tr><td>Last Hour</td><td>0</td></tr>';
  41.         helptext += '<tr><td>Last 4 Hours</td><td>1</td></tr>';
  42.         helptext += '<tr><td>Last 8 Hours</td><td>2</td></tr>';
  43.         helptext += '<tr><td>Last 24 Hours</td><td>3</td></tr>';
  44.         helptext += '<tr><td>Last 7 Days</td><td>4</td></tr>';
  45.         helptext += '<tr><td>Last 14 Days</td><td>5</td></tr>';
  46.         helptext += '<tr><td>Last 30 Days</td><td>6</td></tr>';
  47.         helptext += '<tr><td>Last 3 Months</td><td>7</td></tr>';
  48.         helptext += '<tr><td>Last 12 Months</td><td>8</td></tr>';
  49.         helptext += '<tr><td>Yesterday</td><td>10</td></tr>';
  50.         helptext += '<tr><td>Previous Week</td><td>11</td></tr>';
  51.         helptext += '<tr><td>Previous Month</td><td>12</td></tr>';
  52.         helptext += '<tr><td>Today</td><td>14</td></tr>';
  53.         helptext += '<tr><td>Current Week</td><td>15</td></tr>';
  54.         helptext += '<tr><td>Current Month</td><td>16</td></tr>';
  55.         helptext += '</table>';
  56.         helpdiv.innerHTML = helptext;
  57. }}
  58. </script>
RAW Paste Data
Top