').addClass('swipe-container').append($('
').addClass('swipe-action').append($('').addClass('swipe-label')))
);
rcmail.swipe.parent = list_container;
rcmail.swipe.parent.prepend(swipe_action.hide());
// down swipe on list container
var swipe_config = {
'source_obj': rcmail.swipe.parent,
'parent_obj': null,
'vertical': {
'minmove': $(window).height() * 0.19,
'maxmove': $(window).height() * 0.2,
'transition': 'scale',
'action_sytle': function(o) {
return {
'top': '',
'left': 0,
'width': rcmail.swipe.parent.width() + 'px',
'height': ''
};
},
'target_obj': $('#swipe-action'),
'uid': null
}
};
rcmail.swipe.init(swipe_config);
// prevent accidental list scroll when swipe active
rcmail.swipe.parent.on('scroll', function() {
if (!bw.pointer) {
if (rcmail.swipe.active)
return false;
}
else if ($(this).scrollTop() == 0) {
// allow vertical pointer events to fire (if one is configured)
var action = rcmail.swipe.select_action('down');
// Edge does not support pan-down, only pan-y
rcmail.swipe.parent.css('touch-action', action.callback && ! bw.edge ? 'pan-down' : 'pan-y');
}
}).trigger('scroll');
});
// right/left/down swipe on list
rcmail.addEventListener('insertrow', function(props) {
if (rcmail.env.swipe_list.draggable || !$('#' + props.row.id)[0].addEventListener)
return;
var row_width = $('#' + props.row.id).width();
// if no row width is available then use window width as fall back
row_width = row_width == 0 ? $(window).width() : row_width;
var swipe_config = {
'source_obj': $('#' + props.row.id),
'parent_obj': rcmail.swipe.parent,
'horizontal': {
'minmove': row_width * 0.25,
'maxmove': row_width * 0.6,
'transition': 'translatex',
'action_sytle': function(o) {
return {
'top': o.position().top,
'left': o.position().left,
'width': o.width() + 'px',
'height': (o.height() - 2) + 'px' // subtract the border
};
},
'target_obj': $('#' + props.row.id),
'uid': props.uid
}
};
rcmail.swipe.init(swipe_config);
});
// save swipe options
rcmail.set_list_options_core = rcmail.set_list_options;
rcmail.set_list_options = function(cols, sort_col, sort_order, threads, layout) {
var post = {};
$.each(['left', 'right', 'down'], function() {
var option_input = $('.swipeoptions-' + this).find('select,input').first();
if ($(option_input).is('input[type="radio"]')) {
selector = 'input[name="swipe_' + this + '"]:checked';
}
else if ($(option_input).is('select')) {
selector = 'select[name="swipe_' + this + '"]';
selector += $(selector).length > 1 ? ':visible' : '';
}
if ($(selector).val() != rcmail.env.swipe_actions[this]) {
rcmail.env.swipe_actions[this] = $(selector).val();
post['swipe_' + this] = rcmail.env.swipe_actions[this];
}
});
if (!$.isEmptyObject(post))
rcmail.http_post('plugin.swipe.save_settings', post);
rcmail.set_list_options_core(cols, sort_col, sort_order, threads, layout);
};
}
// show swipe options in the list options menu
rcmail.addEventListener('beforemenu-open', function(name) {
if (name == rcmail.env.swipe_menuname) {
var menu_obj = $('.swipe-menu');
if (!rcmail.env.swipe_list.draggable && menu_obj.find('select > option,input').length > 0) {
if (bw.edge)
menu_obj.find('.swipeoptions-down').hide();
menu_obj.show();
}
else {
menu_obj.hide();
}
}
});
// set the values swipe options menu
// done in menu-open not beforemenu-open because of Elastic's Bootstrap popovers
rcmail.addEventListener('menu-open', function(p) {
if (p.name == rcmail.env.swipe_menuname && $('.swipe-menu').is(':visible')) {
$.each(rcmail.env.swipe_actions, function(direction, action) {
var option_input = $('.swipeoptions-' + direction).find('select,input');
if (option_input.is('input[type="radio"]')) {
option_input.filter('[value="' + action + '"]').prop('checked', true);
}
else if (option_input.is('select') && option_input.first().children('option').length > 0) {
option_input.val(action);
}
else {
$('.swipeoptions-' + direction).hide();
}
});
}
});
});