Skip to content

Instantly share code, notes, and snippets.

@duellj
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save duellj/9957265 to your computer and use it in GitHub Desktop.

Select an option

Save duellj/9957265 to your computer and use it in GitHub Desktop.
Patch for Media alpha1 and jQuery 1.10
diff --git a/css/media.css b/css/media.css
index 92df514..0873b28 100644
--- a/css/media.css
+++ b/css/media.css
@@ -73,7 +73,6 @@
}
.media-item img {
- height: auto;
margin-bottom: 10px;
}
diff --git a/js/media.browser.js b/js/media.browser.js
index 3506263..42e0a10 100644
--- a/js/media.browser.js
+++ b/js/media.browser.js
@@ -26,7 +26,8 @@ Drupal.behaviors.MediaBrowser = {
// Instantiate the tabs.
$('#media-browser-tabset').tabs({
// Ensure that the modal resizes to the content on each tab switch.
- show: Drupal.media.browser.resizeIframe
+ show: Drupal.media.browser.resizeIframe,
+ activate: Drupal.media.browser.resizeIframe
});
$('.ui-tabs-nav li').mouseup(function() {
@@ -109,7 +110,7 @@ Drupal.media.browser.finalizeSelection = function () {
*/
Drupal.media.browser.resizeIframe = function (event) {
var h = $('body').height();
- $(parent.window.document).find('#mediaBrowser').height(h);
+ $(parent.window.document).find('.media-modal-frame:visible').height(h);
};
Drupal.media.browser.selectErrorTab = function() {
@@ -132,7 +133,7 @@ Drupal.media.browser.selectErrorTab = function() {
Drupal.media.browser.selectActiveTab = function() {
// Find the index of the last active tab.
setTimeout(function() {
- $('#media-browser-tabset').tabs('select', Drupal.media.browser.activeTab);
+ $('#media-browser-tabset').tabs('option', 'active', Drupal.media.browser.activeTab);
Drupal.media.browser.resizeIframe();
}, 10);
};
diff --git a/js/wysiwyg-media.js b/js/wysiwyg-media.js
index 5de03f9..2df8817 100644
--- a/js/wysiwyg-media.js
+++ b/js/wysiwyg-media.js
@@ -19,9 +19,12 @@ Drupal.wysiwyg.plugins.media = {
* @param node
* A DOM element
*/
- isNode: function(node) {
- return $(node).is('img.media-element');
- },
+ isNode: function(node, selection) {
+ if (node == null) {
+ node = selection.getStartElement().$;
+ }
+ return $(node).closest('.media-element').length > 0;
+ },
/**
* Execute the button.
*
@@ -39,10 +42,20 @@ Drupal.wysiwyg.plugins.media = {
*/
invoke: function (data, settings, instanceId) {
if (data.format == 'html') {
+ if (data.node == null) {
+ data.node = data.selection.getStartElement().$;
+ }
var insert = new InsertMedia(instanceId);
if (this.isNode(data.node)) {
+ // Get the whole media element.
+ var media_element = $(data.node).closest('.media-element');
// Change the view mode for already-inserted media.
- var media_file = extract_file_info($(data.node));
+ var media_file = extract_file_info($(media_element));
+
+ // Ensure that element is properly selected.
+ var ckeditor_element = new CKEDITOR.dom.element(media_element[0]);
+ CKEDITOR.instances[instanceId].getSelection().selectElement(ckeditor_element);
+
insert.onSelect([media_file]);
}
else {
@@ -221,6 +234,7 @@ function create_element (html, info) {
html = '<span>' + html + '</span>';
}
var element = $(html);
+ element.children().wrapAll('<span contenteditable="false" />');
// Move attributes from the file info array to the placeholder element.
if (info.attributes) {
diff --git a/editors/js/ckeditor-3.0.js b/editors/js/ckeditor-3.0.js
index f288928..fa49f21 100644
--- a/editors/js/ckeditor-3.0.js
+++ b/editors/js/ckeditor-3.0.js
@@ -122,7 +122,7 @@ Drupal.wysiwyg.editor.attach.ckeditor = function(context, params, settings) {
var plugin = Drupal.wysiwyg.plugins[name];
if ($.isFunction(plugin.isNode)) {
var node = event.data.selection.getSelectedElement();
- var state = plugin.isNode(node ? node.$ : null) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF;
+ var state = plugin.isNode(node ? node.$ : null, event.data.selection) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF;
event.editor.getCommand(name).setState(state);
}
});
@@ -184,27 +184,24 @@ Drupal.wysiwyg.editor.instance.ckeditor = {
editor.on('mode', function(ev) {
if (ev.editor.mode == 'wysiwyg') {
// Inject CSS files directly into the editing area head tag.
- $('head', $('#cke_contents_' + ev.editor.name + ' iframe').eq(0).contents()).append('<link rel="stylesheet" href="' + settings.css + '" type="text/css" >');
+ var iframe = $('#cke_contents_' + ev.editor.name + ' iframe, #' + ev.editor.id + '_contents iframe');
+ $('head', iframe.eq(0).contents()).append('<link rel="stylesheet" href="' + settings.css + '" type="text/css" >');
}
});
}
if (typeof Drupal.wysiwyg.plugins[pluginName].invoke == 'function') {
var pluginCommand = {
exec: function (editor) {
- var data = { format: 'html', node: null, content: '' };
+ var data = { format: 'html', node: null, content: '', selection: {} };
var selection = editor.getSelection();
+ data.selection = selection;
if (selection) {
data.node = selection.getSelectedElement();
if (data.node) {
data.node = data.node.$;
}
if (selection.getType() == CKEDITOR.SELECTION_TEXT) {
- if (CKEDITOR.env.ie) {
- data.content = selection.getNative().createRange().text;
- }
- else {
- data.content = selection.getNative().toString();
- }
+ data.content = selection.getSelectedText();
}
else if (data.node) {
// content is supposed to contain the "outerHTML".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment