[TASK] Rewrite JavaScript of ext:documentation to RequireJS 78/37578/6
authorWouter Wolters <typo3@wouterwolters.nl>
Thu, 5 Mar 2015 22:12:33 +0000 (23:12 +0100)
committerMarkus Klein <klein.t3@reelworx.at>
Fri, 6 Mar 2015 12:59:52 +0000 (13:59 +0100)
Due to a JavaScript error in the current situation the code
is now ported to RequireJS.

Resolves: #65557
Releases: master
Change-Id: I3dab5fa8ba95088e60acca5d28f3829f201ddf76
Reviewed-on: http://review.typo3.org/37578
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/documentation/Resources/Private/Layouts/Default.html
typo3/sysext/documentation/Resources/Private/Templates/Document/Download.html
typo3/sysext/documentation/Resources/Private/Templates/Document/List.html
typo3/sysext/documentation/Resources/Public/JavaScript/Main.js [new file with mode: 0644]
typo3/sysext/documentation/Resources/Public/JavaScript/configuration.js [deleted file]
typo3/sysext/documentation/Resources/Public/JavaScript/main.js [deleted file]

index 736bc47..1104a6c 100644 (file)
@@ -1,15 +1,12 @@
 {namespace doc=TYPO3\CMS\Documentation\ViewHelpers}
 
-<f:be.container pageTitle="{f:translate(key: 'documentation_manager')}" enableClickMenu="false" loadPrototype="false" loadScriptaculous="false" loadExtJs="false" loadExtJsTheme="true" loadJQuery="true"
+<f:be.container pageTitle="{f:translate(key: 'documentation_manager')}" enableClickMenu="false" loadPrototype="false" loadJQuery="true"
 
        includeCssFiles="{
                0:'{f:uri.resource(path:\'Css/main.css\')}'
        }"
-       includeJsFiles="{
-               0:'contrib/jquery/jquery.dataTables.min.js',
-               1:'contrib/jquery/jquery.clearable.js',
-               2:'{f:uri.resource(path:\'JavaScript/main.js\')}',
-               3:'{f:uri.resource(path:\'JavaScript/configuration.js\')}'
+       includeRequireJsModules="{
+               0: 'TYPO3/CMS/Documentation/Main'
        }">
 
        <div id="typo3-docheader">
@@ -21,9 +18,7 @@
                                </doc:be.security.ifAdmin>
                        </f:be.menus.actionMenu>
                </div>
-               <div class="typo3-docheader-buttons">
-                       <f:render section="docheader-buttons" />
-               </div>
+               <div class="typo3-docheader-buttons"></div>
        </div>
        <div id="typo3-docbody">
                <div id="typo3-inner-docbody" class="typo3-documentation">
@@ -32,4 +27,4 @@
                        <f:render section="Content" />
                </div>
        </div>
-</f:be.container>
+</f:be.container>
\ No newline at end of file
index 33e25d7..ccc19d3 100644 (file)
@@ -1,9 +1,5 @@
 <f:layout name="Default"/>
 
-<f:section name="docheader-buttons">
-
-</f:section>
-
 <f:section name="module-headline">
        <h1><f:translate key="downloadDocumentation">Download Documentation</f:translate></h1>
 </f:section>
@@ -41,5 +37,4 @@
                </f:for>
                </tbody>
        </table>
-
-</f:section>
+</f:section>
\ No newline at end of file
index 8da13db..a9d55af 100644 (file)
@@ -2,10 +2,6 @@
 
 <f:layout name="Default" />
 
-<f:section name="docheader-buttons">
-
-</f:section>
-
 <f:section name="module-headline">
        <h1><f:translate key="showDocumentation">Show Documentation</f:translate></h1>
 </f:section>
diff --git a/typo3/sysext/documentation/Resources/Public/JavaScript/Main.js b/typo3/sysext/documentation/Resources/Public/JavaScript/Main.js
new file mode 100644 (file)
index 0000000..afad62a
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 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!
+ */
+
+/**
+ * JavaScript module for ext:documentation
+ */
+define('TYPO3/CMS/Documentation/Main', ['jquery', 'datatables', 'jquery/jquery.clearable'], function($) {
+
+       var Documentation = {
+               datatable: null
+       };
+
+       // Initializes the data table, depending on the current view
+       Documentation.initializeView = function() {
+               var getVars = Documentation.getUrlVars();
+               // getVars[2] contains the name of the action key
+               // List view is the default view
+               if (getVars[getVars[2]] === 'download') {
+                       Documentation.documentationDownloadView(getVars);
+               } else {
+                       Documentation.documentationListView(getVars);
+               }
+       };
+
+       // Initializes the list view
+       Documentation.documentationListView = function(getVars) {
+               Documentation.datatable = $('#typo3-documentation-list').DataTable({
+                       'paging': false,
+                       'jQueryUI': true,
+                       'lengthChange': false,
+                       'pageLength': 15,
+                       'stateSave': true
+               });
+
+               // restore filter
+               if (Documentation.datatable.length && getVars['search']) {
+                       Documentation.datatable.search(getVars['search']);
+               }
+       };
+
+       // Initializes the download view
+       Documentation.documentationDownloadView = function(getVars) {
+               Documentation.datatable = $('#typo3-documentation-download').DataTable({
+                       'paging': false,
+                       'jQueryUI': true,
+                       'lengthChange': false,
+                       'pageLength': 15,
+                       'stateSave': true,
+                       'order': [[ 1, 'asc' ]]
+               });
+
+               // restore filter
+               if (Documentation.datatable.length && getVars['search']) {
+                       Documentation.datatable.search(getVars['search']);
+               }
+       };
+
+       // Utility method to retrieve query parameters
+       Documentation.getUrlVars = function getUrlVars() {
+               var vars = [], hash;
+               var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
+               for (var i = 0; i < hashes.length; i++) {
+                       hash = hashes[i].split('=');
+                       vars.push(hash[0]);
+                       vars[hash[0]] = hash[1];
+               }
+               return vars;
+       };
+
+       $(document).ready(function() {
+               // Initialize the view
+               Documentation.initializeView();
+
+               // Make the data table filter react to the clearing of the filter field
+               $('.dataTables_wrapper .dataTables_filter input').clearable({
+                       onClear: function() {
+                               Documentation.datatable.search('');
+                       }
+               });
+       });
+});
\ No newline at end of file
diff --git a/typo3/sysext/documentation/Resources/Public/JavaScript/configuration.js b/typo3/sysext/documentation/Resources/Public/JavaScript/configuration.js
deleted file mode 100644 (file)
index 234c040..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-// IIFE for faster access to $ and save $ use
-(function ($) {
-
-       $(document).ready(function() {
-               configurationFieldSupport();
-       });
-
-       function configurationFieldSupport() {
-               $('.offset').each(function() {
-                       $(this).hide();
-                       val = $(this).attr('value');
-                       valArr = val.split(',');
-
-                       $(this).wrap('<div class="offsetSelector"></div>');
-                       $(this).parent().append('x: <input value="' + $.trim(valArr[0]) + '" class="tempOffset1 tempOffset">');
-                       $(this).parent().append('<span>, </span>');
-                       $(this).parent().append('y: <input value="' + $.trim(valArr[1]) + '" class="tempOffset2 tempOffset">');
-
-                       $(this).siblings('.tempOffset').keyup(function() {
-                               $(this).siblings('.offset').attr(
-                                       'value',
-                                       $(this).parent().children('.tempOffset1').attr('value') + ',' + $(this).parent().children('.tempOffset2').attr('value')
-                               );
-                       });
-               });
-
-               $('.wrap').each(function() {
-                       $(this).hide();
-                       val = $(this).attr('value');
-                       valArr = val.split('|');
-
-                       $(this).wrap('<div class="wrapSelector"></div>');
-                       $(this).parent().append('<input value="' + $.trim(valArr[0]) + '" class="tempWrap1 tempWrap">');
-                       $(this).parent().append('<span>|</span>');
-                       $(this).parent().append('<input value="' + $.trim(valArr[1]) + '" class="tempWrap2 tempWrap">');
-
-                       $(this).siblings('.tempWrap').keyup(function() {
-                               $(this).siblings('.wrap').attr(
-                                       'value',
-                                       $(this).parent().children('.tempWrap1').attr('value') + '|' + $(this).parent().children('.tempWrap2').attr('value')
-                               );
-                       });
-               });
-       }
-}(jQuery));
\ No newline at end of file
diff --git a/typo3/sysext/documentation/Resources/Public/JavaScript/main.js b/typo3/sysext/documentation/Resources/Public/JavaScript/main.js
deleted file mode 100644 (file)
index 61712a1..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-TYPO3.DocumentationApplication = {
-       datatable: null,
-       // Utility method to retrieve query parameters
-       getUrlVars: function getUrlVars() {
-               var vars = [], hash;
-               var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
-               for(var i = 0; i < hashes.length; i++) {
-                       hash = hashes[i].split('=');
-                       vars.push(hash[0]);
-                       vars[hash[0]] = hash[1];
-               }
-               return vars;
-       },
-       // Initializes the data table, depending on the current view
-       initializeView: function() {
-               var getVars = this.getUrlVars();
-               // getVars[1] contains the name of the action key
-               // List view is the default view
-               if (getVars[getVars[1]] == 'download') {
-                       this.documentationDownloadView(getVars);
-               } else {
-                       this.documentationListView(getVars);
-               }
-       },
-       // Initializes the list view
-       documentationListView: function(getVars) {
-               this.datatable = jQuery('#typo3-documentation-list').DataTable({
-                       'paging': false,
-                       'jQueryUI': true,
-                       'lengthChange': false,
-                       'pageLength': 15,
-                       'stateSave': true
-               });
-
-               // restore filter
-               if (this.datatable.length && getVars['search']) {
-                       this.datatable.search(getVars['search']);
-               }
-       },
-       // Initializes the download view
-       documentationDownloadView: function(getVars) {
-               this.datatable = jQuery('#typo3-documentation-download').DataTable({
-                       'paging': false,
-                       'jQueryUI': true,
-                       'lengthChange': false,
-                       'pageLength': 15,
-                       'stateSave': true,
-                       'order': [[ 1, 'asc' ]]
-               });
-
-               // restore filter
-               if (this.datatable.length && getVars['search']) {
-                       this.datatable.search(getVars['search']);
-               }
-       }
-};
-
-// IIFE for faster access to $ and save $ use
-(function ($) {
-
-       $(document).ready(function() {
-               // Initialize the view
-               TYPO3.DocumentationApplication.initializeView();
-
-               // Make the data table filter react to the clearing of the filter field
-               $('.dataTables_wrapper .dataTables_filter input').clearable({
-                       onClear: function() {
-                               TYPO3.DocumentationApplication.datatable.search('');
-                       }
-               });
-       });
-}(jQuery));