Projet

Général

Profil

Révision ca0757b9

Ajouté par Assos Assos il y a plus de 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/media/js/media.browser.js
7 7
namespace('Drupal.media.browser');
8 8

  
9 9
Drupal.media.browser.selectedMedia = [];
10
Drupal.media.browser.activeTab = 0;
11 10
Drupal.media.browser.mediaAdded = function () {};
12 11
Drupal.media.browser.selectionFinalized = function (selectedMedia) {
13 12
  // This is intended to be overridden if a callee wants to be triggered
......
24 23
    }
25 24

  
26 25
    // Instantiate the tabs.
26
    var showFunc = function(event, ui) {
27
      // Store index of the tab being activated.
28
      if (parent_iframe = Drupal.media.browser.getParentIframe(window)) {
29
        $(parent_iframe).attr('current_tab', $('#media-tabs-wrapper > ul > li.ui-state-active').index());
30
      }
31
    };
32
    var activeTab = Drupal.media.browser.tabFromHash();
27 33
    $('#media-browser-tabset').tabs({
28
      // Ensure that the modal resizes to the content on each tab switch.
29
      show: Drupal.media.browser.resizeIframe, // jquery ui < 1.8
30
      activate: Drupal.media.browser.resizeIframe // jquery ui >= 1.8
31
    });
32

  
33
    $('.ui-tabs-nav li').mouseup(function() {
34
      Drupal.media.browser.activeTab = $(this).index();
34
      selected: activeTab, // jquery < 1.9
35
      active: activeTab, // jquery >= 1.9
36
      show: showFunc, // jquery ui < 1.8
37
      activate: showFunc // jquery ui >= 1.8
35 38
    });
36 39

  
37 40
    $('.media-browser-tab').each( Drupal.media.browser.validateButtons );
41
  }
42
  // Wait for additional params to be passed in.
43
};
38 44

  
39
    Drupal.media.browser.selectActiveTab();
40
    Drupal.media.browser.selectErrorTab();
45
Drupal.media.browser.getParentIframe = function (window) {
46
  var arrFrames = parent.document.getElementsByTagName("IFRAME");
47
  for (var i = 0; i < arrFrames.length; i++) {
48
    if (arrFrames[i].contentWindow === window) {
49
      return arrFrames[i];
50
    }
51
  }
52
}
41 53

  
54
/**
55
 * Get index of the active tab from window.location.hash
56
 */
57
Drupal.media.browser.tabFromHash = function () {
58
  if (parent_iframe = Drupal.media.browser.getParentIframe(window)) {
59
    return $(parent_iframe).attr('current_tab');
42 60
  }
43
  // Wait for additional params to be passed in.
61
  return 0;
44 62
};
45 63

  
46 64
Drupal.media.browser.launch = function () {
......
49 67

  
50 68
Drupal.media.browser.validateButtons = function() {
51 69
  // The media browser runs in an IFRAME. The Drupal.media.popups.mediaBrowser()
52
  // function sets up the IFRAME and "OK" and "Cancel" buttons that are outside
53
  // of the IFRAME, so that their click handlers can destroy the IFRAME while
54
  // retaining information about what media items were selected. However,
55
  // Drupal UI convention is to place all action buttons on the same "line"
56
  // at the bottom of the form, so if the form within the IFRAME contains a
57
  // "Submit" button or other action buttons, then the "OK" and "Cancel"
58
  // buttons below the IFRAME break this convention and confuse the user.
59
  // Therefore, we add "Submit" and "Cancel" buttons inside the IFRAME, and
60
  // have their click action trigger the click action of the corresonding
61
  // "OK" and "Cancel" buttons that are outside the IFRAME. media.css contains
62
  // CSS rules that hide the outside buttons.
70
  // function sets up the IFRAME and an "OK" button that is outside of the
71
  // IFRAME, so that its click handlers can destroy the IFRAME while retaining
72
  // information about what media items were selected. However, Drupal UI
73
  // convention is to place all action buttons on the same "line" at the bottom
74
  // of the form, so if the form within the IFRAME contains a "Submit" button or
75
  // other action buttons, then the "OK" button will appear below the IFRAME
76
  // which breaks this convention and is confusing to the user. Therefore, we
77
  // add a "Submit" button inside the IFRAME, and have its click action trigger
78
  // the click action of the corresponding "OK" button that is outside the
79
  // IFRAME. media.css contains CSS rules that hide the outside buttons.
63 80

  
64 81
  // If a submit button is present, another round-trip to the server is needed
65 82
  // before the user's selection is finalized. For these cases, when the form's
......
69 86
  // Drupal.media.popups.mediaBrowser.mediaBrowserOnLoad() auto-triggers the
70 87
  // "OK" button action to finalize the selection and remove the IFRAME.
71 88

  
72
  // We need to check for the fake submit/cancel buttons that are used on
73
  // non-form based pane content. On these items we need to bind the clicks
74
  // so that media can be selected or the window can be closed. This is still a
75
  // hacky approach, but it is a step in the right direction.
89
  // We need to check for the fake submit button that is used on non-form based
90
  // pane content. On these items we need to bind the clicks so that media can
91
  // be selected or the window can be closed. This is still a hacky approach,
92
  // but it is a step in the right direction.
76 93

  
77 94
  $('a.button.fake-submit', this).once().bind('click', Drupal.media.browser.submit);
78
  $('a.button.fake-cancel', this).once().bind('click', Drupal.media.browser.submit);
79 95
};
80 96

  
81 97
Drupal.media.browser.submit = function () {
82 98
  // @see Drupal.media.browser.validateButtons().
83 99
  var buttons = $(parent.window.document.body).find('#mediaBrowser').parent('.ui-dialog').find('.ui-dialog-buttonpane button');
84
  if ($(this).hasClass('fake-cancel')) {
85
    buttons[1].click();
86
  }
87
  else {
88
    buttons[0].click();
89
  }
100
  buttons[0].click();
90 101

  
91 102
  // Return false to prevent the fake link "click" from continuing.
92 103
  return false;
......
105 116
  }
106 117
};
107 118

  
108
/**
109
 * Resize the Media Browser to the content height.
110
 */
111
Drupal.media.browser.resizeIframe = function (event) {
112
  var h = $('body').height();
113
  $(parent.window.document).find('#mediaBrowser').height(h);
114
};
115

  
116
Drupal.media.browser.selectErrorTab = function() {
117
  // Find the ID of a tab with an error in it
118
  var errorTabID = $('#media-browser-tabset')
119
    .find('.error')
120
    .parents('.media-browser-tab')
121
    .attr('id');
122

  
123
  if (errorTabID !== undefined) {
124
    // Find the Tab Link with errorTabID
125
    var tab = $('a[href="#' + errorTabID + '"]');
126
    // Find the index of the tab
127
    var index = $('#media-browser-tabset a').index(tab);
128
    // Select the tab
129
    Drupal.media.browser.selectTab(index);
130
  }
131
}
132

  
133
Drupal.media.browser.selectActiveTab = function() {
134
  // Find the index of the last active tab.
135
  setTimeout(function() {
136
    Drupal.media.browser.selectTab(Drupal.media.browser.activeTab);
137
    Drupal.media.browser.resizeIframe();
138
  }, 10);
139
};
140

  
141
/**
142
 * Helper function to change the media browser jQuery UI tabs
143
 * since it requires two different methods dependingon the version.
144
 */
145
Drupal.media.browser.selectTab = function(index) {
146
  var ver = jQuery.ui.version.split('.');
147
  if (ver[0] == '1' && parseInt(ver[1]) <= 8) {
148
    // jQuery UI <= 1.8
149
    $('#media-browser-tabset').tabs('select', index);
150
  }
151
  else {
152
    // jQuery UI 1.9+
153
    $('#media-browser-tabset').tabs('option', 'active', index);
154
  }
155

  
156
  // Update the active tab variable.
157
  Drupal.media.browser.activeTab = index;
158
};
159

  
160 119
}(jQuery));

Formats disponibles : Unified diff