CoreFiles by mySites.guru
skipto.php92 lines, 2,302 bytes, from Joomla_4.0.0-beta5-Beta-Full_Package.zip
Raw History Compare with 4.0.0-beta4
md5
21c19d90e7f749613f140de8a2bf57a4
sha1
43ab6d05c226335ea342e4ade768ca08b7913532
sha256
de7b7400f66c201f4883a6f0d7116c47c1eb8d2494ebf4087ae8cd8f1a10aa05
<?php
/**
 * @package     Joomla.Plugin
 * @subpackage  System.skipto
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;

/**
 * Skipto plugin to add accessible keyboard navigation to the site and administrator templates.
 *
 * @since  4.0.0
 */
class PlgSystemSkipto extends CMSPlugin
{
	/**
	 * Application object.
	 *
	 * @var    CMSApplicationInterface
	 * @since  4.0.0
	 */
	protected $app;

	/**
	 * Add the CSS and JavaScript for the skipto navigation menu.
	 *
	 * @return  void
	 *
	 * @since   4.0.0
	 */
	public function onAfterDispatch()
	{
		$section = $this->params->get('section', 'administrator');

		if ($section !== 'both' && $this->app->isClient($section) !== true)
		{
			return;
		}

		// Get the document object.
		$document = $this->app->getDocument();

		if ($document->getType() !== 'html')
		{
			return;
		}

		// Load language file.
		$this->loadLanguage();

		// Add strings for translations in JavaScript.
		$document->addScriptOptions(
			'skipto-settings',
			[
				'settings' => [
					'skipTo' => [
						'buttonDivRole'  => 'navigation',
						'buttonDivLabel' => Text::_('PLG_SYSTEM_SKIPTO_SKIP_TO_KEYBOARD'),
						'buttonLabel'    => Text::_('PLG_SYSTEM_SKIPTO_SKIP_TO'),
						'buttonDivTitle' => '',
						'menuLabel'      => Text::_('PLG_SYSTEM_SKIPTO_SKIP_TO_AND_PAGE_OUTLINE'),
						'landmarksLabel' => Text::_('PLG_SYSTEM_SKIPTO_SKIP_TO'),
						'headingsLabel'	 => Text::_('PLG_SYSTEM_SKIPTO_PAGE_OUTLINE'),
						// The following string begins with a space
						'contentLabel'   => ' ' . Text::_('PLG_SYSTEM_SKIPTO_CONTENT'),
					]
				]
			]
		);

		/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
		$wa = $document->getWebAssetManager();
		$wa->useStyle('skipto')
			->useScript('skipto.dropmenu')
			->useScript('skipto')
			->addInlineScript(
				'document.addEventListener(\'DOMContentLoaded\', function() {'
				. 'window.SkipToConfig = Joomla.getOptions(\'skipto-settings\');'
				. 'window.skipToMenuInit();});',
				[],
				['type' => 'module'],
				['skipto']
			);
	}
}

The same content is in 5 releases, Joomla 4.0.0-beta to 4.0.0-beta5. See them all, or every version of this file.