[TASK] Migrate LayoutModule/DragDrop.js to TypeScript
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / LayoutModule / DragDrop.js
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13 define(["require","exports","jquery","TYPO3/CMS/Backend/AjaxDataHandler","jquery-ui/droppable"],function(e,t,n,a){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(){}return e.initialize=function(){n(e.contentIdentifier).draggable({handle:e.dragHeaderIdentifier,scope:"tt_content",cursor:"move",distance:20,revert:"invalid",zIndex:100,start:function(t,a){e.onDragStart(n(t.target))},stop:function(t,a){e.onDragStop(n(t.target))}}),n(e.dropZoneIdentifier).droppable({accept:this.contentIdentifier,scope:"tt_content",tolerance:"pointer",over:function(t,a){e.onDropHoverOver(n(a.draggable),n(t.target))},out:function(t,a){e.onDropHoverOut(n(a.draggable),n(t.target))},drop:function(t,a){e.onDrop(n(a.draggable),n(t.target),t)}})},e.onDragStart=function(t){e.originalStyles=t.get(0).style.cssText,t.children(e.dragIdentifier).addClass("dragitem-shadow"),t.append('<div class="ui-draggable-copy-message">'+TYPO3.lang["dragdrop.copy.message"]+"</div>"),t.children(e.dropZoneIdentifier).addClass("drag-start"),t.closest(e.columnIdentifier).removeClass("active"),t.find(e.dropZoneIdentifier).hide(),n(e.dropZoneIdentifier).each(function(t,a){var o=n(a);o.parent().find(".t3js-toggle-new-content-element-wizard").length?o.addClass(e.validDropZoneClass):o.closest(e.contentIdentifier).find("> "+e.addContentIdentifier+", > > "+e.addContentIdentifier).show()})},e.onDragStop=function(t){t.children(e.dragIdentifier).removeClass("dragitem-shadow"),t.children(e.dropZoneIdentifier).removeClass("drag-start"),t.closest(e.columnIdentifier).addClass("active"),t.find(e.dropZoneIdentifier).show(),t.find(".ui-draggable-copy-message").remove(),t.get(0).style.cssText=e.originalStyles,n(e.dropZoneIdentifier+"."+e.validDropZoneClass).removeClass(e.validDropZoneClass)},e.onDropHoverOver=function(t,n){n.hasClass(e.validDropZoneClass)&&n.addClass(e.dropPossibleHoverClass)},e.onDropHoverOut=function(t,n){n.removeClass(e.dropPossibleHoverClass)},e.onDrop=function(t,a,o){var r=e.getColumnPositionForElement(a);a.removeClass(e.dropPossibleHoverClass);var i="number"==typeof t,s=!0===i?t:parseInt(t.data("uid"),10);if("number"==typeof s&&s>0){var d={},l=a.closest(e.contentIdentifier).data("uid"),c=0;c=void 0===l?n("[data-page]").first().data("page"):0-parseInt(l,10);var p=parseInt(a.closest("[data-language-uid]").data("language-uid"),10),g=0;0!==c&&(g=r),d.cmd={tt_content:{}},d.data={tt_content:{}};var f=o&&o.originalEvent.ctrlKey||a.hasClass("t3js-paste-copy");f?(d.cmd.tt_content[s]={copy:{action:"paste",target:c,update:{colPos:g,sys_language_uid:p}}},e.ajaxAction(a,t,d,f,i)):(d.data.tt_content[s]={colPos:g,sys_language_uid:p},i?d={CB:{paste:"tt_content|"+c,update:{colPos:g,sys_language_uid:p}}}:d.cmd.tt_content[s]={move:c},e.ajaxAction(a,t,d,f,i))}},e.ajaxAction=function(t,n,o,r,i){a.default.process(o).done(function(a){a.hasErrors||(i||(t.parent().hasClass(e.contentIdentifier.substring(1))?n.detach().css({top:0,left:0}).insertAfter(t.closest(e.contentIdentifier)):n.detach().css({top:0,left:0}).insertAfter(t.closest(e.dropZoneIdentifier))),self.location.reload(!0))})},e.getColumnPositionForElement=function(e){var t=e.closest("[data-colpos]");return!(!t.length||"undefined"===t.data("colpos"))&&t.data("colpos")},e.contentIdentifier=".t3js-page-ce",e.dragIdentifier=".t3-page-ce-dragitem",e.dragHeaderIdentifier=".t3js-page-ce-draghandle",e.dropZoneIdentifier=".t3js-page-ce-dropzone-available",e.columnIdentifier=".t3js-page-column",e.validDropZoneClass="active",e.dropPossibleHoverClass="t3-page-ce-dropzone-possible",e.addContentIdentifier=".t3js-page-new-ce",e.originalStyles="",e}();t.default=o,n(o.initialize)});