Revision 2b3c8cc1
Added by Assos Assos about 9 years ago
drupal7/sites/all/modules/media/includes/media.browser.inc | ||
---|---|---|
24 | 24 |
} |
25 | 25 |
$files = file_load_multiple($fids); |
26 | 26 |
foreach ($files as $file) { |
27 |
media_browser_build_media_item($file); |
|
27 |
$view_mode = isset($params['view_mode']) ? $params['view_mode'] : 'preview'; |
|
28 |
media_browser_build_media_item($file, $view_mode); |
|
28 | 29 |
} |
29 | 30 |
$setting = array('media' => array('selectedMedia' => array_values($files))); |
30 | 31 |
drupal_add_js($setting, 'setting'); |
... | ... | |
148 | 149 |
return $output; |
149 | 150 |
} |
150 | 151 |
|
151 |
/** |
|
152 |
* Attaches media browser javascript to an element. |
|
153 |
* |
|
154 |
* @param array $element |
|
155 |
* The element array to attach to. |
|
156 |
*/ |
|
157 |
function media_attach_browser_js(&$element) { |
|
158 |
$javascript = media_browser_js(); |
|
159 |
foreach ($javascript as $key => $definitions) { |
|
160 |
foreach ($definitions as $definition) { |
|
161 |
$element['#attached'][$key][] = $definition; |
|
162 |
} |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
/** |
|
167 |
* Helper function to define browser javascript. |
|
168 |
*/ |
|
169 |
function media_browser_js() { |
|
170 |
$settings = array( |
|
171 |
'browserUrl' => url('media/browser', array( |
|
172 |
'query' => array( |
|
173 |
'render' => 'media-popup' |
|
174 |
)) |
|
175 |
), |
|
176 |
'styleSelectorUrl' => url('media/-media_id-/format-form', array( |
|
177 |
'query' => array( |
|
178 |
'render' => 'media-popup' |
|
179 |
)) |
|
180 |
), |
|
181 |
'dialogOptions' => array( |
|
182 |
'dialogclass' => variable_get('media_dialogclass', 'media-wrapper'), |
|
183 |
'modal' => (boolean)variable_get('media_modal', TRUE), |
|
184 |
'draggable' => (boolean)variable_get('media_draggable', FALSE), |
|
185 |
'resizable' => (boolean)variable_get('media_resizable', FALSE), |
|
186 |
'minwidth' => (int)variable_get('media_minwidth', 500), |
|
187 |
'width' => (int)variable_get('media_width', 670), |
|
188 |
'height' => (int)variable_get('media_height', 280), |
|
189 |
'position' => variable_get('media_position', 'center'), |
|
190 |
'overlay' => array( |
|
191 |
'backgroundcolor' => variable_get('media_backgroundcolor', '#000000'), |
|
192 |
'opacity' => (float)variable_get('media_opacity', 0.4), |
|
193 |
), |
|
194 |
'zindex' => (int)variable_get('media_zindex', 10000), |
|
195 |
), |
|
196 |
); |
|
197 |
|
|
198 |
return array( |
|
199 |
'library' => array( |
|
200 |
array('media', 'media_browser'), |
|
201 |
), |
|
202 |
'js' => array( |
|
203 |
array( |
|
204 |
'data' => array('media' => $settings), |
|
205 |
'type' => 'setting', |
|
206 |
), |
|
207 |
), |
|
208 |
); |
|
209 |
} |
|
210 |
|
|
211 | 152 |
/** |
212 | 153 |
* Menu callback for testing the media browser. |
213 | 154 |
*/ |
214 | 155 |
function media_browser_testbed($form) { |
215 |
media_attach_browser_js($form); |
|
156 |
$form['#attached']['library'][] = array('media', 'media_browser'); |
|
157 |
$form['#attached']['library'][] = array('media', 'media_browser_settings'); |
|
216 | 158 |
|
217 | 159 |
$form['test_element'] = array( |
218 | 160 |
'#type' => 'media', |
... | ... | |
290 | 232 |
} |
291 | 233 |
|
292 | 234 |
/** |
293 |
* Adds properties to the file.
|
|
235 |
* Adds additional properties to a file which are needed by the browser JS code.
|
|
294 | 236 |
* |
295 |
* Additional properties on this file are needed by the media browser JS code. |
|
237 |
* @param object $file |
|
238 |
* A Drupal file object. |
|
296 | 239 |
*/ |
297 |
function media_browser_build_media_item($file) { |
|
298 |
$preview = media_get_thumbnail_preview($file); |
|
240 |
function media_browser_build_media_item($file, $view_mode = 'preview') {
|
|
241 |
$preview = media_get_thumbnail_preview($file, NULL, $view_mode);
|
|
299 | 242 |
$file->preview = drupal_render($preview); |
300 | 243 |
$file->url = file_create_url($file->uri); |
301 | 244 |
} |
Also available in: Unified diff
Weekly update of contrib modules