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

 
Number 4: Infrastructure - 5 lỗi cần tránh trong Drupal

Number 4: Infrastructure - 5 lỗi cần tránh trong Drupal

In previous articles in this series, we’ve covered the areas of architecture, security and performance. All of these aspects are affected by your infrastructure from the time of development to deployment.

Hướng dẫn cài đặt Mac OS X 10.4.3 trên PC Intel

Hướng dẫn cài đặt Mac OS X 10.4.3 trên PC Intel

Trong bài viết này chúng tôi sẽ giới thiệu cho các bạn cách cài đặt Apple Mac OS X 10.4.3 trên các máy tính Intel. Trước hết bạn cần thực hiện kiểm tra danh sách phần cứng tương thích (HCL - Hardware Compatibility List)

Hướng dẫn gửi dữ liệu đi bằng Curl post

Hướng dẫn gửi dữ liệu đi bằng Curl post

Ở bài viết này mình sẽ hướng dẫn các bạn sử dụng curl để gửi dữ liệu sang một site khác. cái này khó ở phần thiết lập các thuộc tính curl_setopt thôi nhưng không sao đừng có nản  mình sẽ cung cấp cho các bạn một function mà mình đã làm sẵn các bạn chỉ cần sử dụng function đó và chạy thui ...

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

 

Diet con trung