diff --git includes/media.filter.inc includes/media.filter.inc index 64b72a3..452856c 100644 --- includes/media.filter.inc +++ includes/media.filter.inc @@ -318,7 +318,6 @@ function media_token_to_markup($match, $wysiwyg = FALSE) { $settings['fields'] = $fields; if (!empty($tag_info['attributes']) && is_array($tag_info['attributes'])) { - $attribute_whitelist = variable_get('media__wysiwyg_allowed_attributes', array('height', 'width', 'hspace', 'vspace', 'border', 'align', 'style', 'class', 'id', 'usemap', 'data-picture-group', 'data-picture-align')); $settings['attributes'] = array_intersect_key($tag_info['attributes'], array_flip($attribute_whitelist)); $settings['fields'] = $fields; diff --git js/media.filter.js js/media.filter.js index 2e4ceda..e1a12d4 100644 --- js/media.filter.js +++ js/media.filter.js @@ -38,7 +38,10 @@ var element = Drupal.media.filter.create_element(tagmap[macro], media_definition); var markup = Drupal.media.filter.outerHTML(element); - content = content.replace(macro, Drupal.media.filter.getWrapperStart(i) + markup + Drupal.media.filter.getWrapperEnd(i)); + // Rebuild the tagmap with the markup that will actually be in + // the editor. + Drupal.settings.tagmap[macro] = markup; + content = content.replace(macro, markup); } } i++; @@ -52,20 +55,27 @@ * @param content */ replacePlaceholderWithToken: function(content) { + // Convert all xhtml markup to html for cleaner matching/replacing. + content = content.replace(/[\s]\/\>/g, '>'); + var tagmap = Drupal.media.filter.ensure_tagmap(); var i = 1; for (var macro in tagmap) { var startTag = Drupal.media.filter.getWrapperStart(i), endTag = Drupal.media.filter.getWrapperEnd(i); - var startPos = content.indexOf(startTag), endPos = content.indexOf(endTag); - if (startPos !== -1 && endPos !== -1) { - // If the placeholder wrappers are empty, remove the macro too. - if (endPos - startPos - startTag.length === 0) { - macro = ''; - } - content = content.substr(0, startPos) + macro + content.substr(endPos + (new String(endTag)).length); - } + content = content.replace(startTag, ''); + content = content.replace(endTag, ''); i++; } + + Drupal.settings.tagmap = []; + + // Re-build the macros in case any element has changed in the editor. + $('.media-element', content).each(function(i, element) { + var macro = Drupal.media.filter.create_macro($(element)); + Drupal.settings.tagmap[macro] = element.outerHTML; + content = content.replace(element.outerHTML, macro); + }); + return content; }, @@ -182,7 +192,7 @@ file_info.attributes = {}; // Extract whitelisted attributes. - $.each(Drupal.media.filter.allowed_attributes, function(i, a) { + $.each(Drupal.media.filter.allowed_attributes(), function(i, a) { if (value = element.attr(a)) { file_info.attributes[a] = value; } @@ -219,15 +229,8 @@ // Store macro/markup in the tagmap. Drupal.media.filter.ensure_tagmap(); - var i = 1; - for (var key in Drupal.settings.tagmap) { - i++; - } Drupal.settings.tagmap[macro] = markup; - - // Return the wrapped html code to insert in an editor and use it with - // replacePlaceholderWithToken() - return Drupal.media.filter.getWrapperStart(i) + markup + Drupal.media.filter.getWrapperEnd(i); + return markup; }, /** diff --git js/media.popups.js js/media.popups.js index 95b72e3..0821c8b 100644 --- js/media.popups.js +++ js/media.popups.js @@ -175,6 +175,7 @@ Drupal.media.popups.mediaStyleSelector = function (mediaFile, onSelect, options) dialogOptions.buttons[ok] = function () { var formattedMedia = this.contentWindow.Drupal.media.formatForm.getFormattedMedia(); + formattedMedia.options = $.extend({}, mediaFile.attributes, formattedMedia.options); if (!formattedMedia) { alert(notSelected); return;