1 |
85ad3d82
|
Assos Assos
|
|
2 |
ca0757b9
|
Assos Assos
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
85ad3d82
|
Assos Assos
|
|
9 |
|
|
|
10 |
|
|
(function ($) {
|
11 |
|
|
|
12 |
|
|
|
13 |
0ccfec7f
|
Assos Assos
|
|
14 |
85ad3d82
|
Assos Assos
|
|
15 |
|
|
Drupal.behaviors.mediaElement = {
|
16 |
|
|
attach: function (context, settings) {
|
17 |
0ccfec7f
|
Assos Assos
|
var $context = $(context);
|
18 |
|
|
var elements;
|
19 |
|
|
|
20 |
|
|
function initMediaBrowser(selector) {
|
21 |
d1c64ea8
|
Assos Assos
|
var widget=$context.find(selector).once('media-browser-launch');
|
22 |
|
|
var browse=widget.siblings('.browse').add(widget.find('.browse'));
|
23 |
|
|
var upload=browse.siblings('.upload').add(widget.find('.upload'));
|
24 |
|
|
var attach=upload.siblings('.attach').add(widget.find('.attach'));
|
25 |
|
|
browse.show();
|
26 |
|
|
upload.hide();
|
27 |
|
|
attach.hide();
|
28 |
|
|
browse.bind('click', {configuration: settings.media.elements[selector]}, Drupal.media.openBrowser);
|
29 |
0ccfec7f
|
Assos Assos
|
}
|
30 |
|
|
|
31 |
ca0757b9
|
Assos Assos
|
if (settings.media && settings.media.elements) {
|
32 |
0ccfec7f
|
Assos Assos
|
elements = settings.media.elements;
|
33 |
|
|
Object.keys(elements).forEach(initMediaBrowser);
|
34 |
|
|
}
|
35 |
|
|
},
|
36 |
|
|
detach: function (context, settings, trigger) {
|
37 |
|
|
var $context = $(context);
|
38 |
|
|
var elements;
|
39 |
|
|
|
40 |
|
|
function removeMediaBrowser(selector) {
|
41 |
|
|
$context.find(selector)
|
42 |
|
|
.removeOnce('media-browser-launch')
|
43 |
|
|
.siblings('.browse').hide()
|
44 |
|
|
.siblings('.upload').show()
|
45 |
|
|
.siblings('.attach').show()
|
46 |
|
|
.siblings('.browse').unbind('click', Drupal.media.openBrowser);
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
if (trigger === 'unload' && settings.media && settings.media.elements) {
|
50 |
|
|
elements = settings.media.elements;
|
51 |
|
|
Object.keys(elements).forEach(removeMediaBrowser);
|
52 |
ca0757b9
|
Assos Assos
|
}
|
53 |
|
|
}
|
54 |
|
|
};
|
55 |
85ad3d82
|
Assos Assos
|
|
56 |
ca0757b9
|
Assos Assos
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
Drupal.behaviors.mediaButtons = {
|
60 |
|
|
attach: function (context) {
|
61 |
|
|
$('input.form-submit', context).bind('mousedown', Drupal.media.disableFields);
|
62 |
|
|
},
|
63 |
|
|
detach: function (context) {
|
64 |
|
|
$('input.form-submit', context).unbind('mousedown', Drupal.media.disableFields);
|
65 |
|
|
}
|
66 |
|
|
};
|
67 |
85ad3d82
|
Assos Assos
|
|
68 |
ca0757b9
|
Assos Assos
|
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
Drupal.media = Drupal.media || {};
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
Drupal.media.openBrowser = function (event) {
|
77 |
|
|
var clickedButton = this;
|
78 |
|
|
var configuration = event.data.configuration.global;
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
var fidField = $(this).siblings('.fid');
|
82 |
|
|
var previewField = $(this).siblings('.preview');
|
83 |
|
|
var uploadField = $(this).siblings('.upload');
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
var editButton = $(this).siblings('.edit');
|
87 |
|
|
var removeButton = $(this).siblings('.remove');
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
Drupal.media.popups.mediaBrowser(function (mediaFiles) {
|
91 |
|
|
|
92 |
|
|
if (mediaFiles.length < 0) {
|
93 |
|
|
return;
|
94 |
|
|
}
|
95 |
|
|
|
96 |
fc3d89c3
|
Assos Assos
|
var mediaFileValue;
|
97 |
|
|
|
98 |
|
|
if (mediaFiles.length > 1) {
|
99 |
|
|
|
100 |
|
|
mediaFileValue = mediaFiles.map(function(file) {
|
101 |
|
|
return file.fid;
|
102 |
|
|
}).join(',');
|
103 |
|
|
}
|
104 |
|
|
else {
|
105 |
|
|
|
106 |
|
|
mediaFileValue = mediaFiles[0].fid;
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
previewField.html(mediaFileValue.preview);
|
110 |
|
|
}
|
111 |
ca0757b9
|
Assos Assos
|
|
112 |
|
|
|
113 |
fc3d89c3
|
Assos Assos
|
uploadField.val(mediaFileValue);
|
114 |
ca0757b9
|
Assos Assos
|
uploadField.trigger('change');
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
var attachButton = uploadField.siblings('.attach');
|
118 |
|
|
attachButton.trigger('mousedown');
|
119 |
|
|
}, configuration);
|
120 |
|
|
|
121 |
|
|
return false;
|
122 |
|
|
};
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
Drupal.media.disableFields = function (event) {
|
128 |
|
|
var clickedButton = this;
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
if (!$(clickedButton).hasClass('ajax-processed')) {
|
132 |
|
|
return;
|
133 |
85ad3d82
|
Assos Assos
|
}
|
134 |
ca0757b9
|
Assos Assos
|
|
135 |
|
|
|
136 |
|
|
var $enabledFields = [];
|
137 |
|
|
if ($(this).closest('div.media-widget').length > 0) {
|
138 |
|
|
$enabledFields = $(this).closest('div.media-widget').find('input.attach');
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
var $fieldsToTemporarilyDisable = $('div.media-widget input.attach').not($enabledFields).not(':disabled');
|
150 |
|
|
$fieldsToTemporarilyDisable.attr('disabled', 'disabled');
|
151 |
|
|
setTimeout(function (){
|
152 |
|
|
$fieldsToTemporarilyDisable.attr('disabled', false);
|
153 |
|
|
}, 1000);
|
154 |
85ad3d82
|
Assos Assos
|
};
|
155 |
|
|
|
156 |
|
|
})(jQuery); |