1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

add helpers

This commit is contained in:
Luke Pulverenti 2016-07-18 14:50:00 -04:00
parent 91b07f9cc7
commit d7bb32b760
6 changed files with 76 additions and 110 deletions

View file

@ -1,22 +1,9 @@
define(['browser', 'appStorage', 'apphost', 'loading', 'connectionManager', 'globalize', 'embyRouter', 'css!./multiselect'], function (browser, appStorage, appHost, loading, connectionManager, globalize, embyRouter) {
define(['browser', 'appStorage', 'apphost', 'loading', 'connectionManager', 'globalize', 'embyRouter', 'dom', 'css!./multiselect'], function (browser, appStorage, appHost, loading, connectionManager, globalize, embyRouter, dom) {
var selectedItems = [];
var selectedElements = [];
var currentSelectionCommandsPanel;
function parentWithClass(elem, className) {
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
function hideSelections() {
var selectionCommandsPanel = currentSelectionCommandsPanel;
@ -66,7 +53,7 @@
function onItemSelectionPanelClick(e, itemSelectionPanel) {
// toggle the checkbox, if it wasn't clicked on
if (!parentWithClass(e.target, 'chkItemSelect')) {
if (!dom.parentWithClass(e.target, 'chkItemSelect')) {
var chkItemSelect = itemSelectionPanel.querySelector('.chkItemSelect');
if (chkItemSelect) {
@ -88,7 +75,7 @@
function updateItemSelection(chkItemSelect, selected) {
var id = parentWithClass(chkItemSelect, 'card').getAttribute('data-id');
var id = dom.parentWithClass(chkItemSelect, 'card').getAttribute('data-id');
if (selected) {
@ -377,26 +364,13 @@
});
}
function parentWithAttribute(elem, name, value) {
while ((value ? elem.getAttribute(name) != value : !elem.getAttribute(name))) {
elem = elem.parentNode;
if (!elem || !elem.getAttribute) {
return null;
}
}
return elem;
}
function dispatchNeedsRefresh() {
var elems = [];
[].forEach.call(selectedElements, function (i) {
var container = parentWithAttribute(i, 'is', 'emby-itemscontainer');
var container = dom.parentWithAttribute(i, 'is', 'emby-itemscontainer');
if (container && elems.indexOf(container) == -1) {
elems.push(container);
@ -466,7 +440,7 @@
if (selectedItems.length) {
var card = parentWithClass(target, 'card');
var card = dom.parentWithClass(target, 'card');
if (card) {
var itemSelectionPanel = card.querySelector('.itemSelectionPanel');
if (itemSelectionPanel) {
@ -488,7 +462,7 @@
function onTapHold(e) {
var card = parentWithClass(e.target, 'card');
var card = dom.parentWithClass(e.target, 'card');
if (card) {