Projet

Général

Profil

Paste
Télécharger (2,75 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / addthis / addthis.js @ ba09eb79

1 2c8c2b87 Assos Assos
/**
2
 * @file
3
 * AddThis javascript actions.
4
 */
5 85ad3d82 Assos Assos
6 2c8c2b87 Assos Assos
(function ($) {
7 85ad3d82 Assos Assos
  Drupal.behaviors.addthis = {
8 2c8c2b87 Assos Assos
    scriptLoaded: false,
9
10 85ad3d82 Assos Assos
    attach: function(context, settings) {
11 4543c6c7 Assos Assos
12 2c8c2b87 Assos Assos
      // 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 85ad3d82 Assos Assos
        }
22
      }
23 2c8c2b87 Assos Assos
      // 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 4543c6c7 Assos Assos
44 2c8c2b87 Assos Assos
    // 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 85ad3d82 Assos Assos
    }
81 2c8c2b87 Assos Assos
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 4543c6c7 Assos Assos
  }
89 85ad3d82 Assos Assos
90 2c8c2b87 Assos Assos
  // 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 85ad3d82 Assos Assos
}(jQuery));