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

 
Chạy sốt vó đăng kí sim số

Chạy sốt vó đăng kí sim số

Sau ngày 31/12, hai mạng Vinaphone và Mobifone sẽ thu hồi các SIM đã phát hành trước 1/8/2011 nhưng chưa kích hoạt, đưa về kho để tái sử dụng. Thông báo này đã khiến giới buôn bán SIM chạy sốt vó tìm cách đăng kí hàng trăm, thậm chí hàng ngàn SIM số đẹp của mình.

 
August's hottest apps to download

Best Apps 2011: This year's hottest apps

As the Apple App Store, Android Market and BlackBerry App World continue to swell, keeping an eye on the apps that are actually of any use remains a trickier task than ever.

công ty Snapseed

Google đã chính thức mua lại công ty Snapseed

Theo trang tin Cnet, vào ngày hôm qua, gã khổng lồ trong lĩnh vực tìm kiếm trực tuyến Google đã chính thức mua lại công ty đứng đằng sau ứng dụng chỉnh sửa và chia sẻ hình ảnh trên iOS Snapseed - một trong những đối thủ sừng sỏ của Instagram - nhằm mục tiêu cạnh tranh trực tiếp với Facebook.

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

 

Diet con trung