1/*
2 * jquery.socialshareprivacy.js
3 *
4 * Copyright (c) 2012 Mathias Panzenböck
5 *
6 * is released under the MIT License http://www.opensource.org/licenses/mit-license.php
7 *
8 * Code inspired by Delicious Button v1.1:
9 * http://code.google.com/p/delicious-button/
10 */
11(function ($, undefined) {
12	"use strict";
13
14	$.fn.socialSharePrivacy.settings.services.delicious = {
15		'status'            : true,
16		'dummy_line_img'    : 'images/dummy_delicious.png',
17		'dummy_box_img'     : 'images/dummy_box_delicious.png',
18		'dummy_alt'         : '"Delicious"-Dummy',
19		'txt_info'          : 'Two clicks for more privacy: The Delicious button will be enabled once you click here. Activating the button already sends data to Delicious &ndash; see <em>i</em>.',
20		'txt_off'           : 'not connected to Delicious',
21		'txt_on'            : 'connected to Delicious',
22		'perma_option'      : true,
23		'display_name'      : 'Delicious',
24		'txt_button'        : 'Save',
25		'referrer_track'    : '',
26		'title'             : $.fn.socialSharePrivacy.getTitle,
27		'button'            : function (options, uri, settings) {
28			var $button = $('<div class="delicious-widget"/>');
29			var url = uri + options.referrer_track;
30
31			$.ajax({
32				url: "http://feeds.delicious.com/v2/json/urlinfo/data",
33				data: {url: url},
34				dataType: "jsonp",
35				success: function (counts) {
36					var hash, total_posts, title, txt_button;
37					for (var i = 0; i < counts.length; ++ i) {
38						var count = counts[i];
39						if (count.url === url) {
40							total_posts = parseInt(count.total_posts, 10);
41							hash = count.hash;
42							title = count.title;
43							break;
44						}
45					}
46					if (total_posts) txt_button = $.fn.socialSharePrivacy.formatNumber(total_posts);
47					else txt_button = options.txt_button;
48					var save_url = "http://delicious.com/save?"+$.param({
49						v:     "5",
50						url:   url,
51						title: (typeof options.title === "function" ?
52							options.title.call(this, options, uri, settings) :
53							String(options.title)) || title
54					});
55
56					$button.html('<a target="delicious" class="icon"><div class="delicious1"></div><div class="delicious2"></div><div class="delicious3"></div></a><a class="count" target="delicious"><i></i><b></b></a>');
57					$button.find('i').text(options.txt_button);
58					$button.find('b').text(txt_button);
59					$button.find('a.icon').attr("href", hash ? "http://delicious.com/url/" + hash : save_url);
60					var $count = $button.find('a.count').attr("href", save_url).click(function (event) {
61						window.open(save_url + "&noui&jump=close", "delicious", "toolbar=no,width=555,height=555");
62						event.preventDefault();
63					});
64
65					if (total_posts) {
66						$count.hover(function () {
67							var $self = $(this);
68							$self.find("b").stop(1, 1).css("display", "none");
69							$self.find("i").fadeIn();
70						}, function () {
71							var $self = $(this);
72							$self.find("i").stop(1, 1).css("display", "none");
73							$self.find("b").fadeIn();
74						});
75					}
76				}
77			});
78
79			return $button;
80		}
81	};
82})(jQuery);
83