Thủ thuật custom facebook login button trong Drupal 7

Thủ thuật custom facebook login button trong Drupal 7

Thủ thuật custom facebook login button trong Drupal 7Working on current Drupal 7 project we had to create customized facebook login button to fit nicely with the rest of oversized login option links. The target was to create completely custom CSS-able login buttons. It took a couple of hours to fix the puzzle into working condition.

This solution tested with facebook connect (https://drupal.org/project/fbcon...) 7x-2.0-beta4 module. Setting up fbconnect is out of scope of this article, but just to mention all settings are pretty much default. It will take care of fb initialization on particular login page.

First, we want to create a small javascript file to handle facebook authorization popup (we call it js/fblogin.js).


function fb_login(){
    FB.login(function(response) {

        if (response.authResponse) {
            console.log('Welcome!  Fetching your information.... ');
            access_token = response.authResponse.accessToken; //get access token
            user_id = response.authResponse.userID; //get FB UID

            FB.api('/me', function(response) {
                user_email = response.email; //get user email
            });

        } else {
            //user hit cancel button
            console.log('User cancelled login or did not fully authorize.');

        }
    }, {
        scope: 'publish_stream, email, user_birthday'
    });
}

(thanks to http://stackoverflow.com/questio... for inspiration)

Then we need to alter fbconnect login form in your theme's template.php (fbconnect module provides example):

/**
* Theme function for Facebook connect/login button.
*/
function THEMENAME_fbconnect_login_button($variables) {
  drupal_add_js(drupal_get_path('theme', 'YOURTHEMENAME') . '/js/fblogin.js', 'file');
  $op = $variables['op'];
  $user_profile = $variables['user_profile'];
  $text = $variables['text'];
  $attr = $variables['attr'];
  if ($op == 'login') {
    $title = t('Hello stranger');
    $desc = t('Login to this site using your Facebook credentials.');
    $link = l('<span class="fb_button_text">' . $text . '</span>', 'fbconnect/register/create', array('html' => TRUE, 'attributes' => array('class' => array('button button-blue fb_button fb_button_' . $attr['size']))));
    return '<h2>' . $title . '</h2>' . $desc . $link;
  }
  else {
    $attr['data-scope'] = "email";
    $button = '<fb:login-button ' . drupal_attributes($attr) . '>' . $text . '</fb:login-button>';
    return $button;
  }
}

Then you just have to style .button.button-blue with CSS to your liking. Say:

button,
a.button {
  color: #fff;
  padding: 5px 10px;
  white-space: nowrap;
  text-align: center;
  font: 300 16px Helvetica, sans-serif;
  float: left;
  border-radius: 3px;
}

button,
a.button:hover {
  text-decoration: none;
  cursor: pointer;
}

button,
.button-blue {
  background: -webkit-linear-gradient(top, #1574cc 0%, #1064af 100%) #1d7cdc;
  background: -moz-linear-gradient(top, #1574cc 0%, #1064af 100%) #1d7cdc;
  background: -ms-linear-gradient(top, #1574cc 0%, #1064af 100%) #1d7cdc;
  background: linear-gradient(to bottom, #1574cc 0%, #1064af 100%) #1d7cdc;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#1574cc', endColorstr='#1064af');
  border: none;
  color: #fff;
}

button:hover,
.button-blue:hover {
  background: -webkit-linear-gradient(top, #1574cc 0%, #094f8e 100%) #1d7cdc;
  background: -moz-linear-gradient(top, #1574cc 0%, #094f8e 100%) #1d7cdc;
  background: -ms-linear-gradient(top, #1574cc 0%, #094f8e 100%) #1d7cdc;
  background: linear-gradient(to bottom, #1574cc 0%, #094f8e 100%) #1d7cdc;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#1574cc', endColorstr='#094f8e');
  border: none;
  color: #fff;
}

That's it and hope it was helpful.

Bạn thấy bài viết này như thế nào?: 
Average: 5 (1 vote)
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
OSTraining sẽ xuất bản 200 Drupal 8 Videos miễn phí

OSTraining sẽ xuất bản 200 Drupal 8 Videos miễn phí

Yes, you read that right: we're going to release 200 free Drupal 8 videos.

Hướng dẫn update cho theme trong Drupal

Hướng dẫn update cho theme trong Drupal

In the example below, we have version 7.x.-1.0 of the Zero Point theme on our site.

Giới thiệu module Organic Groups trong Drupal 6

Giới thiệu module Organic Groups trong Drupal 6

OG allows users to create and manage their own groups. Other members can then join those groups and share content either privately or publicly.

Công ty diệt chuột T&C

 

Diet con trung