Révision ca0757b9
Ajouté par Assos Assos il y a plus de 9 ans
drupal7/sites/all/modules/media/js/media.popups.js | ||
---|---|---|
58 | 58 |
var mediaIframe = Drupal.media.popups.getPopupIframe(browserSrc, 'mediaBrowser'); |
59 | 59 |
// Attach the onLoad event |
60 | 60 |
mediaIframe.bind('load', options, options.widget.onLoad); |
61 |
|
|
61 | 62 |
/** |
62 | 63 |
* Setting up the modal dialog |
63 | 64 |
*/ |
64 |
|
|
65 | 65 |
var ok = 'OK'; |
66 |
var cancel = 'Cancel'; |
|
67 | 66 |
var notSelected = 'You have not selected anything!'; |
68 | 67 |
|
69 | 68 |
if (Drupal && Drupal.t) { |
70 | 69 |
ok = Drupal.t(ok); |
71 |
cancel = Drupal.t(cancel); |
|
72 | 70 |
notSelected = Drupal.t(notSelected); |
73 | 71 |
} |
74 | 72 |
|
... | ... | |
85 | 83 |
$(this).dialog("close"); |
86 | 84 |
}; |
87 | 85 |
|
88 |
dialogOptions.buttons[cancel] = function () { |
|
89 |
$(this).dialog("close"); |
|
90 |
}; |
|
86 |
var dialog = mediaIframe.dialog(dialogOptions); |
|
87 |
|
|
88 |
Drupal.media.popups.sizeDialog(dialog); |
|
89 |
Drupal.media.popups.resizeDialog(dialog); |
|
90 |
Drupal.media.popups.scrollDialog(dialog); |
|
91 |
Drupal.media.popups.overlayDisplace(dialog.parents(".ui-dialog")); |
|
91 | 92 |
|
92 |
Drupal.media.popups.setDialogPadding(mediaIframe.dialog(dialogOptions)); |
|
93 |
// Remove the title bar. |
|
94 |
mediaIframe.parents(".ui-dialog").find(".ui-dialog-titlebar").remove(); |
|
95 |
Drupal.media.popups.overlayDisplace(mediaIframe.parents(".ui-dialog")); |
|
96 | 93 |
return mediaIframe; |
97 | 94 |
}; |
98 | 95 |
|
... | ... | |
149 | 146 |
Drupal.media.popups.mediaStyleSelector = function (mediaFile, onSelect, options) { |
150 | 147 |
var defaults = Drupal.media.popups.mediaStyleSelector.getDefaults(); |
151 | 148 |
// @todo: remove this awful hack :( |
152 |
defaults.src = defaults.src.replace('-media_id-', mediaFile.fid) + '&fields=' + JSON.stringify(mediaFile.fields); |
|
149 |
if (typeof defaults.src === 'string' ) { |
|
150 |
defaults.src = defaults.src.replace('-media_id-', mediaFile.fid) + '&fields=' + encodeURIComponent(JSON.stringify(mediaFile.fields)); |
|
151 |
} |
|
152 |
else { |
|
153 |
var src = defaults.src.shift(); |
|
154 |
defaults.src.unshift(src); |
|
155 |
defaults.src = src.replace('-media_id-', mediaFile.fid) + '&fields=' + encodeURIComponent(JSON.stringify(mediaFile.fields)); |
|
156 |
} |
|
153 | 157 |
options = $.extend({}, defaults, options); |
154 | 158 |
// Create it as a modal window. |
155 | 159 |
var mediaIframe = Drupal.media.popups.getPopupIframe(options.src, 'mediaStyleSelector'); |
... | ... | |
160 | 164 |
* Set up the button text |
161 | 165 |
*/ |
162 | 166 |
var ok = 'OK'; |
163 |
var cancel = 'Cancel'; |
|
164 | 167 |
var notSelected = 'Very sorry, there was an unknown error embedding media.'; |
165 | 168 |
|
166 | 169 |
if (Drupal && Drupal.t) { |
167 | 170 |
ok = Drupal.t(ok); |
168 |
cancel = Drupal.t(cancel); |
|
169 | 171 |
notSelected = Drupal.t(notSelected); |
170 | 172 |
} |
171 | 173 |
|
... | ... | |
183 | 185 |
$(this).dialog("close"); |
184 | 186 |
}; |
185 | 187 |
|
186 |
dialogOptions.buttons[cancel] = function () { |
|
187 |
$(this).dialog("close"); |
|
188 |
}; |
|
188 |
var dialog = mediaIframe.dialog(dialogOptions); |
|
189 |
|
|
190 |
Drupal.media.popups.sizeDialog(dialog); |
|
191 |
Drupal.media.popups.resizeDialog(dialog); |
|
192 |
Drupal.media.popups.scrollDialog(dialog); |
|
193 |
Drupal.media.popups.overlayDisplace(dialog.parents(".ui-dialog")); |
|
189 | 194 |
|
190 |
Drupal.media.popups.setDialogPadding(mediaIframe.dialog(dialogOptions)); |
|
191 |
// Remove the title bar. |
|
192 |
mediaIframe.parents(".ui-dialog").find(".ui-dialog-titlebar").remove(); |
|
193 |
Drupal.media.popups.overlayDisplace(mediaIframe.parents(".ui-dialog")); |
|
194 | 195 |
return mediaIframe; |
195 | 196 |
}; |
196 | 197 |
|
... | ... | |
235 | 236 |
* Set up the button text |
236 | 237 |
*/ |
237 | 238 |
var ok = 'OK'; |
238 |
var cancel = 'Cancel'; |
|
239 | 239 |
var notSelected = 'Very sorry, there was an unknown error embedding media.'; |
240 | 240 |
|
241 | 241 |
if (Drupal && Drupal.t) { |
242 | 242 |
ok = Drupal.t(ok); |
243 |
cancel = Drupal.t(cancel); |
|
244 | 243 |
notSelected = Drupal.t(notSelected); |
245 | 244 |
} |
246 | 245 |
|
... | ... | |
257 | 256 |
$(this).dialog("close"); |
258 | 257 |
}; |
259 | 258 |
|
260 |
dialogOptions.buttons[cancel] = function () { |
|
261 |
$(this).dialog("close"); |
|
262 |
}; |
|
259 |
var dialog = mediaIframe.dialog(dialogOptions); |
|
260 |
|
|
261 |
Drupal.media.popups.sizeDialog(dialog); |
|
262 |
Drupal.media.popups.resizeDialog(dialog); |
|
263 |
Drupal.media.popups.scrollDialog(dialog); |
|
264 |
Drupal.media.popups.overlayDisplace(dialog); |
|
263 | 265 |
|
264 |
Drupal.media.popups.setDialogPadding(mediaIframe.dialog(dialogOptions)); |
|
265 |
// Remove the title bar. |
|
266 |
mediaIframe.parents(".ui-dialog").find(".ui-dialog-titlebar").remove(); |
|
267 |
Drupal.media.popups.overlayDisplace(mediaIframe.parents(".ui-dialog")); |
|
268 | 266 |
return mediaIframe; |
269 | 267 |
}; |
270 | 268 |
|
... | ... | |
291 | 289 |
Drupal.media.popups.getDialogOptions = function () { |
292 | 290 |
return { |
293 | 291 |
buttons: {}, |
294 |
dialogClass: 'media-wrapper',
|
|
295 |
modal: true,
|
|
296 |
draggable: false,
|
|
297 |
resizable: false,
|
|
298 |
minWidth: 500,
|
|
299 |
width: 670,
|
|
300 |
height: 280,
|
|
301 |
position: 'center',
|
|
292 |
dialogClass: Drupal.settings.media.dialogOptions.dialogclass,
|
|
293 |
modal: Drupal.settings.media.dialogOptions.modal,
|
|
294 |
draggable: Drupal.settings.media.dialogOptions.draggable,
|
|
295 |
resizable: Drupal.settings.media.dialogOptions.resizable,
|
|
296 |
minWidth: Drupal.settings.media.dialogOptions.minwidth,
|
|
297 |
width: Drupal.settings.media.dialogOptions.width,
|
|
298 |
height: Drupal.settings.media.dialogOptions.height,
|
|
299 |
position: Drupal.settings.media.dialogOptions.position,
|
|
302 | 300 |
overlay: { |
303 |
backgroundColor: '#000000',
|
|
304 |
opacity: 0.4
|
|
301 |
backgroundColor: Drupal.settings.media.dialogOptions.overlay.backgroundcolor,
|
|
302 |
opacity: Drupal.settings.media.dialogOptions.overlay.opacity
|
|
305 | 303 |
}, |
306 |
zIndex: 10000,
|
|
304 |
zIndex: Drupal.settings.media.dialogOptions.zindex,
|
|
307 | 305 |
close: function (event, ui) { |
308 | 306 |
$(event.target).remove(); |
309 | 307 |
} |
310 | 308 |
}; |
311 | 309 |
}; |
312 | 310 |
|
313 |
/** |
|
314 |
* Created padding on a dialog |
|
315 |
* |
|
316 |
* @param jQuery dialogElement |
|
317 |
* The element which has .dialog() attached to it. |
|
318 |
*/ |
|
319 |
Drupal.media.popups.setDialogPadding = function (dialogElement) { |
|
320 |
// @TODO: Perhaps remove this hardcoded reference to height. |
|
321 |
// - It's included to make IE on Windows 7 display the dialog without |
|
322 |
// collapsing. 550 is the height that displays all of the tab panes |
|
323 |
// within the Add Media overlay. This is either a bug in the jQuery |
|
324 |
// UI library, a bug in IE on Windows 7 or a bug in the way the |
|
325 |
// dialog is instantiated. Or a combo of the three. |
|
326 |
// All browsers except IE on Win7 ignore these defaults and adjust |
|
327 |
// the height of the iframe correctly to match the content in the panes |
|
328 |
dialogElement.height(dialogElement.dialog('option', 'height')); |
|
329 |
dialogElement.width(dialogElement.dialog('option', 'width')); |
|
330 |
}; |
|
331 |
|
|
332 | 311 |
/** |
333 | 312 |
* Get an iframe to serve as the dialog's contents. Common to both plugins. |
334 | 313 |
*/ |
335 | 314 |
Drupal.media.popups.getPopupIframe = function (src, id, options) { |
336 |
var defaults = {width: '800px', scrolling: 'auto'};
|
|
315 |
var defaults = {width: '100%', scrolling: 'auto'};
|
|
337 | 316 |
var options = $.extend({}, defaults, options); |
338 | 317 |
|
339 | 318 |
return $('<iframe class="media-modal-frame"/>') |
... | ... | |
352 | 331 |
} |
353 | 332 |
} |
354 | 333 |
|
334 |
/** |
|
335 |
* Size the dialog when it is first loaded and keep it centered when scrolling. |
|
336 |
* |
|
337 |
* @param jQuery dialogElement |
|
338 |
* The element which has .dialog() attached to it. |
|
339 |
*/ |
|
340 |
Drupal.media.popups.sizeDialog = function (dialogElement) { |
|
341 |
if (!dialogElement.is(':visible')) { |
|
342 |
return; |
|
343 |
} |
|
344 |
var windowWidth = $(window).width(); |
|
345 |
var dialogWidth = windowWidth * 0.8; |
|
346 |
var windowHeight = $(window).height(); |
|
347 |
var dialogHeight = windowHeight * 0.8; |
|
348 |
|
|
349 |
dialogElement.dialog("option", "width", dialogWidth); |
|
350 |
dialogElement.dialog("option", "height", dialogHeight); |
|
351 |
dialogElement.dialog("option", "position", 'center'); |
|
352 |
|
|
353 |
$('.media-modal-frame').width('100%'); |
|
354 |
} |
|
355 |
|
|
356 |
/** |
|
357 |
* Resize the dialog when the window changes. |
|
358 |
* |
|
359 |
* @param jQuery dialogElement |
|
360 |
* The element which has .dialog() attached to it. |
|
361 |
*/ |
|
362 |
Drupal.media.popups.resizeDialog = function (dialogElement) { |
|
363 |
$(window).resize(function() { |
|
364 |
Drupal.media.popups.sizeDialog(dialogElement); |
|
365 |
}); |
|
366 |
} |
|
367 |
|
|
368 |
/** |
|
369 |
* Keeps the dialog centered when the window is scrolled. |
|
370 |
* |
|
371 |
* @param jQuery dialogElement |
|
372 |
* The element which has .dialog() attached to it. |
|
373 |
*/ |
|
374 |
Drupal.media.popups.scrollDialog = function (dialogElement) { |
|
375 |
// Keep the dialog window centered when scrolling. |
|
376 |
$(window).scroll(function() { |
|
377 |
if (!dialogElement.is(':visible')) { |
|
378 |
return; |
|
379 |
} |
|
380 |
dialogElement.dialog("option", "position", 'center'); |
|
381 |
}); |
|
382 |
} |
|
383 |
|
|
355 | 384 |
})(jQuery); |
Formats disponibles : Unified diff
Weekly update of contrib modules