1/** 2 * @file 3 * AddThis javascript actions. 4 */ 5 6(function ($) { 7 Drupal.behaviors.addthis = { 8 scriptLoaded: false, 9 10 attach: function(context, settings) { 11 12 // The addthis configuration is not loaded but the settings are passed 13 // to do so. 14 if (!this.isConfigLoaded() && this.isSettingsLoaded()) { 15 // Initialize config. 16 this.initConfig(); 17 18 // Load widget js. 19 if (!this.scriptLoaded) { 20 this.loadDomready(); 21 } 22 } 23 // The addthis configuration is not loaded but no setting are available 24 // to load anything. 25 else if(!this.isConfigLoaded() && !this.isSettingsLoaded()) { 26 // Do nothing 27 } 28 29 // Trigger ready on ajax attach. 30 if (context != window.document) { 31 Drupal.behaviors.addthis.ajaxLoad(context, settings); 32 } 33 34 }, 35 36 // Returns if the settings defined by the addthis module are loaded. 37 isSettingsLoaded: function () { 38 if (typeof Drupal.settings.addthis == 'undefined') { 39 return false; 40 } 41 return true; 42 }, 43 44 // Returns if the configuration variables needed for widget.js are defined. 45 isConfigLoaded: function() { 46 if (typeof addthis_config == 'undefined' || typeof addthis_share == 'undefined') { 47 return false; 48 } 49 return true; 50 }, 51 52 initConfig: function () { 53 addthis_config = Drupal.settings.addthis.addthis_config; 54 addthis_share = Drupal.settings.addthis.addthis_share; 55 }, 56 57 // Load the js library when the dom is ready. 58 loadDomready: function() { 59 // If settings asks for loading the script after the dom is loaded, then 60 // load the script here. 61 if (!this.scriptLoaded && 62 this.isConfigLoaded() && 63 Drupal.settings.addthis.domready) { 64 $.getScript(Drupal.settings.addthis.widget_url, Drupal.behaviors.addthis.scriptReady); 65 } 66 }, 67 68 // Callback for loading the widget.js dynamically. 69 scriptReady: function () { 70 this.scriptLoaded = true; 71 }, 72 73 // Called when a ajax request returned. 74 ajaxLoad: function(context, settings) { 75 if (typeof window.addthis != 'undefined' && 76 typeof window.addthis.toolbox == 'function') 77 { 78 window.addthis.toolbox('.addthis_toolbox'); 79 } 80 } 81 82 }; 83 84 // This load the config in time to run any addthis functionality. 85 if (Drupal.behaviors.addthis.isConfigLoaded()) { 86 addthis_config = Drupal.settings.addthis.addthis_config; 87 addthis_share = Drupal.settings.addthis.addthis_share; 88 } 89 90 // Document ready in case we want to load AddThis into the dom after every 91 // thing is loaded. 92 // 93 // Is executed once after the attach happened. 94 $(document).ready(function() { 95 Drupal.behaviors.addthis.loadDomready(); 96 }); 97 98});
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.