1/** 2 * Component Social 3 * @module Social 4 * @param {jQuery} $ Instance of jQuery 5 * @param {document} document document object 6 * @return {Object} List of Social component methods 7 */ 8XA.component.social = (function($, document) { 9 /** 10 * This object stores all public api methods 11 * @type {Object.<Methods>} 12 * @memberOf module:Social 13 * @ 14 * */ 15 var api = {}; 16 api.shareProperties; 17 /** 18 * Creates connector for facebook 19 * initInstance method of a Social component 20 * @memberOf module:Social 21 * @method 22 * @alias module:Social.initFacebook 23 */ 24 api.initFacebook = function() { 25 (function(d, s, id) { 26 var js, 27 fjs = d.getElementsByTagName(s)[0]; 28 if (d.getElementById(id)) { 29 return; 30 } 31 js = d.createElement(s); 32 js.id = id; 33 js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; 34 fjs.parentNode.insertBefore(js, fjs); 35 })(document, "script", "facebook-jssdk"); 36 }; 37 /** 38 * Creates connector for facebook 39 * initInstance method of a Social component 40 * @memberOf module:Social 41 * @param {Array} properties properties for external scripts 42 * @method 43 * @alias module:Social.initFacebook 44 */ 45 var attachExternalScript = function(properties) { 46 var component = $(".sharethis"), 47 shareThisExternal; 48 if (window.stLight === undefined) { 49 shareThisExternal = document.createElement("script"); 50 shareThisExternal.type = "text/javascript"; 51 shareThisExternal.src = "//w.sharethis.com/button/buttons.js"; 52 $(window).on("load", function() { 53 $(properties).each(function() { 54 try { 55 window.stLight.options(this); 56 } catch (e) {} 57 }); 58 }); 59 $(component[0]).append(shareThisExternal); 60 } 61 }; 62 /** 63 * initInstance method of a Social component 64 * @memberOf module:Social 65 * @method 66 * @param {jQuery} component Root DOM element of Social component wrapped by jQuery 67 * @param {Object} prop Social component properties 68 * @alias module:Social.initInstance 69 */ 70 api.initInstance = function(component, prop) { 71 api.shareProperties.push(prop); 72 }; 73 /** 74 * init method calls in a loop for each 75 * social component on a page and run 76 * ["initInstance"]{@link module:Snippet.api.initInstance} methods. 77 * @memberOf module:Social 78 * @alias module:Social.init 79 */ 80 api.init = function() { 81 var shareThis = $(".sharethis:not(.initialized)"); 82 api.shareProperties = []; 83 shareThis.each(function() { 84 var properties = $(this).data("properties"); 85 api.initInstance($(this), properties); 86 $(this).addClass("initialized"); 87 }); 88 attachExternalScript(api.shareProperties); 89 }; 90 return api; 91})(jQuery, document); 92 93XA.register("social", XA.component.social);
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.