Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 1170067 - [Stingray][EPG] Make program element as a web component
Browse files Browse the repository at this point in the history
  * Make program element as a web component in epg_program
  * Move out related css
  * Add test cases
  • Loading branch information
sean2449 committed Jun 1, 2015
1 parent 7b31544 commit 13a0bde
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 198 deletions.
2 changes: 2 additions & 0 deletions tv_apps/tv-epg/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<!-- stylesheets of building blocks -->
<link rel="stylesheet" type="text/css" href="shared/style/smart-screen/navigation.css">
<link rel="stylesheet" type="text/css" href="shared/style/smart-screen/icons.css">
<link rel="stylesheet" type="text/css" href="style/epg_program.css">
<link rel="stylesheet" type="text/css" href="style/tv_epg.css">

<!-- For test purpose on phone only -->
Expand All @@ -29,6 +30,7 @@
<!-- building blocks -->

<!-- Specific code -->
<script defer src="js/epg_program.js"></script>
<script defer src="js/epg_controller.js"></script>
<script defer src="js/epg.js"></script>
<script defer src="js/index.js"></script>
Expand Down
92 changes: 28 additions & 64 deletions tv_apps/tv-epg/js/epg.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
};

proto._onScanned = function epg__onScanned(stream) {
this.videoElement.src = stream;
this.videoElement.mozSrcObject = stream;
this.epgController.fetchPrograms(
this.visibleTimeOffset - this.visibleTimeSize,
3 * this.visibleTimeSize
Expand Down Expand Up @@ -137,25 +137,16 @@
*/
proto._addProgramSlot = function epg__addProgramSlot(index, time) {
var rowElement;
var columnElement;
var textElement;
var progressElement;
var programElement;
var i;
for (i = 0; i < this.programListElement.children.length; i++) {
rowElement = this.programListElement.children[i];
columnElement = document.createElement('LI');
columnElement.dataset.duration = '1';
columnElement.dataset.startTime = time;
progressElement = document.createElement('DIV');
progressElement.classList.add('background-progress');
textElement = document.createElement('DIV');
textElement.classList.add('title');
columnElement.appendChild(progressElement);
columnElement.appendChild(textElement);
programElement = document.createElement('epg-program');
programElement.setStartTime(time);
if (index < this.timelineElement.children.length) {
rowElement.insertBefore(columnElement, rowElement.children[index]);
rowElement.insertBefore(programElement, rowElement.children[index]);
} else {
rowElement.appendChild(columnElement);
rowElement.appendChild(programElement);
}
}
};
Expand All @@ -181,43 +172,35 @@

proto._updateProgramSlot = function epg__updateProgramSlot(configs) {
var rowElement = this.programListElement.children[configs.row];
var columnElement = rowElement.children[configs.column];
var duration = parseInt(columnElement.dataset.duration, 10);
var progressElement;
var currentColumn;
var programElement = rowElement.children[configs.column];
var duration = programElement.duration;

if (configs.title) {
columnElement.querySelector('.title').textContent = configs.title;
programElement.setTitle(configs.title);
}

if (configs.duration) {
duration = configs.duration;
columnElement.dataset.duration = duration;
programElement.setDuration(duration);
}

if (configs.isVisible) {
columnElement.classList.remove('hidden');
this.spatialNavigator.add(columnElement);
currentColumn = this.initialTime - this.epgController.timelineOffset;
progressElement = columnElement.querySelector('.background-progress');
if (configs.column + duration <= currentColumn) {
progressElement.style.transform = 'scaleX(1)';
} else {
progressElement.classList.add('smooth');
}
programElement.show();
this.spatialNavigator.add(programElement);
programElement.resetProgressElement(this.initialTime);
} else {
columnElement.classList.add('hidden');
programElement.hide();
// If the old focus element only contains partial program segment, we have
// to refocus to the first visible element of the same program.
if (columnElement === this.spatialNavigator.getFocusedElement()) {
if (programElement === this.spatialNavigator.getFocusedElement()) {
this.spatialNavigator.focus(
this.epgController.programTable[configs.column][configs.row].element);
}
this.spatialNavigator.remove(columnElement);
this.spatialNavigator.remove(programElement);
}

if (configs.item) {
configs.item.element = columnElement;
configs.item.element = programElement;
}
};

Expand All @@ -236,23 +219,11 @@
var prevPrograms = this.epgController.programTable[timeIndex - 1];
var row;
var programElement;
var startTime;
var duration;
var scaleX;

// Update progress bar in every currently playing program
for (row in playingPrograms) {
programElement = playingPrograms[row].element;
startTime = parseInt(programElement.dataset.startTime, 10);
duration = parseInt(programElement.dataset.duration, 10);

// There is a margin between two programs, so scale has to be normalized
scaleX = (time / this.timelineUnit - startTime) * EPG.COLUMN_WIDTH;
scaleX = scaleX / (duration * EPG.COLUMN_WIDTH - EPG.COLUMN_MARGIN);
scaleX = Math.min(scaleX, 1);
programElement.querySelector('.background-progress').style.transform =
'scaleX(' + scaleX + ')';

programElement.setProgress(time / this.timelineUnit);
this.timeMarkerElement.style.transform =
'translateX(' +
((time / this.timelineUnit - this.initialTime) * EPG.COLUMN_WIDTH) +
Expand All @@ -263,8 +234,7 @@
if (prevPrograms && prevPrograms[row] &&
programElement !== prevPrograms[row].element) {
programElement = prevPrograms[row].element;
programElement.querySelector('.background-progress').style.transform =
'scaleX(1)';
programElement.fillProgress();
}
}
};
Expand All @@ -287,15 +257,14 @@
};
};

proto._onFocus = function epg__onFocus(element) {
var rowElement = element.parentElement;
proto._onFocus = function epg__onFocus(programElement) {
var rowElement = programElement.parentElement;
var rowIndex = parseInt(rowElement.dataset.row, 10);
var rowOffset = this.epgController.channelOffset;

var startTime = parseInt(element.dataset.startTime, 10);
var startTime = programElement.startTime;
var timelineOffset = this.epgController.timelineOffset;

element.classList.add('focus');
programElement.classList.add('focus');
rowElement.classList.remove('hidden');
this._setTitlePadding({
setToNull: true
Expand Down Expand Up @@ -373,20 +342,15 @@
var row;
var timeOffset = this.visibleTimeOffset - this.epgController.timelineOffset;
var programElement;
var programTitleElement;
var programStartTime;
for(row = rowOffset; row < rowOffset + size; row++) {
if (this.epgController.programTable[timeOffset][row]) {
programElement =
this.epgController.programTable[timeOffset][row].element;
programTitleElement = programElement.querySelector('.title');
if (opts && opts.setToNull) {
programTitleElement.style.paddingLeft = null;
programElement.setTitlePadding(null);
} else {
programStartTime = parseInt(programElement.dataset.startTime, 10);
programTitleElement.style.paddingLeft =
EPG.COLUMN_WIDTH * (this.visibleTimeOffset - programStartTime) +
'rem';
programElement.setTitlePadding(EPG.COLUMN_WIDTH *
(this.visibleTimeOffset - programElement.startTime) + 'rem');
}
}
}
Expand Down Expand Up @@ -415,8 +379,8 @@
this.dateElement.textContent = dtf.localeFormat(now, timeFormat);
};

proto._onUnfocus = function epg__onUnfocus(element) {
element.classList.remove('focus');
proto._onUnfocus = function epg__onUnfocus(programElement) {
programElement.classList.remove('focus');
};

proto._onMove = function epg__onMove(key) {
Expand Down
74 changes: 74 additions & 0 deletions tv_apps/tv-epg/js/epg_program.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* global EPG */

'use strict';

window.EPGProgram = (function(exports) {
var proto = Object.create(HTMLElement.prototype);

proto.createdCallback = function() {
this.duration = 1;
this.dataset.duration = '1';
this.titleElement = document.createElement('DIV');
this.titleElement.classList.add('title');
this.appendChild(this.titleElement);

this.progressElement = document.createElement('DIV');
this.progressElement.classList.add('background-progress');
this.appendChild(this.progressElement);
};

proto.resetProgressElement = function(time) {
if (!this.startTime || !time) {
return;
}

if (this.startTime + this.duration <= time) {
this.fillProgress();
} else {
this.progressElement.classList.add('smooth');
}
this.appendChild(this.progressElement);
};

proto.setProgress = function(time) {
if (!this.startTime || !time) {
return;
}

var scaleX = (time - this.startTime) * EPG.COLUMN_WIDTH;
scaleX = scaleX / (this.duration * EPG.COLUMN_WIDTH - EPG.COLUMN_MARGIN);
scaleX = Math.min(scaleX, 1);
this.progressElement.style.transform = 'scaleX(' + scaleX + ')';
};

proto.fillProgress = function() {
this.progressElement.style.transform = 'scaleX(1)';
};

proto.setStartTime = function(time) {
this.startTime = time;
};

proto.setTitle = function(title) {
this.titleElement.textContent = title;
};

proto.setTitlePadding = function(padding) {
this.titleElement.style.paddingLeft = padding;
};

proto.setDuration = function(duration) {
this.duration = duration;
this.dataset.duration = duration;
};

proto.hide = function() {
this.classList.add('hidden');
};

proto.show = function() {
this.classList.remove('hidden');
};

return document.registerElement('epg-program', { prototype: proto });
})(window);
85 changes: 85 additions & 0 deletions tv_apps/tv-epg/style/epg_program.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
epg-program {
display: inline-block;
position: relative;
width: 33.5rem;
font-size: 2.5rem;
line-height: 10.8rem;
overflow: hidden;
padding-bottom: 0.3rem;
padding-right: 0.3rem;
border-bottom: 0.1rem #5e5e5e solid;
margin-top: 0.3rem;
background-color: #404040;
height: 11.2rem;
background-clip: content-box;
box-sizing: border-box;
outline: none;
}

epg-program:after {
content: '';
position: absolute;
top: 0;
right: 0;
width: 0.1rem;
background-color: #5e5e5e;
height: 10.8rem;
}

epg-program.focus {
background-color: #00caf2;
}

epg-program.hidden {
display: none;
}

epg-program[data-duration="1"] {
width: 33.8rem;
}

epg-program[data-duration="2"] {
width: 67.6rem;
}

epg-program[data-duration="3"] {
width: 101.4rem;
}

epg-program[data-duration="4"] {
width: 135.2rem;
}

epg-program[data-duration="5"] {
width: 169rem;
}

epg-program[data-duration="6"] {
width: 202.8rem;
}

epg-program[data-duration="7"] {
width: 236.9rem;
}

epg-program > .title {
margin-left: 2rem;
overflow: hidden;
text-overflow: ellipsis;
width: calc(100% - 2rem);
box-sizing: border-box;
position: absolute;
}

epg-program > .background-progress {
position: absolute;
background-color: rgba(0, 0, 0, 0.2);
height: calc(100% - 0.3rem);
transform: scaleX(0);
transform-origin: 0;
width: calc(100% - 0.3rem);
}

epg-program > .background-progress.smooth {
transition: transform 0.3s;
}
Loading

0 comments on commit 13a0bde

Please sign in to comment.