Advertisement
Guest User

Untitled

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