1 |
85ad3d82
|
Assos Assos
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
0ccfec7f
|
Assos Assos
|
|
10 |
|
|
|
11 |
85ad3d82
|
Assos Assos
|
|
12 |
|
|
|
13 |
|
|
(function ($) {
|
14 |
|
|
namespace('Drupal.media.popups');
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
0ccfec7f
|
Assos Assos
|
|
21 |
|
|
|
22 |
85ad3d82
|
Assos Assos
|
|
23 |
0ccfec7f
|
Assos Assos
|
|
24 |
|
|
|
25 |
85ad3d82
|
Assos Assos
|
|
26 |
0ccfec7f
|
Assos Assos
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
85ad3d82
|
Assos Assos
|
|
32 |
0ccfec7f
|
Assos Assos
|
|
33 |
|
|
|
34 |
85ad3d82
|
Assos Assos
|
|
35 |
|
|
Drupal.media.popups.mediaBrowser = function (onSelect, globalOptions, pluginOptions, widgetOptions) {
|
36 |
0ccfec7f
|
Assos Assos
|
|
37 |
85ad3d82
|
Assos Assos
|
var options = Drupal.media.popups.mediaBrowser.getDefaults();
|
38 |
0ccfec7f
|
Assos Assos
|
|
39 |
|
|
|
40 |
85ad3d82
|
Assos Assos
|
options.global = $.extend({}, options.global, globalOptions);
|
41 |
|
|
options.plugins = pluginOptions;
|
42 |
|
|
options.widget = $.extend({}, options.widget, widgetOptions);
|
43 |
|
|
|
44 |
0ccfec7f
|
Assos Assos
|
|
45 |
85ad3d82
|
Assos Assos
|
var browserSrc = options.widget.src;
|
46 |
0ccfec7f
|
Assos Assos
|
|
47 |
85ad3d82
|
Assos Assos
|
if ($.isArray(browserSrc) && browserSrc.length) {
|
48 |
|
|
browserSrc = browserSrc[browserSrc.length - 1];
|
49 |
|
|
}
|
50 |
0ccfec7f
|
Assos Assos
|
|
51 |
|
|
|
52 |
85ad3d82
|
Assos Assos
|
var params = {};
|
53 |
0ccfec7f
|
Assos Assos
|
|
54 |
|
|
|
55 |
85ad3d82
|
Assos Assos
|
$.extend(params, options.global);
|
56 |
|
|
params.plugins = options.plugins;
|
57 |
|
|
|
58 |
0ccfec7f
|
Assos Assos
|
|
59 |
85ad3d82
|
Assos Assos
|
browserSrc += '&' + $.param(params);
|
60 |
ca0757b9
|
Assos Assos
|
|
61 |
0ccfec7f
|
Assos Assos
|
|
62 |
|
|
var mediaIframe = Drupal.media.popups.getPopupIframe(browserSrc, 'mediaBrowser');
|
63 |
85ad3d82
|
Assos Assos
|
|
64 |
0ccfec7f
|
Assos Assos
|
|
65 |
|
|
mediaIframe.bind('load', options, options.widget.onLoad);
|
66 |
85ad3d82
|
Assos Assos
|
|
67 |
0ccfec7f
|
Assos Assos
|
|
68 |
85ad3d82
|
Assos Assos
|
var dialogOptions = options.dialog;
|
69 |
|
|
|
70 |
0ccfec7f
|
Assos Assos
|
|
71 |
|
|
var ok = Drupal.t('OK');
|
72 |
|
|
var notSelected = Drupal.t('You have not selected anything!');
|
73 |
|
|
|
74 |
85ad3d82
|
Assos Assos
|
dialogOptions.buttons[ok] = function () {
|
75 |
0ccfec7f
|
Assos Assos
|
|
76 |
85ad3d82
|
Assos Assos
|
var selected = this.contentWindow.Drupal.media.browser.selectedMedia;
|
77 |
0ccfec7f
|
Assos Assos
|
|
78 |
|
|
|
79 |
85ad3d82
|
Assos Assos
|
if (selected.length < 1) {
|
80 |
|
|
alert(notSelected);
|
81 |
0ccfec7f
|
Assos Assos
|
|
82 |
85ad3d82
|
Assos Assos
|
return;
|
83 |
|
|
}
|
84 |
0ccfec7f
|
Assos Assos
|
|
85 |
|
|
|
86 |
85ad3d82
|
Assos Assos
|
onSelect(selected);
|
87 |
0ccfec7f
|
Assos Assos
|
|
88 |
|
|
|
89 |
|
|
$(this).dialog('close');
|
90 |
85ad3d82
|
Assos Assos
|
};
|
91 |
|
|
|
92 |
0ccfec7f
|
Assos Assos
|
|
93 |
ca0757b9
|
Assos Assos
|
var dialog = mediaIframe.dialog(dialogOptions);
|
94 |
|
|
|
95 |
0ccfec7f
|
Assos Assos
|
|
96 |
ca0757b9
|
Assos Assos
|
Drupal.media.popups.sizeDialog(dialog);
|
97 |
|
|
Drupal.media.popups.resizeDialog(dialog);
|
98 |
|
|
Drupal.media.popups.scrollDialog(dialog);
|
99 |
|
|
Drupal.media.popups.overlayDisplace(dialog.parents(".ui-dialog"));
|
100 |
85ad3d82
|
Assos Assos
|
|
101 |
|
|
return mediaIframe;
|
102 |
|
|
};
|
103 |
|
|
|
104 |
0ccfec7f
|
Assos Assos
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
85ad3d82
|
Assos Assos
|
Drupal.media.popups.mediaBrowser.getDefaults = function () {
|
111 |
|
|
return {
|
112 |
|
|
global: {
|
113 |
|
|
types: [],
|
114 |
|
|
activePlugins: []
|
115 |
|
|
},
|
116 |
|
|
widget: {
|
117 |
|
|
src: Drupal.settings.media.browserUrl,
|
118 |
|
|
onLoad: Drupal.media.popups.mediaBrowser.mediaBrowserOnLoad
|
119 |
|
|
},
|
120 |
|
|
dialog: Drupal.media.popups.getDialogOptions()
|
121 |
|
|
};
|
122 |
|
|
};
|
123 |
|
|
|
124 |
0ccfec7f
|
Assos Assos
|
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
Drupal.media.popups.mediaBrowser.mediaBrowserOnLoad = function (e) {
|
128 |
|
|
var options = e.data;
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
if (this.contentWindow.Drupal.media == undefined) {
|
132 |
|
|
return;
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
if (this.contentWindow.Drupal.media.browser.selectedMedia.length > 0) {
|
137 |
|
|
var ok = Drupal.t('OK');
|
138 |
|
|
var ok_func = $(this).dialog('option', 'buttons')[ok];
|
139 |
|
|
|
140 |
|
|
ok_func.call(this);
|
141 |
|
|
|
142 |
|
|
return;
|
143 |
|
|
}
|
144 |
|
|
};
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
85ad3d82
|
Assos Assos
|
Drupal.media.popups.mediaBrowser.finalizeSelection = function () {
|
153 |
0ccfec7f
|
Assos Assos
|
|
154 |
85ad3d82
|
Assos Assos
|
var selected = this.contentWindow.Drupal.media.browser.selectedMedia;
|
155 |
0ccfec7f
|
Assos Assos
|
|
156 |
|
|
|
157 |
85ad3d82
|
Assos Assos
|
if (selected.length < 1) {
|
158 |
|
|
alert(notSelected);
|
159 |
0ccfec7f
|
Assos Assos
|
|
160 |
85ad3d82
|
Assos Assos
|
return;
|
161 |
|
|
}
|
162 |
0ccfec7f
|
Assos Assos
|
|
163 |
|
|
|
164 |
85ad3d82
|
Assos Assos
|
onSelect(selected);
|
165 |
0ccfec7f
|
Assos Assos
|
|
166 |
|
|
|
167 |
|
|
$(this).dialog('close');
|
168 |
|
|
};
|
169 |
85ad3d82
|
Assos Assos
|
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
0ccfec7f
|
Assos Assos
|
|
175 |
|
|
|
176 |
85ad3d82
|
Assos Assos
|
|
177 |
|
|
|
178 |
0ccfec7f
|
Assos Assos
|
|
179 |
|
|
|
180 |
85ad3d82
|
Assos Assos
|
|
181 |
|
|
|
182 |
0ccfec7f
|
Assos Assos
|
|
183 |
85ad3d82
|
Assos Assos
|
|
184 |
|
|
Drupal.media.popups.mediaStyleSelector = function (mediaFile, onSelect, options) {
|
185 |
|
|
var defaults = Drupal.media.popups.mediaStyleSelector.getDefaults();
|
186 |
0ccfec7f
|
Assos Assos
|
|
187 |
85ad3d82
|
Assos Assos
|
|
188 |
ca0757b9
|
Assos Assos
|
if (typeof defaults.src === 'string' ) {
|
189 |
|
|
defaults.src = defaults.src.replace('-media_id-', mediaFile.fid) + '&fields=' + encodeURIComponent(JSON.stringify(mediaFile.fields));
|
190 |
|
|
}
|
191 |
|
|
else {
|
192 |
|
|
var src = defaults.src.shift();
|
193 |
0ccfec7f
|
Assos Assos
|
|
194 |
ca0757b9
|
Assos Assos
|
defaults.src.unshift(src);
|
195 |
|
|
defaults.src = src.replace('-media_id-', mediaFile.fid) + '&fields=' + encodeURIComponent(JSON.stringify(mediaFile.fields));
|
196 |
|
|
}
|
197 |
0ccfec7f
|
Assos Assos
|
|
198 |
85ad3d82
|
Assos Assos
|
options = $.extend({}, defaults, options);
|
199 |
|
|
|
200 |
0ccfec7f
|
Assos Assos
|
|
201 |
|
|
var mediaIframe = Drupal.media.popups.getPopupIframe(options.src, 'mediaStyleSelector');
|
202 |
85ad3d82
|
Assos Assos
|
|
203 |
0ccfec7f
|
Assos Assos
|
|
204 |
|
|
mediaIframe.bind('load', options, options.onLoad);
|
205 |
85ad3d82
|
Assos Assos
|
|
206 |
0ccfec7f
|
Assos Assos
|
|
207 |
85ad3d82
|
Assos Assos
|
var dialogOptions = Drupal.media.popups.getDialogOptions();
|
208 |
|
|
|
209 |
0ccfec7f
|
Assos Assos
|
|
210 |
|
|
var ok = Drupal.t('OK');
|
211 |
|
|
var notSelected = Drupal.t('Very sorry, there was an unknown error embedding media.');
|
212 |
85ad3d82
|
Assos Assos
|
|
213 |
0ccfec7f
|
Assos Assos
|
dialogOptions.buttons[ok] = function () {
|
214 |
|
|
|
215 |
85ad3d82
|
Assos Assos
|
var formattedMedia = this.contentWindow.Drupal.media.formatForm.getFormattedMedia();
|
216 |
0ccfec7f
|
Assos Assos
|
|
217 |
|
|
|
218 |
85ad3d82
|
Assos Assos
|
if (!formattedMedia) {
|
219 |
|
|
alert(notSelected);
|
220 |
0ccfec7f
|
Assos Assos
|
|
221 |
85ad3d82
|
Assos Assos
|
return;
|
222 |
|
|
}
|
223 |
0ccfec7f
|
Assos Assos
|
|
224 |
|
|
|
225 |
85ad3d82
|
Assos Assos
|
onSelect(formattedMedia);
|
226 |
0ccfec7f
|
Assos Assos
|
|
227 |
|
|
|
228 |
|
|
$(this).dialog('close');
|
229 |
85ad3d82
|
Assos Assos
|
};
|
230 |
|
|
|
231 |
0ccfec7f
|
Assos Assos
|
|
232 |
ca0757b9
|
Assos Assos
|
var dialog = mediaIframe.dialog(dialogOptions);
|
233 |
|
|
|
234 |
0ccfec7f
|
Assos Assos
|
|
235 |
ca0757b9
|
Assos Assos
|
Drupal.media.popups.sizeDialog(dialog);
|
236 |
|
|
Drupal.media.popups.resizeDialog(dialog);
|
237 |
|
|
Drupal.media.popups.scrollDialog(dialog);
|
238 |
|
|
Drupal.media.popups.overlayDisplace(dialog.parents(".ui-dialog"));
|
239 |
85ad3d82
|
Assos Assos
|
|
240 |
|
|
return mediaIframe;
|
241 |
|
|
};
|
242 |
|
|
|
243 |
|
|
Drupal.media.popups.mediaStyleSelector.mediaBrowserOnLoad = function (e) {
|
244 |
|
|
};
|
245 |
|
|
|
246 |
|
|
Drupal.media.popups.mediaStyleSelector.getDefaults = function () {
|
247 |
|
|
return {
|
248 |
|
|
src: Drupal.settings.media.styleSelectorUrl,
|
249 |
|
|
onLoad: Drupal.media.popups.mediaStyleSelector.mediaBrowserOnLoad
|
250 |
|
|
};
|
251 |
|
|
};
|
252 |
|
|
|
253 |
|
|
|
254 |
|
|
|
255 |
|
|
|
256 |
|
|
|
257 |
0ccfec7f
|
Assos Assos
|
|
258 |
|
|
|
259 |
85ad3d82
|
Assos Assos
|
|
260 |
|
|
|
261 |
0ccfec7f
|
Assos Assos
|
|
262 |
|
|
|
263 |
85ad3d82
|
Assos Assos
|
|
264 |
|
|
|
265 |
0ccfec7f
|
Assos Assos
|
|
266 |
85ad3d82
|
Assos Assos
|
|
267 |
|
|
Drupal.media.popups.mediaFieldEditor = function (fid, onSelect, options) {
|
268 |
|
|
var defaults = Drupal.media.popups.mediaFieldEditor.getDefaults();
|
269 |
0ccfec7f
|
Assos Assos
|
|
270 |
85ad3d82
|
Assos Assos
|
|
271 |
|
|
defaults.src = defaults.src.replace('-media_id-', fid);
|
272 |
|
|
options = $.extend({}, defaults, options);
|
273 |
|
|
|
274 |
0ccfec7f
|
Assos Assos
|
|
275 |
|
|
var mediaIframe = Drupal.media.popups.getPopupIframe(options.src, 'mediaFieldEditor');
|
276 |
85ad3d82
|
Assos Assos
|
|
277 |
0ccfec7f
|
Assos Assos
|
|
278 |
|
|
mediaIframe.bind('load', options, options.onLoad);
|
279 |
85ad3d82
|
Assos Assos
|
|
280 |
0ccfec7f
|
Assos Assos
|
|
281 |
85ad3d82
|
Assos Assos
|
var dialogOptions = Drupal.media.popups.getDialogOptions();
|
282 |
|
|
|
283 |
0ccfec7f
|
Assos Assos
|
|
284 |
|
|
var ok = Drupal.t('OK');
|
285 |
|
|
var notSelected = Drupal.t('Very sorry, there was an unknown error embedding media.');
|
286 |
|
|
|
287 |
85ad3d82
|
Assos Assos
|
dialogOptions.buttons[ok] = function () {
|
288 |
0ccfec7f
|
Assos Assos
|
|
289 |
85ad3d82
|
Assos Assos
|
var formattedMedia = this.contentWindow.Drupal.media.formatForm.getFormattedMedia();
|
290 |
0ccfec7f
|
Assos Assos
|
|
291 |
|
|
|
292 |
85ad3d82
|
Assos Assos
|
if (!formattedMedia) {
|
293 |
|
|
alert(notSelected);
|
294 |
0ccfec7f
|
Assos Assos
|
|
295 |
85ad3d82
|
Assos Assos
|
return;
|
296 |
|
|
}
|
297 |
0ccfec7f
|
Assos Assos
|
|
298 |
|
|
|
299 |
85ad3d82
|
Assos Assos
|
onSelect(formattedMedia);
|
300 |
0ccfec7f
|
Assos Assos
|
|
301 |
|
|
|
302 |
|
|
$(this).dialog('close');
|
303 |
85ad3d82
|
Assos Assos
|
};
|
304 |
|
|
|
305 |
0ccfec7f
|
Assos Assos
|
|
306 |
ca0757b9
|
Assos Assos
|
var dialog = mediaIframe.dialog(dialogOptions);
|
307 |
|
|
|
308 |
0ccfec7f
|
Assos Assos
|
|
309 |
ca0757b9
|
Assos Assos
|
Drupal.media.popups.sizeDialog(dialog);
|
310 |
|
|
Drupal.media.popups.resizeDialog(dialog);
|
311 |
|
|
Drupal.media.popups.scrollDialog(dialog);
|
312 |
|
|
Drupal.media.popups.overlayDisplace(dialog);
|
313 |
85ad3d82
|
Assos Assos
|
|
314 |
|
|
return mediaIframe;
|
315 |
|
|
};
|
316 |
|
|
|
317 |
|
|
Drupal.media.popups.mediaFieldEditor.mediaBrowserOnLoad = function (e) {
|
318 |
|
|
|
319 |
|
|
};
|
320 |
|
|
|
321 |
|
|
Drupal.media.popups.mediaFieldEditor.getDefaults = function () {
|
322 |
|
|
return {
|
323 |
|
|
|
324 |
|
|
src: '/media/-media_id-/edit?render=media-popup',
|
325 |
|
|
onLoad: Drupal.media.popups.mediaFieldEditor.mediaBrowserOnLoad
|
326 |
|
|
};
|
327 |
|
|
};
|
328 |
|
|
|
329 |
|
|
|
330 |
0ccfec7f
|
Assos Assos
|
|
331 |
85ad3d82
|
Assos Assos
|
|
332 |
|
|
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
|
336 |
|
|
Drupal.media.popups.getDialogOptions = function () {
|
337 |
|
|
return {
|
338 |
0ccfec7f
|
Assos Assos
|
title: Drupal.t('Media browser'),
|
339 |
85ad3d82
|
Assos Assos
|
buttons: {},
|
340 |
ca0757b9
|
Assos Assos
|
dialogClass: Drupal.settings.media.dialogOptions.dialogclass,
|
341 |
|
|
modal: Drupal.settings.media.dialogOptions.modal,
|
342 |
|
|
draggable: Drupal.settings.media.dialogOptions.draggable,
|
343 |
|
|
resizable: Drupal.settings.media.dialogOptions.resizable,
|
344 |
|
|
minWidth: Drupal.settings.media.dialogOptions.minwidth,
|
345 |
|
|
width: Drupal.settings.media.dialogOptions.width,
|
346 |
|
|
height: Drupal.settings.media.dialogOptions.height,
|
347 |
|
|
position: Drupal.settings.media.dialogOptions.position,
|
348 |
85ad3d82
|
Assos Assos
|
overlay: {
|
349 |
ca0757b9
|
Assos Assos
|
backgroundColor: Drupal.settings.media.dialogOptions.overlay.backgroundcolor,
|
350 |
|
|
opacity: Drupal.settings.media.dialogOptions.overlay.opacity
|
351 |
85ad3d82
|
Assos Assos
|
},
|
352 |
ca0757b9
|
Assos Assos
|
zIndex: Drupal.settings.media.dialogOptions.zindex,
|
353 |
85ad3d82
|
Assos Assos
|
close: function (event, ui) {
|
354 |
da542b7b
|
Assos Assos
|
var elem = $(event.target);
|
355 |
|
|
var id = elem.attr('id');
|
356 |
|
|
if(id == 'mediaStyleSelector') {
|
357 |
|
|
$(this).dialog("destroy");
|
358 |
|
|
$('#mediaStyleSelector').remove();
|
359 |
|
|
}
|
360 |
|
|
else {
|
361 |
|
|
$(this).dialog("destroy");
|
362 |
|
|
$('#mediaBrowser').remove();
|
363 |
|
|
}
|
364 |
85ad3d82
|
Assos Assos
|
}
|
365 |
|
|
};
|
366 |
|
|
};
|
367 |
|
|
|
368 |
|
|
|
369 |
|
|
|
370 |
|
|
|
371 |
|
|
Drupal.media.popups.getPopupIframe = function (src, id, options) {
|
372 |
ca0757b9
|
Assos Assos
|
var defaults = {width: '100%', scrolling: 'auto'};
|
373 |
85ad3d82
|
Assos Assos
|
var options = $.extend({}, defaults, options);
|
374 |
|
|
|
375 |
|
|
return $('<iframe class="media-modal-frame"/>')
|
376 |
|
|
.attr('src', src)
|
377 |
|
|
.attr('width', options.width)
|
378 |
|
|
.attr('id', id)
|
379 |
|
|
.attr('scrolling', options.scrolling);
|
380 |
|
|
};
|
381 |
|
|
|
382 |
|
|
Drupal.media.popups.overlayDisplace = function (dialog) {
|
383 |
|
|
if (parent.window.Drupal.overlay && jQuery.isFunction(parent.window.Drupal.overlay.getDisplacement)) {
|
384 |
|
|
var overlayDisplace = parent.window.Drupal.overlay.getDisplacement('top');
|
385 |
0ccfec7f
|
Assos Assos
|
|
386 |
85ad3d82
|
Assos Assos
|
if (dialog.offset().top < overlayDisplace) {
|
387 |
|
|
dialog.css('top', overlayDisplace);
|
388 |
|
|
}
|
389 |
|
|
}
|
390 |
|
|
}
|
391 |
|
|
|
392 |
ca0757b9
|
Assos Assos
|
|
393 |
|
|
|
394 |
|
|
|
395 |
|
|
|
396 |
|
|
|
397 |
|
|
|
398 |
|
|
Drupal.media.popups.sizeDialog = function (dialogElement) {
|
399 |
|
|
if (!dialogElement.is(':visible')) {
|
400 |
|
|
return;
|
401 |
|
|
}
|
402 |
0ccfec7f
|
Assos Assos
|
|
403 |
ca0757b9
|
Assos Assos
|
var windowWidth = $(window).width();
|
404 |
|
|
var dialogWidth = windowWidth * 0.8;
|
405 |
|
|
var windowHeight = $(window).height();
|
406 |
|
|
var dialogHeight = windowHeight * 0.8;
|
407 |
|
|
|
408 |
|
|
dialogElement.dialog("option", "width", dialogWidth);
|
409 |
|
|
dialogElement.dialog("option", "height", dialogHeight);
|
410 |
|
|
dialogElement.dialog("option", "position", 'center');
|
411 |
|
|
|
412 |
|
|
$('.media-modal-frame').width('100%');
|
413 |
|
|
}
|
414 |
|
|
|
415 |
|
|
|
416 |
|
|
|
417 |
|
|
|
418 |
|
|
|
419 |
|
|
|
420 |
|
|
|
421 |
|
|
Drupal.media.popups.resizeDialog = function (dialogElement) {
|
422 |
|
|
$(window).resize(function() {
|
423 |
|
|
Drupal.media.popups.sizeDialog(dialogElement);
|
424 |
|
|
});
|
425 |
|
|
}
|
426 |
|
|
|
427 |
|
|
|
428 |
|
|
|
429 |
|
|
|
430 |
|
|
|
431 |
|
|
|
432 |
|
|
|
433 |
|
|
Drupal.media.popups.scrollDialog = function (dialogElement) {
|
434 |
|
|
|
435 |
|
|
$(window).scroll(function() {
|
436 |
|
|
if (!dialogElement.is(':visible')) {
|
437 |
|
|
return;
|
438 |
|
|
}
|
439 |
0ccfec7f
|
Assos Assos
|
|
440 |
ca0757b9
|
Assos Assos
|
dialogElement.dialog("option", "position", 'center');
|
441 |
|
|
});
|
442 |
|
|
}
|
443 |
|
|
|
444 |
85ad3d82
|
Assos Assos
|
})(jQuery); |