/* ------------------------------------------------------------------------- */
/*
* smb.js
*
* Copyright (c) 2011, clown.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - No names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* ------------------------------------------------------------------------- */
var smb = new function() {
/* --------------------------------------------------------------------- */
// variables
/* --------------------------------------------------------------------- */
var horizontal = 7; // ソーシャルボタン間の水平方向のマージン
var vertical = 2; // 小さなボタンを上下中央に揃えるためのマージン
/* --------------------------------------------------------------------- */
// kinds
/* --------------------------------------------------------------------- */
var kinds = {
twitter : 0x0001, // http://twitter.com/
facebook : 0x0002, // http://www.facebook.com/
hatena : 0x0004, // http://b.hatena.ne.jp/
hatena_old : 0x0008, // http://b.hatena.ne.jp/
delicious : 0x0010, // http://www.delicious.com/
livedoor : 0x0020, // http://clip.livedoor.com/
yahoo : 0x0040, // http://bookmarks.yahoo.co.jp/
buzzurl : 0x0080, // http://buzzurl.jp/
evernote : 0x0100, // http://www.evernote.com/
newsing : 0x0200, // http://newsing.jp/
gree : 0x0400, // http://gree.jp/
nifty : 0x0800, // サービス終了
atode : 0x1000, // http://news.atode.cc/
google : 0x2000, // http://www.google.com/bookmarks/
tumblr : 0x4000, // http://www.tumblr.com/
google_plus1 : 0x8000, // http://www.google.com/webmasters/+1/button/
};
/* --------------------------------------------------------------------- */
// options
/* --------------------------------------------------------------------- */
var options = {
detail : 0x0001, // カウント値も併せて表示
showentry : 0x0002 // クリック時に該当サービスのエントリーページを開く
};
/* --------------------------------------------------------------------- */
// escape
/* --------------------------------------------------------------------- */
var escape = function(str) {
return str.replace(/<|>|&|'|"|\s/g, function(s){
var map = {"<":"<", ">":">", "&":"&", "'":"'", "\"":""", " ":" "};
return map[s];
});
};
/* --------------------------------------------------------------------- */
/*
* md5
*
* CybozuLabs.MD5 を利用して MD5 ハッシュ値を計算する.
* ロードされなかった場合は,空文字列を返す.
* http://labs.cybozu.co.jp/blog/mitsunari/2007/07/md5js_1.html
*/
/* --------------------------------------------------------------------- */
var md5 = function(str) {
var defined = (typeof CybozuLabs != "undefined") && (typeof CybozuLabs.MD5 != "undefined") && (typeof CybozuLabs.MD5.calc != "undefined");
return defined ? CybozuLabs.MD5.calc(str) : "";
};
/* --------------------------------------------------------------------- */
/*
* show_google_plus1
*/
/* --------------------------------------------------------------------- */
var show_google_plus1 = function(option) {
var count = ((option & options.detail) != 0) ? "true" : "false";
document.write('');
document.write('');
document.write('');
if ((option & options.detail) == 0) document.write('');
};
/* --------------------------------------------------------------------- */
/*
* show_twitter
*
* Twitter のソーシャルボタンを表示する.
* http://twitter.com/goodies/tweetbutton
*/
/* --------------------------------------------------------------------- */
var show_twitter = function(option) {
var count = ((option & options.detail) != 0) ? "horizontal" : "none";
document.write('');
document.write('');
if ((option & options.detail) == 0) document.write('');
};
/* --------------------------------------------------------------------- */
/*
* show_tumblr
*
* Tumblr のソーシャルボタン(「いいね!」ボタン)を表示する.
* NOTE: Tumblr はカウントの非表示が効かない.
* http://www.tumblr.com/docs/ja/share_button
*/
/* --------------------------------------------------------------------- */
var show_tumblr = function(option) {
var image = ((option & options.detail) != 0) ? 'share_2.png' : 'share_4.png';
var width = ((option & options.detail) != 0) ? 62 : 20;
document.write(' ');
document.write('');
document.write('');
}
/* --------------------------------------------------------------------- */
/*
* show_facebook
*
* Facebook のソーシャルボタン(「いいね!」ボタン)を表示する.
* NOTE: Facebook はカウントの非表示が効かない.
* http://developers.facebook.com/docs/reference/plugins/like/
*/
/* --------------------------------------------------------------------- */
var show_facebook = function(option) {
document.write('');
document.write('');
};
/* --------------------------------------------------------------------- */
/*
* show_gree
*
* GREE の Social Feedback ボタンを表示する.
* NOTE: GREE はカウントの表示機能が存在しない?
* http://developer.gree.co.jp/connect/plugins/sf
*/
/* --------------------------------------------------------------------- */
var show_gree = function(option) {
var type = ((option & options.detail) != 0) ? 0 : 4;
var width = ((option & options.detail) != 0) ? 70 : 16;
var height = ((option & options.detail) != 0) ? 20 : 16;
var bottom = ((option & options.detail) != 0) ? 0 : 2;
document.write('');
document.write('');
};
/* --------------------------------------------------------------------- */
/*
* show_google
*
* Google ブックマークボタンを表示する.
*/
/* --------------------------------------------------------------------- */
var show_google = function(option) {
document.write('');
document.write('');
document.write('');
document.write('');
}
/* --------------------------------------------------------------------- */
/*
* show_hatena
*
* はてなブックマークボタンを表示する.
* http://b.hatena.ne.jp/guide/bbutton
*/
/* --------------------------------------------------------------------- */
var show_hatena = function(option) {
var count = ((option & options.detail) != 0) ? "standard" : "simple";
var link = ((option & options.showentry) != 0) ?
"http://b.hatena.ne.jp/entry/" :
"http://b.hatena.ne.jp/entry/add/";
var title = ((option & options.showentry) != 0) ?
"このエントリーを含むはてブックマーク" :
"このエントリーをはてなブックマークに追加";
document.write('');
document.write('');
document.write('');
document.write('');
document.write('');
};
/* --------------------------------------------------------------------- */
/*
* show_hatena_old
*
* 旧タイプのはてなブックマークボタンを表示する.
*/
/* --------------------------------------------------------------------- */
var show_hatena_old = function(option) {
var uri = escape(location.href);
var link = ((option & options.showentry) != 0) ?
"http://b.hatena.ne.jp/entry/" + uri:
"http://b.hatena.ne.jp/entry/add/" + uri;
var image = ((option & options.showentry) != 0) ?
"http://b.hatena.ne.jp/images/entry.gif" :
"http://b.hatena.ne.jp/images/append.gif";
var title = ((option & options.showentry) != 0) ?
"このエントリーを含むはてブックマーク" :
"このエントリーをはてなブックマークに追加";
document.write('');
document.write('');
document.write('');
if ((option & options.detail) != 0) {
document.write('');
document.write('');
document.write('');
document.write('');
}
document.write('');
};
/* --------------------------------------------------------------------- */
/*
* show_evernote
*
* Evernote のソーシャルボタンを表示する.
* NOTE: Evernote はカウントの表示機能が存在しない.
* http://www.evernote.com/about/developer/sitememory/
*/
/* --------------------------------------------------------------------- */
var show_evernote = function(option) {
document.write('');
document.write('');
if ((option & options.detail) != 0) document.write('');
document.write('');
document.write('');
};
/* --------------------------------------------------------------------- */
/*
* show_delicious
*
* Delicious のブックマークボタンを表示する.
* NOTE: Delicious はカウントの表示機能が存在しない.
*/
/* --------------------------------------------------------------------- */
var show_delicious = function(option) {
if ((option & options.showentry) != 0) {
document.write('');
}
else {
document.write('');
}
var image = "http://l.yimg.com/hr/img/delicious16.gif";
var title = ((option & options.showentry) != 0) ?
"このエントリーを含む delicious ブックマーク" :
"このエントリーを delicious に追加";
document.write('');
document.write('');
document.write('');
};
/* --------------------------------------------------------------------- */
/*
* show_livedoor
*
* livedoor クリップのクリップボタンを表示する.
*/
/* --------------------------------------------------------------------- */
var show_livedoor = function(option) {
var uri = escape(location.href);
var link = ((option & options.showentry) != 0) ?
"http://clip.livedoor.com/page/" + uri :
"http://clip.livedoor.com/clip/add?link=" + encodeURIComponent(location.href);
var image = "http://parts.blog.livedoor.jp/img/cmn/clip_16_16_w.gif";
var title = ((option & options.showentry) != 0) ?
"このエントリーを含む livedoor クリップ" :
"このエントリーを livedoor クリップに追加";
document.write('');
document.write('');
document.write('');
if ((option & options.detail) != 0) {
document.write('');
document.write('');
document.write('');
document.write('');
}
document.write('');
};
/* --------------------------------------------------------------------- */
/*
* show_buzzurl
*
* Buzzurl のブックマークボタンを表示する.
*/
/* --------------------------------------------------------------------- */
var show_buzzurl = function(option) {
var uri = escape(location.href);
var link = ((option & options.showentry) != 0) ?
"http://buzzurl.jp/entry/" + uri :
"http://buzzurl.jp/config/add/confirm?url=" + encodeURIComponent(location.href);
var image = ((option & options.showentry) != 0) ?
"http://buzzurl.jp/favicon.ico" :
"http://buzzurl.jp.eimg.jp/static/image/api/icon/add_icon_mini_08.gif";
var title = ((option & options.showentry) != 0) ?
"このエントリーを含む Buzzurl ブックマーク" :
"このエントリーを Buzzurl に追加";
document.write('');
document.write('');
document.write('');
if ((option & options.detail) != 0) {
document.write('');
document.write('');
document.write('');
document.write('');
}
document.write('');
};
/* --------------------------------------------------------------------- */
/*
* show_yahoo
*
* Yahoo! ブックマークのブックマークボタンを表示する.
*/
/* --------------------------------------------------------------------- */
var show_yahoo = function(option) {
var uri = escape(location.href);
if ((option & options.showentry) != 0) {
document.write('');
}
else {
document.write('');
}
var image = "http://i.yimg.jp/images/sicons/ybm16.gif";
var title = ((option & options.showentry) != 0) ?
"このエントリーを含む Yahoo! ブックマーク" :
"このエントリーを Yahoo! ブックマークに追加";
document.write('');
document.write('');
if ((option & options.detail) != 0) {
document.write('');
document.write('');
document.write('');
document.write('');
}
document.write('');
};
/* --------------------------------------------------------------------- */
/*
* show_newsing
*
* Delicious のピックアップボタンを表示する.
* NOTE: newsing はカウントの表示機能が存在しない?
*/
/* --------------------------------------------------------------------- */
var show_newsing = function(option) {
var uri = encodeURIComponent(location.href);
if ((option & options.showentry) != 0) {
document.write('');
}
else {
document.write('');
}
//var image = "http://image.newsing.jp/common/images/newsingit/newsingit_s.gif";
var image = "http://image.newsing.jp/common/images/newsingit/newsing_button_16.gif";
var title = ((option & options.showentry) != 0) ?
"このエントリーを含む newsing" :
"このエントリーを newsing でピックアップ";
document.write('');
document.write('');
document.write('');
};
/* --------------------------------------------------------------------- */
/*
* show_atode
*
* あとで新聞のブックマークボタンを表示する.
* NOTE: あとで新聞用のボタン画像を取りあえず favicon.ico から取得
* している.正式なボタン画像を探す.
*/
/* --------------------------------------------------------------------- */
var show_atode = function(option) {
if ((option & options.showentry) != 0) {
document.write('');
document.write('');
document.write('');
}
else {
document.write('');
var image = ((option & options.detail) != 0) ?
"http://atode.cc/img/iconnja.gif" :
"http://atode.cc/img/iconsja.gif";
var title = "このエントリーをあとで読む";
var width = ((option & options.detail) != 0) ? 66 : 16;
var height = ((option & options.detail) != 0) ? 20 : 16;
var bottom = ((option & options.detail) != 0) ? 0 : vertical;
document.write('');
document.write('');
}
document.write('');
};
/* --------------------------------------------------------------------- */
// public variables/functions
/* --------------------------------------------------------------------- */
var public = {
/* ----------------------------------------------------------------- */
// version
/* ----------------------------------------------------------------- */
version : "0.1.3",
/* ----------------------------------------------------------------- */
// kinds
/* ----------------------------------------------------------------- */
twitter : kinds.twitter,
facebook : kinds.facebook,
google : kinds.google,
hatena : kinds.hatena,
hatena_old : kinds.hatena_old,
delicious : kinds.delicious,
livedoor : kinds.livedoor,
yahoo : kinds.yahoo,
buzzurl : kinds.buzzurl,
nifty : kinds.nifty,
newsing : kinds.newsing,
atode : kinds.atode,
evernote : kinds.evernote,
gree : kinds.gree,
tumblr : kinds.tumblr,
google_plus1 : kinds.google_plus1,
/* ----------------------------------------------------------------- */
// options
/* ----------------------------------------------------------------- */
detail : options.detail,
showentry : options.showentry,
/* ----------------------------------------------------------------- */
/*
* show
*
* メイン関数.
*
* 引数 kind には twitter, facebook, hatena, hatena_old,
* delicious, livedoor, yahoo, buzzurl, evernote, newsing,
* gree のうち,表示したいものを | 演算子で繋げて指定する.
*/
/* ----------------------------------------------------------------- */
show : function(kind, option) {
var tmp = 0;
if (arguments.length == 2) {
// version 0.0.* との互換性を保つため.
if (typeof option == "boolean" && option == true) tmp = options.detail;
else tmp = option;
}
if ((kind & kinds.hatena_old) != 0) show_hatena_old(tmp);
if ((kind & kinds.google) != 0) show_google(tmp);
if ((kind & kinds.delicious) != 0) show_delicious(tmp);
if ((kind & kinds.livedoor) != 0) show_livedoor(tmp);
if ((kind & kinds.yahoo) != 0) show_yahoo(tmp);
if ((kind & kinds.buzzurl) != 0) show_buzzurl(tmp);
if ((kind & kinds.newsing) != 0) show_newsing(tmp);
if ((kind & kinds.atode) != 0 && ((tmp & options.detail) == 0 || (tmp & options.showentry) != 0)) show_atode(tmp);
if ((kind & kinds.evernote) != 0) show_evernote(tmp);
if ((kind & kinds.gree) != 0 && (tmp & options.detail) == 0) show_gree(tmp);
if ((kind & kinds.atode) != 0 && ((tmp & options.detail) != 0 && (tmp & options.showentry) == 0)) show_atode(tmp);
if ((kind & kinds.tumblr) != 0) show_tumblr(tmp);
if ((kind & kinds.hatena) != 0) show_hatena(tmp);
if ((kind & kinds.google_plus1) != 0) show_google_plus1(tmp);
if ((kind & kinds.twitter) != 0) show_twitter(tmp);
if ((kind & kinds.gree) != 0 && (tmp & options.detail) != 0) show_gree(tmp);
if ((kind & kinds.facebook) != 0) show_facebook(tmp);
}
};
return public;
}