Projet

Général

Profil

Révision 2c8c2b87

Ajouté par Assos Assos il y a presque 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/addthis/addthis.js
1
(function ($) {
1
/**
2
 * @file
3
 * AddThis javascript actions.
4
 */
2 5

  
6
(function ($) {
3 7
  Drupal.behaviors.addthis = {
8
    scriptLoaded: false,
9

  
4 10
    attach: function(context, settings) {
5 11

  
6
      // If addthis settings are provided a display is loaded.
7
      if (typeof Drupal.settings.addthis != 'undefined') {
8

  
9
        if (typeof Drupal.settings.addthis.load_type != 'undefined') {
10
          if (Drupal.settings.addthis.load_type == 'async') {
11
            addthis.init();
12
          }
13
          if (Drupal.settings.addthis.load_type == 'domready') {
14
            $.getScript(
15
              Drupal.settings.addthis.widget_url,
16
              function(data, textStatus) {});
17
          }
18
          // Trigger ready on ajax attach.
19
          if (context != window.document && window.addthis != null) {
20
            window.addthis.ost = 0;
21
            window.addthis.ready();
22
          }
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();
23 21
        }
24 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
    },
25 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
      }
26 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;
27 88
  }
28 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

  
29 98
}(jQuery));

Formats disponibles : Unified diff