Commit 520dc986 authored by Benni Mack's avatar Benni Mack Committed by Andreas Fernandez
Browse files

[!!!][TASK] Remove TYPO3.jQuery

This change removes the availability of TYPO3.jQuery within the
TYPO3 Core by default.

The constants PageRenderer::JQUERY_NAMESPACE_DEFAULT / and
PageRenderer: JQUERY_NAMESPACE_DEFAULT_NOCONFLICT namespace options
"jQuery" are removed. This also means the removal
of having custom namespaces of jQuery (e.g. TYPO3.bennis_jQuery) leaving
"noConflict" to be used by default.

Related: #79221
Resolves: #82378
Releases: master
Change-Id: Ibc939999159dbf376b09f53aacac618ed7cc40e8
Reviewed-on: https://review.typo3.org/53237

Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
parent 866858c1
......@@ -60,6 +60,7 @@ declare module 'TYPO3/CMS/Backend/Severity' {
// Type definition for global namespace object
interface Window {
TYPO3: any;
$: any;
}
/**
......
......@@ -397,7 +397,7 @@ class ImageManipulation {
* The top.require is now inlined @see ImageManipulationElemen.php:143
* TODO: Find a better solution for cross iframe communications
*/
this.cropper = (top.TYPO3.jQuery(image) as any).cropper($.extend(this.defaultOpts, {
this.cropper = (top.$(image) as any).cropper($.extend(this.defaultOpts, {
built: this.cropBuiltHandler,
crop: this.cropMoveHandler,
cropend: this.cropEndHandler,
......
......@@ -389,7 +389,7 @@ define(["require", "exports", "jquery", "TYPO3/CMS/Backend/Modal", "TYPO3/CMS/Co
* The top.require is now inlined @see ImageManipulationElemen.php:143
* TODO: Find a better solution for cross iframe communications
*/
this.cropper = top.TYPO3.jQuery(image).cropper($.extend(this.defaultOpts, {
this.cropper = top.$(image).cropper($.extend(this.defaultOpts, {
built: this.cropBuiltHandler,
crop: this.cropMoveHandler,
cropend: this.cropEndHandler,
......
......@@ -650,7 +650,7 @@ var inline = {
if (!records[i].length) {
continue;
}
$headerObj = TYPO3.jQuery('#' + partOfHeaderObj + records[i] + '_header');
$headerObj = $('#' + partOfHeaderObj + records[i] + '_header');
sortUp = $headerObj.find('.sortingUp');
iconIdentifier = 'actions-move-up';
if (sortUp) {
......
......@@ -39,8 +39,6 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
const JQUERY_VERSION_LATEST = '3.2.1';
// jQuery namespace options
const JQUERY_NAMESPACE_NONE = 'none';
const JQUERY_NAMESPACE_DEFAULT = 'jQuery';
const JQUERY_NAMESPACE_DEFAULT_NOCONFLICT = 'defaultNoConflict';
/**
* @var bool
......@@ -1433,7 +1431,7 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
* @param string $namespace The namespace in which the jQuery object of the specific version should be stored.
* @throws \UnexpectedValueException
*/
public function loadJquery($version = null, $source = null, $namespace = self::JQUERY_NAMESPACE_DEFAULT)
public function loadJquery($version = null, $source = null, $namespace = self::JQUERY_NAMESPACE_NONE)
{
// Set it to the version that is shipped with the TYPO3 core
if ($version === null || $version === 'latest') {
......@@ -2168,19 +2166,10 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
default:
$jQueryFileName = $source;
}
// Include the jQuery Core
$scriptTag = '<script src="' . htmlspecialchars($jQueryFileName) . '" type="text/javascript"></script>' . LF;
// Set the noConflict mode to be available via "TYPO3.jQuery" in all installations
switch ($namespace) {
case self::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT:
$scriptTag .= GeneralUtility::wrapJS('jQuery.noConflict();') . LF;
break;
case self::JQUERY_NAMESPACE_NONE:
break;
case self::JQUERY_NAMESPACE_DEFAULT:
default:
$scriptTag .= GeneralUtility::wrapJS('var TYPO3 = TYPO3 || {}; TYPO3.' . $namespace . ' = jQuery.noConflict(true); var $ = TYPO3.' . $namespace . ';') . LF;
// Set the noConflict mode to be globally available via "jQuery"
if ($namespace !== self::JQUERY_NAMESPACE_NONE) {
$scriptTag .= GeneralUtility::wrapJS('jQuery.noConflict();') . LF;
}
return $scriptTag;
}
......
.. include:: ../../Includes.txt
===========================================
Breaking: #82378 - Remove namespaced jQuery
===========================================
See :issue:`82378`
Description
===========
The possibility to jail jQuery into a namespace has been removed. This affects custom namespaces and
:js:`TYPO3.jQuery` as well.
The class constants :php:`TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_DEFAULT` and
:php:`TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT` have been removed without
substitution, any usage will be detected by the Extension Scanner.
Impact
======
Namespaces will be ignored and automatically fall back to noConflict behavior.
Calling :js:`TYPO3.jQuery.*` will result in a TypeError.
Affected Installations
======================
All installations using a custom namespace, :php:`PageRenderer::JQUERY_NAMESPACE_DEFAULT`
:php:`PageRenderer::JQUERY_NAMESPACE_DEFAULT` or relying on :js:`TYPO3.jQuery` are affected.
Migration
=========
Remove :php:`$namespace` argument in :php:`PageRenderer->loadJquery()` and either use :js:`window.$` or migrate
to RequireJS.
.. index:: Backend, Frontend, JavaScript, PartiallyScanned
......@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Tests\Functional\Page;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Page\PageRenderer;
/**
* Test case
*/
......@@ -24,7 +26,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
*/
public function pageRendererRendersInsertsMainContentStringsInOutput()
{
$subject = new \TYPO3\CMS\Core\Page\PageRenderer();
$subject = new PageRenderer();
$subject->setCharSet('utf-8');
$subject->setLanguage('default');
......@@ -80,8 +82,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
$subject->addCssInlineBlock('general3', 'h1 {margin:20px;}', null, true);
$subject->loadJquery();
$expectedJqueryRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
$expectedJqueryStatement = 'var TYPO3 = TYPO3 || {}; TYPO3.jQuery = jQuery.noConflict(true);';
$expectedJqueryRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery-' . PageRenderer::JQUERY_VERSION_LATEST . '\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
$expectedBodyContent = $this->getUniqueId('ABCDE-');
$subject->setBodyContent($expectedBodyContent);
......@@ -104,7 +105,6 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
$this->assertContains($expectedCssFileString, $renderedString);
$this->assertContains($expectedCssInlineBlockOnTopString, $renderedString);
$this->assertRegExp($expectedJqueryRegExp, $renderedString);
$this->assertContains($expectedJqueryStatement, $renderedString);
$this->assertContains($expectedBodyContent, $renderedString);
}
......@@ -113,7 +113,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
*/
public function pageRendererRendersFooterValues()
{
$subject = new \TYPO3\CMS\Core\Page\PageRenderer();
$subject = new PageRenderer();
$subject->setCharSet('utf-8');
$subject->setLanguage('default');
......@@ -158,7 +158,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
]);
$expectedInlineSettingsReturnValue = 'TYPO3.settings = {"myApp":{"myKey":"myValue","myKey1":"myValue1","myKey2":"myValue2","myKey3":"myValue3"}';
$renderedString = $subject->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
$renderedString = $subject->render(PageRenderer::PART_FOOTER);
$this->assertContains($expectedFooterData, $renderedString);
$this->assertRegExp($expectedJsFooterLibraryRegExp, $renderedString);
......@@ -171,18 +171,45 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
}
/**
* @return array
*/
public function jqueryNamespaceDataProvider()
{
return [
'Custom namespace falls back to "no conflict"' => [
'namespace' => 'MyNameSpace',
'matchNoConflict' => true,
],
'"None" namespace is respected' => [
'namespace' => PageRenderer::JQUERY_NAMESPACE_NONE,
'matchNoConflict' => false,
],
];
}
/**
* @param string $namespace
* @param bool $matchNoConflict
* @test
* @dataProvider jqueryNamespaceDataProvider
*/
public function loadJqueryRespectsGivenNamespace()
public function loadJqueryRespectsNamespace($namespace, $matchNoConflict)
{
$subject = new \TYPO3\CMS\Core\Page\PageRenderer();
$subject = new PageRenderer();
$expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
$expectedStatement = 'var TYPO3 = TYPO3 || {}; TYPO3.MyNameSpace = jQuery.noConflict(true);';
$subject->loadJquery(null, null, 'MyNameSpace');
$expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery-' . PageRenderer::JQUERY_VERSION_LATEST . '\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
$noConflictStatement = 'jQuery.noConflict();';
$subject->loadJquery(null, null, $namespace);
//jQuery.noConflict();
$out = $subject->render();
$this->assertRegExp($expectedRegExp, $out);
$this->assertContains($expectedStatement, $out);
if ($matchNoConflict) {
$this->assertContains($noConflictStatement, $out);
} else {
$this->assertNotContains($noConflictStatement, $out);
}
}
/**
......@@ -190,11 +217,11 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
*/
public function loadJqueryWithDefaultNoConflictModeDoesNotSetNamespace()
{
$subject = new \TYPO3\CMS\Core\Page\PageRenderer();
$subject = new PageRenderer();
$expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
$expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery-' . PageRenderer::JQUERY_VERSION_LATEST . '\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
$expectedStatement = 'jQuery.noConflict();';
$subject->loadJquery(null, null, \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT);
$subject->loadJquery(null, null, 'MyNameSpace');
$out = $subject->render();
$this->assertRegExp($expectedRegExp, $out);
$this->assertContains($expectedStatement, $out);
......@@ -206,10 +233,10 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
*/
public function loadJqueryWithNamespaceNoneDoesNotIncludeNoConflictHandling()
{
$subject = new \TYPO3\CMS\Core\Page\PageRenderer();
$subject = new PageRenderer();
$expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
$subject->loadJquery(null, null, \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_NONE);
$expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery-' . PageRenderer::JQUERY_VERSION_LATEST . '\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
$subject->loadJquery(null, null, PageRenderer::JQUERY_NAMESPACE_NONE);
$out = $subject->render();
$this->assertRegExp($expectedRegExp, $out);
$this->assertNotContains('jQuery.noConflict', $out);
......@@ -220,11 +247,11 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
*/
public function loadJqueryLoadsTheLatestJqueryVersionInNoConflictModeUncompressedInDebugMode()
{
$subject = new \TYPO3\CMS\Core\Page\PageRenderer();
$subject = new PageRenderer();
$expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
$expectedStatement = 'var TYPO3 = TYPO3 || {}; TYPO3.jQuery = jQuery.noConflict(true);';
$subject->loadJquery();
$expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery-' . PageRenderer::JQUERY_VERSION_LATEST . '\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
$expectedStatement = 'jQuery.noConflict();';
$subject->loadJquery(null, null, 'MyNameSpace');
$subject->enableDebugMode();
$out = $subject->render();
$this->assertRegExp($expectedRegExp, $out);
......@@ -261,12 +288,15 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
}
/**
* @param string $version
* @param string $source
* @param string $regex
* @dataProvider loadJqueryFromSourceDataProvider
* @test
*/
public function isJqueryLoadedFromSourceUncompressedIfDebugModeIsEnabled($version, $source, $regex)
{
$subject = new \TYPO3\CMS\Core\Page\PageRenderer();
$subject = new PageRenderer();
$subject->loadJquery($version, $source);
$subject->enableDebugMode();
......@@ -279,7 +309,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
*/
public function isJqueryLoadedMinifiedFromGoogleByDefault()
{
$subject = new \TYPO3\CMS\Core\Page\PageRenderer();
$subject = new PageRenderer();
$expectedRegex = '#<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js" type="text/javascript"></script>#';
$subject->loadJquery('1.6.3', 'google');
......@@ -292,7 +322,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
*/
public function loadExtJsInDebugLoadsDebugExtJs()
{
$subject = new \TYPO3\CMS\Core\Page\PageRenderer();
$subject = new PageRenderer();
$expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/extjs/ext-all-debug\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
$subject->loadExtJS(true, true);
......
......@@ -20,4 +20,14 @@ return [
'Breaking-80700-DeprecatedFunctionalityRemoved.rst',
],
],
'TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_DEFAULT' => [
'restFiles' => [
'Breaking-82378-RemoveNamespacedJQuery.rst',
],
],
'TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT' => [
'restFiles' => [
'Breaking-82378-RemoveNamespacedJQuery.rst',
],
],
];
......@@ -46,6 +46,11 @@ class ClassConstantMatcherTest extends UnitTestCase
'Breaking-80700-DeprecatedFunctionalityRemoved.rst',
],
],
'TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_DEFAULT' => [
'restFiles' => [
'Breaking-82378-RemoveNamespacedJQuery.rst',
],
],
];
$subject = new ClassConstantMatcher($configuration);
$traverser->addVisitor($subject);
......@@ -53,6 +58,7 @@ class ClassConstantMatcherTest extends UnitTestCase
$expectedHitLineNumbers = [
28,
29,
30,
];
$actualHitLineNumbers = [];
foreach ($subject->getMatches() as $hit) {
......
......@@ -27,6 +27,7 @@ class ClassConstantMatcherFixture
// Matches
$foo = \TYPO3\CMS\Backend\Template\DocumentTemplate::STATUS_ICON_ERROR;
$foo = DocumentTemplate::STATUS_ICON_ERROR;
$foo = \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_DEFAULT;
// No match
$foo = \My\Project\AClass::MY_CONSTANT;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment