epgd.pages.magazine = { startTime: null, endTime: null, $head: null, $con: null, list: [], viewCnt: 0, scrollStart:0, timeLineL: null, timeLineR: null, qt:{}, imgPath: epgd.profile.eventImgPath ? epgd.profile.eventImgPath + '?no=0&maxW=100&maxH=70&id=' : false, init: function () { //this.initQT(); this.select = epgd.channels.selBox; $(window).bind('channels_load', function () { var self= epgd.pages.magazine, id; if (!self.$head) return; self.$head.empty(); for (id in self.list) self.list[id].index = -1; self._initChannels(); for (id in self.list) if (self.list[id].index == -1) { self.preTime.removeChild(self.list[id].col); delete self.list[id]; }; }); }, initQT: function () { var qt = {}; epgd.profile.quickTimes.replace(/=([0-9]{1,2}):([0-9]{1,2})/g, function (a, h, m) { qt[parseInt(h,10)] = '
'; }); this.qt= qt; }, _initChannels: function () { var ch,i; for (i = 0; i < this.select.length; i++) { ch = this.list[this.select[i].value]; if (!ch) { ch = new epgd.pages.magazine.channel(this.select[i].value, i, $('')[0]); this.list[ch.id] = ch; } else { ch.index = i; } this.preTime.appendChild(ch.col); this.select[i].ch = ch; this.$head.append(' ') } this.$head.css('width',(208 * this.select.length + 55) + 'px'); }, _initWinBindings: function(){ $(window) .bind("epgd_close.pages_magazine", function () { epgd.$dtPicker.hide(); $(window).unbind(".pages_magazine"); clearInterval(this.pages_magazine.timeInterval); delete this.pages_magazine; }) .bind("resize.pages_magazine", function () { var w = $(window).width(), l = $(this).scrollLeft(); this.pages_magazine.$nav.width(w + 'px'); this.pages_magazine.$con.css('height', ($(window).height() - 10 - $('#magazine').offset().top) + 'px'); this.pages_magazine.viewCnt = parseInt((w - 110) / 208, 10); if (this.pages_magazine.viewCnt < 5 ) { this.pages_magazine.timeLineR.style.left = '-50px'; this.pages_magazine.$con.css('width', (208 * this.pages_magazine.select.length + 25) + 'px'); } else if (this.pages_magazine.viewCnt >= this.pages_magazine.select.length) { this.pages_magazine.viewCnt = this.pages_magazine.select.length; this.pages_magazine.timeLineR.style.left = '-50px'; w = this.pages_magazine.viewCnt * 208 + 55; this.pages_magazine.$con.css('width', (w -30) + 'px'); } else { this.pages_magazine.timeLineR.style.left = (l + w - 52) + 'px'; this.pages_magazine.$con.css('width', (208 * this.pages_magazine.select.length + 150) + 'px'); } this.pages_magazine.lineNow.style.width = (w - 10) + 'px'; epgd.$menu.parent().offset({ 'left': l }); this.pages_magazine.$nav.offset({ 'left': l }); this.pages_magazine.update(); }) .bind("scroll.pages_magazine", function () { this.pages_magazine.timeLineL.style.left = '-50px'; this.pages_magazine.timeLineR.style.left = '-50px'; }) .bind("scrollstop.pages_magazine", function () { var l = $(this).scrollLeft(); this.pages_magazine.timeLineL.style.left = this.pages_magazine.lineNow.style.left = l + 'px'; if (this.pages_magazine.viewCnt >= 5 && this.pages_magazine.viewCnt < this.pages_magazine.select.length) this.pages_magazine.timeLineR.style.left = (l + $(window).width() - 52) + 'px'; this.pages_magazine.nextMain = parseInt((l + 104) / 208, 10); if (this.pages_magazine.select.selectedIndex != this.pages_magazine.nextMain) this.pages_magazine.setMain(0, this.pages_magazine.nextMain, true); epgd.$menu.parent().offset({ 'left': l }); this.pages_magazine.$nav.offset({ 'left': l }); return false; }) .bind("datepicker.pages_magazine", function () { this.pages_magazine.setTime(epgd.utils.unixTime(epgd.$dtPicker.datetimepicker('getDate') || epgd.utils.now()), true); })[0].pages_magazine = this; this.$con.bind('scrollstop.pages_magazine', function () { var s = $(this).scrollTop(); if (s > this.pages_magazine.scrollEnd) this.pages_magazine.setTime(s * 30 + epgd.profile.minEventTime); else if (s < this.pages_magazine.scrollStart) this.pages_magazine.setTime(Math.max(this.pages_magazine.startTime - 43200, epgd.profile.minEventTime)); // 60 * 60 *12 }); this._setLineNow(); this.timeInterval = setInterval(this._setLineNow, 60000); }, _setLineNow: function(){ var m = window.pages_magazine, now = new Date().getTime() / 1000; if (now > m.endTime || (m.startTime - epgd.profile.minEventTime) < -3600 ) { $(window).trigger("epgd_close"); $('').click(function () { epgd.profile.minEventTime = epgd.utils.now().getTime() / 1000 - 10800; $(window).trigger("profile_updated", { "minEventTime": true }); epgd.$dtPicker.datetimepicker('setDate', epgd.utils.now()); m.$con.empty(); m.render(); $(this).remove(); }).appendTo(document.body); return; } m.lineNow.style.top = ((now - m.startTime) / 30 + m.scrollStart) + 'px'; m.lineNow.innerHTML= epgd.utils.formatTime(now); }, render: function (channel) { $('#menu_magazine').addClass("menu-active").append(epgd.$dtPicker.show()); var startTime = epgd.utils.unixTime(epgd.utils.now()), d; if (this.startTime && (this.startTime - epgd.profile.minEventTime) < -3600) { this.startTime = null; this.list = []; } if (!this.startTime) { $(window).trigger("epgd_close"); $(this.select).appendTo(epgd.$menu.find('#menu_magazine')).mousedown(function (ev) { ev.stopPropagation(); return true; }).click(function (ev) { return false; }).change(function () { epgd.pages.magazine.render($(this).val()); }); if (this.select.selectedIndex < 0) this.select.selectedIndex = 0; this.$nav= $(' ') this.$head = $(''); this.$con = $(''); this.$con[0].pages_magazine = this; this.preTime = $('').appendTo(this.$con)[0]; this.timeLineL = $('').appendTo(this.preTime)[0]; this.timeLineR = $('').appendTo(this.preTime)[0]; this.lineNow = $('').appendTo(this.preTime)[0]; this._initChannels(); this.startTime = startTime+3600; d = new Date(this.startTime * 1000); if (d.getMinutes() > 0) { d.setMinutes(0); this.startTime = d.getTime() / 1000; } this.endTime = this.startTime; this.setTime(this.startTime-7200); } if (!window.pages_magazine) { this._initWinBindings(); epgd.$con.empty(); this.$nav.appendTo(epgd.$con).bind("click", this.actionHead); this.$head.appendTo(epgd.$con).bind('click', function (ev) { if (ev.target.className == 'i-tv') epgd.vdrs.current.switchChannel(ev.target.parentNode.id); }); this.$con.appendTo(epgd.$con).bind("click", this.actionCon).bind("touchend",this.actionConOpen); if (!$.support.touch && epgd.profile.magazinePan > 0) this._pan(); } $(window).trigger("resize.pages_magazine"); if (channel) this.setChannel(channel); if (startTime < this.startTime || startTime > this.endTime) this.setTime(startTime); this.$con.scrollTop((startTime - epgd.profile.minEventTime) / 30 - 15); $(window).trigger("resize.pages_magazine"); }, _pan: function(){ var pan = false, tp = $('').prependTo(epgd.$con)[0], bot = $('').appendTo(epgd.$con)[0]; this.timeLineL.pan = -1; this.timeLineR.pan = 1; tp.pan = epgd.profile.magazinePan * -30; bot.pan = epgd.profile.magazinePan * 30; window.tp = tp; window.bp = bot; window.p = pan; $([this.timeLineL, this.timeLineR, tp, bot]).mouseover(function (ev) { if (pan) return; pan = this.pan; window.setTimeout(function () { if (pan) { var checkPan = window.setInterval(function () { if (!pan || !window.pages_magazine) return window.clearInterval(checkPan); if (pan < -1 || pan > 1) window.pages_magazine.setTime((window.pages_magazine.$con.scrollTop() + 15) * 30 + epgd.profile.minEventTime + pan, true); else window.pages_magazine.setMain(pan); }, (pan < -1 || pan > 1 ? 100 : 1200)); } }, epgd.profile.magazinePanDelay); }).mouseout(function () { pan = false; }); }, setChannel: function (channel) { this.setMain(0, this.list[channel].index); }, setMain: function (delta, baseIndex, dontScroll) { var optList = this.select, i = isNaN(baseIndex) ? optList.selectedIndex : baseIndex; i += delta; if (i < 0) i = 0;//+= optList.length; else if (i >= optList.length - this.viewCnt) i = optList.length - this.viewCnt;// -= optList.length; optList.selectedIndex = i; this.update(); !dontScroll && $(window).scrollLeft(i * 208); }, setTime: function (start, doScroll) { var t, insHtml = '', h, newEndTime = start + 43200; //86400; //60 * 60 * 24 if (start < this.startTime) { do { this.startTime -= 3600; t = epgd.utils.formatTime(this.startTime); h = parseInt(t, 10); if (h % 4 == 0) //if (t == '00:00') t += $.datepicker.formatDate('