Skip to content

Commit b4300a4

Browse files
[Bugfix] init PasteReference with internal promise, to get most recent clipboard data (#79),
[Bugfix] correct comment markers in paste_reference-drag-drop.js
1 parent 16ad538 commit b4300a4

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

Resources/Public/JavaScript/paste-reference-drag-drop.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ DragDrop.default = {
4444

4545
/**
4646
* initializes Drag+Drop for all content elements on the page
47-
*/
4847
initialize: function () {
4948
(DragDrop.default.draggableIdentifier).draggable({
5049
handle: this.draggableContentHandle,
@@ -80,6 +79,7 @@ DragDrop.default = {
8079
draggableElement: draggableElement
8180
};
8281
},
82+
*/
8383

8484
/**
8585
* this method does the whole logic when a draggable is dropped
@@ -158,10 +158,12 @@ DragDrop.default = {
158158
if (typeof foundTarget === 'undefined') {
159159
targetPid = draggable.getPid();
160160
sorting = 0;
161-
// console.log('Setting sorting=0 for first element in container column:', {
161+
/*
162+
console.log('Setting sorting=0 for first element in container column:', {
162163
colPos: colPos,
163164
txContainerParent: txContainerParent,
164165
});
166+
*/
165167
} else {
166168
// the negative value of the content element after where it should be moved
167169
targetPid = 0 - parseInt(foundTarget);
@@ -403,6 +405,7 @@ console.log(draggable);
403405
}
404406
}
405407
}
408+
/*
406409
if (parameters.basicAction == 'copy' || parameters.basicAction == 'move') {
407410
thisClass.broadcast('elementChanged', {
408411
pid: draggableElement.pid,
@@ -411,6 +414,7 @@ console.log(draggable);
411414
action: parameters.basicAction
412415
});
413416
}
417+
*/
414418
self.location.hash = droppableElement.closest(DragDrop.default.contentIdentifier).id;
415419
/*
416420
console.log(parameters.basicAction,{

Resources/Public/JavaScript/paste-reference.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,23 @@ class PasteReference {
4545
this.copyMode = args.copyMode;
4646
DocumentService.ready().then(() => {
4747
if (document.querySelectorAll('.t3js-page-columns').length > 0) {
48-
this.getClipboardData();
49-
this.generateButtonTemplates();
50-
this.activatePasteIcons();
51-
this.initializeEvents();
52-
this.initModalEventListener();
48+
// promise to assure that most recent data are used
49+
this.getClipboardData()
50+
.then(() => {
51+
this.generateButtonTemplates();
52+
this.activatePasteIcons();
53+
this.initializeEvents();
54+
this.initModalEventListener();
55+
})
56+
.catch((err) => {
57+
console.error('Error initializing PasteReference:', err);
58+
});
5359
}
5460
});
5561
}
5662

5763
getClipboardData() {
58-
(new AjaxRequest(top.TYPO3.settings.Clipboard.moduleUrl))
64+
return (new AjaxRequest(top.TYPO3.settings.Clipboard.moduleUrl))
5965
.withQueryArguments({ action: 'getClipboardData' })
6066
.post({ table: 'tt_content' })
6167
.then(async (response) => {
@@ -73,6 +79,9 @@ class PasteReference {
7379
this.itemOnClipboardTitleHtml = record ? record.title : '';
7480
this.itemOnClipboardTable = table;
7581
}
82+
else {
83+
console.error('Error: ClipboardData couldn\'t be retieved.');
84+
};
7685
});
7786
}
7887

@@ -112,7 +121,8 @@ class PasteReference {
112121
resolve(elementAbove.querySelector(selector));
113122
}
114123
});
115-
// If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
124+
// If you get "parameter 1 is not of type 'Node'" error,
125+
// see https://stackoverflow.com/a/77855838/492336
116126
observer.observe(document.body, {
117127
childList: true,
118128
subtree: true
@@ -215,7 +225,7 @@ class PasteReference {
215225
.setPid(page)
216226
.setColpos(colpos)
217227
.setUid(tableUid);
218-
228+
219229
if (txContainerParent > 0) {
220230
draggableObj.setTxContainerParent(txContainerParent);
221231
}
@@ -255,9 +265,12 @@ class PasteReference {
255265
+ ' title="' + TYPO3.lang['tx_paste_reference_js.copyfrompage'] + '">'
256266
+ '<typo3-backend-icon identifier="actions-insert-reference" size="small"></typo3-backend-icon>'
257267
+ '</button>';
268+
/*
269+
// might removal fix issue #79?
258270
if (!this.itemOnClipboardUid) {
259271
return;
260272
}
273+
*/
261274
this.pasteAfterLinkTemplate = '<button'
262275
+ ' type="button"'
263276
+ ' class="t3js-paste t3js-paste' + (this.copyMode ? '-' + this.copyMode : '') + ' t3js-paste-after btn btn-default btn-sm"'
@@ -570,12 +583,3 @@ class PasteReference {
570583
}
571584

572585
export default PasteReference;
573-
574-
if (!PasteReference.instance && top.pasteReferenceAllowed) {
575-
const pollTime = 100;
576-
window.setTimeout(function() {
577-
if (!PasteReference.instance) {
578-
const pasteReference = new PasteReference({});
579-
}
580-
}, pollTime);
581-
}

0 commit comments

Comments
 (0)