[TASK] Make fileedit hook JavaScript for ext:t3editor an AMD module 34/39634/3
authorWouter Wolters <typo3@wouterwolters.nl>
Wed, 20 May 2015 18:51:55 +0000 (20:51 +0200)
committerFrank Nägler <typo3@naegler.net>
Wed, 20 May 2015 21:44:27 +0000 (23:44 +0200)
Resolves: #67065
Releases: master
Change-Id: Iff8ece078dc612c362b3e291da466b29250c8cb1
Reviewed-on: http://review.typo3.org/39634
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Frank Nägler <typo3@naegler.net>
Tested-by: Frank Nägler <typo3@naegler.net>
typo3/sysext/t3editor/Classes/Hook/FileEditHook.php
typo3/sysext/t3editor/Resources/Public/JavaScript/FileEdit.js [new file with mode: 0644]
typo3/sysext/t3editor/res/jslib/fileedit.js [deleted file]

index 0732f73..a46a021 100644 (file)
@@ -64,17 +64,17 @@ class FileEditHook {
         * called in \TYPO3\CMS\Backend\Template\DocumentTemplate:startPage
         *
         * @param array $parameters
-        * @param \TYPO3\CMS\Backend\Template\DocumentTemplate $pObj
+        * @param \TYPO3\CMS\Backend\Template\DocumentTemplate $documentTemplate
         * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::startPage
         */
-       public function preStartPageHook($parameters, $pObj) {
+       public function preStartPageHook($parameters, $documentTemplate) {
                if (GeneralUtility::_GET('M') === 'file_edit') {
                        $t3editor = $this->getT3editor();
                        if (!$t3editor->isEnabled()) {
                                return;
                        }
-                       $pObj->JScode .= $t3editor->getJavascriptCode($pObj);
-                       $pObj->loadJavascriptLib(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('t3editor') . 'res/jslib/fileedit.js');
+                       $documentTemplate->JScode .= $t3editor->getJavascriptCode($documentTemplate);
+                       $documentTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/T3editor/FileEdit');
                }
        }
 
diff --git a/typo3/sysext/t3editor/Resources/Public/JavaScript/FileEdit.js b/typo3/sysext/t3editor/Resources/Public/JavaScript/FileEdit.js
new file mode 100644 (file)
index 0000000..40234d6
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * File edit for ext:t3editor
+ */
+define('TYPO3/CMS/T3editor/FileEdit', ['jquery'], function ($) {
+
+       $(document).ready(function() {
+               $('.t3-icon-document-save, .t3-icon-document-save-close').each(function() {
+                       var $link = $(this).parent('a');
+                       if ($link) {
+                               $link.removeAttr('onclick');
+
+                               $link.on('click', function(e) {
+                                       e.preventDefault();
+                                       if (!T3editor || !T3editor.instances[0]) {
+                                               document.editform.submit();
+                                               return false;
+                                       }
+                                       if ($(this).children('span').hasClass('t3-icon-document-save')) {
+                                               if (!T3editor.instances[0].disabled) {
+                                                       T3editor.instances[0].saveFunctionEvent();
+                                               } else {
+                                                       document.editform.submit();
+                                               }
+                                       } else {
+                                               if (!T3editor.instances[0].disabled) {
+                                                       T3editor.instances[0].updateTextareaEvent();
+                                               }
+                                               document.editform.submit();
+                                       }
+                                       return false;
+                               });
+                       }
+               });
+       });
+});
diff --git a/typo3/sysext/t3editor/res/jslib/fileedit.js b/typo3/sysext/t3editor/res/jslib/fileedit.js
deleted file mode 100644 (file)
index 24ff188..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-Ext.onReady(function() {
-       Ext.select('.t3-icon-document-save, .t3-icon-document-save-close').each(function(element) {
-               var link = element.up('a');
-               if (link) {
-                       link.dom.setAttribute(
-                               'onclick',
-                               link.dom.getAttribute('onclick').replace('document.editform.submit();', '')
-                       );
-                       link.on('click', function(event, target) {
-                               event.stopEvent();
-                               if (!T3editor || !T3editor.instances[0]) {
-                                       document.editform.submit();
-                                       return false;
-                               }
-                               if (Ext.get(target).hasClass('t3-icon-document-save')) {
-                                       if (!T3editor.instances[0].disabled) {
-                                               T3editor.instances[0].saveFunctionEvent();
-                                       } else {
-                                               document.editform.submit();
-                                       }
-                               } else {
-                                       if (!T3editor.instances[0].disabled) {
-                                               T3editor.instances[0].updateTextareaEvent();
-                                       }
-                                       document.editform.submit();
-                               }
-                               return false;
-                       });
-               }
-       });
-});