You are here

function template_preprocess_hybridauth_popup_provider in HybridAuth Social Login 7

File

./hybridauth.widget.inc, line 225

Code

function template_preprocess_hybridauth_popup_provider(&$vars, $hook) {
  $provider_id = $vars['provider_id'];
  $destination = isset($_GET['destination']) ? $_GET['destination'] : 'user';
  unset($_GET['destination']);
  $query = drupal_get_query_parameters();
  $query['destination'] = $destination;
  $vars['provider_name'] = hybridauth_get_provider_name($provider_id);
  $vars['provider_icon'] = theme('hybridauth_provider_icon', array(
    'size' => 64,
    'provider_id' => $provider_id,
  ));
  $overlay = $vars['overlay'];
  $vars['popup_id'] = drupal_html_id('hybridauth-popup-provider-' . $provider_id);
  $vars['classes_array'][] = drupal_html_class('hybridauth-popup-provider');
  $button_id = drupal_html_id('hybridauth-popup-' . $provider_id . '-button');
  $vars['provider_button'] = l(t('Sign in'), 'hybridauth/popup', array(
    'query' => $query,
    'attributes' => array(
      'id' => $button_id,
      'class' => array(
        'hybridauth-popup-button',
        'hybridauth-popup-button-login',
      ),
    ),
  ));

  // Create cancel button
  $cancel_query = $query;
  $cancel_query['provider'] = 'list';
  $vars['cancel_button'] = l(t('Use another account'), 'hybridauth/popup', array(
    'query' => $cancel_query,
    'attributes' => array(
      'id' => $button_id . '-cancel',
      'class' => array(
        'hybridauth-popup-button',
        'hybridauth-popup-button-cancel',
      ),
    ),
  ));
  drupal_add_js('
    (function ($) {
      Drupal.behaviors.hybridauthPopupProvider = {
        attach: function (context, settings) {
          $(".hybridauth-popup-button-login", context).once("hybridauth-popup-button-login", function() {
            $(this).click(function(event) {
              event.preventDefault();
              var url = $(this).attr("href");
              window.open(
                url + "&authenticate=1",
                "hybridauth_social_sign_on",
                "location=0,status=0,scrollbars=0,width=800,height=500"
              );
              return false;
            });
          });
        }
      };
    }(jQuery));
  ', 'inline');
}