mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Cleanup some knockout code
This commit is contained in:
parent
893364d52d
commit
722e345cbe
3 changed files with 14 additions and 16 deletions
|
|
@ -25,7 +25,7 @@ export const
|
||||||
* @param {string} uid
|
* @param {string} uid
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
getMessageKey = (folderFullName, uid) => `${folderFullName}#${uid}`,
|
getMessageKey = (folderFullName, uid) => folderFullName + '#' + uid,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} folder
|
* @param {string} folder
|
||||||
|
|
|
||||||
24
dev/External/User/ko.js
vendored
24
dev/External/User/ko.js
vendored
|
|
@ -14,7 +14,8 @@ const rlContentType = 'snappymail/action',
|
||||||
|
|
||||||
// In Chrome we have no access to dataTransfer.getData unless it's the 'drop' event
|
// In Chrome we have no access to dataTransfer.getData unless it's the 'drop' event
|
||||||
// In Chrome Mobile dataTransfer.types.includes(rlContentType) fails, only text/plain is set
|
// In Chrome Mobile dataTransfer.types.includes(rlContentType) fails, only text/plain is set
|
||||||
getDragAction = () => dragData ? dragData.action : false,
|
dragMessages = () => dragData && 'messages' === dragData.action,
|
||||||
|
dragSortable = () => dragData && 'sortable' === dragData.action,
|
||||||
setDragAction = (e, action, effect, data, img) => {
|
setDragAction = (e, action, effect, data, img) => {
|
||||||
dragData = {
|
dragData = {
|
||||||
action: action,
|
action: action,
|
||||||
|
|
@ -71,16 +72,17 @@ Object.assign(ko.bindingHandlers, {
|
||||||
|
|
||||||
emailsTags: {
|
emailsTags: {
|
||||||
init: (element, fValueAccessor, fAllBindings) => {
|
init: (element, fValueAccessor, fAllBindings) => {
|
||||||
const fValue = fValueAccessor();
|
const fValue = fValueAccessor(),
|
||||||
|
focused = fValue.focused;
|
||||||
|
|
||||||
element.addresses = new EmailAddressesComponent(element, {
|
element.addresses = new EmailAddressesComponent(element, {
|
||||||
focusCallback: value => fValue.focused && fValue.focused(!!value),
|
focusCallback: value => focused && focused(!!value),
|
||||||
autoCompleteSource: fAllBindings.get('autoCompleteSource'),
|
autoCompleteSource: fAllBindings.get('autoCompleteSource'),
|
||||||
onChange: value => fValue(value)
|
onChange: value => fValue(value)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (fValue.focused && fValue.focused.subscribe) {
|
if (focused) {
|
||||||
fValue.focused.subscribe(value =>
|
focused.subscribe(value =>
|
||||||
element.addresses[value ? 'focus' : 'blur']()
|
element.addresses[value ? 'focus' : 'blur']()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +134,7 @@ Object.assign(ko.bindingHandlers, {
|
||||||
dragTimer.stop();
|
dragTimer.stop();
|
||||||
},
|
},
|
||||||
fnHover = e => {
|
fnHover = e => {
|
||||||
if ('messages' === getDragAction(e)) {
|
if (dragMessages()) {
|
||||||
fnStop(e);
|
fnStop(e);
|
||||||
element.classList.add('droppableHover');
|
element.classList.add('droppableHover');
|
||||||
if (folder && folder.collapsed()) {
|
if (folder && folder.collapsed()) {
|
||||||
|
|
@ -149,7 +151,7 @@ Object.assign(ko.bindingHandlers, {
|
||||||
dragleave: fnStop,
|
dragleave: fnStop,
|
||||||
drop: e => {
|
drop: e => {
|
||||||
fnStop(e);
|
fnStop(e);
|
||||||
if ('messages' === getDragAction(e) && ['move','copy'].includes(e.dataTransfer.effectAllowed)) {
|
if (dragMessages() && ['move','copy'].includes(e.dataTransfer.effectAllowed)) {
|
||||||
let data = dragData.data;
|
let data = dragData.data;
|
||||||
if (folder && data && data.folder && isArray(data.uids)) {
|
if (folder && data && data.folder && isArray(data.uids)) {
|
||||||
moveMessagesToFolder(data.folder, data.uids, folder.fullName, data.copy && e.ctrlKey);
|
moveMessagesToFolder(data.folder, data.uids, folder.fullName, data.copy && e.ctrlKey);
|
||||||
|
|
@ -165,7 +167,7 @@ Object.assign(ko.bindingHandlers, {
|
||||||
let options = ko.unwrap(fValueAccessor()) || {},
|
let options = ko.unwrap(fValueAccessor()) || {},
|
||||||
parent = element.parentNode,
|
parent = element.parentNode,
|
||||||
fnHover = e => {
|
fnHover = e => {
|
||||||
if ('sortable' === getDragAction(e)) {
|
if (dragSortable()) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let node = (e.target.closest ? e.target : e.target.parentNode).closest('[draggable]');
|
let node = (e.target.closest ? e.target : e.target.parentNode).closest('[draggable]');
|
||||||
if (node && node !== dragData.data && parent.contains(node)) {
|
if (node && node !== dragData.data && parent.contains(node)) {
|
||||||
|
|
@ -189,9 +191,9 @@ Object.assign(ko.bindingHandlers, {
|
||||||
setDragAction(e, 'sortable', 'move', element, element);
|
setDragAction(e, 'sortable', 'move', element, element);
|
||||||
element.style.opacity = 0.25;
|
element.style.opacity = 0.25;
|
||||||
},
|
},
|
||||||
dragend: e => {
|
dragend: () => {
|
||||||
element.style.opacity = null;
|
element.style.opacity = null;
|
||||||
if ('sortable' === getDragAction(e)) {
|
if (dragSortable()) {
|
||||||
dragData.data.style.cssText = '';
|
dragData.data.style.cssText = '';
|
||||||
let row = parent.rows[options.list.indexOf(ko.dataFor(element))];
|
let row = parent.rows[options.list.indexOf(ko.dataFor(element))];
|
||||||
if (row != dragData.data) {
|
if (row != dragData.data) {
|
||||||
|
|
@ -207,7 +209,7 @@ Object.assign(ko.bindingHandlers, {
|
||||||
dragenter: fnHover,
|
dragenter: fnHover,
|
||||||
dragover: fnHover,
|
dragover: fnHover,
|
||||||
drop: e => {
|
drop: e => {
|
||||||
if ('sortable' === getDragAction(e)) {
|
if (dragSortable()) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let data = ko.dataFor(dragData.data),
|
let data = ko.dataFor(dragData.data),
|
||||||
from = options.list.indexOf(data),
|
from = options.list.indexOf(data),
|
||||||
|
|
|
||||||
4
dev/External/ko.js
vendored
4
dev/External/ko.js
vendored
|
|
@ -169,10 +169,6 @@ ko.extenders.limitedList = (target, limitedList) => {
|
||||||
|
|
||||||
result(target());
|
result(target());
|
||||||
|
|
||||||
if (!result.valueHasMutated) {
|
|
||||||
result.valueHasMutated = () => target.valueHasMutated();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue