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