Révision 0939d55c
Ajouté par Assos Assos il y a environ 7 ans
drupal7/sites/all/modules/media/modules/media_wysiwyg/js/media_wysiwyg.filter.js | ||
---|---|---|
181 | 181 |
$(mediaElements).each(function (i) { |
182 | 182 |
// Attempt to derive a JSON macro representation of the media placeholder. |
183 | 183 |
// Note: Drupal 7 ships with JQuery 1.4.4, which allows $(this).attr('outerHTML') to retrieve the eement's HTML, |
184 |
// but many sites use JQuery update to increate this to 1.6+, which insists on $(this).prop('outerHTML).
|
|
185 |
// Until the minimum jQuery is >= 1.6, we need to do this the old-school way.
|
|
184 |
// but many sites use JQuery update to increate this to 1.6+, which insists on $(this).prop('outerHTML). |
|
185 |
// Until the minimum jQuery is >= 1.6, we need to do this the old-school way. |
|
186 | 186 |
// See http://stackoverflow.com/questions/2419749/get-selected-elements-outer-html |
187 | 187 |
var markup = $(this).get(0).outerHTML; |
188 | 188 |
if (markup === undefined) { |
... | ... | |
291 | 291 |
} |
292 | 292 |
element.addClass(classes.join(' ')); |
293 | 293 |
|
294 |
// Attempt to override the link_title if the user has chosen to do this. |
|
295 |
info.link_text = this.overrideLinkTitle(info); |
|
294 | 296 |
// Apply link_text if present. |
295 | 297 |
if (info.link_text) { |
296 | 298 |
$('a', element).html(info.link_text); |
... | ... | |
309 | 311 |
var file_info = Drupal.media.filter.extract_file_info(element); |
310 | 312 |
if (file_info) { |
311 | 313 |
if (typeof file_info.link_text == 'string') { |
314 |
file_info.link_text = this.overrideLinkTitle(file_info); |
|
312 | 315 |
// Make sure the link_text-html-tags are properly escaped. |
313 | 316 |
file_info.link_text = file_info.link_text.replace(/</g, '<').replace(/>/g, '>'); |
314 | 317 |
} |
... | ... | |
430 | 433 |
return Drupal.settings.tagmap; |
431 | 434 |
}, |
432 | 435 |
|
436 |
/** |
|
437 |
* Return the overridden link title based on the file_entity title field |
|
438 |
* set. |
|
439 |
* @param file the file object. |
|
440 |
* @returns the overridden link_title or the existing link text if no |
|
441 |
* overridden. |
|
442 |
*/ |
|
443 |
overrideLinkTitle: function(file) { |
|
444 |
var file_title_field = Drupal.settings.media.img_title_field.replace('field_', ''); |
|
445 |
var file_title_field_machine_name = ''; |
|
446 |
if (typeof(file.fields) != 'undefined') { |
|
447 |
jQuery.each(file.fields, function(field, fieldValue) { |
|
448 |
if (field.indexOf(file_title_field) != -1) { |
|
449 |
file_title_field_machine_name = field; |
|
450 |
} |
|
451 |
}); |
|
452 |
|
|
453 |
if (typeof(file.fields[file_title_field_machine_name]) != 'undefined' && file.fields[file_title_field_machine_name] != '') { |
|
454 |
return file.fields[file_title_field_machine_name]; |
|
455 |
} |
|
456 |
else { |
|
457 |
return file.link_text; |
|
458 |
} |
|
459 |
} |
|
460 |
else { |
|
461 |
return file.link_text; |
|
462 |
} |
|
463 |
}, |
|
464 |
|
|
433 | 465 |
/** |
434 | 466 |
* Generates a unique "delta" for each embedding of a particular file. |
435 | 467 |
*/ |
436 | 468 |
fileEmbedDelta: function(fid, element) { |
437 | 469 |
// Ensure we have an object to track our deltas. |
438 | 470 |
Drupal.settings.mediaDeltas = Drupal.settings.mediaDeltas || {}; |
471 |
Drupal.settings.maxMediaDelta = Drupal.settings.maxMediaDelta || 0; |
|
439 | 472 |
|
440 | 473 |
// Check to see if the element already has one. |
441 | 474 |
if (element && element.data('delta')) { |
442 | 475 |
var existingDelta = element.data('delta'); |
443 |
// If so, make sure that it is being tracked in mediaDeltas. |
|
444 |
if (!Drupal.settings.mediaDeltas[fid]) { |
|
445 |
Drupal.settings.mediaDeltas[fid] = existingDelta; |
|
476 |
// If so, make sure that it is being tracked in mediaDeltas. If we're |
|
477 |
// going to create new deltas later on, make sure they do not overwrite |
|
478 |
// other mediaDeltas. |
|
479 |
if (!Drupal.settings.mediaDeltas[existingDelta]) { |
|
480 |
Drupal.settings.mediaDeltas[existingDelta] = fid; |
|
481 |
Drupal.settings.maxMediaDelta = Math.max(Drupal.settings.maxMediaDelta, existingDelta); |
|
446 | 482 |
} |
447 | 483 |
return existingDelta; |
448 | 484 |
} |
449 |
// Otherwise, generate a new one. Arbitrarily start with 1. |
|
450 |
var delta = 1; |
|
451 |
if (Drupal.settings.mediaDeltas[fid]) { |
|
452 |
delta = Drupal.settings.mediaDeltas[fid] + 1; |
|
453 |
} |
|
454 |
Drupal.settings.mediaDeltas[fid] = delta; |
|
455 |
return delta; |
|
485 |
// Otherwise, generate a new one. |
|
486 |
var newDelta = Drupal.settings.maxMediaDelta + 1; |
|
487 |
Drupal.settings.mediaDeltas[newDelta] = fid; |
|
488 |
Drupal.settings.maxMediaDelta = newDelta; |
|
489 |
return newDelta; |
|
456 | 490 |
} |
457 | 491 |
} |
458 | 492 |
|
Formats disponibles : Unified diff
Weekly update of contrib modules