/*
* jQuery SocialMediaBtns Plugin
*
* Copyright (c) 2011 TORU KOKUBUN (http://d-s-b.jp/)
* Licensed under MIT Lisence:
* http://www.opensource.org/licenses/mit-license.php
* http://sourceforge.jp/projects/opensource/wiki/licenses%2FMIT_license
*
* Last Modified: 2011-04-22
* version: 1.00
*
* This program checked the oparation on jQuery 1.5.2.
*
*/
(function($){
$.fn.SocialMediaBtns = function( options ) {
var opts = $.extend( {}, $.fn.SocialMediaBtns.defaults, options );
var defs = $.fn.SocialMediaBtns.defines;
return this.each(function(){
/* -------------------------------------------------------------------------
Properties
-------------------------------------------------------------------------- */
var $self = this;
var margin_h = opts.margin_h ;
var margin_v = opts.margin_v ;
var align = opts.align;
var btn_align = ( align == 'left') ? 'padding-right' : 'padding-left';
var span_style = btn_align + ': ' + margin_h + 'px;';
var url = ( opts.url ) ? opts.url : location.href;
var title = ( opts.title ) ? opts.title : document.title;
// Twitter Properties
var tw = opts.twitter;
var tw_count = ( tw['count'] ) ? tw['count'] : 'none';
var tw_lang = ( tw['lang'] ) ? tw['lang'] : 'ja';
var tw_via = ( tw['via'] ) ? tw['via'] : '';
var tw_url = url;
var tw_text = ( tw['text'] ) ? tw['text'] : title;
// Facebook Properties
var fb = opts.facebook;
var fb_url = '';
var fb_layout = ( fb['layout'] ) ? fb['layout'] : 'button_count';
var fb_show_face = ( fb['show_face'] ) ? fb['show_face'] : true;
var fb_colorscheme = ( fb['colorscheme'] ) ? fb['colorscheme'] : 'light';
var fb_width = ( fb['width'] ) ? fb['width'] : '';
var fb_height = ( fb['height'] ) ? fb['height'] : '';
var fb_sizes = defs.facebook.sizes;
// Hatena Bookmark Properties
var hatena = opts.hatena;
var hatena_url = '';
var hatena_layout = ( hatena['layout'] ) ? hatena['layout'] : 'standard';
var hatena_title = title;
// Yahoo! Bookmark Properties
var yahoo = defs.yahoo;
var yahoo_type = ( opts.yahoo.type ) ? opts.yahoo.type : 'type_a';
var yahoo_url = '';
var yahoo_title = '';
// livedoor Clip Properties
var livedoor = defs.livedoor;
var livedoor_type = ( opts.livedoor.type ) ? opts.livedoor.type : 'type_a';
var livedoor_url = url;
var livedoor_title = '';
// del.icio.us Properties
var delicious_url = '';
var delicious_title = '';
// Evernote Properties
var evernote = defs.evernote;
var evernote_type = ( opts.evernote.type ) ? opts.evernote.type : 'type_g';
var evernote_content_id = ( opts.evernote.content_id ) ? "contentId:'" + opts.evernote.content_id + "'" : '';
// mixi Check Properties
var mixi_dev_key = ( opts.mixi_dev_key ) ? opts.mixi_dev_key : '';
var mixi_check_type = ( !opts.mixi_check.type ) ? opts.mixi_check.type : 'button-1';
fb_url = yahoo_url = delicious_url = encodeURIComponent( url );
hatena_url = escape( url );
yahoo_title = delicious_title = encodeURIComponent( title );
livedoor_title = escape( title );
/* -------------------------------------------------------------------------
Initialize
-------------------------------------------------------------------------- */
init();
/* -------------------------------------------------------------------------
Function
-------------------------------------------------------------------------- */
// initialize
function init(){
$($self).css({ textAlign: opts.align });
var str = opts.btn_set;
str = str.replace(/ /g,"");
var arr = str.split(',');
for(var i in arr){
switch (arr[i]){
case 'tw':
createBtnTw( tw_count, tw_lang, tw_url, tw_text, tw_via );
break;
case 'fb':
createBtnFb( fb_layout, fb_url, fb_show_face, fb_colorscheme );
break;
case 'hatena':
createBtnHatena( hatena_layout, hatena_url, hatena_title );
break;
case 'yahoo':
createBtnYahoo( yahoo_type, yahoo_url, yahoo_title );
break;
case 'livedoor':
createBtnLivedoor( livedoor_type, livedoor_url, livedoor_title );
break;
case 'delicious':
createBtnDelicious( delicious_url, delicious_title );
break;
case 'evernote':
createBtnEvernote( evernote_type, evernote_content_id );
break;
case 'mixi_check':
if( mixi_dev_key ){
createBtnMixiCheck( mixi_dev_key, mixi_check_type );
}
break;
}
}
};
// Create Twitter Btn
function createBtnTw( count, lang, url, text, via ){
var tpl = '';
tpl += '';
var script = '';
$($self).append('');
var obj_span = $('span.btn-twitter', $self);
obj_span.attr({ style: span_style })
.append( tpl )
.append( script );
};
// Create Facebook Like/Share Btn
function createBtnFb( layout, url, show_face, colorscheme ){
var w = ( fb_width ) ? fb_width : fb_sizes[ layout ].width;
var h = ( fb_height ) ? fb_height : fb_sizes[ layout ].height;
var tpl = '';
tpl += '';
$($self).append('');
var obj_span = $('span.btn-facebook', $self);
obj_span.attr({ style: span_style })
.append( tpl );
};
// Create HatenaBookmark Btn
function createBtnHatena( layout, url, title ){
var tpl = '';
tpl += '';
tpl += '';
var script = '';
$($self).append('');
var obj_span = $('span.btn-hatena', $self);
obj_span.attr({ style: span_style })
.append( tpl )
.children('a').append('
');
var obj_img = $('span.btn-hatena > a > img', $self);
obj_img.attr({
src: 'https://b.st-hatena.com/images/entry-button/button-only.gif',
alt: 'はてなブックマークに追加',
width: 20,
height: 20,
style: 'border:none;'
});
obj_span.append( script );
};
// Create Yahoo! Bookmark Btn
function createBtnYahoo( type, url, title ){
var href = '';
href += ( type == 'type_a' || type == 'type_b' ) ? "javascript:void window.open('https://bookmarks.yahoo.co.jp/bookmarklet/showpopup?t=" : "javascript:location.href='https://bookmarks.yahoo.co.jp/action/bookmark?t=";
href += title + '&u=' + url;
href += ( type == 'type_a' || type == 'type_b' ) ? "&ei=UTF-8','_blank','width=550,height=480,left=100,top=50,scrollbars=1,resizable=1',0);" : "';";
var tpl = '';
tpl += '';
$($self).append('');
var obj_span = $('span.btn-yahoo', $self)
obj_span.attr({ style: span_style })
.append( tpl )
.children('a').append('
');
var icon_type = '';
icon_type = ( type == 'type_a' || type == 'type_c' ) ? 'icon_l' : 'icon_s' ;
var obj_img = $('span.btn-yahoo > a > img', $self);
obj_img.attr({
src: 'https://i.yimg.jp/images/' + yahoo[ icon_type ].src,
alt: 'Yahoo!ブックマークに登録',
width: yahoo[ icon_type ].img_w,
height: yahoo[ icon_type ].img_h,
style: 'border:none;'
});
};
// Create livedoor Clip Btn
function createBtnLivedoor( type, url, title ){
var tpl = '';
tpl += '';
tpl += '';
$($self).append('');
var obj_span = $('span.btn-livedoor', $self)
obj_span.attr({ style: span_style })
.append( tpl )
.children('a').append('
');
var obj_img = $('span.btn-livedoor > a > img', $self);
obj_img.attr({
src: 'https://parts.blog.livedoor.jp/img/cmn/' + livedoor[ type ].src,
width: livedoor[ type ].img_w,
height: livedoor[ type ].img_h,
alt: 'この記事をクリップ!',
style: 'border: none;'
});
};
// Create Delicious Btn
function createBtnDelicious( url, title ){
var tpl = '';
tpl += '';
$($self).append('');
var obj_span = $('span.btn-delicious', $self)
obj_span.attr({ style: span_style })
.append( tpl )
.children('a').append('
');
var obj_img = $('span.btn-delicious > a > img', $self);
obj_img.attr({
src: 'https://l.yimg.com/hr/img/delicious.gif',
width: 16,
height: 16,
alt: 'del.icio.usに追加',
style: 'border: none;'
});
};
// Create Evernote Btn
function createBtnEvernote( type, content_id ){
var tpl = '';
tpl += '';
tpl += '';
tpl += '';
$($self).append('');
var obj_span = $('span.btn-evernote', $self)
obj_span.attr({ style: span_style })
.append( tpl )
.children('a').append('
');
var obj_img = $('span.btn-evernote > a > img', $self);
obj_img.attr({
src: 'https://static.evernote.com/' + evernote[ type ].src,
alt: 'Evernoteにクリップ',
style: 'border: none;'
});
};
// Create mixi Check Btn
function createBtnMixiCheck( dev_key, type ){
var tpl = '';
tpl += 'mixiチェック';
tpl += '';
$($self).append('');
var obj_span = $('span.btn-mixi-check', $self)
obj_span.attr({ style: span_style })
.append( tpl );
}
});
};
/* -------------------------------------------------------------------------
set default options
-------------------------------------------------------------------------- */
$.fn.SocialMediaBtns.defaults = {
margin_h: 5,
margin_v: 2,
url: null,
title: null,
btn_set: 'yahoo, livedoor, delicious, evernote, hatena, mixi_check, tw, fb',
align: 'left',
twitter: {
count: 'none',
lang: 'ja',
via: null,
text: null
},
facebook: {
layout: 'button_count',
show_face: true,
colorscheme: 'light',
width: 120,
height: 21
},
hatena: {
layout: 'simple'
},
yahoo: {
type: 'type_d'
},
livedoor: {
type: 'type_a'
},
evernote: {
type: 'type_g',
content_id: null
},
mixi_dev_key: null,
mixi_check: {
type: 'button-1'
}
};
$.fn.SocialMediaBtns.defines = {
facebook: {
sizes: {
standard: {
width: 450,
height: 80
},
button_count: {
width: 90,
height: 20
},
box_count: {
width: 55,
height: 65
}
}
},
yahoo: {
icon_l: {
src: 'ybm/blogparts/addmy_btn.gif',
img_w: 125,
img_h: 17
},
icon_s: {
src: 'sicons/ybm16.gif',
img_w: 16,
img_h: 16
}
},
livedoor: {
type_a: {
src: 'clip_16_16_w.gif',
img_w: 16,
img_h: 16
},
type_b: {
src: 'clip_16_16_b.gif',
img_w: 16,
img_h: 16
},
type_c: {
src: 'clip_16_12_w.gif',
img_w: 16,
img_h: 12
},
type_d: {
src: 'clip_16_12_b.gif',
img_w: 16,
img_h: 12
}
},
evernote: {
type_a: { src: 'article-clipper.png' },
type_b: { src: 'article-clipper-jp.png' },
type_c: { src: 'article-clipper-vert.png' },
type_d: { src: 'site-mem-36.png' },
type_e: { src: 'site-mem-32.png' },
type_f: { src: 'site-mem-22.png' },
type_g: { src: 'site-mem-16.png' }
}
};
})(jQuery);