[BUGFIX] Trigger DragUploader and OnlineMedia js after loading IRRE 66/43766/7
authorFrans Saris <franssaris@gmail.com>
Sat, 3 Oct 2015 19:07:08 +0000 (21:07 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Thu, 15 Oct 2015 12:47:54 +0000 (14:47 +0200)
The DragUploader is now initialized by the requireJs callback option.
Each "Add online media by Url" button is initialized by first click.

Resolves: #70326
Releases: master
Change-Id: I5011aefa01488e073e0367ebbae1c0c615c700fd
Reviewed-on: http://review.typo3.org/43766
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/backend/Classes/Form/Container/InlineControlContainer.php
typo3/sysext/backend/Classes/Form/FormResultCompiler.php
typo3/sysext/backend/Resources/Public/JavaScript/OnlineMedia.js

index 9a387db..8ce6b10 100644 (file)
@@ -62,6 +62,11 @@ class InlineControlContainer extends AbstractContainer
     protected $iconFactory;
 
     /**
+     * @var string[]
+     */
+    protected $requireJsModules = [];
+
+    /**
      * Container objects give $nodeFactory down to other containers.
      *
      * @param NodeFactory $nodeFactory
@@ -282,6 +287,8 @@ class InlineControlContainer extends AbstractContainer
         if (count($sortableRecordUids) > 1 && $config['appearance']['useSortable']) {
             $resultArray['additionalJavaScriptPost'][] = 'inline.createDragAndDropSorting("' . $nameObject . '_records' . '");';
         }
+        $resultArray['requireJsModules'] = $this->requireJsModules;
+
         // Publish the uids of the child records in the given order to the browser
         $html .= '<input type="hidden" name="' . $nameForm . '" value="' . implode(',', $sortableRecordUids) . '" '
             . $this->getValidationDataAsDataAttribute(array('type' => 'inline', 'minitems' => $config['minitems'], 'maxitems' => $config['maxitems']))
@@ -574,7 +581,9 @@ class InlineControlContainer extends AbstractContainer
                 $item .= $languageService->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.select-and-submit', true);
                 $item .= '</a>';
 
+                $this->requireJsModules[] = ['TYPO3/CMS/Backend/DragUploader' => 'function(dragUploader){dragUploader.initialize()}'];
                 if (!empty($onlineMediaAllowed)) {
+                    $this->requireJsModules[] = 'TYPO3/CMS/Backend/OnlineMedia';
                     $buttonText = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.button', true);
                     $placeholder = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.placeholder', true);
                     $buttonSubmit = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.submit', true);
index fb9fb21..6cdf5d2 100644 (file)
@@ -249,8 +249,6 @@ class FormResultCompiler
         }
 
         $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileListLocalisation');
-        $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DragUploader');
-        $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/OnlineMedia');
 
         $pageRenderer->addInlineLanguagelabelFile(
             \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('lang') . 'locallang_core.xlf',
index bbe594f..75d3472 100644 (file)
@@ -26,12 +26,6 @@ define(['jquery', 'nprogress', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Lang/Lang']
                me.btnSubmit = me.$btn.data('data-btn-submit') || 'Add';
                me.placeholder = me.$btn.data('placeholder') || 'Paste media url here...';
 
-               // No IRRE element found then hide input+button
-               if (!me.irreObjectUid) {
-                       me.$btn.hide();
-                       return;
-               }
-
                me.addOnlineMedia = function(url) {
                        NProgress.start();
                        $.post(TYPO3.settings.ajaxUrls['online_media_create'],
@@ -68,10 +62,7 @@ define(['jquery', 'nprogress', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Lang/Lang']
                        );
                };
 
-               // Bind key press enter event
-               me.$btn.on('click', function(evt) {
-                       evt.preventDefault();
-
+               me.triggerModal = function() {
                        var $modal = Modal.show(
                                me.$btn.attr('title'),
                                '<div class="form-control-wrap">' +
@@ -100,24 +91,19 @@ define(['jquery', 'nprogress', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Lang/Lang']
                                        }
                                });
                        });
-               });
-       };
+               };
 
-       // register the jQuery plugin "OnlineMediaPlugin"
-       $.fn.onlineMedia = function(option) {
-               return this.each(function() {
-                       var $this = $(this),
-                               data = $this.data('OnlineMediaPlugin');
-                       if (!data) {
-                               $this.data('OnlineMediaPlugin', (data = new OnlineMediaPlugin(this)));
-                       }
-                       if (typeof option === 'string') {
-                               data[option]();
-                       }
-               });
+               return {triggerModal: me.triggerModal};
        };
 
-       $(function() {
-               $('.t3js-online-media-add-btn').onlineMedia();
+       $(document).on('click', '.t3js-online-media-add-btn', function(evt) {
+               evt.preventDefault();
+               var $this = $(this),
+                       onlineMediaPlugin = $this.data('OnlineMediaPlugin');
+               if (!onlineMediaPlugin) {
+                       $this.data('OnlineMediaPlugin', (onlineMediaPlugin = new OnlineMediaPlugin(this)));
+               }
+               onlineMediaPlugin.triggerModal();
        });
+
 });