/** * jQuery Hatenabookmark Entry Plugin * http://code.google.com/p/jquery-hatenabookmark-entry/ * * Copyright (c) 2009 Yusuke Horie * * Released under the MIT License: * http://www.opensource.org/licenses/mit-license.php * * Since : 0.1.0 - 08/13/2009 * Version: 0.2.0 - 09/14/2009 */ (function(jQuery){ var _baseUrl = 'http://b.hatena.ne.jp'; var _endPoint = ['/entry/json/', '/entry/jsonlite/']; /** public methods **/ jQuery.fn.hatenaEntry = function (url, a) { var c, opts = {}; if (jQuery.isFunction(a)) { c = a; } else if (typeof a == 'object') { opts = jQuery.extend({}, jQuery.fn.hatenaEntry.defaults, a); c = jQuery.isFunction(opts.callback) ? opts.callback: _callback; } else if (typeof a == 'undefined') { opts = jQuery.fn.hatenaEntry.defaults; c = _callback; } else { return this; } var endPoint = (opts.useJsonlite) ? _endPoint[1]: _endPoint[0]; return this.each(function(i, e) { jQuery.getJSON(_baseUrl + endPoint + '?url=' + encodeURIComponent(url) + '&callback=?', function (o) { if ($.isFunction(opts.onLoad)) opts.onLoad.call(e, o); c.apply(this, [o, e, opts]); } ); }); }; jQuery.fn.hatenaEntry.defaults = { callback: null, icon: true, username: true, tags: true, comment: true, timestamp: true, useJsonlite: false, headerBgColor: '#2C6EBD', headerColor: '#ffffff', userColor: '#0000DD', tagColor: '#6666cc', timeColor: '#666666', limit: 7, headerLabel: 'ブックマークしているユーザー', onLoad: null }; jQuery.extend({ hatenaEntry: function (url, a) { var c = jQuery.isFunction(a) ? a: _callback; jQuery.getJSON(_baseUrl + '?url=' + encodeURIComponent(url) + '&callback=?', function (o) { var args = [o]; if (typeof a == 'string') args.push($(a).get()); args.push(jQuery.fn.hatenaEntry.defaults); c.apply(this, args); }); } }); /** private method **/ var _callback = function (o, e, opts) { var $this = $(e); if (!o || $this.length == 0) return false; $this.data('_inc', 1); var h = '