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.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / assets / lib / SocialShare / SocialShare.js
tutor / assets / lib / SocialShare Last commit date
SocialShare.js 11 months ago SocialShare.min.js 11 months ago
SocialShare.js
145 lines
1 /**
2 * SocialShare - jQuery plugin
3 */
4 (function ($) {
5
6 function get_class_list(elem){
7 if(elem.classList){
8 return elem.classList;
9 }else{
10 return $(elem).attr('class').match(/\S+/gi);
11 }
12 }
13
14 $.fn.ShareLink = function(options){
15 var defaults = {
16 title: '',
17 text: '',
18 image: '',
19 url: window.location.href,
20 class_prefix: 's_'
21 };
22
23 var options = $.extend({}, defaults, options);
24
25 var class_prefix_length = options.class_prefix.length;
26
27 var templates = {
28 twitter: 'https://twitter.com/intent/tweet?url={url}&text={text}',
29 pinterest: 'https://www.pinterest.com/pin/create/button/?media={image}&url={url}&description={text}',
30 facebook: 'https://www.facebook.com/sharer/sharer.php?u={url}',
31 linkedin: 'https://www.linkedin.com/shareArticle?url={url}&title={title}',
32 reddit: 'https://www.reddit.com/submit?url={url}&title={title}',
33 whatsapp: 'https://api.whatsapp.com/send?text={url} {title}',
34 email: 'mailto:?subject={title}&body={url}'
35 }
36
37 function link(network){
38 var url = templates[network];
39 url = url.replace(/{url}/g, encodeURIComponent(options.url));
40 url = url.replace(/{title}/g, encodeURIComponent(options.title));
41 url = url.replace(/{text}/g, encodeURIComponent(options.text));
42 url = url.replace(/{image}/g, encodeURIComponent(options.image));
43 return url;
44 }
45
46 return this.each(function(i, elem){
47 var classlist = get_class_list(elem);
48 for(var i = 0; i < classlist.length; i++){
49 var cls = classlist[i];
50 if(cls.substr(0, class_prefix_length) == options.class_prefix && templates[cls.substr(class_prefix_length)]){
51 var final_link = link(cls.substr(class_prefix_length));
52 $(elem).attr('href', final_link).click(function(){
53 if($(this).attr('href').indexOf('http://') === -1 && $(this).attr('href').indexOf('https://') === -1){
54 return window.open($(this).attr('href')) && false;
55 }
56 var screen_width = screen.width;
57 var screen_height = screen.height;
58 var popup_width = options.width ? options.width : (screen_width - (screen_width*0.2));
59 var popup_height = options.height ? options.height : (screen_height - (screen_height*0.2));
60 var left = (screen_width/2)-(popup_width/2);
61 var top = (screen_height/2)-(popup_height/2);
62 var parameters = 'toolbar=0,status=0,width=' + popup_width + ',height=' + popup_height + ',top=' + top + ',left=' + left;
63 return window.open($(this).attr('href'), '', parameters) && false;
64 });
65 }
66 }
67 });
68 }
69
70 $.fn.ShareCounter = function(options){
71 var defaults = {
72 url: window.location.href,
73 class_prefix: 'c_',
74 display_counter_from: 0,
75 increment: false
76 };
77
78 var options = $.extend({}, defaults, options);
79
80 var class_prefix_length = options.class_prefix.length
81
82 var social = {
83 'linkedin': linkedin,
84 'facebook': facebook,
85 'pinterest': pinterest
86 }
87
88 return this.each(function(i, elem){
89 var classlist = get_class_list(elem);
90 for(var i = 0; i < classlist.length; i++){
91 var cls = classlist[i];
92 if(cls.substr(0, class_prefix_length) == options.class_prefix && social[cls.substr(class_prefix_length)]){
93 social[cls.substr(class_prefix_length)](options.url, function(count){
94 count = parseInt(count);
95 if (count >= options.display_counter_from){
96 var current_value = parseInt($(elem).text());
97 if(options.increment && !isNaN(current_value)){
98 count += current_value;
99 }
100 $(elem).text(count);
101 }
102 })
103 }
104 }
105 });
106
107 function linkedin(url, callback){
108 $.ajax({
109 type: 'GET',
110 dataType: 'jsonp',
111 url: 'https://www.linkedin.com/countserv/count/share',
112 data: {'url': url, 'format': 'jsonp'}
113 })
114 .done(function(data){callback(data.count)})
115 .fail(function(){callback(0)})
116 }
117
118 function facebook(url, callback){
119 $.ajax({
120 type: 'GET',
121 dataType: 'jsonp',
122 url: 'https://graph.facebook.com',
123 data: {'id': url}
124 })
125 .done(function (data){
126 if(data.share != undefined && data.share.share_count != undefined){
127 callback(data.share.share_count)
128 }
129 })
130 .fail(function(){callback(0)})
131 }
132
133 function pinterest(url, callback){
134 $.ajax({
135 type: 'GET',
136 dataType: 'jsonp',
137 url: 'https://api.pinterest.com/v1/urls/count.json',
138 data: {'url': url}
139 })
140 .done(function(data){callback(data.count)})
141 .fail(function(){callback(0)})
142 }
143 }
144 })(jQuery);
145