Advertisement
Guest User

ANOther1

a guest
Jun 22nd, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.43 KB | None | 0 0
  1. //Cut and pasted for test purposes.
  2. <div class="page-header-info" id="header-generic">
  3. <h2>Schedule</h2>
  4. </div>
  5. <!-- ============================================= Main ============================================= -->
  6. <div class="content-inner">
  7.  
  8. <!-- This comment must not be removed - it makes IE7 behave correctly. No-one knows why. -->
  9.  
  10.  
  11. <div class="page-area clearfix">
  12. <div class="main-col main-col-large">
  13. <table class="schedule-table">
  14. <!-- column headers -->
  15. <thead>
  16. <tr>
  17. <th class="hide">Units</th>
  18. <th>Hours</th>
  19.  
  20. <th>Monday</th>
  21. <th>Tuesday</th>
  22. <th>Wednesday</th>
  23. <th>Thursday</th>
  24. <th>Friday</th>
  25. <th>Saturday</th>
  26.  
  27. <th>Sunday</th>
  28. </tr>
  29. </thead>
  30. <tbody>
  31.  
  32. <tr id="units-0">
  33. <td class="hide">0</td>
  34. <!-- Every other row echo an hour block -->
  35. <td class="time" rowspan="2">00:00</td>
  36.  
  37. <!-- start polling days -->
  38.  
  39. <!-- finish echo a row for each of the 48 units -->
  40. </tr>
  41. <tr id="units-1">
  42. <td class="hide">1</td>
  43. <!-- Every other row echo an hour block -->
  44. </tr>
  45.  
  46. <!-- echo a row for each of the 48 units -->
  47.  
  48. <tr id="units-2">
  49. <td class="hide">2</td>
  50. <!-- Every other row echo an hour block -->
  51. <td class="time" rowspan="2">01:00</td>
  52. <!-- start polling days -->
  53.  
  54. <!-- finish echo a row for each of the 48 units -->
  55. </tr>
  56.  
  57. <tr id="units-3">
  58.  
  59. <td class="hide">3</td>
  60. <!-- start polling days -->
  61. <!-- finish echo a row for each of the 48 units -->
  62. </tr>
  63.  
  64. <tr id="units-4">
  65. <td class="hide">4</td>
  66. <!-- Every other row echo an hour block -->
  67. <td class="time" rowspan="2">02:00</td>
  68.  
  69. </tr>
  70.  
  71. <tr id="units-5">
  72. <td class="hide">5</td>
  73. <!-- start polling days -->
  74.  
  75. <!-- finish echo a row for each of the 48 units -->
  76. </tr>
  77.  
  78. <tr id="units-6">
  79. <td class="hide">6</td>
  80.  
  81. <!-- Every other row echo an hour block -->
  82. <td class="time" rowspan="2">03:00</td>
  83. <!-- start polling days -->
  84. <!-- finish echo a row for each of the 48 units -->
  85. </tr>
  86.  
  87. <tr id="units-7">
  88. <td class="hide">7</td>
  89. <!-- start polling days -->
  90.  
  91. <!-- finish echo a row for each of the 48 units -->
  92. </tr>
  93.  
  94. <tr id="units-8">
  95. <td class="hide">8</td>
  96. <!-- Every other row echo an hour block -->
  97. <td class="time" rowspan="2">04:00</td>
  98. <!-- start polling days -->
  99. <!-- finish echo a row for each of the 48 units -->
  100.  
  101. </tr>
  102.  
  103. <tr id="units-9">
  104. <td class="hide">9</td>
  105. <!-- start polling days -->
  106. <!-- finish echo a row for each of the 48 units -->
  107. </tr>
  108.  
  109. <tr id="units-10">
  110. <td class="hide">10</td>
  111.  
  112. <!-- Every other row echo an hour block -->
  113. <td class="time" rowspan="2">05:00</td>
  114. <!-- start polling days -->
  115. <!-- finish echo a row for each of the 48 units -->
  116. </tr>
  117.  
  118. <tr id="units-11">
  119. <td class="hide">11</td>
  120. <!-- start polling days -->
  121.  
  122. <!-- finish echo a row for each of the 48 units -->
  123. </tr>
  124.  
  125. <tr id="units-12">
  126. <td class="hide">12</td>
  127. <!-- Every other row echo an hour block -->
  128. <td class="time" rowspan="2">06:00</td>
  129. <!-- start polling days -->
  130. <!-- finish echo a row for each of the 48 units -->
  131.  
  132. </tr>
  133.  
  134. <tr id="units-13">
  135. <td class="hide">13</td>
  136. <!-- start polling days -->
  137. <!-- finish echo a row for each of the 48 units -->
  138. </tr>
  139.  
  140. <tr id="units-14">
  141. <td class="hide">14</td>
  142.  
  143. <!-- Every other row echo an hour block -->
  144. <td class="time" rowspan="2">07:00</td>
  145. <!-- start polling days -->
  146. <!-- finish echo a row for each of the 48 units -->
  147. </tr>
  148.  
  149. <tr id="units-15">
  150. <td class="hide">15</td>
  151. <!-- start polling days -->
  152.  
  153. <!-- finish echo a row for each of the 48 units -->
  154. </tr>
  155.  
  156. <tr id="units-16">
  157. <td class="hide">16</td>
  158. <!-- Every other row echo an hour block -->
  159. <td class="time" rowspan="2">08:00</td>
  160. <!-- start polling days -->
  161. <!-- finish echo a row for each of the 48 units -->
  162.  
  163. </tr>
  164.  
  165. <tr id="units-17">
  166. <td class="hide">17</td>
  167. <!-- start polling days -->
  168. <!-- finish echo a row for each of the 48 units -->
  169. </tr>
  170.  
  171. <tr id="units-18">
  172. <td class="hide">18</td>
  173.  
  174. <!-- Every other row echo an hour block -->
  175. <td class="time" rowspan="2">09:00</td>
  176. <!-- start polling days -->
  177. <!-- finish echo a row for each of the 48 units -->
  178. </tr>
  179.  
  180. <tr id="units-19">
  181. <td class="hide">19</td>
  182. <!-- start polling days -->
  183.  
  184. <!-- finish echo a row for each of the 48 units -->
  185. </tr>
  186.  
  187. <tr id="units-20">
  188. <td class="hide">20</td>
  189. <!-- Every other row echo an hour block -->
  190. <td class="time" rowspan="2">10:00</td>
  191. <!-- start polling days -->
  192. <!-- finish echo a row for each of the 48 units -->
  193.  
  194. </tr>
  195.  
  196. <tr id="units-21">
  197. <td class="hide">21</td>
  198. <!-- start polling days -->
  199. <!-- finish echo a row for each of the 48 units -->
  200. </tr>
  201.  
  202. <tr id="units-22">
  203. <td class="hide">22</td>
  204.  
  205. <!-- Every other row echo an hour block -->
  206. <td class="time" rowspan="2">11:00</td>
  207. <!-- start polling days -->
  208. <!-- finish echo a row for each of the 48 units -->
  209. </tr>
  210.  
  211. <tr id="units-23">
  212. <td class="hide">23</td>
  213. <!-- start polling days -->
  214.  
  215. <!-- finish echo a row for each of the 48 units -->
  216. </tr>
  217.  
  218. <tr id="units-24">
  219. <td class="hide">24</td>
  220. <!-- Every other row echo an hour block -->
  221. <td class="time" rowspan="2">12:00</td>
  222. <!-- start polling days -->
  223. <!-- finish echo a row for each of the 48 units -->
  224.  
  225. </tr>
  226.  
  227. <tr id="units-25">
  228. <td class="hide">25</td>
  229. <!-- start polling days -->
  230. <!-- finish echo a row for each of the 48 units -->
  231. </tr>
  232.  
  233. <tr id="units-26">
  234. <td class="hide">26</td>
  235.  
  236. <!-- Every other row echo an hour block -->
  237. <td class="time" rowspan="2">13:00</td>
  238. <!-- start polling days -->
  239. <!-- finish echo a row for each of the 48 units -->
  240. </tr>
  241.  
  242. <tr id="units-27">
  243. <td class="hide">27</td>
  244. <!-- start polling days -->
  245.  
  246. <!-- finish echo a row for each of the 48 units -->
  247. </tr>
  248.  
  249. <tr id="units-28">
  250. <td class="hide">28</td>
  251. <!-- Every other row echo an hour block -->
  252. <td class="time" rowspan="2">14:00</td>
  253. <!-- start polling days -->
  254. <!-- finish echo a row for each of the 48 units -->
  255.  
  256. </tr>
  257.  
  258. <tr id="units-29">
  259. <td class="hide">29</td>
  260. <!-- start polling days -->
  261. <!-- finish echo a row for each of the 48 units -->
  262. </tr>
  263.  
  264. <tr id="units-30">
  265. <td class="hide">30</td>
  266.  
  267. <!-- Every other row echo an hour block -->
  268. <td class="time" rowspan="2">15:00</td>
  269. <!-- start polling days -->
  270. <!-- finish echo a row for each of the 48 units -->
  271. </tr>
  272.  
  273. <tr id="units-31">
  274. <td class="hide">31</td>
  275. <!-- start polling days -->
  276.  
  277. <!-- finish echo a row for each of the 48 units -->
  278. </tr>
  279.  
  280. <tr id="units-32">
  281. <td class="hide">32</td>
  282. <!-- Every other row echo an hour block -->
  283. <td class="time" rowspan="2">16:00</td>
  284. <!-- start polling days -->
  285. <!-- finish echo a row for each of the 48 units -->
  286.  
  287. </tr>
  288.  
  289. <tr id="units-33">
  290. <td class="hide">33</td>
  291. <!-- start polling days -->
  292. <!-- finish echo a row for each of the 48 units -->
  293. </tr>
  294.  
  295. <tr id="units-34">
  296. <td class="hide">34</td>
  297.  
  298. <!-- Every other row echo an hour block -->
  299. <td class="time" rowspan="2">17:00</td>
  300. <!-- start polling days -->
  301. <!-- finish echo a row for each of the 48 units -->
  302. </tr>
  303.  
  304. <tr id="units-35">
  305. <td class="hide">35</td>
  306. <!-- start polling days -->
  307.  
  308. <!-- finish echo a row for each of the 48 units -->
  309. </tr>
  310.  
  311. <tr id="units-36">
  312. <td class="hide">36</td>
  313. <!-- Every other row echo an hour block -->
  314. <td class="time" rowspan="2">18:00</td>
  315. <!-- start polling days -->
  316. <!-- finish echo a row for each of the 48 units -->
  317.  
  318. </tr>
  319.  
  320. <tr id="units-37">
  321. <td class="hide">37</td>
  322. <!-- start polling days -->
  323. <!-- finish echo a row for each of the 48 units -->
  324. </tr>
  325.  
  326. <tr id="units-38">
  327. <td class="hide">38</td>
  328.  
  329. <!-- Every other row echo an hour block -->
  330. <td class="time" rowspan="2">19:00</td>
  331. <!-- start polling days -->
  332. <!-- finish echo a row for each of the 48 units -->
  333. </tr>
  334.  
  335. <tr id="units-39">
  336. <td class="hide">39</td>
  337. <!-- start polling days -->
  338.  
  339. <!-- finish echo a row for each of the 48 units -->
  340. </tr>
  341.  
  342. <tr id="units-40">
  343. <td class="hide">40</td>
  344. <!-- Every other row echo an hour block -->
  345. <td class="time" rowspan="2">20:00</td>
  346. <!-- start polling days -->
  347. <!-- finish echo a row for each of the 48 units -->
  348.  
  349. </tr>
  350.  
  351. <tr id="units-41">
  352. <td class="hide">41</td>
  353. <!-- start polling days -->
  354. <!-- finish echo a row for each of the 48 units -->
  355. </tr>
  356.  
  357. <tr id="units-42">
  358. <td class="hide">42</td>
  359.  
  360. <!-- Every other row echo an hour block -->
  361. <td class="time" rowspan="2">21:00</td>
  362. <!-- start polling days -->
  363. <!-- finish echo a row for each of the 48 units -->
  364. </tr>
  365.  
  366. <tr id="units-43">
  367. <td class="hide">43</td>
  368. <!-- start polling days -->
  369.  
  370. <!-- finish echo a row for each of the 48 units -->
  371. </tr>
  372.  
  373. <tr id="units-44">
  374. <td class="hide">44</td>
  375. <!-- Every other row echo an hour block -->
  376. <td class="time" rowspan="2">22:00</td>
  377. <!-- start polling days -->
  378. <!-- finish echo a row for each of the 48 units -->
  379.  
  380. </tr>
  381.  
  382. <tr id="units-45">
  383. <td class="hide">45</td>
  384. <!-- start polling days -->
  385. <!-- finish echo a row for each of the 48 units -->
  386. </tr>
  387.  
  388. <tr id="units-46">
  389. <td class="hide">46</td>
  390.  
  391. <!-- Every other row echo an hour block -->
  392. <td class="time" rowspan="2">23:00</td>
  393. <!-- start polling days -->
  394. <!-- finish echo a row for each of the 48 units -->
  395. </tr>
  396.  
  397. <tr id="units-47">
  398. <td class="hide">47</td>
  399. <!-- start polling days -->
  400.  
  401. <!-- finish echo a row for each of the 48 units -->
  402. </tr>
  403.  
  404. <tr id="units-48">
  405. <td class="hide">48</td>
  406. <!-- start polling days -->
  407. <!-- finish echo a row for each of the 48 units -->
  408. </tr>
  409.  
  410.  
  411. </tbody>
  412. </table>
  413.  
  414. <script type="text/javascript">
  415.  
  416. var doFades = true;
  417.  
  418. var BauerStations = {
  419. Schedule : {}
  420. };
  421.  
  422. $(document).ready(function(){
  423.  
  424. BauerStations.Schedule.days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
  425.  
  426. BauerStations.Schedule.Show = function () {
  427. _s = null;
  428. _startDate = null;
  429. _endDate = null;
  430. this.days = BauerStations.Schedule.days;
  431. _selector = '';
  432.  
  433. this.setShow = function(s) {
  434. this._s = s;
  435.  
  436. this._startDate = new Date( parseInt(s.startminutes, 10) * 1000);
  437. this._endDate = new Date(parseInt(s.endminutes, 10) * 1000 );
  438.  
  439. };
  440.  
  441. this.getEndDate = function(){
  442. return this._endDate;
  443. }
  444.  
  445. this.getStartDate = function(){
  446. return this._startDate;
  447. }
  448.  
  449. this._getShowDay = function (){
  450. return this.days[this.getStartDate().getDay()];
  451. };
  452.  
  453. this._getShowUnitsTaken = function(){
  454. // if it's the same day
  455. return this._getEndUnits() - this._getStartUnits();
  456. };
  457.  
  458. this._getEndUnits = function(){
  459. if(this.getEndDate().getHours() == 0)
  460. {
  461. //console.log(this._s.longname +' ends at midnight');
  462. return 48;
  463. }
  464.  
  465. return this.getEndDate().getMinutes() !== 0 ? (this.getEndDate().getHours() * 2) : (this.getEndDate().getHours() * 2);
  466. };
  467.  
  468. this._getStartUnits = function(){
  469. if(this.getStartDate().getHours() == 0)
  470. {
  471. return 0;
  472. }
  473.  
  474. return this.getStartDate().getMinutes() !== 0 ? (this.getStartDate().getHours() * 2) : (this.getStartDate().getHours() * 2);
  475. };
  476.  
  477. this.getCellPositions = function() {
  478. return {
  479. 'start' : this.getStartDate(),
  480. 'end' : this.getEndDate(),
  481. 'colIndex' : this.getStartDate().getDay() + 2,
  482. 'startUnits' : this._getStartUnits(),
  483. 'endUnits' : this._getEndUnits(),
  484. 'unitsTaken' : this._getShowUnitsTaken()
  485. }
  486. };
  487.  
  488. this.pad = function(number){
  489. return number < 10 ? '0'+number : number;
  490. };
  491.  
  492. // return the table cell html.
  493. this.toHtml = function () {
  494.  
  495. var d = new Date();
  496. var units = this._getStartUnits();
  497.  
  498. var rowspan = this._getShowUnitsTaken();
  499. var desc = this._s.description;
  500. var name = this._s.longname;
  501.  
  502. var starttime = this.pad(this.getStartDate().getHours()) + ':' + this.pad(this.getStartDate().getMinutes());
  503. var endtime = this.pad(this.getEndDate().getHours()) + ':' + this.pad(this.getEndDate().getMinutes());
  504.  
  505. var site = this._s.websitelink;
  506.  
  507. var cls = this.isActive() ? 'current-program' : '';
  508.  
  509. var isToday = this.getStartDate().getDay() === d.getDay() ? 'active-program' : '';
  510.  
  511. var html = '<td class="schedule-show ' + isToday + ' ' + cls + '" rowspan="' + rowspan + '" data-start="' + this.getStartDate() + '" data-end="' + this.getEndDate() + '">';
  512. html += '<div>';
  513. html += '<a href="' + site + '" title="' + desc + '">' + name + '</a>';
  514. html += '</div>';
  515. if(doFades)
  516. {
  517. html += '<div class="schedule_details clearfix" style="display:none;">';
  518. html += '<img width="105px" height="105px" alt="' + desc + '" src="' + this._s.showimage + '">';
  519. html += '<strong>' + name + '</strong>';
  520. html += '<p>' + desc + '</p>';
  521. html += '<span>' + starttime + ' - ' + endtime +'</span>';
  522. html += '</div>';
  523. }
  524. html += '</td>';
  525.  
  526. return html;
  527. };
  528.  
  529. this.setTableSelector = function(sel){
  530. this._selector = sel;
  531. };
  532.  
  533. // check if we should add the active class.
  534. this.isActive = function(){
  535. var t = new Date();
  536.  
  537. return t >= this.getStartDate() && t <= this.getEndDate();
  538. };
  539. };
  540.  
  541. BauerStations.Schedule.ScheduleGen = function(){
  542.  
  543. return {
  544. insertShow : function(show) {
  545. var p = show.getCellPositions();
  546.  
  547. $('tr#units-' + p.startUnits).append(show.toHtml());
  548. },
  549.  
  550. init : function (stationName){
  551. var self = this;
  552.  
  553. // load the schedule.
  554. $.getJSON('http://radioplayer.bauerradio.com/schedule.php?callback=?', {
  555. name: 'Radio Borders'
  556. }, function(json){
  557. // loop each show and append to our giant table.
  558. // this is well sick.
  559.  
  560. if(json.success === false)
  561. {
  562. $('.content-inner table').remove();
  563.  
  564. $('<div>errors</div>').appendTo('.content-inner');
  565. }
  566. else
  567. {
  568. var currentDay = '';
  569. var day = 0;
  570. // highlight the current time..
  571. var d = new Date();
  572. var weekStart = new Date();
  573.  
  574. weekStart.setDate(d.getDate()-6-(d.getDay()||7));
  575.  
  576. $.each(json.data.schedule, function(i, broadcast){
  577.  
  578.  
  579. var dStart = new Date( parseInt(broadcast.startminutes, 10) * 1000);
  580. var dEnd = new Date(parseInt(broadcast.endminutes, 10) * 1000 );
  581.  
  582.  
  583. /*// transform to a show object defined above, if the show spans 2 days we create two show objects.
  584. // IF THE SHOW STARTS/ENDS AT MIDNIGHT, DON'T SPLIT IT.
  585. if(dStart.getHours() !== 0 && dEnd.getHours() !== 0 && dStart.getDate() != dEnd.getDate())
  586. {
  587. var showOne = new BauerStations.Schedule.Show();
  588. showOne.setShow(broadcast);
  589.  
  590. // set to midnight
  591. showOne.getEndDate().setHours(0);
  592. showOne.getEndDate().setMinutes(dStart.getMinutes());
  593.  
  594.  
  595. // append first half of show.
  596. self.insertShow(showOne);
  597.  
  598. // handle second half.
  599. var showTwo = new BauerStations.Schedule.Show();
  600. showTwo.setShow(broadcast);
  601.  
  602. showTwo.getStartDate().setDate(showTwo.getStartDate().getDate() + 1);
  603. showTwo.getStartDate().setHours(0);
  604. showTwo.getStartDate().setMinutes(dEnd.getMinutes());
  605.  
  606. //console.log('2nd Half Start: ' + showTwo.getStartDate());
  607. //console.log('2nd Half End: ' + showTwo.getEndDate());
  608.  
  609. self.insertShow(showTwo);
  610.  
  611.  
  612. }
  613. else
  614. {*/
  615. var show = new BauerStations.Schedule.Show();
  616.  
  617. show.setShow(broadcast);
  618. show.setTableSelector('table#schedule');
  619.  
  620. // add the show to the table. Thankfully the order these come out the API means they get added
  621. // in the right place. So don't change the schedule builder code!
  622.  
  623. self.insertShow(show);
  624. //}
  625.  
  626.  
  627. });
  628.  
  629. var days = BauerStations.Schedule.days;
  630.  
  631. // apply the current day / time classes
  632. $('th:contains('+ days[d.getDay()]+')').addClass('active');
  633.  
  634. $('td.time').each(function(i, cell){
  635. // get the value, convert to int.
  636. var hours = $(cell).html().split(':')[0];
  637.  
  638. // compare the hours with now, add class if matched.
  639. if(parseInt(hours, 10) === d.getHours())
  640. {
  641. $(cell).addClass('current_time');
  642. }
  643. });
  644. }
  645.  
  646.  
  647. if(doFades)
  648. {
  649. // apply events to show info fade in / out.
  650. $('td.schedule-show').hover(function(){
  651. $(this).find('.schedule_details').fadeIn('fast');
  652. }, function(){
  653. $(this).find('.schedule_details').fadeOut('fast');
  654. });
  655. }
  656. });
  657.  
  658.  
  659. }
  660. };
  661. }();
  662.  
  663.  
  664. BauerStations.Schedule.ScheduleGen.init();
  665.  
  666. });
  667. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement