The login popup being available in other locations (like you're looking for) is something we're planning. It will be a nice feature and well used, but a little complex to implement.
For now, I'd recommend trying to update the line above to:
$uri = JURI::getInstance();
$url = $uri->toString(array('scheme', 'host', 'port', 'path', 'query'));
$url = base64_encode($url);
$mainframe->redirect( JRoute::_('index.php?option=com_users&view=login&return=' . $url , false ) );
Please try that and let me know how it goes. It should redirect the user when using the social login buttons. I *believe* it should also work with standard Joomla logins as well.
Let me know how that goes, and best of luck!
Alex