PageSourceSearch

https://russianhighways.ru/app/js/plugins/jsshare/jsshare.js?v=2

js russianhighways.ru collected 2026-09-24 18:57:31 UTC 12,753 bytes, 374 lines download raw bytes

1/**
2 * JS-Share - vanilla javascript social networks and messengers sharing
3 * https://github.com/delfimov/JS-Share
4 *
5 * Copyright (c) 2017-2018 by Dmitry Elfimov
6 * Released under the MIT License.
7 * http://www.opensource.org/licenses/mit-license.php
8 */
9
10/**
11 * Minimum setup example:
12 *
13 <div>Share:
14 <button class="social_share" data-type="vk">VK.com</button>
15 <button class="social_share" data-type="facebook">Facebook</button>
16 <button class="social_share" data-type="twitter">Twitter</button>
17 <button class="social_share" data-type="livejournal">LiveJournal</button>
18 <button class="social_share" data-type="ok">ok.ru</button>
19 <button class="social_share" data-type="mailru">Mail.Ru</button>
20 <button class="social_share" data-type="reddit">Reddit</button>
21 <button class="social_share" data-type="googleplus">Google+</button>
22 <button class="social_share" data-type="telegram">Telegram</button>
23 <button class="social_share" data-type="whatsapp">Whatsapp</button>
24 <button class="social_share" data-type="viber">Viber</button>
25 <button class="social_share" data-type="email">Email</button>
26 </div>
27
28 var shareItems = document.querySelectorAll('.social_share');
29 for (var i = 0; i < shareItems.length; i += 1) {
30   shareItems[i].addEventListener('click', function share(e) {
31     return JSShare.go(this);
32   });
33 }
34
35 *
36 * Inline example:
37 *
38 <a href="#" onclick="return JSShare.go(this)" data-type="facebook">I like it</a>
39
40 */
41
42
43;(function (factory) {
44    var registeredInModuleLoader;
45    if (typeof define === 'function' && define.amd) {
46        define(factory);
47        registeredInModuleLoader = true;
48    }
49    if (typeof exports === 'object') {
50        module.exports = factory();
51        registeredInModuleLoader = true;
52    }
53    if (!registeredInModuleLoader) {
54        return window.JSShare = factory();
55    }
56}(function () {
57
58    /**
59     * indexOf for old browsers
60     */
61    if (!('indexOf' in Array.prototype)) {
62        Array.prototype.indexOf = function(find, i /*opt*/) {
63            if (i === undefined) i = 0;
64            if (i < 0) i += this.length;
65            if (i < 0) i = 0;
66            for (var n = this.length; i < n; i++)
67                if (i in this && this[i] === find)
68                    return i;
69            return -1;
70        };
71    }
72
73    /**
74     * Object Extending Functionality
75     */
76    function _extend(out) {
77        out = out || {};
78        for (var i = 1; i < arguments.length; i++) {
79            if (!arguments[i]) {
80                continue;
81            }
82            for (var key in arguments[i]) {
83                if (arguments[i].hasOwnProperty(key)) {
84                    out[key] = arguments[i][key];
85                }
86            }
87        }
88        return out;
89    }
90
91    /**
92     * Get data-attributes
93     */
94    function _getData(el, defaultOptions) {
95        var data = {};
96        for (var key in defaultOptions) {
97            if (defaultOptions.hasOwnProperty(key)) {
98                var value = el.getAttribute('data-' + key);
99                if (value !== null && typeof value != 'undefined') {
100                    data[key] = value;
101                }
102            }
103        }
104        return data;
105    }
106
107    /**
108     * Open a popup window with sharing info
109     * @param url
110     * @param _options
111     * @returns {Window}
112     * @private
113     */
114    function _popup (url, _options) {
115        return window.open(url, '', 'toolbar=0,status=0,scrollbars=1,width=' + _options.popup_width + ',height=' + _options.popup_height);
116    }
117
118    /**
119     * Get URL for sharing based on options
120     * @param options
121     * @returns {string | *}
122     * @private
123     */
124    function _getURL(options) {
125        if (options.url === '') {
126            options.url = location.href;
127        }
128        var url = options.url;
129        var utm = '';
130        if (options.utm_source !== '') {
131            utm += '&utm_source=' + options.utm_source;
132        }
133        if (options.utm_medium !== '') {
134            utm += '&utm_medium=' + options.utm_medium;
135        }
136        if (options.utm_campaign !== '') {
137            utm += '&utm_campaign=' + options.utm_campaign;
138        }
139        if (utm !== '') {
140            url = url + '?' + utm;
141        }
142        return url;
143    }
144
145    var social = {
146        // default handler
147        unknown: function (options) {
148            return encodeURIComponent(_getURL(options));
149        },
150
151        // vk.com - ВКонтакте
152        vk: function (options) {
153            return 'http://vk.com/share.php'
154                + '?url=' + encodeURIComponent(_getURL(options))
155                + '&title=' + encodeURIComponent(options.title)
156                + '&description=' + encodeURIComponent(options.text)
157                + '&image=' + encodeURIComponent(options.image)
158                + '&noparse=true';
159        },
160
161        // ok.ru - Одноклассники
162        ok: function (options) {
163            return 'https://connect.ok.ru/offer'
164                + '?url=' + encodeURIComponent(_getURL(options))
165                + '&title=' + encodeURIComponent(options.title)
166                + '&description=' + encodeURIComponent(options.text)
167                + '&imageUrl=' + encodeURIComponent(options.image);
168        },
169
170        // Facebook
171        fb: function (options) {
172            return 'https://www.facebook.com/sharer.php'
173                + '?u=' + encodeURIComponent(_getURL(options));
174        },
175
176        facebook: function (options) {
177            return 'https://www.facebook.com/sharer.php'
178                + '?u=' + encodeURIComponent(_getURL(options));
179        },
180
181        // Google bookmarks
182        googlebookmarks: function (options) {
183            return 'https://www.google.com/bookmarks/mark'
184                + '?op=edit'
185                + '&bkmk=' + encodeURIComponent(_getURL(options))
186                + '&title=' + encodeURIComponent(options.title)
187                + '&annotation=' + encodeURIComponent(options.text)
188                + '&labels=';
189        },
190
191        // Livejournal
192        livejournal: function (options) {
193            return 'http://livejournal.com/update.bml'
194                + '?subject=' + encodeURIComponent(options.title)
195                + '&event=' + encodeURIComponent(options.text + '<br/><a href="' + _getURL(options) + '">' + options.title + '</a>')
196                + '&transform=1';
197        },
198
199        // Tumblr
200        tumblr: function (options) {
201            return 'https://www.tumblr.com/widgets/share/tool'
202                + '?canonicalUrl=' + encodeURIComponent(_getURL(options))
203                + '&title=' + encodeURIComponent(options.title)
204                + '&caption=' + encodeURIComponent(options.text)
205                + '&tags=';
206        },
207
208        // Pinterest
209        pinterest: function (options) {
210            return 'http://pinterest.com/pin/create/link/'
211                + '?url=' + encodeURIComponent(_getURL(options));
212        },
213
214        // linkedin
215        linkedin: function (options) {
216            return 'https://www.linkedin.com/shareArticle'
217                + '?mini=true'
218                + '&url=' + encodeURIComponent(_getURL(options))
219                + '&title=' + encodeURIComponent(options.title)
220                + '&summary=' + encodeURIComponent(options.text);
221        },
222
223        // Reddit
224        reddit: function (options) {
225            return 'https://reddit.com/submit'
226                + '?url=' + encodeURIComponent(_getURL(options))
227                + '&title=' + encodeURIComponent(options.title);
228        },
229
230        // Twitter
231        twitter: function (options) {
232            var url = _getURL(options);
233            return 'http://twitter.com/share'
234                + '?text=' + encodeURIComponent(options.title)
235                + '&url=' + encodeURIComponent(url)
236                + '&counturl=' + encodeURIComponent(url);
237        },
238
239        // Mail.ru
240        mailru: function (options) {
241            return 'http://connect.mail.ru/share'
242                + '?url=' + encodeURIComponent(_getURL(options))
243                + '&title=' + encodeURIComponent(options.title)
244                + '&description=' + encodeURIComponent(options.text)
245                + '&imageurl=' + encodeURIComponent(options.image);
246        },
247
248        // Google+
249        googleplus: function (options) {
250            return 'https://plus.google.com/share'
251                + '?url=' + encodeURIComponent(_getURL(options));
252        },
253
254        // Weibo
255        weibo: function (options) {
256            return 'http://service.weibo.com/share/share.php'
257                + '?url=' + encodeURIComponent(_getURL(options))
258                + '&title=' + encodeURIComponent(options.title)
259                + '&pic=' + encodeURIComponent(options.image);
260        },
261
262        // Telegram
263        telegram: function (options) {
264            return 'https://telegram.me/share/url'
265                + '?url=' + encodeURIComponent(_getURL(options))
266                + '&text=' + encodeURIComponent(options.title);
267        },
268
269        // WhatsApp
270        whatsapp: function (options) {
271            return 'https://wa.me/'
272                + '?text=' + encodeURIComponent(_getURL(options) + "\n" + options.title);
273        },
274
275        // Viber
276        viber: function (options) {
277            return 'viber://forward'
278                + '?text=' + encodeURIComponent(_getURL(options) + "\n" + options.title);
279        },
280
281        // Skype
282        skype: function (options) {
283            return 'https://web.skype.com/share'
284                + '?url=' + encodeURIComponent(_getURL(options))
285                + '&text=' + encodeURIComponent(options.title);
286        },
287
288        // Line.me
289        line: function (options) {
290            return 'https://lineit.line.me/share/ui'
291                + '?url=' + encodeURIComponent(_getURL(options))
292                + '&text=' + encodeURIComponent(options.title);
293        },
294
295        // E-mail
296        email: function (options) {
297            return 'mailto:'
298                + '?subject=' + encodeURIComponent(options.title)
299                + '&body=' + encodeURIComponent(_getURL(options))
300                + encodeURIComponent("\n" + options.text);
301        },
302
303        // MAX  - временно ссылка на канал, диплинк на десктопе ещё в разработке
304        max: function (options) {
305            return 'https://max.ru/avtodorgk';
306        }
307    };
308
309    function init() {
310        var defaultOptions = {
311            type: 'email',         // default share type
312            url: '',               // url to share
313            title: document.title, // title to share
314            image: '',             // image to share
315            text: '',              // text to share
316            utm_source: '',
317            utm_medium: '',
318            utm_campaign: '',
319            popup_width: 626,
320            popup_height: 436
321        };
322
323        function api() {}
324
325        function go(element, options) {
326            var withoutPopup = [
327                'unknown',
328                'viber',
329                'telegram',
330                'whatsapp',
331                'email',
332                'skype',
333                'line'
334            ];
335            var tryLocation = true; // should we try to redirect user following share link
336            var link;
337
338            options = _extend(
339                defaultOptions,                    // default options - low priority
340                _getData(element, defaultOptions), // options from data-* attributes
341                options                            // options from method call - highest proprity
342            );
343
344            if (typeof social[options.type] == 'undefined') {
345                options.type = 'unknown'
346            }
347
348            link = social[options.type](options);
349
350            if (withoutPopup.indexOf(options.type) === -1) { // if we must try to open a popup window we will try
351                tryLocation = _popup(link, options) === null;
352            }
353
354            if (tryLocation) {                      // and if we succeed, we will not redirect user to share link location, otherwise
355                if (element.tagName === 'A'
356                    && element.tagName === 'a') {       // if element is <a> tag
357                    element.setAttribute('href', link); // set attribute href
358                    return true;                        // and return true, so this tag will behave as a usual link
359                } else {
360                    location.href = link;               // if it's not <a> tag, change location to redirect
361                    return false;
362                }
363            } else {
364                return false;
365            }
366        }
367
368        api.go = go;
369        api.options = defaultOptions;
370        return api;
371    }
372
373    return init();
374}));

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.