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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -