Closed (fixed)
Project:
Scald: Media Management made easy
Version:
7.x-1.x-dev
Component:
Library/DnD
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
15 Dec 2014 at 12:33 UTC
Updated:
2 Apr 2015 at 20:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
nagy.balint commentedCant reproduce it on IE 11 either, only on firefox so far.
Comment #2
gifad commentedFound a tricky but working workaround on firefox : insert atom at the end of document, if the liner llistener did not catch it...
Does not change anything on Safari (and Chrome, I presume)
Warning : Not tested, at all, on IE...
NB: I did not remove the console logs, which show who caught what...
Comment #3
nagy.balint commentedThanks for the patch!
It seemed to work for a while but then i started to get JS errors.
My log is the following
"legacy onDrop" plugin.js:110
"legacy onDrop" plugin.js:110
TypeError: this.relations[d.uid] is undefined ckeditor.js:1023
"liner onDrop" plugin.js:402
"legacy onDrop" plugin.js:110
"liner onDrop" plugin.js:402
"legacy onDrop" plugin.js:110
"liner onDrop" plugin.js:402
"legacy onDrop" plugin.js:110
"liner onDrop" plugin.js:402
"legacy onDrop" plugin.js:110
IndexSizeError: Index or size is negative or greater than the allowed amount ckeditor.js:409
"legacy onDrop" plugin.js:110
The first two was when i dropped to the bottom edge, and then i only got the legacy.
Then the first typeError i got when i tried to drop in between two atoms. But it worked the second time. The atom is not broken in that case just the drop does not happen.
Then the last error i got when I already had many atoms in the body and then i dropped again to the bottom edge. And then that one was again a broken atom.
Tried again, and got the same result from just dropping a single atom to the edge, then it worked, and then when i tried to do the same dropping again to the edge i got the error and the broken atom.
"legacy onDrop" plugin.js:110
IndexSizeError: Index or size is negative or greater than the allowed amount ckeditor.js:409
"legacy onDrop" plugin.js:110
Then i tried again. Dropped an atom to the bottom line, and then tried to drop one at the top line, and twice i could not do it because of the TypeError above. It worked the third time though.
Comment #4
yched commentedStill can't reproduce the bug, even on Firefox 34 :-(
Are we talking about a drop in an empty textarea, or a drop in a taxtarea that already contains text paragraphs ?
Comment #5
gifad commentedThanks nagy.balint for the report, it gives me several hints...
First, I'd always thought that false drop swere drops beyond document limits
Now I see that false drops occur when over a non editable content, what an atom typically is.
The errors occurring on drop "between two adjacent atoms" are probably occuring over one of these two atoms (it depends on css theming (magins, border, ...) but for my atoms, there is a single 1 pixel high line "free" between two consecutive atoms !)
As my patch would try to insert the atom at the end of yhe document, it is already wrong...
Second, during my tests, I was satisfied when I got ONE successfull drop...
I never ran a second trial immediately after (that's why I did not experience JS errors...)
The problem is : after a false drop, the "onLibraryAtomDrag" process is more or less broken, but it is not cleaned up, and a lot of elements (locator, relation, ... are still around, and there is a destructive competition with the new listeners of the second drag...
More over, the dragend event ('On dragend (without drop), stop the liner.") is never fired !
This last issue has to be fixed before we go farther in false drop workaround..
Comment #6
yched commentedOn Chrome, I can reproduce the fact that a drop fails when the mouse pointer is over an atom when the drop occurs.
The
editable.once('drop', function (evt) {... insert dropped atom ...})listener added in onLibraryAtomDrag is not triggered in that case. Dunno which other event to use, though :-/Comment #7
nagy.balint commented@gifad
The dragend does not fire because by definition:
"The source of the drag will receive a dragend event when the drag operation is complete, whether it was successful or not. "
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Drag_and_drop
So for example if i switch the definition to this:
$(document).bind('dragend', function (evt) {
console.log('dragend');
stopLiner();
});
It works fine the dragend fires. Because the library item where the dragstart was bound to will receive the event.
Comment #8
nagy.balint commentedAbout the IndexSizeError, the issue is definitely with the
var range = editor.createRange();
range.selectNodeContents(element);
range.collapse(false);
part of the "legacy onDrop" part.
Because if i switch it with the insert link code of
var range = editor.getSelection().getRanges()[0];
Then everything works fine, granted the drop will not be dropping the atom at the proper place, and if the cursor does not move then it will replace existing atoms, but it does not break for me, and throws no errors.
Comment #9
nagy.balint commentedReplacing:
var range = editor.createRange();
range.selectNodeContents(element);
range.collapse(false);
with:
var range = editor.createRange();
range.moveToElementEditablePosition(element, true);
Seems to work for me.
Comment #10
nagy.balint commented@gifad
Also did you consider adding "evt.data.stopPropagation();" inside listeners.push(editable.once('drop', function (evt) {
then it wont call the legacy code at all when dndck4 got it. So that check "if (!Drupal.dndck4.gotIt) {" would be unnecessary.
Comment #11
gifad commentedCongratulations, nagy, you're right on all points !
I've integrated your suggestions, now works ok on firefox and safari.
Can you test on IE ?
Thanks
Comment #12
yched commentedTesting this, but :
The code just above uses
Drupal.dnd.sas2array(Drupal.dnd.currentAtom)rather than
Drupal.dnd.sas2array(evt.data.$.dataTransfer.getData('Text'));Let's stay consistent ?
Also : I might be confused, but couldn't this be moved into the onLibraryAtomDrag() function ?
(in which case, the previous remark gets fixed as well, since the Drupal.dnd.sas2array() gets passed as the atomInfo param)
Comment #13
yched commentedDunno about the false drops, since I haven't been able to reproduce them so far (also, no-one aswered my question in #4 :-p)
But on Chrome, even with the patch, I still get the "nothing happens when an atom is dropped from the library onto an existing ebedded atom" behavior mentioned in #6
Comment #14
gifad commented#yched,
#12.1 : fixed
#12.2 : no, just because the drop event of onLibraryAtomDrag is NOT fired
#13 drop on an atom seems to be prohibited just by the [content-editable=false] property
("This is read only area, no drop allowed")
same behaviour exists with image2 widget
The goal of this issue is not to make drops always working, it's just to prevent Firefox drop the html part of the drag, if no valid listener is present to catch it;
Webkit browsers already prevent this kind of drop, so there is nothing to, in the scope of this issue
Finally for #4
"Are we talking about a drop in an empty textarea, or a drop in a taxtarea that already contains text paragraphs ?"
We are talking about drop in a textarea which is empty, or contains limited text, so that the "end of document" position is visible on screen, and leaves an empty area below, where "false drops" occur with firefox
Comment #15
yched commentedOK - native widget drag-n-drop (dragging a widget that is already present in the editor to a different location, using the crosshair icon that appears on mouseover) does work when the mouse is over another widget when you do the drop. But it internally uses mousedown / mouseup events, not drag events.
But dnd-library.js initiates a drag event, so we probably don't have a choice for our case here.
I'm not suggesting that the *content* your editor.document.on('drop') listener should move into the existing editable.once('drop') listener in onLibraryAtomDrag(),
I'm suggesting that your whole editor.document.on('drop') could move into onLibraryAtomDrag(), as a new listener *in addition* to the existing one.
I think doing so would be cleaner by keeping similar code together, and would probably let us refactor so that we don't duplicate the code that does the actual insert (the Drupal.dndck4.getDefaultInsertData() / Drupal.dndck4.insertNewWidget() part)
Comment #16
yched commentedOh, OK, that may be why I can't reproduce it. My setup uses CKEditor in div mode, not in iframe mode, so I don't have this "end of document" issue, since my CK doesn't contain a "document".
Comment #17
yched commented#15 : I'm thinking of something lilke that - does this work for you guys ?
Comment #18
gifad commentedyes it works (for me)
and it's of course a better solution ;-)
thanks
Comment #19
gifad commentedoup's, forgot to mention : I had to fix a typo (missing parenthesis)
Comment #22
yched commentedCool ! Sorry about the typo, I wrote this in a dumb text editor and did not actually test it, since I can't reproduce the problem anyway ;-)
Then I guess it would be good to add some comments to clarify:
- that this second listener is needed to catch some cases (which ones ?) that the first one doesn't,
- that when the first one runs, it cancels the second one with stopPropagation();
Possibly it could make it easier to explain if the listener to editor.document was attached first ?
Something like : "Add a default drop listener that catches all the drops." / "Add a more specific listener that accounts for the liner, but does not detect XXXX. In the cases where it runs, cancel the default listener by stopping the event propagation." ?
Same here - although they really look damn close...
Really really needed ? ;-)
Comment #23
nagy.balint commentedThis part
Was supposed to be replaced by the new part so, it should be deleted in fact, as its never going to be called (unless we are dragging from the wysiwyg which is not going to happen in this context)
There is a remaining problem with the $(document).bind('dragend' in the onLibraryAtomDrag function approach, and its that the onLibraryAtomDrag will be called several times, and that means that this bind will happen several times, and so the dragend is called twice and then 4 times and then 6 times and so on. So in fact there should be a once function or some other way of binding this function only once. So something like (not sure what the class name should be):
Comment #24
yched commentedYep, that is why the existing code in onLibraryAtomDrag() does
listeners.push(foo.on('event'), callback);The listeners in that
listenersarray are unbound in stopLiner().But I still don't get why that new dragend listener is better than the existing one :-)
Comment #25
nagy.balint commented@yched
Because the existing one does: editor.document.on('dragend'
At least on the iframe version that means that the document of the editor, not the whole document of the entire page.
The dragend will be triggered on the element where the drag started, which is in the library.
Therefore we need to bind an event to the entire page and not just to the ckeditor iframe.
Comment #26
yched commented[edit: scratch the interdiff here. Patch is in #27, and interdiff in #28 :-/ ]
@nagy.balint : OK, thanks, got it now.
Then, the 'dragend' event should be attached by :
listeners.push(CKEDITOR.document.on('dragend'), function() {stopLiner();});
- CKEDITOR.document is the CK object for the whole containing document, which is what we want.
- Attaching the event through CK objects and API rather than jQuery lets us stay consistent with the other events added here and how they are cleaned up (added to the
listenersarray, unbound in stopLiner()),Comment #27
yched commentedEr, patch got lost somehow
Comment #28
yched commentedGee, and the interdiff in #26 was crap, here it is.
#notmydaytoday
Comment #29
yched commentedComment #30
nagy.balint commentedThere is a typo:
"CKEITOR.document"
Comment #31
yched commentedOh god, definitely not my day.
Fix silly typo. I shouldn't be posting patches on a sunday :-/
Interdiff is with #19, for clarity.
Comment #32
yched commentedAlso, found out that the "catch all" drop listener added on editor.document is not good if the CK is in divarea mode, because in that case, editor.document is the whole page, and so it reacts to drops on all the page (for example on the "node title" textfield), which then leads to JS errors.
Added a check to only add it if not in divarea mode.
We should definitely add some comments here - not today :-)
Comment #33
yched commentedI'm still trying to see if we can somehow unify the two drop listeners. Will report later.
Meanwhile, found out that the 'dragstart' listener gets reattached each time we go in and out of "source mode" / "wysiwyg mode" using the "Source" button, which then makes the drop listeners fire several times on atom drop. Updated patch fixes that.
Comment #34
yched commentedOK, I think I brought this down to one single listener. The trick is to attach it to either the iframe document or the editable div, depending on whether the CK is in divarea mode or in iframe mode.
I think I tested all the cases (divarea / iframe, editor with no content / content smaller then the editor area / lots of contents) on both chrome and firefox.
Could not check on IE / Safari though.
Also, renamed the stopLiner() internal function, since it does more than just cleaning up the liner thing.
Comment #35
yched commentedAlso, noticed that on Chrome, the 'drop' listener on the iframe document does not fire if the current editor content is smaller than the iframe height, and the drop is made in the iframe but outside the body content.
This can also be observed with the "old / non-widget" scald plugin : if the CK contains only one small paragraph of text, then atom drops below that paragraph are not caught.
Updated patch adds a workaround : add a min-height on the iframe body during the drop, to make sure it extends to the whole iframe area. I kind of suck at manipulating DOM dimensions, so maybe the code is not as smart as it could be :-/
Comment #36
gifad commentedHi all,
Found a last little bug for 2014 :
If a textarea is in the form 'Text with summary', everything is OK in the main (value) part, but drop (and insert) fail in the summary part :
The getDefaultInsertData() function fails on
context : editor.element.$.attributes['data-dnd-context'].value,which is not defined for the summary;solved by this tricky addition :
[I'm sorry I can't build a real patch at the moment]
Note that this could be better handled in dnd.module : dnd_process_textarea(), but summary element is processed before value element, and I could not find the info in the form_state... (and the comment ahead of this function does not help...)
Happy new year to the scald team !
Comment #37
gifad commentedNo, #36 was not the last :
Clicking Switch to plain text editor and then Switch to rich text editor breaks the dragstart handler (it's still linked to the old instance(s));
Preventively unbinding the event solves the problem;
pseudo-interdiff :
As usual, this is certainly not the best solution, but how to dynamically update the editor argument ?
(The dnd library widget (where the dragstart occurs) is persistent while the textareas CKEditor instances are destroyed/rebuilt...)
Comment #38
yched commented@gifad: Thanks, will try to look into that.
However, it might be good to check if thoses issues exist with the old plugin as well. If yes, we might want to defer to a sperate issue, as the best place for the fix could possibly be outside the new plugin JS file.
Also - does that mean that, other from the remarks in #36 / #37, the patch in #35 works for you ?
Comment #39
gifad commentedHi @yched,
Yes the patch in #35, (as all previous ones) work fine to me, ... until I find an unexpected behaviour in 'border' cases ...
Forgot to mention : the two previous issues are on drag and drop only : 'Insert' button always work flawlessly - so I suppose the old plugin is ok... [but I have limited access to dev environments at the moment]
Edit:
Sorry, yet another glitch with #35 :
Open an existing, potentially large, document;
Scroll anywhere in the document (or not), using only scroll bar or mousewheel (without clicking (focusing) in the document;
Initiate a drag; the liner behaves correctly, following cursor position;
Now drop the atom;
The atom will be inserted at the very top of the document, the document will eventually scroll up to make the atom visible;
No JS error, the dropped widget seems perfectly functional, although misplaced;
Note : this drop cannot be undone..
Repeating the same operation, but with a click inside the document (just a right click to "delete the atom from the textarea", for instance), everything is correct
As far as I can trust firebug, a
console.log(range);fromrange = finder.getRange(sorted[0]);show exactly the same object in both casesComment #40
nagy.balint commented#35 seems to work fine for me on firefox (for the original issue).
I can confirm the issue in #37 - can reproduce it on chrome, for me the fix in #37 actually breaks dragstart on chrome and firefox.
About the issue in #39 (the large document and scrolling without focus and dropping results in an insert to the top of the document) seems to be a firefox issue again :( As it works fine on chrome, but i was able to reproduce it on firefox.
Comment #41
yched commentedWell, the old plugin does drag-n-drop too, that's why I'm asking ;-)
Comment #42
gifad commented@yched, #41 : "" the old plugin does drag-n-drop too""
short answer : (but see below)
yes but the operations are on the drop side, and are actually the same as the insert button (just adds moving the insertion point during drag)
=====
@yched, #35, to review last issues in the legacy dnd/plugins/ckeditor/plugin.js :
#36 : Text with summary
The legacy plugin fails at the same point, but this is masked most of the times :
- if the browser is firefox
- if the default context is sdl_editor_representation
The failure occurs before the handler have modified anything in the DOM, and, more importantly, before it executes evt.preventdefault().
So the default is executed, that is insert the text/html embedded in the drag at the insertion point (BTW, this drop handler is totally useless with firefox...)
If the atom needs to be refreshed later, this will succeed, as the representation is in the cache;
Now, if the default context is not sdl_editor_rep., we get the "undefined" label for the atom...
The fix in #36 is tightly related to the text with summary anomaly, it can be applied as well, and solves the problem;
#37 : switching plain text <> rich text editors
The problem does not exist in the legacy plugin, as the drag and drop operation is "drop driven", and the drop handler has, by definition, the same lifecycle as the instance it applies to;
The problem in the widget plugin is that the operation is bound to the drag side, which is not aware of the death and rebirth of the drop side (mostly the "editable")
@nagy.balint : be sure to apply also #33 (on instanceReady instead of contentDom)
what do you experiment, when "it breaks dragstart" ?
I'm not sure at all of my fix, as I know nothing about the lifecycle of so-called "objects" in javascript ;/
#39 insert at top, if document never focused
Same behavior with legacy plugin
Unfortunately, I have no idea of a solution : I suspect the document (or rather the editable) is not fully initialized before a first focus...
see http://docs.ckeditor.com/#!/api/CKEDITOR.editable-property-status :
"" The ready status is set after the first CKEDITOR.editor.setData is called. ""
Comment #43
nagy.balint commented@gifad about #37
I used patch from #35 which as far as i see includes #33
The problem is that if i add that line in comment #37 then dragstart is not called at all anymore, so all drops are broken, not atoms.
So far not sure why it happens, since the event is rebound right after.
Comment #44
gifad commented@nagy.balint : I don't know why, but the code at #37 works randomly
(I usually embed a lot of console.log() in the code, does it modify the relative timing of events ?)
@all : I finally got rid of this dangling "editor" argument
Tested on firefox only, this works :
note the removal of the "editor" argument.
and the function definition, with a reliable "editor" :
This way, the drag handler is explicitly linked to the (active) instance that will receive the drop
Test with a "Text with summary" document : with "Edit summary" clicked, you can drag the atom over the two parts of the textarea, you see the liner is drawn (and the drop succeed) only in the "active" (last focused) part...
At least, there was a relation between #37 and #39 ...
Enough for 2014, happy new year !
Comment #45
nagy.balint commented@gifad : #37 is still not working for me. I tried the following:
console.log('unbinding dragstart');
$(document).unbind('dragstart');
console.log('binding dragstart');
$(document).bind('dragstart', function (evt) {
Then i get the following on a page with 3 ckeditor instances:
unbinding dragstart
binding dragstart
unbinding dragstart
binding dragstart
unbinding dragstart
binding dragstart
But this listener should be global, isnt there some other way to bind this listener? so it only happens once?
But dragging seems to start working once i focused on one of the editors, so maybe my problem is not about the dragstart.
Also will this line work if i have several ckeditor instances on the same page?
var editor = Drupal.ckeditorInstance._.editable.editor;
Comment #46
nagy.balint commentedBinding several times can be mitigated by wrapping the dragstart bind like this:
$('body').once('dndck4-dragstart', function () {
$(document).bind('dragstart', function (evt) {
So now it only binds once. However it still wont work, it seems that i can only drag successfully to an editor where i have focus, if i try to drag to an editor which is not in focus, it will break.
Comment #47
nagy.balint commentedI reverted to patch #35 before your fixes @gifad, and it seems to have fixed my issue with the focus, so i think the editor argument removal broke it for me.
Comment #48
nagy.balint commentedIt seems that with #35 the once solution cannot be used as if we have the editor argument, then each instance should have its own dragstart event with a different editor argument.
However if we can somehow remove the editor argument, then we can use the once method, but then inside the event we have to somehow query the editor, but since its on a dragstart event, how would it know where its going to be dropped.
So maybe that editor argument cannot be removed, or we need a new event?
Comment #49
gifad commentedHi nagy.balint,
The key point of #44 is that each instance monitors drag, and is ready to receive the drop in its editable;
This is just something I can understand;
With a single binding, I just can't figure out how can the single "editor" variable can delegate the events to the relevant instance (again, I'm not javascript expert)
Comment #50
nagy.balint commented@gifad, precisely thats the issue we would need to solve if we have only 1 binding, how will the function code know which editor to act upon.
However this is also why your snippet wont work (with the unbind before bind), because when you call unbind it will unbind all dragstart events, including those that were bind for other instances, because the document bind is a global thing, and the unbind is also global and unbinds everything.
"Once" will not help us because even if we use the once for each instance wrapper, we would not solve the issue when you reinitialize the instance and then the event should be unbinded.
Maybe we could use namespaces?
http://api.jquery.com/unbind/
Under Using Namespaces
So like we could generate a unique namespace tag for each instance, and then that would not change for an instance, and then we could unbind an event for a specific instance and redo it?
That way it would solve all issues.
An other way could be to unbind the event when the switch to plain text happens, not sure if we can do this or not.
Comment #51
nagy.balint commentedI created a new patch.
This includes the workaround at #36
It includes the namespace implementation from #50 which fixes #37
The only thing left to fix is #39, which works fine on chrome, the issue is only on firefox, and only when the editor was not focused before a drop, in which case the atom will be added on the top no matter what.
I have not included the editor argument removal, because i think that solution wont work in the case of having several editors on the same page.
Comment #52
nagy.balint commentedPatch #51 seems to work fine with
Chrome,
Firefox (except the issue mentioned in #51)
on Ubuntu
And also with
Chrome
IE 11
on Windows 8.1
Comment #53
gifad commentednice, nagy.balint, very nice ;-)
#51 passes all my tests, on firefox and safari, on macOSX
#39 may be definitely cast to a ckeditor on firefox issue, and is minor.
Thanks again,
Comment #54
yched commentedRe: the "summary" textarea not having the 'data-dnd-context' attribute
The old plugin (scald/modules/library/dnd/plugins/ckeditor/plugin.js) also has code that relies on editor.element.$.attributes['data-dnd-context'].value, so it's likely to be broken as well for the "summary" textareas ?
So :
- if it's not a bug specific to the new plugin, it would be better off adressed in a separate issue
- Plus, I'd tend to consider the issue is rather that dnd_process_textarea() doesn't place the attribute on the "summary" textarea, rather than having a not-too-beautiful workaround in the JS side to fetch it from a different textarea (and have to duplicate it in the two plugins).
The "summary" is a textarea with CK & support for scald drag-n-n-drop, so it should have the attribute, just like the main "body" textarea does.
Comment #55
nagy.balint commented@yched , since this issue was created for a major issue with the drag and drop on firefox, which this patch solves and it seems to be well tested now. Maybe its best to try to get this patch commited, and can open a new issue to deal with making the code nicer for the textarea for summary, but until then the workaround works fine at least.
Comment #56
yched commentedBut that bug was fixed in #35, and is not related to the "summary" thing, right ?
So yeah, I agree with "let's commit the fix for *that* major firefox bug, and leave out the summary stuff, which is a totally different (and larger) bug, for a separate issue :-)
Meaning, #51 without the "// Get a valid default context, in case of summary in 'text and summary' textarea" hunk ?
Comment #57
nagy.balint commentedI would personally leave it in, because its a working workaround, and does not hurt anyone, in fact fixes a bug until the proper fix lands.
I dont see a point in taking it out.
Comment #58
gifad commented@yched,
not really : the
$elementdoes not even has a#field_nameThe only hint I can find is the
$element[#id]( edit-body-und-0-summary ), and then navigate through the form_state (via#parents) to find the "real" textarea...(same algorithm as my workaround, in fact, but the code would be yet more "not-too-beautiful", by a large step)
My conclusion is exactly the same as nagy.balint...
Comment #59
gifad commented@yched
[Edit : Finally wrote really terrible code for a fixed
dnd_process_textarea()(attached)will submit an issue (and patch) when I get back to a git-enabled computer, if my js workaround is definitely rejected;
At least, it's on server side, your boss and customers won't see this code with your signature ;-)
[Edit: some one to fix the comment ahead
dnd_process_textarea()?really not intended pun...]]
Comment #60
yched commented@gifad :
I was just looking into that as well. I was more inclined to fix this in mee_field_widget_form_alter() - it's the function that adds #dnd-enabled on the main (non-summary) textarea, and should IMO set it as well on the 'summary' textarea if the widget is 'text_textarea_with_summary'
(as a side note, the part in there about $element['#id'] and '#dnd-settings' looks like dead code, nothing ever uses that)
But then I noticed a lot of other things are broken regarding atoms in 'summary' :
1) The resource manager does not detect the atoms that are in there (mee's text_field_insert() / text_field_update()), so the atoms included in the summary are not tracked in the {mee_resource} table
2) When using the old plugin (mee_store_format() == 'sas'), the 'summary' value is not processed like the main textarea (the "sas code <--> rendered atom" transformations on form display and form submit - mee's text_field_presave() / mee_field_widget_form_alter()).
Which means that "atoms in summaries" does not seem to be an intended feature in scald so far. The "new widget" just happens to work a bit better with them since it is not affected by 2), but that still leaves 1), atom tracking is broken in summaries.
Thus, I still think "atoms in summaries" would be better off in a separate issue, since, again :
- it's completely unrelated to the original issue here, and we're already at 60 posts
- the current workaround is kind of ugly :-)
- the problem space about supporting 'summary' textareas is much larger
Just reattaching #51 with a couple minor style/comment fixes [edit: also, namespaced the event a bit more specifically].
I'll leave it to @jcisio to decide if he wants to keep the "Get a valid default context, in case of summary in 'text and summary' textarea" snippet.
Comment #61
yched commentedAlso : removing the event on destroy might be a good idea anyway, even if the editor is not re-enabled after that.
Comment #62
gifad commented#61 does not work :
Safari:
TypeError: null is not an object (evaluating 'editable.getFirst')
Firefox:
TypeError: editable is null
var editableHasContent = (editable.getFirst() != null);
in onLibraryAtomDrag: function (editor, atomInfo)
after "Switch to plain text editor" / "Switch to rich text editor"
#60 was OK
Comment #63
gifad commentedComment #64
yched commented@gifad : Weird, can't reproduce #62.
With patch #61, "Switch to plain text editor / Switch to rich text editor / drag an atom into the editor" works fine for me on both Chrome and Firefox - tested both iframe and divarea modes.
Comment #65
nagy.balint commentedI also cant reproduce #62, i even put console log before the bind and unbind and it works fine on both firefox and chrome.
"bindedit-field-page-teaser-und-0-value" plugin.js:101
"bindedit-field-page-body-und-0-value" plugin.js:101
"bindedit-field-page-sidebar-und-0-value" plugin.js:101
"unbindedit-field-page-body-und-0-value" plugin.js:128
"bindedit-field-page-body-und-0-value" plugin.js:101
However i discovered a new bug:
If you try to drop an atom into a textarea which does not have dnd enabled you get the following:
On Chrome:
plugin.js?t=EAPE:320 Uncaught TypeError: Cannot read property 'value' of undefined
plugin.js?t=EAPE:320 Drupal.dndck4.getDefaultInsertData
plugin.js?t=EAPE:431 (anonymous function)
ckeditor.js?nhrxvk:10 i
ckeditor.js?nhrxvk:12 CKEDITOR.event.CKEDITOR.event.fire
ckeditor.js?nhrxvk:45 (anonymous function)
On Firefox: TypeError: editor.element.$.attributes['data-dnd-context'] is undefined plugin.js:320
Comment #66
gifad commented@yched : my bad : I kept the nagy.balint's (#51) namespace in the bind statement, and yours in the unbind;
Actually, #61 works ok
sorry..
Comment #67
nagy.balint commentedI suppose we need a condition just before " var data = Drupal.dndck4.getDefaultInsertData(editor, atomInfo);" under listeners.push(dropElement.on('drop', function (evt) {
To check if dnd is enabled on the target and prevent the drop if its not the case.
Comment #68
yched commented@nagy.balint #65 :
Can't reproduce. Can you provide specific info about the "textarea which does not have dnd enabled" ? Is it a field ? which configuration ? Does it have a CKEditor enabled or is it a plain textarea ?
Comment #69
nagy.balint commented@yched :
Teaser field_page_teaser Long text Text area (multiple rows)
Filtered text (user selects text format)
" Drag'n'Drop Enabled" and "MEE Enabled" is unchecked
Default text format "Full Html"
And uses ckeditor.
Comment #70
gifad commented@nagy.balint : I have exactly the same configuration;
problem solved by :
Rather than "prevent the drop", this lets it go with site default context
I think "dnd-enabled" is there to provide the library widget, rather than allow/prevent drop
EDIT : this was my first workaround for the text and summary problem, I missed to publish it...
REEDIT : Text and summary solved by this patch to mee.module :
and then remove
dnd_element_info_alter()anddnd_process_textarea()Comment #71
nagy.balint commented@gifad , can you make a patch for #70 with all those removals? Or do we need to move those to a separate issue?
Comment #72
nagy.balint commentedOkey, to move this forward and concentrate on the original issue, i have removed the text and summary JS workaround from the patch and added the fix for the drag into not dnd enabled textarea.
If it works for you as well, we can mark this as RTBC, and i created a new issue for the text and summary problem. #2407023: CKEditor: dragging into a summary field of a text and summary is broken
Comment #73
nagy.balint commentedTested patch #72 with IE 9 as well, seems to work fine.
Comment #74
nagy.balint commented@gifad : Can you check #72 if we can put it on RTBC? Did not want to do that right after i posted a new patch.
Comment #75
gifad commented@nagy.balint : I mostly use this code mixed with my "mutable" version, but the drop part is not affected;
I just re-did a quick test of this patch alone with a clean 7x-1.3+1-dev, and drag and drop are just OK.
So I'm OK for RTBC (just missing @jcisio review ?)
Comment #76
nagy.balint commentedComment #77
yched commentedSorry for letting this slide a bit.
I still don't get exactly why we do this ? Is that for the case mentioned in #68 / #69 ? (text field with 'Drag'n'Drop Enabled' and 'MEE Enabled' checked off)
Why would we want to allow the drop in those cases ? The field says it wants to completely stay out of scald...
Shouldn't the plugin simply return immediately in its
init: function (editor) {if the editor.element.$.attributes['data-dnd-context'] is not present ?Comment #78
nagy.balint commented@jcisio : Can you help with the intended behavior when those checkboxes are disabled? Should we totally disallow the drag and drop into a textarea which has dnd disabled?
Arguments can be found in comment #70 and #77
Comment #79
nagy.balint commentedI checked this one again, and it is not clear in the code and on the interface whether it was meant to allow drag when dnd is disabled for a field, or not.
If its the only field, and dnd is disabled, then of course the user does not have a library to drag from.
So this is only an issue when we have several fields, where at least one field has dnd enabled.
The checkbox at dnd enabled says this "Enable DnD for this field will show the Atom library and will allow you to drag and drop atoms to this field."
But the rest of the text only talks about the library being disabled or enabled, and nothing about the drag being enabled or disabled.
Also it is possible currently to enable mee resource tracking while dnd is disabled.
If dnd was meant to disable all drag, then basically the UI should be a single checkbox, where if you check the dnd enabled then it shows the rest of the options (contexts and the mee checkbox), but not until that.
Maybe it was just not implemented.
So from the code alone, its hard to see what was the intended behaviour.
Seems that we are divided on this issue. But either way is fine in my opinion.
Because even if we allow the drop, it wont cause any real issues, cause the atom will appear in the render anyways even if dnd is disabled, since the input filter does not check if this setting is off or not.
So i think i will commit the patch as we have tested it, and if it is a problem, we can discuss it further in a new issue.
Comment #81
nagy.balint commentedCommitted, thanks!