/* * 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 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 += '