Factorize javascript/jquery code for hiding modal when click outside -
i have code work don't know how factorize it. seems able they're same code first desktyop touch devices:
//desktop $(document).mouseup(function (e) { var container = $(".messenger"); if (!container.is(e.target) // if target of click isn't container... && container.has(e.target).length === 0) // ... nor descendant of container { container.empty(); container.off( 'click', clickdocument ); } }); // touch devices ipad , iphone can use following code $(document).on('touchstart', function (e) { var container = $(".messenger"); if (!container.is(e.target) // if target of click isn't container... && container.has(e.target).length === 0) // ... nor descendant of container { container.empty(); container.off( 'click', clickdocument ); } });
quite easy:
// desktop (mouseup) // or touch devices ipad , iphone can use following code $(document).on('mouseup touchstart', function (e) { var container = $(".messenger"); if (!container.is(e.target) // if target of click isn't container... && container.has(e.target).length === 0) // ... nor descendant of container { container.empty(); container.off( 'click', clickdocument ); } });
Comments
Post a Comment