PageSourceSearch

https://arte.it/public/js/sharer.js

js arte.it collected 2026-10-02 02:56:08 UTC 15,337 bytes, 500 lines download raw bytes

vendor: 15,337 bytes, lines 1-500
1/**
2 * @preserve
3 * Sharer.js
4 *
5 * @description Create your own social share buttons
6 * @version 0.5.1
7 * @author Ellison Leao <[email protected]>
8 * @license MIT
9 *
10 */
11
12(function(window, document) {
13  'use strict';
14  /**
15   * @constructor
16   */
17  var Sharer = function(elem) {
18    this.elem = elem;
19  };
20
21  /**
22   *  @function init
23   *  @description bind the events for multiple sharer elements
24   *  @returns {Empty}
25   */
26  Sharer.init = function() {
27    var elems = document.querySelectorAll('[data-sharer]'),
28      i,
29      l = elems.length;
30
31    for (i = 0; i < l; i++) {
32      elems[i].addEventListener('click', Sharer.add);
33    }
34  };
35
36  /**
37   *  @function add
38   *  @description bind the share event for a single dom element
39   *  @returns {Empty}
40   */
41  Sharer.add = function(elem) {
42    var target = elem.currentTarget || elem.srcElement;
43    var sharer = new Sharer(target);
44    sharer.share();
45  };
46
47  // instance methods
48  Sharer.prototype = {
49    constructor: Sharer,
50    /**
51     *  @function getValue
52     *  @description Helper to get the attribute of a DOM element
53     *  @param {String} attr DOM element attribute
54     *  @returns {String|Empty} returns the attr value or empty string
55     */
56    getValue: function(attr) {
57      var val = this.elem.getAttribute('data-' + attr);
58      // handing facebook hashtag attribute
59      if (val && attr === 'hashtag') {
60        if (!val.startsWith('#')) {
61          val = '#' + val;
62        }
63      }
64      return val === null ? '' : val;
65    },
66
67    /**
68     * @event share
69     * @description Main share event. Will pop a window or redirect to a link
70     * based on the data-sharer attribute.
71     */
72    share: function() {
73      var sharer = this.getValue('sharer').toLowerCase(),
74        sharers = {
75          facebook: {
76            shareUrl: 'https://www.facebook.com/sharer/sharer.php',
77            params: {
78              u: this.getValue('url'),
79              hashtag: this.getValue('hashtag'),
80              quote: this.getValue('quote'),
81            },
82          },
83          linkedin: {
84            shareUrl: 'https://www.linkedin.com/shareArticle',
85            params: {
86              url: this.getValue('url'),
87              mini: true,
88            },
89          },
90          twitter: {
91            shareUrl: 'https://twitter.com/intent/tweet',
92            params: {
93              text: this.getValue('title'),
94              url: this.getValue('url'),
95              hashtags: this.getValue('hashtags'),
96              via: this.getValue('via'),
97              related: this.getValue('related'),
98              in_reply_to: this.getValue('in_reply_to'),
99            },
100          },
101          x: {
102            shareUrl: 'https://x.com/intent/tweet',
103            params: {
104              text: this.getValue('title'),
105              url: this.getValue('url'),
106              hashtags: this.getValue('hashtags'),
107              via: this.getValue('via'),
108              related: this.getValue('related'),
109              in_reply_to: this.getValue('in_reply_to'),
110            },
111          },
112          threads: {
113            shareUrl: 'https://threads.net/intent/post',
114            params: {
115              text: this.getValue('title') + ' ' + this.getValue('url'),
116            },
117          },
118          email: {
119            shareUrl: 'mailto:' + this.getValue('to'),
120            params: {
121              subject: this.getValue('subject'),
122              body: this.getValue('title') + '\n' + this.getValue('url'),
123            },
124          },
125          whatsapp: {
126            shareUrl: this.getValue('web') === 'true' ? 'https://web.whatsapp.com/send' : 'https://wa.me/',
127            params: {
128              phone: this.getValue('to'),
129              text: this.getValue('title') + ' ' + this.getValue('url'),
130            },
131          },
132          telegram: {
133            shareUrl: 'https://t.me/share',
134            params: {
135              text: this.getValue('title'),
136              url: this.getValue('url'),
137            },
138          },
139          viber: {
140            shareUrl: 'viber://forward',
141            params: {
142              text: this.getValue('title') + ' ' + this.getValue('url'),
143            },
144          },
145          line: {
146            shareUrl:
147              'http://line.me/R/msg/text/?' + encodeURIComponent(this.getValue('title') + ' ' + this.getValue('url')),
148          },
149          pinterest: {
150            shareUrl: 'https://www.pinterest.com/pin/create/button/',
151            params: {
152              url: this.getValue('url'),
153              media: this.getValue('image'),
154              description: this.getValue('description'),
155            },
156          },
157          tumblr: {
158            shareUrl: 'http://tumblr.com/widgets/share/tool',
159            params: {
160              canonicalUrl: this.getValue('url'),
161              content: this.getValue('url'),
162              posttype: 'link',
163              title: this.getValue('title'),
164              caption: this.getValue('caption'),
165              tags: this.getValue('tags'),
166            },
167          },
168          hackernews: {
169            shareUrl: 'https://news.ycombinator.com/submitlink',
170            params: {
171              u: this.getValue('url'),
172              t: this.getValue('title'),
173            },
174          },
175          reddit: {
176            shareUrl: 'https://www.reddit.com/submit',
177            params: { url: this.getValue('url'), title: this.getValue('title') },
178          },
179          vk: {
180            shareUrl: 'http://vk.com/share.php',
181            params: {
182              url: this.getValue('url'),
183              title: this.getValue('title'),
184              description: this.getValue('caption'),
185              image: this.getValue('image'),
186            },
187          },
188          xing: {
189            shareUrl: 'https://www.xing.com/social/share/spi',
190            params: {
191              url: this.getValue('url'),
192            },
193          },
194          buffer: {
195            shareUrl: 'https://buffer.com/add',
196            params: {
197              url: this.getValue('url'),
198              title: this.getValue('title'),
199              via: this.getValue('via'),
200              picture: this.getValue('picture'),
201            },
202          },
203          instapaper: {
204            shareUrl: 'http://www.instapaper.com/edit',
205            params: {
206              url: this.getValue('url'),
207              title: this.getValue('title'),
208              description: this.getValue('description'),
209            },
210          },
211          pocket: {
212            shareUrl: 'https://getpocket.com/save',
213            params: {
214              url: this.getValue('url'),
215            },
216          },
217          mashable: {
218            shareUrl: 'https://mashable.com/submit',
219            params: {
220              url: this.getValue('url'),
221              title: this.getValue('title'),
222            },
223          },
224          mix: {
225            shareUrl: 'https://mix.com/add',
226            params: {
227              url: this.getValue('url'),
228            },
229          },
230          flipboard: {
231            shareUrl: 'https://share.flipboard.com/bookmarklet/popout',
232            params: {
233              v: 2,
234              title: this.getValue('title'),
235              url: this.getValue('url'),
236              t: Date.now(),
237            },
238          },
239          weibo: {
240            shareUrl: 'http://service.weibo.com/share/share.php',
241            params: {
242              url: this.getValue('url'),
243              title: this.getValue('title'),
244              pic: this.getValue('image'),
245              appkey: this.getValue('appkey'),
246              ralateUid: this.getValue('ralateuid'),
247              language: 'zh_cn',
248            },
249          },
250          blogger: {
251            shareUrl: 'https://www.blogger.com/blog-this.g',
252            params: {
253              u: this.getValue('url'),
254              n: this.getValue('title'),
255              t: this.getValue('description'),
256            },
257          },
258          baidu: {
259            shareUrl: 'http://cang.baidu.com/do/add',
260            params: {
261              it: this.getValue('title'),
262              iu: this.getValue('url'),
263            },
264          },
265          douban: {
266            shareUrl: 'https://www.douban.com/share/service',
267            params: {
268              name: this.getValue('name'),
269              href: this.getValue('url'),
270              image: this.getValue('image'),
271              comment: this.getValue('description'),
272            },
273          },
274          okru: {
275            shareUrl: 'https://connect.ok.ru/dk',
276            params: {
277              'st.cmd': 'WidgetSharePreview',
278              'st.shareUrl': this.getValue('url'),
279              title: this.getValue('title'),
280            },
281          },
282          mailru: {
283            shareUrl: 'http://connect.mail.ru/share',
284            params: {
285              share_url: this.getValue('url'),
286              linkname: this.getValue('title'),
287              linknote: this.getValue('description'),
288              type: 'page',
289            },
290          },
291          evernote: {
292            shareUrl: 'https://www.evernote.com/clip.action',
293            params: {
294              url: this.getValue('url'),
295              title: this.getValue('title'),
296            },
297          },
298          skype: {
299            shareUrl: 'https://web.skype.com/share',
300            params: {
301              url: this.getValue('url'),
302              title: this.getValue('title'),
303            },
304          },
305          delicious: {
306            shareUrl: 'https://del.icio.us/post',
307            params: {
308              url: this.getValue('url'),
309              title: this.getValue('title'),
310            },
311          },
312          sms: {
313            shareUrl: 'sms://',
314            params: {
315              body: this.getValue('body'),
316            },
317          },
318          trello: {
319            shareUrl: 'https://trello.com/add-card',
320            params: {
321              url: this.getValue('url'),
322              name: this.getValue('title'),
323              desc: this.getValue('description'),
324              mode: 'popup',
325            },
326          },
327          messenger: {
328            shareUrl: 'fb-messenger://share',
329            params: {
330              link: this.getValue('url'),
331            },
332          },
333          odnoklassniki: {
334            shareUrl: 'https://connect.ok.ru/dk',
335            params: {
336              st: {
337                cmd: 'WidgetSharePreview',
338                deprecated: 1,
339                shareUrl: this.getValue('url'),
340              },
341            },
342          },
343          meneame: {
344            shareUrl: 'https://www.meneame.net/submit',
345            params: {
346              url: this.getValue('url'),
347            },
348          },
349          diaspora: {
350            shareUrl: 'https://share.diasporafoundation.org',
351            params: {
352              title: this.getValue('title'),
353              url: this.getValue('url'),
354            },
355          },
356          googlebookmarks: {
357            shareUrl: 'https://www.google.com/bookmarks/mark',
358            params: {
359              op: 'edit',
360              bkmk: this.getValue('url'),
361              title: this.getValue('title'),
362            },
363          },
364          qzone: {
365            shareUrl: 'https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey',
366            params: {
367              url: this.getValue('url'),
368            },
369          },
370          refind: {
371            shareUrl: 'https://refind.com',
372            params: {
373              url: this.getValue('url'),
374            },
375          },
376          surfingbird: {
377            shareUrl: 'https://surfingbird.ru/share',
378            params: {
379              url: this.getValue('url'),
380              title: this.getValue('title'),
381              description: this.getValue('description'),
382            },
383          },
384          yahoomail: {
385            shareUrl: 'http://compose.mail.yahoo.com',
386            params: {
387              to: this.getValue('to'),
388              subject: this.getValue('subject'),
389              body: this.getValue('body'),
390            },
391          },
392          wordpress: {
393            shareUrl: 'https://wordpress.com/wp-admin/press-this.php',
394            params: {
395              u: this.getValue('url'),
396              t: this.getValue('title'),
397              s: this.getValue('title'),
398            },
399          },
400          amazon: {
401            shareUrl: 'https://www.amazon.com/gp/wishlist/static-add',
402            params: {
403              u: this.getValue('url'),
404              t: this.getValue('title'),
405            },
406          },
407          pinboard: {
408            shareUrl: 'https://pinboard.in/add',
409            params: {
410              url: this.getValue('url'),
411              title: this.getValue('title'),
412              description: this.getValue('description'),
413            },
414          },
415          threema: {
416            shareUrl: 'threema://compose',
417            params: {
418              text: this.getValue('text'),
419              id: this.getValue('id'),
420            },
421          },
422          kakaostory: {
423            shareUrl: 'https://story.kakao.com/share',
424            params: {
425              url: this.getValue('url'),
426            },
427          },
428          yummly: {
429            shareUrl: 'http://www.yummly.com/urb/verify',
430            params: {
431              url: this.getValue('url'),
432              title: this.getValue('title'),
433              yumtype: 'button',
434            },
435          },
436        },
437        s = sharers[sharer];
438
439      // custom popups sizes
440      if (s) {
441        s.width = this.getValue('width');
442        s.height = this.getValue('height');
443      }
444      return s !== undefined ? this.urlSharer(s) : false;
445    },
446    /**
447     * @event urlSharer
448     * @param {Object} sharer
449     */
450    urlSharer: function(sharer) {
451      var p = sharer.params || {},
452        keys = Object.keys(p),
453        i,
454        str = keys.length > 0 ? '?' : '';
455      for (i = 0; i < keys.length; i++) {
456        if (str !== '?') {
457          str += '&';
458        }
459        if (p[keys[i]]) {
460          str += keys[i] + '=' + encodeURIComponent(p[keys[i]]);
461        }
462      }
463      sharer.shareUrl += str;
464
465      var isLink = this.getValue('link') === 'true';
466      var isBlank = this.getValue('blank') === 'true';
467
468      if (isLink) {
469        if (isBlank) {
470          window.open(sharer.shareUrl, '_blank');
471        } else {
472          window.location.href = sharer.shareUrl;
473        }
474      } else {
475        console.log(sharer.shareUrl);
476        // defaults to popup if no data-link is provided
477        var popWidth = sharer.width || 600,
478          popHeight = sharer.height || 480,
479          left = window.innerWidth / 2 - popWidth / 2 + window.screenX,
480          top = window.innerHeight / 2 - popHeight / 2 + window.screenY,
481          popParams = 'scrollbars=no, width=' + popWidth + ', height=' + popHeight + ', top=' + top + ', left=' + left,
482          newWindow = window.open(sharer.shareUrl, '', popParams);
483
484        if (window.focus) {
485          newWindow.focus();
486        }
487      }
488    },
489  };
490
491  // adding sharer events on domcontentload
492  if (document.readyState === 'complete' || document.readyState !== 'loading') {
493    Sharer.init();
494  } else {
495    document.addEventListener('DOMContentLoaded', Sharer.init);
496  }
497
498  // exporting sharer for external usage
499  window.Sharer = Sharer;
500})(window, document);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.