jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/cardbuilder/cardbuilder.js

1463 lines
54 KiB
JavaScript
Raw Normal View History

2016-08-11 20:23:12 -07:00
define(['datetime', 'imageLoader', 'connectionManager', 'itemHelper', 'mediaInfo', 'focusManager', 'indicators', 'globalize', 'layoutManager', 'apphost', 'dom', 'emby-button', 'css!./card', 'paper-icon-button-light', 'clearButtonStyle'],
function (datetime, imageLoader, connectionManager, itemHelper, mediaInfo, focusManager, indicators, globalize, layoutManager, appHost, dom) {
2016-07-29 12:51:58 -07:00
// Regular Expressions for parsing tags and attributes
var SURROGATE_PAIR_REGEXP = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
// Match everything outside of normal chars and " (quote character)
NON_ALPHANUMERIC_REGEXP = /([^\#-~| |!])/g;
/**
* Escapes all potentially dangerous characters, so that the
* resulting string can be safely inserted into attribute or
* element text.
* @param value
* @returns {string} escaped text
*/
function htmlEncode(value) {
return value.
replace(/&/g, '&').
replace(SURROGATE_PAIR_REGEXP, function (value) {
var hi = value.charCodeAt(0);
var low = value.charCodeAt(1);
return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';';
}).
replace(NON_ALPHANUMERIC_REGEXP, function (value) {
return '&#' + value.charCodeAt(0) + ';';
}).
replace(/</g, '&lt;').
replace(/>/g, '&gt;');
}
2016-07-28 19:42:42 -07:00
2016-07-29 08:54:43 -07:00
function getCardsHtml(items, options) {
2016-07-28 19:42:42 -07:00
2016-07-29 08:54:43 -07:00
var apiClient = connectionManager.currentApiClient();
2016-07-28 19:42:42 -07:00
2016-07-29 12:51:58 -07:00
if (arguments.length == 1) {
options = arguments[0];
items = options.items;
}
2016-07-29 08:54:43 -07:00
var html = buildCardsHtmlInternal(items, apiClient, options);
2016-07-28 19:42:42 -07:00
2016-07-29 08:54:43 -07:00
return html;
}
2016-07-28 19:42:42 -07:00
2016-07-29 08:54:43 -07:00
function getPostersPerRow(shape, screenWidth) {
switch (shape) {
case 'portrait':
if (screenWidth >= 2200) return 10;
if (screenWidth >= 2100) return 9;
if (screenWidth >= 1600) return 8;
if (screenWidth >= 1400) return 7;
if (screenWidth >= 1200) return 6;
if (screenWidth >= 800) return 5;
if (screenWidth >= 640) return 4;
return 3;
case 'square':
if (screenWidth >= 2100) return 9;
if (screenWidth >= 1800) return 8;
if (screenWidth >= 1400) return 7;
if (screenWidth >= 1200) return 6;
if (screenWidth >= 900) return 5;
if (screenWidth >= 700) return 4;
if (screenWidth >= 500) return 3;
return 2;
case 'banner':
if (screenWidth >= 2200) return 4;
if (screenWidth >= 1200) return 3;
if (screenWidth >= 800) return 2;
return 1;
case 'backdrop':
if (screenWidth >= 2500) return 6;
if (screenWidth >= 2100) return 5;
if (screenWidth >= 1200) return 4;
if (screenWidth >= 770) return 3;
if (screenWidth >= 420) return 2;
return 1;
case 'smallBackdrop':
if (screenWidth >= 1440) return 8;
if (screenWidth >= 1100) return 6;
if (screenWidth >= 800) return 5;
if (screenWidth >= 600) return 4;
if (screenWidth >= 540) return 3;
if (screenWidth >= 420) return 2;
return 1;
case 'overflowPortrait':
if (screenWidth >= 1000) return 100 / 23;
if (screenWidth >= 640) return 100 / 36;
return 2.5;
case 'overflowSquare':
if (screenWidth >= 1000) return 100 / 22;
if (screenWidth >= 640) return 100 / 30;
return 100 / 42;
case 'overflowBackdrop':
if (screenWidth >= 1000) return 100 / 40;
if (screenWidth >= 640) return 100 / 60;
return 100 / 84;
default:
return 4;
2016-07-28 19:42:42 -07:00
}
}
2016-08-06 07:07:44 -07:00
function isResizable(windowWidth) {
var screen = window.screen;
if (screen) {
var screenWidth = screen.availWidth;
if ((screenWidth - windowWidth) > 20) {
return true;
}
}
return false;
}
2016-07-29 08:54:43 -07:00
function getImageWidth(shape) {
2016-07-28 19:42:42 -07:00
2016-08-11 20:23:12 -07:00
var screenWidth = dom.getWindowSize().innerWidth;
2016-08-02 18:32:16 -07:00
2016-08-06 07:07:44 -07:00
if (isResizable(screenWidth)) {
2016-08-02 18:32:16 -07:00
var roundScreenTo = 100;
screenWidth = Math.ceil(screenWidth / roundScreenTo) * roundScreenTo;
}
2016-08-06 07:07:44 -07:00
if (window.screen) {
screenWidth = Math.min(screenWidth, screen.availWidth || screenWidth);
}
2016-07-29 08:54:43 -07:00
var imagesPerRow = getPostersPerRow(shape, screenWidth);
2016-07-28 19:42:42 -07:00
2016-07-29 08:54:43 -07:00
var shapeWidth = screenWidth / imagesPerRow;
return Math.round(shapeWidth);
2016-07-28 19:42:42 -07:00
}
2016-07-29 08:54:43 -07:00
function setCardData(items, options) {
2016-07-28 19:42:42 -07:00
2016-07-29 08:54:43 -07:00
options.shape = options.shape || "auto";
2016-07-28 19:42:42 -07:00
2016-07-29 08:54:43 -07:00
var primaryImageAspectRatio = imageLoader.getPrimaryImageAspectRatio(items);
var isThumbAspectRatio = primaryImageAspectRatio && Math.abs(primaryImageAspectRatio - 1.777777778) < .3;
var isSquareAspectRatio = primaryImageAspectRatio && Math.abs(primaryImageAspectRatio - 1) < .33 ||
primaryImageAspectRatio && Math.abs(primaryImageAspectRatio - 1.3333334) < .01;
if (options.shape == 'auto' || options.shape == 'autohome' || options.shape == 'autooverflow' || options.shape == 'autoVertical') {
2016-09-14 09:20:03 -07:00
if (options.preferThumb === true || isThumbAspectRatio) {
2016-07-29 08:54:43 -07:00
options.shape = options.shape == 'autooverflow' ? 'overflowBackdrop' : 'backdrop';
} else if (isSquareAspectRatio) {
options.coverImage = true;
options.shape = options.shape == 'autooverflow' ? 'overflowSquare' : 'square';
} else if (primaryImageAspectRatio && primaryImageAspectRatio > 1.9) {
options.shape = 'banner';
options.coverImage = true;
} else if (primaryImageAspectRatio && Math.abs(primaryImageAspectRatio - 0.6666667) < .2) {
options.shape = options.shape == 'autooverflow' ? 'overflowPortrait' : 'portrait';
} else {
options.shape = options.defaultShape || (options.shape == 'autooverflow' ? 'overflowSquare' : 'square');
2016-07-28 19:42:42 -07:00
}
}
2016-09-14 09:20:03 -07:00
if (options.preferThumb == 'auto') {
options.preferThumb = options.shape == 'backdrop' || options.shape == 'overflowBackdrop';
}
2016-07-29 08:54:43 -07:00
options.uiAspect = getDesiredAspect(options.shape);
options.primaryImageAspectRatio = primaryImageAspectRatio;
2016-07-28 19:42:42 -07:00
2016-07-29 08:54:43 -07:00
if (!options.width && options.widths) {
options.width = options.widths[options.shape];
}
2016-07-28 19:42:42 -07:00
2016-07-29 08:54:43 -07:00
if (options.rows && typeof (options.rows) !== 'number') {
options.rows = options.rows[options.shape];
}
2016-07-28 19:42:42 -07:00
2016-08-01 22:55:52 -07:00
if (layoutManager.tv) {
if (options.shape == 'backdrop') {
options.width = options.width || 500;
}
else if (options.shape == 'portrait') {
options.width = options.width || 243;
}
else if (options.shape == 'square') {
options.width = options.width || 243;
}
2016-07-29 08:54:43 -07:00
}
options.width = options.width || getImageWidth(options.shape);
2016-07-28 19:42:42 -07:00
}
function buildCardsHtmlInternal(items, apiClient, options) {
var isVertical;
if (options.shape == 'autoVertical') {
isVertical = true;
}
2016-07-29 08:54:43 -07:00
setCardData(items, options);
2016-07-28 19:42:42 -07:00
if (options.indexBy == 'Genres') {
return buildCardsByGenreHtmlInternal(items, apiClient, options);
}
var className = 'card';
if (options.shape) {
2016-07-29 08:54:43 -07:00
className += ' ' + options.shape + 'Card';
2016-07-28 19:42:42 -07:00
}
var html = '';
var itemsInRow = 0;
var currentIndexValue;
var hasOpenRow;
var hasOpenSection;
2016-07-29 08:54:43 -07:00
var sectionTitleTagName = options.sectionTitleTagName || 'div';
2016-07-28 19:42:42 -07:00
for (var i = 0, length = items.length; i < length; i++) {
var item = items[i];
if (options.indexBy) {
var newIndexValue = '';
if (options.indexBy == 'PremiereDate') {
if (item.PremiereDate) {
try {
2016-09-15 23:32:40 -07:00
newIndexValue = datetime.toLocaleDateString(datetime.parseISO8601Date(item.PremiereDate), { weekday: 'long', month: 'long', day: 'numeric' });
2016-07-28 19:42:42 -07:00
} catch (err) {
}
}
}
else if (options.indexBy == 'Genres') {
newIndexValue = item.Name;
}
else if (options.indexBy == 'ProductionYear') {
newIndexValue = item.ProductionYear;
}
else if (options.indexBy == 'CommunityRating') {
newIndexValue = item.CommunityRating ? (Math.floor(item.CommunityRating) + (item.CommunityRating % 1 >= .5 ? .5 : 0)) + '+' : null;
}
if (newIndexValue != currentIndexValue) {
if (hasOpenRow) {
html += '</div>';
hasOpenRow = false;
itemsInRow = 0;
}
if (hasOpenSection) {
html += '</div>';
if (isVertical) {
html += '</div>';
}
hasOpenSection = false;
}
if (isVertical) {
html += '<div class="verticalSection">';
} else {
html += '<div class="horizontalSection">';
}
2016-07-29 08:54:43 -07:00
html += '<' + sectionTitleTagName + ' class="sectionTitle">' + newIndexValue + '</' + sectionTitleTagName + '>';
2016-07-28 19:42:42 -07:00
if (isVertical) {
2016-07-29 22:25:07 -07:00
html += '<div class="itemsContainer vertical-wrap">';
2016-07-28 19:42:42 -07:00
}
currentIndexValue = newIndexValue;
hasOpenSection = true;
}
}
if (options.rows && itemsInRow == 0) {
if (hasOpenRow) {
html += '</div>';
hasOpenRow = false;
}
html += '<div class="cardColumn">';
hasOpenRow = true;
}
var cardClass = className;
html += buildCard(i, item, apiClient, options, cardClass);
itemsInRow++;
if (options.rows && itemsInRow >= options.rows) {
html += '</div>';
hasOpenRow = false;
itemsInRow = 0;
}
}
if (hasOpenRow) {
html += '</div>';
}
if (hasOpenSection) {
html += '</div>';
if (isVertical) {
html += '</div>';
}
}
return html;
}
function buildCardsByGenreHtmlInternal(items, apiClient, options) {
var className = 'card';
if (options.shape) {
2016-07-29 08:54:43 -07:00
className += ' ' + options.shape + 'Card';
2016-07-28 19:42:42 -07:00
}
var html = '';
var loopItems = options.genres;
for (var i = 0, length = loopItems.length; i < length; i++) {
var item = loopItems[i];
var genreLower = item.Name.toLowerCase();
var renderItems = items.filter(function (currentItem) {
return currentItem.Genres.filter(function (g) {
return g.toLowerCase() == genreLower;
}).length > 0;
});
if (!renderItems.length) {
continue;
}
html += '<div class="horizontalSection focuscontainer-down">';
html += '<div class="sectionTitle">' + item.Name + '</div>';
var showMoreButton = false;
if (renderItems.length > options.indexLimit) {
renderItems.length = Math.min(renderItems.length, options.indexLimit);
showMoreButton = true;
}
var itemsInRow = 0;
var hasOpenRow = false;
html += renderItems.map(function (renderItem) {
var currentItemHtml = '';
if (options.rows && itemsInRow == 0) {
if (hasOpenRow) {
currentItemHtml += '</div>';
hasOpenRow = false;
}
currentItemHtml += '<div class="cardColumn">';
hasOpenRow = true;
}
var cardClass = className;
currentItemHtml += buildCard(i, renderItem, apiClient, options, cardClass);
itemsInRow++;
if (options.rows && itemsInRow >= options.rows) {
currentItemHtml += '</div>';
hasOpenRow = false;
itemsInRow = 0;
}
return currentItemHtml;
}).join('');
if (showMoreButton) {
html += '<div class="listItemsMoreButtonContainer">';
2016-07-30 21:57:54 -07:00
html += '<button is="emby-button" class="listItemsMoreButton raised" data-parentid="' + options.parentId + '" data-indextype="Genres" data-indexvalue="' + item.Id + '">' + globalize.translate('sharedcomponents#More') + '</button>';
2016-07-28 19:42:42 -07:00
html += '</div>';
}
html += '</div>';
html += '</div>';
}
return html;
}
function getDesiredAspect(shape) {
if (shape) {
shape = shape.toLowerCase();
if (shape.indexOf('portrait') != -1) {
return (2 / 3);
}
if (shape.indexOf('backdrop') != -1) {
return (16 / 9);
}
if (shape.indexOf('square') != -1) {
return 1;
}
}
return null;
}
function getCardImageUrl(item, apiClient, options) {
2016-08-03 13:14:39 -07:00
var imageItem = item.ProgramInfo || item;
item = imageItem;
2016-07-28 19:42:42 -07:00
var width = options.width;
var height = null;
var primaryImageAspectRatio = imageLoader.getPrimaryImageAspectRatio([item]);
var forceName = false;
var imgUrl = null;
var coverImage = false;
2016-09-14 09:20:03 -07:00
if (options.preferThumb && item.ImageTags && item.ImageTags.Thumb) {
2016-07-28 19:42:42 -07:00
imgUrl = apiClient.getScaledImageUrl(item.Id, {
type: "Thumb",
maxWidth: width,
tag: item.ImageTags.Thumb
});
} else if (options.preferBanner && item.ImageTags && item.ImageTags.Banner) {
imgUrl = apiClient.getScaledImageUrl(item.Id, {
type: "Banner",
maxWidth: width,
tag: item.ImageTags.Banner
});
} else if (options.preferThumb && item.SeriesThumbImageTag && options.inheritThumb !== false) {
imgUrl = apiClient.getScaledImageUrl(item.SeriesId, {
type: "Thumb",
maxWidth: width,
tag: item.SeriesThumbImageTag
});
} else if (options.preferThumb && item.ParentThumbItemId && options.inheritThumb !== false) {
imgUrl = apiClient.getScaledImageUrl(item.ParentThumbItemId, {
type: "Thumb",
maxWidth: width,
tag: item.ParentThumbImageTag
});
} else if (options.preferThumb && item.BackdropImageTags && item.BackdropImageTags.length) {
imgUrl = apiClient.getScaledImageUrl(item.Id, {
type: "Backdrop",
maxWidth: width,
tag: item.BackdropImageTags[0]
});
forceName = true;
} else if (item.ImageTags && item.ImageTags.Primary) {
height = width && primaryImageAspectRatio ? Math.round(width / primaryImageAspectRatio) : null;
2016-08-01 22:55:52 -07:00
imgUrl = apiClient.getScaledImageUrl(item.Id, {
2016-07-28 19:42:42 -07:00
type: "Primary",
maxHeight: height,
maxWidth: width,
tag: item.ImageTags.Primary
});
if (options.preferThumb && options.showTitle !== false) {
forceName = true;
}
if (primaryImageAspectRatio) {
var uiAspect = getDesiredAspect(options.shape);
if (uiAspect) {
coverImage = Math.abs(primaryImageAspectRatio - uiAspect) <= .2;
}
}
} else if (item.PrimaryImageTag) {
height = width && primaryImageAspectRatio ? Math.round(width / primaryImageAspectRatio) : null;
2016-08-01 22:55:52 -07:00
imgUrl = apiClient.getScaledImageUrl(item.Id || item.ItemId, {
2016-07-28 19:42:42 -07:00
type: "Primary",
maxHeight: height,
maxWidth: width,
tag: item.PrimaryImageTag
});
if (options.preferThumb && options.showTitle !== false) {
forceName = true;
}
if (primaryImageAspectRatio) {
var uiAspect = getDesiredAspect(options.shape);
if (uiAspect) {
coverImage = Math.abs(primaryImageAspectRatio - uiAspect) <= .2;
}
}
}
else if (item.ParentPrimaryImageTag) {
2016-08-01 22:55:52 -07:00
imgUrl = apiClient.getScaledImageUrl(item.ParentPrimaryImageItemId, {
2016-07-28 19:42:42 -07:00
type: "Primary",
maxWidth: width,
tag: item.ParentPrimaryImageTag
});
}
else if (item.AlbumId && item.AlbumPrimaryImageTag) {
width = primaryImageAspectRatio ? Math.round(height * primaryImageAspectRatio) : null;
imgUrl = apiClient.getScaledImageUrl(item.AlbumId, {
type: "Primary",
maxHeight: height,
maxWidth: width,
tag: item.AlbumPrimaryImageTag
});
if (primaryImageAspectRatio) {
var uiAspect = getDesiredAspect(options.shape);
if (uiAspect) {
coverImage = Math.abs(primaryImageAspectRatio - uiAspect) <= .2;
}
}
}
else if (item.Type == 'Season' && item.ImageTags && item.ImageTags.Thumb) {
imgUrl = apiClient.getScaledImageUrl(item.Id, {
type: "Thumb",
maxWidth: width,
tag: item.ImageTags.Thumb
});
}
else if (item.BackdropImageTags && item.BackdropImageTags.length) {
imgUrl = apiClient.getScaledImageUrl(item.Id, {
type: "Backdrop",
maxWidth: width,
tag: item.BackdropImageTags[0]
});
} else if (item.ImageTags && item.ImageTags.Thumb) {
imgUrl = apiClient.getScaledImageUrl(item.Id, {
type: "Thumb",
maxWidth: width,
tag: item.ImageTags.Thumb
});
2016-08-31 12:17:11 -07:00
} else if (item.SeriesThumbImageTag && options.inheritThumb !== false) {
2016-07-28 19:42:42 -07:00
imgUrl = apiClient.getScaledImageUrl(item.SeriesId, {
type: "Thumb",
maxWidth: width,
tag: item.SeriesThumbImageTag
});
2016-08-31 12:17:11 -07:00
} else if (item.ParentThumbItemId && options.inheritThumb !== false) {
2016-07-28 19:42:42 -07:00
2016-08-31 12:17:11 -07:00
imgUrl = apiClient.getScaledImageUrl(item.ParentThumbItemId, {
2016-07-28 19:42:42 -07:00
type: "Thumb",
maxWidth: width,
tag: item.ParentThumbImageTag
});
}
return {
imgUrl: imgUrl,
forceName: forceName,
coverImage: coverImage
};
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
2016-07-30 12:17:09 -07:00
var numRandomColors = 5;
function getDefaultColorIndex(str) {
if (str) {
2016-07-31 22:09:09 -07:00
var charIndex = Math.floor(str.length / 2);
var character = String(str.substr(charIndex, 1).charCodeAt());
2016-07-30 12:17:09 -07:00
var sum = 0;
for (var i = 0; i < character.length; i++) {
sum += parseInt(character.charAt(i));
}
var index = String(sum).substr(-1);
2016-07-30 13:09:07 -07:00
return (index % numRandomColors) + 1;
2016-07-30 12:17:09 -07:00
} else {
return getRandomInt(1, numRandomColors);
}
}
2016-07-30 13:09:07 -07:00
function getDefaultColorClass(str) {
return 'defaultCardColor' + getDefaultColorIndex(str);
}
2016-09-05 13:07:36 -07:00
function getCardTextLines(lines, cssClass, forceLines, isOuterFooter, cardLayout) {
2016-07-28 19:42:42 -07:00
2016-07-29 12:51:58 -07:00
var html = '';
2016-07-29 08:54:43 -07:00
2016-07-29 12:51:58 -07:00
var valid = 0;
var i, length;
for (i = 0, length = lines.length; i < length; i++) {
var text = lines[i];
2016-09-05 13:07:36 -07:00
if (i == 1 && isOuterFooter) {
2016-08-08 19:10:12 -07:00
cssClass += ' cardText-secondary';
}
2016-09-05 13:07:36 -07:00
if (isOuterFooter && cardLayout) {
cssClass += ' cardText-rightmargin';
}
2016-07-29 12:51:58 -07:00
if (text) {
html += "<div class='" + cssClass + "'>";
html += text;
html += "</div>";
valid++;
}
}
if (forceLines) {
while (valid < length) {
html += "<div class='" + cssClass + "'>&nbsp;</div>";
valid++;
}
}
return html;
}
2016-09-05 13:07:36 -07:00
function getCardFooterText(item, apiClient, options, showTitle, forceName, overlayText, imgUrl, footerClass, progressHtml, isOuterFooter) {
2016-07-29 12:51:58 -07:00
var html = '';
2016-08-24 19:54:21 -07:00
var showOtherText = isOuterFooter ? !overlayText : overlayText;
2016-07-29 12:51:58 -07:00
if (isOuterFooter && options.cardLayout && !layoutManager.tv) {
2016-09-05 13:07:36 -07:00
if (options.cardFooterAside == 'logo') {
}
else if (options.cardFooterAside != 'none') {
var moreIcon = appHost.moreIcon == 'dots-horiz' ? '&#xE5D3;' : '&#xE5D4;';
html += '<button is="paper-icon-button-light" class="itemAction btnCardOptions autoSize" data-action="menu"><i class="md-icon">' + moreIcon + '</i></button>';
}
2016-07-29 12:51:58 -07:00
}
var cssClass = options.centerText && !options.cardLayout ? "cardText cardTextCentered" : "cardText";
var lines = [];
2016-09-30 11:57:56 -07:00
var parentTitleUnderneath = item.Type == 'MusicAlbum' || item.Type == 'Audio' || item.Type == 'MusicVideo';
2016-07-29 12:51:58 -07:00
if (showOtherText) {
2016-08-24 19:54:21 -07:00
if ((options.showParentTitle || options.showParentTitleOrTitle) && !parentTitleUnderneath) {
2016-07-29 12:51:58 -07:00
if (isOuterFooter && item.Type == 'Episode' && item.SeriesName && item.SeriesId) {
lines.push(getTextActionButton({
Id: item.SeriesId,
Name: item.SeriesName,
Type: 'Series',
IsFolder: true
}));
}
else {
2016-09-30 11:57:56 -07:00
var parentTitle = item.Type == 'Program' ? item.Name : (item.SeriesName || item.Album || item.AlbumArtist || item.GameSystem || "");
2016-08-24 19:54:21 -07:00
if (parentTitle || options.showParentTitle) {
lines.push(parentTitle);
}
2016-07-29 12:51:58 -07:00
}
}
}
2016-08-24 19:54:21 -07:00
if (showTitle || forceName || (options.showParentTitleOrTitle && !lines.length)) {
2016-07-29 12:51:58 -07:00
var name = options.showTitle == 'auto' && !item.IsFolder && item.MediaType == 'Photo' ? '' : itemHelper.getDisplayName(item);
lines.push(htmlEncode(name));
2016-07-29 08:54:43 -07:00
}
2016-07-28 19:42:42 -07:00
2016-07-29 12:51:58 -07:00
if (showOtherText) {
if (options.showParentTitle && parentTitleUnderneath) {
if (isOuterFooter && item.AlbumArtists && item.AlbumArtists.length) {
item.AlbumArtists[0].Type = 'MusicArtist';
item.AlbumArtists[0].IsFolder = true;
lines.push(getTextActionButton(item.AlbumArtists[0]));
} else {
2016-09-30 11:57:56 -07:00
lines.push(item.Type == 'Program' ? item.Name : (item.SeriesName || item.Album || item.AlbumArtist || item.GameSystem || ""));
2016-07-29 12:51:58 -07:00
}
}
if (options.showItemCounts) {
var itemCountHtml = getItemCountsHtml(options, item);
lines.push(itemCountHtml);
}
if (options.textLines) {
var additionalLines = options.textLines(item);
for (var i = 0, length = additionalLines.length; i < length; i++) {
lines.push(additionalLines[i]);
}
}
if (options.showSongCount) {
var songLine = '';
if (item.SongCount) {
songLine = item.SongCount == 1 ?
2016-07-30 21:57:54 -07:00
globalize.translate('sharedcomponents#ValueOneSong') :
globalize.translate('sharedcomponents#ValueSongCount', item.SongCount);
2016-07-29 12:51:58 -07:00
}
lines.push(songLine);
}
if (options.showPremiereDate) {
if (item.PremiereDate) {
try {
lines.push(getPremiereDateText(item));
} catch (err) {
lines.push('');
}
} else {
lines.push('');
}
}
if (options.showYear) {
lines.push(item.ProductionYear || '');
}
2016-09-12 14:24:05 -07:00
if (options.showRuntime) {
if (item.RunTimeTicks) {
lines.push(datetime.getDisplayRunningTime(item.RunTimeTicks));
} else {
lines.push('');
}
}
2016-07-29 12:51:58 -07:00
if (options.showAirTime) {
2016-09-30 11:43:59 -07:00
var airTimeText = '';
2016-07-29 12:51:58 -07:00
if (item.StartDate) {
try {
var date = datetime.parseISO8601Date(item.StartDate);
2016-09-30 11:43:59 -07:00
if (options.showAirDateTime) {
airTimeText += datetime.toLocaleDateString(date, { weekday: 'short', month: 'short', day: 'numeric' }) + ' ';
}
2016-07-29 12:51:58 -07:00
2016-09-30 11:43:59 -07:00
airTimeText += datetime.getDisplayTime(date);
2016-07-29 12:51:58 -07:00
2016-09-30 11:43:59 -07:00
if (item.EndDate && options.showAirEndTime) {
2016-07-29 12:51:58 -07:00
date = datetime.parseISO8601Date(item.EndDate);
airTimeText += ' - ' + datetime.getDisplayTime(date);
}
}
catch (e) {
console.log("Error parsing date: " + item.PremiereDate);
}
}
lines.push(airTimeText || '');
}
2016-09-30 11:43:59 -07:00
if (options.showChannelName) {
2016-07-29 12:51:58 -07:00
2016-09-05 13:07:36 -07:00
if (item.ChannelId) {
var channelText = item.ChannelName;
//var logoHeight = 32;
//if (item.ChannelPrimaryImageTag) {
// channelText = '<img src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" class="lazy cardFooterLogo" style="height:' + logoHeight + 'px" data-src="' + apiClient.getScaledImageUrl(item.ChannelId, {
// type: "Primary",
// height: logoHeight,
// tag: item.ChannelPrimaryImageTag
// }) + '" />' + channelText;
//} else {
// channelText += '<div style="height:' + logoHeight + 'px;width:0;"></div>';
//}
lines.push(getTextActionButton({
Id: item.ChannelId,
Name: item.ChannelName,
Type: 'TvChannel',
MediaType: item.MediaType,
IsFolder: false
}, channelText));
} else {
lines.push(item.ChannelName || '&nbsp;');
}
2016-07-29 12:51:58 -07:00
}
2016-09-30 11:43:59 -07:00
if (options.showCurrentProgram && item.Type == 'TvChannel') {
if (item.CurrentProgram) {
lines.push(item.CurrentProgram.Name);
} else {
lines.push('');
}
}
if (options.showSeriesYear) {
if (item.Status == "Continuing") {
lines.push(globalize.translate('sharedcomponents#SeriesYearToPresent', item.ProductionYear || ''));
} else {
lines.push(item.ProductionYear || '');
}
}
2016-07-29 12:51:58 -07:00
}
2016-08-29 00:12:24 -07:00
if ((showTitle || !imgUrl) && forceName && overlayText && lines.length == 1) {
2016-08-16 22:46:15 -07:00
lines = [];
}
2016-09-05 13:07:36 -07:00
html += getCardTextLines(lines, cssClass, !options.overlayText, isOuterFooter, options.cardLayout);
2016-07-29 12:51:58 -07:00
if (progressHtml) {
html += progressHtml;
}
if (html) {
html = '<div class="' + footerClass + '">' + html;
//cardFooter
html += "</div>";
}
return html;
}
function getTextActionButton(item, text) {
if (!text) {
text = itemHelper.getDisplayName(item);
}
var html = '<button data-id="' + item.Id + '" data-type="' + item.Type + '" data-mediatype="' + item.MediaType + '" data-channelid="' + item.ChannelId + '" data-isfolder="' + item.IsFolder + '" type="button" class="itemAction textActionButton" data-action="link">';
html += text;
html += '</button>';
return html;
}
function getItemCountsHtml(options, item) {
var counts = [];
var childText;
if (item.Type == 'Playlist') {
childText = '';
if (item.CumulativeRunTimeTicks) {
var minutes = item.CumulativeRunTimeTicks / 600000000;
minutes = minutes || 1;
childText += globalize.translate('ValueMinutes', Math.round(minutes));
} else {
childText += globalize.translate('ValueMinutes', 0);
}
counts.push(childText);
}
else if (item.Type == 'Genre' || item.Type == 'Studio') {
if (item.MovieCount) {
childText = item.MovieCount == 1 ?
globalize.translate('sharedcomponents#ValueOneMovie') :
globalize.translate('sharedcomponents#ValueMovieCount', item.MovieCount);
2016-07-29 12:51:58 -07:00
counts.push(childText);
}
if (item.SeriesCount) {
childText = item.SeriesCount == 1 ?
globalize.translate('sharedcomponents#ValueOneSeries') :
globalize.translate('sharedcomponents#ValueSeriesCount', item.SeriesCount);
2016-07-29 12:51:58 -07:00
counts.push(childText);
}
if (item.EpisodeCount) {
childText = item.EpisodeCount == 1 ?
globalize.translate('sharedcomponents#ValueOneEpisode') :
globalize.translate('sharedcomponents#ValueEpisodeCount', item.EpisodeCount);
2016-07-29 12:51:58 -07:00
counts.push(childText);
}
if (item.GameCount) {
childText = item.GameCount == 1 ?
globalize.translate('sharedcomponents#ValueOneGame') :
globalize.translate('sharedcomponents#ValueGameCount', item.GameCount);
2016-07-29 12:51:58 -07:00
counts.push(childText);
}
} else if (item.Type == 'GameGenre') {
if (item.GameCount) {
childText = item.GameCount == 1 ?
2016-07-30 21:57:54 -07:00
globalize.translate('sharedcomponents#ValueOneGame') :
globalize.translate('sharedcomponents#ValueGameCount', item.GameCount);
2016-07-29 12:51:58 -07:00
counts.push(childText);
}
} else if (item.Type == 'MusicGenre' || options.context == "MusicArtist") {
if (item.AlbumCount) {
childText = item.AlbumCount == 1 ?
2016-07-30 21:57:54 -07:00
globalize.translate('sharedcomponents#ValueOneAlbum') :
globalize.translate('sharedcomponents#ValueAlbumCount', item.AlbumCount);
2016-07-29 12:51:58 -07:00
counts.push(childText);
}
if (item.SongCount) {
childText = item.SongCount == 1 ?
2016-07-30 21:57:54 -07:00
globalize.translate('sharedcomponents#ValueOneSong') :
globalize.translate('sharedcomponents#ValueSongCount', item.SongCount);
2016-07-29 12:51:58 -07:00
counts.push(childText);
}
if (item.MusicVideoCount) {
childText = item.MusicVideoCount == 1 ?
2016-07-30 21:57:54 -07:00
globalize.translate('sharedcomponents#ValueOneMusicVideo') :
globalize.translate('sharedcomponents#ValueMusicVideoCount', item.MusicVideoCount);
2016-07-29 12:51:58 -07:00
counts.push(childText);
}
} else if (item.Type == 'Series') {
childText = item.RecursiveItemCount == 1 ?
globalize.translate('sharedcomponents#ValueOneEpisode') :
globalize.translate('sharedcomponents#ValueEpisodeCount', item.RecursiveItemCount);
counts.push(childText);
2016-07-29 12:51:58 -07:00
}
2016-08-04 09:39:19 -07:00
return counts.join(', ');
2016-07-29 12:51:58 -07:00
}
function buildCard(index, item, apiClient, options, className) {
var action = options.action || 'link';
var scalable = options.scalable !== false;
if (scalable) {
2016-08-26 10:24:04 -07:00
className += " scalableCard " + options.shape + "Card-scalable";
2016-07-28 19:42:42 -07:00
}
var imgInfo = getCardImageUrl(item, apiClient, options);
var imgUrl = imgInfo.imgUrl;
2016-08-16 22:46:15 -07:00
var forceName = imgInfo.forceName || !imgUrl;
2016-08-11 21:33:56 -07:00
var showTitle = options.showTitle == 'auto' ? true : (options.showTitle || item.Type == 'PhotoAlbum' || item.Type == 'Folder');
var overlayText = options.overlayText;
if (forceName && !options.cardLayout) {
if (overlayText == null) {
overlayText = true;
}
}
2016-07-28 19:42:42 -07:00
var cardImageContainerClass = 'cardImageContainer';
if (options.coverImage || imgInfo.coverImage) {
cardImageContainerClass += ' coveredImage';
2016-09-30 11:43:59 -07:00
if (item.MediaType == 'Photo' || item.Type == 'PhotoAlbum' || item.Type == 'Folder' || item.ProgramInfo || item.Type == 'Program') {
2016-08-19 23:27:48 -07:00
cardImageContainerClass += ' coveredImage-noScale';
2016-07-28 19:42:42 -07:00
}
}
if (!imgUrl) {
2016-07-30 13:09:07 -07:00
cardImageContainerClass += ' ' + getDefaultColorClass(item.Name);
2016-07-28 19:42:42 -07:00
}
2016-07-29 12:51:58 -07:00
var separateCardBox = scalable;
2016-07-30 13:09:07 -07:00
var cardBoxClass = options.cardLayout ? 'cardBox visualCardBox' : 'cardBox';
2016-08-11 21:33:56 -07:00
if (!layoutManager.tv) {
cardBoxClass += ' cardBox-mobile';
2016-08-11 22:59:45 -07:00
} else {
cardBoxClass += ' cardBox-focustransform';
2016-08-11 21:33:56 -07:00
}
var footerCssClass;
var progressHtml = indicators.getProgressBarHtml(item);
var innerCardFooter = '';
var footerOverlayed = false;
if (overlayText) {
footerCssClass = progressHtml ? 'innerCardFooter fullInnerCardFooter' : 'innerCardFooter';
2016-09-05 13:07:36 -07:00
innerCardFooter += getCardFooterText(item, apiClient, options, showTitle, forceName, overlayText, imgUrl, footerCssClass, progressHtml, false);
2016-08-11 21:33:56 -07:00
footerOverlayed = true;
}
else if (progressHtml) {
innerCardFooter += '<div class="innerCardFooter fullInnerCardFooter innerCardFooterClear">';
innerCardFooter += progressHtml;
innerCardFooter += '</div>';
progressHtml = '';
}
var mediaSourceCount = item.MediaSourceCount || 1;
if (mediaSourceCount > 1) {
innerCardFooter += '<div class="mediaSourceIndicator">' + mediaSourceCount + '</div>';
}
var outerCardFooter = '';
if (!overlayText && !footerOverlayed) {
2016-08-23 10:07:50 -07:00
footerCssClass = options.cardLayout ? 'cardFooter visualCardBox-cardFooter' : 'cardFooter transparent';
2016-09-05 13:07:36 -07:00
outerCardFooter = getCardFooterText(item, apiClient, options, showTitle, forceName, overlayText, imgUrl, footerCssClass, progressHtml, true);
2016-08-11 21:33:56 -07:00
}
2016-08-12 08:54:37 -07:00
if (outerCardFooter && !options.cardLayout && options.allowBottomPadding !== false) {
2016-08-11 21:33:56 -07:00
cardBoxClass += ' cardBox-bottompadded';
}
2016-07-28 19:42:42 -07:00
if (!separateCardBox) {
2016-07-30 13:09:07 -07:00
cardImageContainerClass += " " + cardBoxClass;
2016-07-28 19:42:42 -07:00
}
2016-07-30 19:54:17 -07:00
var overlayButtons = '';
2016-08-01 09:26:42 -07:00
if (!layoutManager.tv) {
2016-07-30 19:54:17 -07:00
var overlayPlayButton = options.overlayPlayButton;
2016-08-04 09:39:19 -07:00
if (overlayPlayButton == null && !options.overlayMoreButton && !options.cardLayout) {
2016-07-30 19:54:17 -07:00
overlayPlayButton = item.MediaType == 'Video';
}
if (overlayPlayButton && !item.IsPlaceHolder && (item.LocationType != 'Virtual' || !item.MediaType || item.Type == 'Program') && item.Type != 'Person' && item.PlayAccess == 'Full') {
overlayButtons += '<button is="paper-icon-button-light" class="cardOverlayButton itemAction autoSize" data-action="playmenu" onclick="return false;"><i class="md-icon">play_arrow</i></button>';
}
if (options.overlayMoreButton) {
var moreIcon = appHost.moreIcon == 'dots-horiz' ? '&#xE5D3;' : '&#xE5D4;';
overlayButtons += '<button is="paper-icon-button-light" class="cardOverlayButton itemAction autoSize" data-action="menu" onclick="return false;"><i class="md-icon">' + moreIcon + '</i></button>';
}
}
if (options.showChildCountIndicator && item.ChildCount) {
className += ' groupedCard';
}
2016-07-28 19:42:42 -07:00
// cardBox can be it's own separate element if an outer footer is ever needed
2016-07-30 19:54:17 -07:00
var cardImageContainerOpen;
2016-07-29 08:54:43 -07:00
var cardImageContainerClose = '';
2016-07-30 19:54:17 -07:00
var cardBoxClose = '';
2016-07-29 08:54:43 -07:00
var cardContentClose = '';
var cardScalableClose = '';
2016-07-28 19:42:42 -07:00
if (separateCardBox) {
2016-07-29 08:54:43 -07:00
var cardContentOpen;
if (layoutManager.tv) {
cardContentOpen = '<div class="cardContent">';
cardContentClose = '</div>';
} else {
cardContentOpen = '<button type="button" class="clearButton cardContent itemAction" data-action="' + action + '">';
cardContentClose = '</button>';
}
2016-07-30 19:54:17 -07:00
cardImageContainerOpen = imgUrl ? ('<div class="' + cardImageContainerClass + ' lazy" data-src="' + imgUrl + '">') : ('<div class="' + cardImageContainerClass + '">');
2016-08-23 23:13:15 -07:00
var cardScalableClass = options.cardLayout ? 'cardScalable visualCardBox-cardScalable' : 'cardScalable';
cardImageContainerOpen = '<div class="' + cardBoxClass + '"><div class="' + cardScalableClass + '"><div class="cardPadder-' + options.shape + '"></div>' + cardContentOpen + cardImageContainerOpen;
2016-07-29 08:54:43 -07:00
cardBoxClose = '</div>';
cardScalableClose = '</div>';
cardImageContainerClose = '</div>';
2016-07-30 19:54:17 -07:00
} else {
if (overlayButtons && !separateCardBox) {
2016-08-08 19:10:12 -07:00
cardImageContainerClass += ' cardImageContainerClass-button';
2016-07-30 19:54:17 -07:00
cardImageContainerOpen = imgUrl ? ('<button type="button" data-action="' + action + '" class="itemAction ' + cardImageContainerClass + ' lazy" data-src="' + imgUrl + '">') : ('<button type="button" data-action="' + action + '" class="itemAction ' + cardImageContainerClass + '">');
cardImageContainerClose = '</button>';
className += ' forceRelative';
} else {
cardImageContainerOpen = imgUrl ? ('<div class="' + cardImageContainerClass + ' lazy" data-src="' + imgUrl + '">') : ('<div class="' + cardImageContainerClass + '">');
cardImageContainerClose = '</div>';
}
2016-07-28 19:42:42 -07:00
}
var indicatorsHtml = '';
2016-08-02 23:38:19 -07:00
indicatorsHtml += indicators.getSyncIndicator(item);
2016-07-28 19:42:42 -07:00
indicatorsHtml += indicators.getTimerIndicator(item);
if (options.showGroupCount) {
indicatorsHtml += indicators.getChildCountIndicatorHtml(item, {
minCount: 1
});
}
else {
indicatorsHtml += indicators.getPlayedIndicatorHtml(item);
}
if (indicatorsHtml) {
2016-08-08 11:13:52 -07:00
cardImageContainerOpen += '<div class="cardIndicators ' + options.shape + 'CardIndicators">' + indicatorsHtml + '</div>';
2016-07-28 19:42:42 -07:00
}
2016-07-29 12:51:58 -07:00
if (!imgUrl) {
2016-09-26 22:13:56 -07:00
var defaultName = item.Type == 'Program' ? item.Name : itemHelper.getDisplayName(item);
2016-07-29 12:51:58 -07:00
cardImageContainerOpen += '<div class="cardText cardCenteredText">' + defaultName + '</div>';
2016-07-28 19:42:42 -07:00
}
2016-07-30 19:54:17 -07:00
var tagName = (layoutManager.tv || !scalable) && !overlayButtons ? 'button' : 'div';
2016-07-28 19:42:42 -07:00
var prefix = (item.SortName || item.Name || '')[0];
if (prefix) {
prefix = prefix.toUpperCase();
}
var timerAttributes = '';
if (item.TimerId) {
timerAttributes += ' data-timerid="' + item.TimerId + '"';
}
if (item.SeriesTimerId) {
timerAttributes += ' data-seriestimerid="' + item.SeriesTimerId + '"';
}
2016-07-29 12:51:58 -07:00
var actionAttribute;
if (tagName == 'button') {
className += " itemAction";
actionAttribute = ' data-action="' + action + '"';
} else {
actionAttribute = '';
}
2016-09-09 09:58:08 -07:00
if (item.Type != 'MusicAlbum' && item.Type != 'MusicArtist' && item.Type != 'Audio') {
className += ' card-withuserdata';
}
2016-08-29 00:12:24 -07:00
2016-07-29 21:21:03 -07:00
var positionTicksData = item.UserData && item.UserData.PlaybackPositionTicks ? (' data-positionticks="' + item.UserData.PlaybackPositionTicks + '"') : '';
var collectionIdData = options.collectionId ? (' data-collectionid="' + options.collectionId + '"') : '';
var playlistIdData = options.playlistId ? (' data-playlistid="' + options.playlistId + '"') : '';
var mediaTypeData = item.MediaType ? (' data-mediatype="' + item.MediaType + '"') : '';
var collectionTypeData = item.CollectionType ? (' data-collectiontype="' + item.CollectionType + '"') : '';
var channelIdData = item.ChannelId ? (' data-channelid="' + item.ChannelId + '"') : '';
2016-08-24 20:07:31 -07:00
var contextData = options.context ? (' data-context="' + options.context + '"') : '';
2016-07-29 21:21:03 -07:00
2016-07-28 19:42:42 -07:00
return '\
2016-08-24 20:07:31 -07:00
<' + tagName + ' data-index="' + index + '"' + timerAttributes + actionAttribute + ' data-isfolder="' + (item.IsFolder || false) + '" data-serverid="' + (item.ServerId) + '" data-id="' + (item.Id || item.ItemId) + '" data-type="' + item.Type + '"' + mediaTypeData + collectionTypeData + channelIdData + positionTicksData + collectionIdData + playlistIdData + contextData + ' data-prefix="' + prefix + '" class="' + className + '"> \
2016-07-30 19:54:17 -07:00
' + cardImageContainerOpen + innerCardFooter + cardImageContainerClose + cardContentClose + overlayButtons + cardScalableClose + outerCardFooter + cardBoxClose + '\
2016-07-28 19:42:42 -07:00
</' + tagName + '>';
}
function buildCards(items, options) {
// Abort if the container has been disposed
if (!document.body.contains(options.itemsContainer)) {
return;
}
if (options.parentContainer) {
if (items.length) {
options.parentContainer.classList.remove('hide');
} else {
options.parentContainer.classList.add('hide');
return;
}
}
var apiClient = connectionManager.currentApiClient();
var html = buildCardsHtmlInternal(items, apiClient, options);
if (html) {
if (options.itemsContainer.cardBuilderHtml != html) {
options.itemsContainer.innerHTML = html;
if (items.length < 50) {
options.itemsContainer.cardBuilderHtml = html;
} else {
options.itemsContainer.cardBuilderHtml = null;
}
}
imageLoader.lazyChildren(options.itemsContainer);
} else {
options.itemsContainer.innerHTML = html;
options.itemsContainer.cardBuilderHtml = null;
}
if (options.autoFocus) {
focusManager.autoFocus(options.itemsContainer, true);
}
if (options.indexBy == 'Genres') {
options.itemsContainer.addEventListener('click', onItemsContainerClick);
}
}
function parentWithClass(elem, className) {
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
function onItemsContainerClick(e) {
var listItemsMoreButton = parentWithClass(e.target, 'listItemsMoreButton');
if (listItemsMoreButton) {
var value = listItemsMoreButton.getAttribute('data-indexvalue');
var parentid = listItemsMoreButton.getAttribute('data-parentid');
Emby.Page.showGenre({
ParentId: parentid,
Id: value
});
}
}
function ensureIndicators(card, indicatorsElem) {
if (indicatorsElem) {
return indicatorsElem;
}
2016-09-09 09:58:08 -07:00
indicatorsElem = card.querySelector('.cardIndicators');
2016-07-28 19:42:42 -07:00
if (!indicatorsElem) {
var cardImageContainer = card.querySelector('.cardImageContainer');
indicatorsElem = document.createElement('div');
2016-09-09 09:58:08 -07:00
indicatorsElem.classList.add('cardIndicators');
2016-07-28 19:42:42 -07:00
cardImageContainer.appendChild(indicatorsElem);
}
return indicatorsElem;
}
function updateUserData(card, userData) {
var type = card.getAttribute('data-type');
var enableCountIndicator = type == 'Series' || type == 'BoxSet' || type == 'Season';
var indicatorsElem;
if (userData.Played) {
var playedIndicator = card.querySelector('.playedIndicator');
if (!playedIndicator) {
playedIndicator = document.createElement('div');
playedIndicator.classList.add('playedIndicator');
indicatorsElem = ensureIndicators(card, indicatorsElem);
indicatorsElem.appendChild(playedIndicator);
}
playedIndicator.innerHTML = '<i class="md-icon">check</i>';
} else {
var playedIndicator = card.querySelector('.playedIndicator');
if (playedIndicator) {
playedIndicator.parentNode.removeChild(playedIndicator);
}
}
if (userData.UnplayedItemCount) {
var countIndicator = card.querySelector('.countIndicator');
if (!countIndicator) {
countIndicator = document.createElement('div');
countIndicator.classList.add('countIndicator');
indicatorsElem = ensureIndicators(card, indicatorsElem);
indicatorsElem.appendChild(countIndicator);
}
countIndicator.innerHTML = userData.UnplayedItemCount;
} else if (enableCountIndicator) {
var countIndicator = card.querySelector('.countIndicator');
if (countIndicator) {
countIndicator.parentNode.removeChild(countIndicator);
}
}
var progressHtml = indicators.getProgressBarHtml({
Type: type,
UserData: userData,
MediaType: 'Video'
});
if (progressHtml) {
var itemProgressBar = card.querySelector('.itemProgressBar');
if (!itemProgressBar) {
itemProgressBar = document.createElement('div');
itemProgressBar.classList.add('itemProgressBar');
var innerCardFooter = card.querySelector('.innerCardFooter');
if (!innerCardFooter) {
innerCardFooter = document.createElement('div');
innerCardFooter.classList.add('innerCardFooter');
var cardImageContainer = card.querySelector('.cardImageContainer');
cardImageContainer.appendChild(innerCardFooter);
}
innerCardFooter.appendChild(itemProgressBar);
}
itemProgressBar.innerHTML = progressHtml;
}
else {
var itemProgressBar = card.querySelector('.itemProgressBar');
if (itemProgressBar) {
itemProgressBar.parentNode.removeChild(itemProgressBar);
}
}
}
2016-08-29 21:33:24 -07:00
function onUserDataChanged(userData, scope) {
2016-07-28 19:42:42 -07:00
2016-08-29 21:33:24 -07:00
var cards = (scope || document.body).querySelectorAll('.card-withuserdata[data-id="' + userData.ItemId + '"]');
2016-07-28 19:42:42 -07:00
for (var i = 0, length = cards.length; i < length; i++) {
updateUserData(cards[i], userData);
}
}
2016-09-19 08:41:35 -07:00
function onTimerCreated(programId, newTimerId, itemsContainer) {
2016-09-30 11:43:59 -07:00
2016-09-19 08:41:35 -07:00
var cells = itemsContainer.querySelectorAll('.card[data-id="' + programId + '"]');
for (var i = 0, length = cells.length; i < length; i++) {
var cell = cells[i];
var icon = cell.querySelector('.timerIndicator');
if (!icon) {
var indicatorsElem = ensureIndicators(cell);
indicatorsElem.insertAdjacentHTML('beforeend', '<i class="md-icon timerIndicator indicatorIcon">&#xE061;</i>');
}
cell.setAttribute('data-timerid', newTimerId);
}
}
function onTimerCancelled(id, itemsContainer) {
var cells = itemsContainer.querySelectorAll('.card[data-timerid="' + id + '"]');
for (var i = 0, length = cells.length; i < length; i++) {
var cell = cells[i];
var icon = cell.querySelector('.timerIndicator');
if (icon) {
icon.parentNode.removeChild(icon);
}
cell.removeAttribute('data-timerid');
}
}
function onSeriesTimerCancelled(id, itemsContainer) {
var cells = itemsContainer.querySelectorAll('.card[data-seriestimerid="' + id + '"]');
for (var i = 0, length = cells.length; i < length; i++) {
var cell = cells[i];
var icon = cell.querySelector('.timerIndicator');
if (icon) {
icon.parentNode.removeChild(icon);
}
cell.removeAttribute('data-seriestimerid');
}
}
2016-07-28 19:42:42 -07:00
return {
2016-07-29 08:54:43 -07:00
getCardsHtml: getCardsHtml,
2016-07-28 19:42:42 -07:00
buildCards: buildCards,
2016-07-30 13:09:07 -07:00
onUserDataChanged: onUserDataChanged,
2016-09-19 08:41:35 -07:00
getDefaultColorClass: getDefaultColorClass,
onTimerCreated: onTimerCreated,
onTimerCancelled: onTimerCancelled,
onSeriesTimerCancelled: onSeriesTimerCancelled
2016-07-28 19:42:42 -07:00
};
});