2019-01-23 11:33:34 +00:00
|
|
|
define(['browser', 'appStorage', 'apphost', 'loading', 'connectionManager', 'globalize', 'appRouter', 'dom', 'css!./multiselect'], function (browser, appStorage, appHost, loading, connectionManager, globalize, appRouter, dom) {
|
2019-01-10 15:39:37 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var selectedItems = [];
|
|
|
|
var selectedElements = [];
|
|
|
|
var currentSelectionCommandsPanel;
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function hideSelections() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var selectionCommandsPanel = currentSelectionCommandsPanel;
|
|
|
|
if (selectionCommandsPanel) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
selectionCommandsPanel.parentNode.removeChild(selectionCommandsPanel);
|
|
|
|
currentSelectionCommandsPanel = null;
|
|
|
|
|
|
|
|
selectedItems = [];
|
|
|
|
selectedElements = [];
|
|
|
|
var elems = document.querySelectorAll('.itemSelectionPanel');
|
|
|
|
for (var i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var parent = elems[i].parentNode;
|
2019-01-10 15:39:37 +03:00
|
|
|
parent.removeChild(elems[i]);
|
|
|
|
parent.classList.remove('withMultiSelect');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onItemSelectionPanelClick(e, itemSelectionPanel) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
// toggle the checkbox, if it wasn't clicked on
|
|
|
|
if (!dom.parentWithClass(e.target, 'chkItemSelect')) {
|
|
|
|
var chkItemSelect = itemSelectionPanel.querySelector('.chkItemSelect');
|
|
|
|
|
|
|
|
if (chkItemSelect) {
|
|
|
|
|
|
|
|
if (chkItemSelect.classList.contains('checkedInitial')) {
|
|
|
|
chkItemSelect.classList.remove('checkedInitial');
|
|
|
|
} else {
|
2018-10-23 01:05:09 +03:00
|
|
|
var newValue = !chkItemSelect.checked;
|
2019-01-10 15:39:37 +03:00
|
|
|
chkItemSelect.checked = newValue;
|
|
|
|
updateItemSelection(chkItemSelect, newValue);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
return false;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateItemSelection(chkItemSelect, selected) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var id = dom.parentWithAttribute(chkItemSelect, 'data-id').getAttribute('data-id');
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (selected) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var current = selectedItems.filter(function (i) {
|
|
|
|
return i === id;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!current.length) {
|
|
|
|
selectedItems.push(id);
|
|
|
|
selectedElements.push(chkItemSelect);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
selectedItems = selectedItems.filter(function (i) {
|
|
|
|
return i !== id;
|
|
|
|
});
|
|
|
|
selectedElements = selectedElements.filter(function (i) {
|
|
|
|
return i !== chkItemSelect;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (selectedItems.length) {
|
2019-01-10 15:39:37 +03:00
|
|
|
var itemSelectionCount = document.querySelector('.itemSelectionCount');
|
|
|
|
if (itemSelectionCount) {
|
|
|
|
itemSelectionCount.innerHTML = selectedItems.length;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hideSelections();
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSelectionChange(e) {
|
2019-01-10 15:39:37 +03:00
|
|
|
updateItemSelection(this, this.checked);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showSelection(item, isChecked) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var itemSelectionPanel = item.querySelector('.itemSelectionPanel');
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (!itemSelectionPanel) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
itemSelectionPanel = document.createElement('div');
|
|
|
|
itemSelectionPanel.classList.add('itemSelectionPanel');
|
|
|
|
|
|
|
|
var parent = item.querySelector('.cardBox') || item.querySelector('.cardContent');
|
|
|
|
parent.classList.add('withMultiSelect');
|
|
|
|
parent.appendChild(itemSelectionPanel);
|
|
|
|
|
|
|
|
var cssClass = 'chkItemSelect';
|
|
|
|
if (isChecked && !browser.firefox) {
|
|
|
|
// In firefox, the initial tap hold doesnt' get treated as a click
|
|
|
|
// In other browsers it does, so we need to make sure that initial click is ignored
|
|
|
|
cssClass += ' checkedInitial';
|
|
|
|
}
|
|
|
|
var checkedAttribute = isChecked ? ' checked' : '';
|
|
|
|
itemSelectionPanel.innerHTML = '<label class="checkboxContainer"><input type="checkbox" is="emby-checkbox" data-outlineclass="multiSelectCheckboxOutline" class="' + cssClass + '"' + checkedAttribute + '/><span></span></label>';
|
|
|
|
var chkItemSelect = itemSelectionPanel.querySelector('.chkItemSelect');
|
|
|
|
chkItemSelect.addEventListener('change', onSelectionChange);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showSelectionCommands() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var selectionCommandsPanel = currentSelectionCommandsPanel;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (!selectionCommandsPanel) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
selectionCommandsPanel = document.createElement('div');
|
|
|
|
selectionCommandsPanel.classList.add('selectionCommandsPanel');
|
|
|
|
|
|
|
|
document.body.appendChild(selectionCommandsPanel);
|
|
|
|
currentSelectionCommandsPanel = selectionCommandsPanel;
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
html += '<button is="paper-icon-button-light" class="btnCloseSelectionPanel autoSize"><i class="md-icon">close</i></button>';
|
|
|
|
html += '<h1 class="itemSelectionCount"></h1>';
|
|
|
|
|
2019-11-20 00:24:54 +03:00
|
|
|
var moreIcon = 'more_horiz';
|
2019-01-10 15:39:37 +03:00
|
|
|
html += '<button is="paper-icon-button-light" class="btnSelectionPanelOptions autoSize" style="margin-left:auto;"><i class="md-icon">' + moreIcon + '</i></button>';
|
|
|
|
|
|
|
|
selectionCommandsPanel.innerHTML = html;
|
|
|
|
|
|
|
|
selectionCommandsPanel.querySelector('.btnCloseSelectionPanel').addEventListener('click', hideSelections);
|
|
|
|
|
|
|
|
var btnSelectionPanelOptions = selectionCommandsPanel.querySelector('.btnSelectionPanelOptions');
|
|
|
|
|
|
|
|
dom.addEventListener(btnSelectionPanelOptions, 'click', showMenuForSelectedItems, { passive: true });
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function alertText(options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
|
|
|
require(['alert'], function (alert) {
|
|
|
|
alert(options).then(resolve, resolve);
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteItems(apiClient, itemIds) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
2019-02-03 02:41:16 +09:00
|
|
|
var msg = globalize.translate('ConfirmDeleteItem');
|
|
|
|
var title = globalize.translate('HeaderDeleteItem');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (itemIds.length > 1) {
|
2019-02-03 02:41:16 +09:00
|
|
|
msg = globalize.translate('ConfirmDeleteItems');
|
|
|
|
title = globalize.translate('HeaderDeleteItems');
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
require(['confirm'], function (confirm) {
|
|
|
|
|
|
|
|
confirm(msg, title).then(function () {
|
|
|
|
var promises = itemIds.map(function (itemId) {
|
|
|
|
apiClient.deleteItem(itemId);
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
Promise.all(promises).then(resolve, function () {
|
|
|
|
|
2019-02-03 02:41:16 +09:00
|
|
|
alertText(globalize.translate('ErrorDeletingItem')).then(reject, reject);
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
}, reject);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showMenuForSelectedItems(e) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var apiClient = connectionManager.currentApiClient();
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
apiClient.getCurrentUser().then(function (user) {
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var menuItems = [];
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
menuItems.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('AddToCollection'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'addtocollection',
|
|
|
|
ironIcon: 'add'
|
|
|
|
});
|
|
|
|
|
|
|
|
menuItems.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('AddToPlaylist'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'playlist',
|
|
|
|
ironIcon: 'playlist-add'
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO: Be more dynamic based on what is selected
|
|
|
|
if (user.Policy.EnableContentDeletion) {
|
|
|
|
menuItems.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Delete'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'delete',
|
|
|
|
ironIcon: 'delete'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user.Policy.EnableContentDownloading && appHost.supports('filedownload')) {
|
2019-01-25 22:43:26 +01:00
|
|
|
menuItems.push({
|
2019-08-15 18:37:37 +03:00
|
|
|
name: Globalize.translate('ButtonDownload'),
|
|
|
|
id: 'download',
|
|
|
|
ironIcon: 'file-download'
|
2019-01-25 22:43:26 +01:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2019-08-15 18:37:37 +03:00
|
|
|
if (user.Policy.IsAdministrator) {
|
|
|
|
menuItems.push({
|
|
|
|
name: globalize.translate('GroupVersions'),
|
|
|
|
id: 'groupvideos',
|
|
|
|
ironIcon: 'call-merge'
|
|
|
|
});
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
menuItems.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('MarkPlayed'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'markplayed'
|
|
|
|
});
|
|
|
|
|
|
|
|
menuItems.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('MarkUnplayed'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'markunplayed'
|
|
|
|
});
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
menuItems.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('RefreshMetadata'),
|
2019-01-10 15:39:37 +03:00
|
|
|
id: 'refresh'
|
|
|
|
});
|
|
|
|
|
2019-03-23 02:16:02 +03:00
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
require(['actionsheet'], function (actionsheet) {
|
2018-10-23 01:05:09 +03:00
|
|
|
actionsheet.show({
|
|
|
|
items: menuItems,
|
|
|
|
positionTo: e.target,
|
2019-01-10 15:39:37 +03:00
|
|
|
callback: function (id) {
|
|
|
|
var items = selectedItems.slice(0);
|
|
|
|
var serverId = apiClient.serverInfo().Id;
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
switch (id) {
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'addtocollection':
|
|
|
|
require(['collectionEditor'], function (collectionEditor) {
|
|
|
|
new collectionEditor().show({
|
2018-10-23 01:05:09 +03:00
|
|
|
items: items,
|
|
|
|
serverId: serverId
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
hideSelections();
|
|
|
|
dispatchNeedsRefresh();
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'playlist':
|
|
|
|
require(['playlistEditor'], function (playlistEditor) {
|
|
|
|
new playlistEditor().show({
|
2018-10-23 01:05:09 +03:00
|
|
|
items: items,
|
|
|
|
serverId: serverId
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
hideSelections();
|
|
|
|
dispatchNeedsRefresh();
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'delete':
|
|
|
|
deleteItems(apiClient, items).then(dispatchNeedsRefresh);
|
|
|
|
hideSelections();
|
|
|
|
dispatchNeedsRefresh();
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'groupvideos':
|
2018-10-23 01:05:09 +03:00
|
|
|
combineVersions(apiClient, items);
|
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'markplayed':
|
|
|
|
items.forEach(function (itemId) {
|
|
|
|
apiClient.markPlayed(apiClient.getCurrentUserId(), itemId);
|
|
|
|
});
|
|
|
|
hideSelections();
|
|
|
|
dispatchNeedsRefresh();
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'markunplayed':
|
|
|
|
items.forEach(function (itemId) {
|
|
|
|
apiClient.markUnplayed(apiClient.getCurrentUserId(), itemId);
|
|
|
|
});
|
|
|
|
hideSelections();
|
|
|
|
dispatchNeedsRefresh();
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
case 'refresh':
|
|
|
|
require(['refreshDialog'], function (refreshDialog) {
|
2018-10-23 01:05:09 +03:00
|
|
|
new refreshDialog({
|
|
|
|
itemIds: items,
|
|
|
|
serverId: serverId
|
2019-01-10 15:39:37 +03:00
|
|
|
}).show();
|
|
|
|
});
|
|
|
|
hideSelections();
|
|
|
|
dispatchNeedsRefresh();
|
2018-10-23 01:05:09 +03:00
|
|
|
break;
|
2019-01-10 15:39:37 +03:00
|
|
|
default:
|
|
|
|
break;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function dispatchNeedsRefresh() {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var elems = [];
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
[].forEach.call(selectedElements, function (i) {
|
|
|
|
|
|
|
|
var container = dom.parentWithAttribute(i, 'is', 'emby-itemscontainer');
|
|
|
|
|
|
|
|
if (container && elems.indexOf(container) === -1) {
|
|
|
|
elems.push(container);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
for (var i = 0, length = elems.length; i < length; i++) {
|
|
|
|
elems[i].notifyRefreshNeeded(true);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function combineVersions(apiClient, selection) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (selection.length < 2) {
|
|
|
|
|
|
|
|
require(['alert'], function (alert) {
|
|
|
|
alert({
|
2019-02-03 02:41:16 +09:00
|
|
|
text: globalize.translate('PleaseSelectTwoItems')
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
loading.show();
|
|
|
|
|
|
|
|
apiClient.ajax({
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
type: "POST",
|
2019-01-10 15:39:37 +03:00
|
|
|
url: apiClient.getUrl("Videos/MergeVersions", { Ids: selection.join(',') })
|
|
|
|
|
|
|
|
}).then(function () {
|
|
|
|
|
|
|
|
loading.hide();
|
|
|
|
hideSelections();
|
|
|
|
dispatchNeedsRefresh();
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showSelections(initialCard) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
require(['emby-checkbox'], function () {
|
|
|
|
var cards = document.querySelectorAll('.card');
|
|
|
|
for (var i = 0, length = cards.length; i < length; i++) {
|
|
|
|
showSelection(cards[i], initialCard === cards[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
showSelectionCommands();
|
|
|
|
updateItemSelection(initialCard, true);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onContainerClick(e) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var target = e.target;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (selectedItems.length) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
var card = dom.parentWithClass(target, 'card');
|
2018-10-23 01:05:09 +03:00
|
|
|
if (card) {
|
2019-01-10 15:39:37 +03:00
|
|
|
var itemSelectionPanel = card.querySelector('.itemSelectionPanel');
|
|
|
|
if (itemSelectionPanel) {
|
|
|
|
return onItemSelectionPanelClick(e, itemSelectionPanel);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
return false;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
document.addEventListener('viewbeforehide', hideSelections);
|
|
|
|
|
|
|
|
return function (options) {
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var container = options.container;
|
|
|
|
|
|
|
|
function onTapHold(e) {
|
|
|
|
|
|
|
|
var card = dom.parentWithClass(e.target, 'card');
|
|
|
|
|
|
|
|
if (card) {
|
|
|
|
|
|
|
|
showSelections(card);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
e.preventDefault();
|
|
|
|
// It won't have this if it's a hammer event
|
|
|
|
if (e.stopPropagation) {
|
|
|
|
e.stopPropagation();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
function getTouches(e) {
|
|
|
|
|
|
|
|
return e.changedTouches || e.targetTouches || e.touches;
|
|
|
|
}
|
|
|
|
|
|
|
|
var touchTarget;
|
|
|
|
var touchStartTimeout;
|
|
|
|
var touchStartX;
|
|
|
|
var touchStartY;
|
|
|
|
function onTouchStart(e) {
|
|
|
|
|
|
|
|
var touch = getTouches(e)[0];
|
|
|
|
touchTarget = null;
|
|
|
|
touchStartX = 0;
|
|
|
|
touchStartY = 0;
|
|
|
|
|
|
|
|
if (touch) {
|
|
|
|
touchStartX = touch.clientX;
|
|
|
|
touchStartY = touch.clientY;
|
|
|
|
var element = touch.target;
|
|
|
|
|
|
|
|
if (element) {
|
|
|
|
var card = dom.parentWithClass(element, 'card');
|
|
|
|
|
|
|
|
if (card) {
|
|
|
|
|
|
|
|
if (touchStartTimeout) {
|
|
|
|
clearTimeout(touchStartTimeout);
|
|
|
|
touchStartTimeout = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
touchTarget = card;
|
|
|
|
touchStartTimeout = setTimeout(onTouchStartTimerFired, 550);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onTouchMove(e) {
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
if (touchTarget) {
|
|
|
|
var touch = getTouches(e)[0];
|
|
|
|
var deltaX;
|
|
|
|
var deltaY;
|
|
|
|
|
|
|
|
if (touch) {
|
|
|
|
var touchEndX = touch.clientX || 0;
|
|
|
|
var touchEndY = touch.clientY || 0;
|
|
|
|
deltaX = Math.abs(touchEndX - (touchStartX || 0));
|
|
|
|
deltaY = Math.abs(touchEndY - (touchStartY || 0));
|
|
|
|
} else {
|
|
|
|
deltaX = 100;
|
|
|
|
deltaY = 100;
|
|
|
|
}
|
|
|
|
if (deltaX >= 5 || deltaY >= 5) {
|
|
|
|
onMouseOut(e);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onTouchEnd(e) {
|
|
|
|
|
|
|
|
onMouseOut(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseDown(e) {
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
if (touchStartTimeout) {
|
|
|
|
clearTimeout(touchStartTimeout);
|
|
|
|
touchStartTimeout = null;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
touchTarget = e.target;
|
|
|
|
touchStartTimeout = setTimeout(onTouchStartTimerFired, 550);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseOut(e) {
|
|
|
|
|
|
|
|
if (touchStartTimeout) {
|
|
|
|
clearTimeout(touchStartTimeout);
|
|
|
|
touchStartTimeout = null;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
touchTarget = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTouchStartTimerFired() {
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!touchTarget) {
|
|
|
|
return;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
var card = dom.parentWithClass(touchTarget, 'card');
|
|
|
|
touchTarget = null;
|
|
|
|
|
|
|
|
if (card) {
|
|
|
|
|
|
|
|
showSelections(card);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function initTapHold(element) {
|
|
|
|
|
|
|
|
// mobile safari doesn't allow contextmenu override
|
|
|
|
if (browser.touch && !browser.safari) {
|
|
|
|
element.addEventListener('contextmenu', onTapHold);
|
|
|
|
} else {
|
|
|
|
dom.addEventListener(element, 'touchstart', onTouchStart, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
dom.addEventListener(element, 'touchmove', onTouchMove, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
dom.addEventListener(element, 'touchend', onTouchEnd, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
dom.addEventListener(element, 'touchcancel', onTouchEnd, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
dom.addEventListener(element, 'mousedown', onMouseDown, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
dom.addEventListener(element, 'mouseleave', onMouseOut, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
dom.addEventListener(element, 'mouseup', onMouseOut, {
|
|
|
|
passive: true
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
initTapHold(container);
|
|
|
|
|
|
|
|
if (options.bindOnClick !== false) {
|
|
|
|
container.addEventListener('click', onContainerClick);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.onContainerClick = onContainerClick;
|
|
|
|
|
|
|
|
self.destroy = function () {
|
|
|
|
|
|
|
|
container.removeEventListener('click', onContainerClick);
|
|
|
|
container.removeEventListener('contextmenu', onTapHold);
|
|
|
|
|
|
|
|
var element = container;
|
|
|
|
|
|
|
|
dom.removeEventListener(element, 'touchstart', onTouchStart, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
dom.removeEventListener(element, 'touchmove', onTouchMove, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
dom.removeEventListener(element, 'touchend', onTouchEnd, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
// this fires in safari due to magnifying class
|
|
|
|
//dom.removeEventListener(element, 'touchcancel', onTouchEnd, {
|
|
|
|
// passive: true
|
|
|
|
//});
|
|
|
|
dom.removeEventListener(element, 'mousedown', onMouseDown, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
dom.removeEventListener(element, 'mouseleave', onMouseOut, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
dom.removeEventListener(element, 'mouseup', onMouseOut, {
|
|
|
|
passive: true
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
2019-01-25 22:43:26 +01:00
|
|
|
});
|