From 6c68bcad5d7f7bd239e8f6210e061113e5773d9a Mon Sep 17 00:00:00 2001 From: Tuan Pham Ngoc Date: Fri, 25 Jun 2021 23:56:03 +0700 Subject: [PATCH] Make weblink editor-xtd works --- .../com_weblinks/tmpl/weblinks/modal.php | 44 ++++++++++--------- .../com_weblinks/js/admin-weblinks-modal.js | 14 ++---- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/administrator/components/com_weblinks/tmpl/weblinks/modal.php b/src/administrator/components/com_weblinks/tmpl/weblinks/modal.php index a4d52fd..8a93fe6 100644 --- a/src/administrator/components/com_weblinks/tmpl/weblinks/modal.php +++ b/src/administrator/components/com_weblinks/tmpl/weblinks/modal.php @@ -8,27 +8,29 @@ */ defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Multilanguage; +use Joomla\CMS\Language\Text; use Joomla\Component\Weblinks\Site\Helper\RouteHelper; -$app = JFactory::getApplication(); +$app = Factory::getApplication(); if ($app->isClient('site')) { - JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN')); + JSession::checkToken('get') or die(Text::_('JINVALID_TOKEN')); } // Include the component HTML helpers. -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); -JHtml::_('behavior.core'); -JHtml::_('behavior.polyfill', array('event'), 'lt IE 9'); -JHtml::_('script', 'com_weblinks/admin-weblinks-modal.js', array('version' => 'auto', 'relative' => true)); -JHtml::_('bootstrap.tooltip', '.hasTooltip', array('placement' => 'bottom')); -JHtml::_('formbehavior.chosen', 'select'); +HTMLHelper::_('behavior.core'); +HTMLHelper::_('script', 'com_weblinks/admin-weblinks-modal.js', array('version' => 'auto', 'relative' => true)); +HTMLHelper::_('bootstrap.tooltip', '.hasTooltip', array('placement' => 'bottom')); +HTMLHelper::_('formbehavior.chosen', 'select'); // Special case for the search field tooltip. $searchFilterDesc = $this->filterForm->getFieldAttribute('search', 'description', null, 'filter'); -JHtml::_('bootstrap.tooltip', '#filter_search', array('title' => JText::_($searchFilterDesc), 'placement' => 'bottom')); +HTMLHelper::_('bootstrap.tooltip', '#filter_search', array('title' => Text::_($searchFilterDesc), 'placement' => 'bottom')); $function = $app->input->getCmd('function', 'jSelectWeblink'); $editor = $app->input->getCmd('editor', ''); @@ -39,7 +41,7 @@ $onclick = $this->escape($function); if (!empty($editor)) { // This view is used also in com_menus. Load the xtd script only if the editor is set! - JFactory::getDocument()->addScriptOptions('xtd-weblinks', array('editor' => $editor)); + $app->getDocument()->addScriptOptions('xtd-weblinks', array('editor' => $editor)); $onclick = "jSelectWeblink"; } @@ -58,29 +60,29 @@ $iconStates = array(
items)) : ?>
- +
@@ -94,7 +96,7 @@ $iconStates = array( items as $i => $item) : ?> - language && JLanguageMultilang::isEnabled()) : ?> + language && Multilanguage::isEnabled()) : ?> language); ?> language, 0, 2); ?> @@ -118,7 +120,7 @@ $iconStates = array( escape($item->title); ?>
- escape($item->category_title); ?> + escape($item->category_title); ?>
- + - + - + - + - + - +
@@ -128,7 +130,7 @@ $iconStates = array( - created, JText::_('DATE_FORMAT_LC4')); ?> + created, Text::_('DATE_FORMAT_LC4')); ?> id; ?> @@ -142,7 +144,7 @@ $iconStates = array( - + diff --git a/src/media/com_weblinks/js/admin-weblinks-modal.js b/src/media/com_weblinks/js/admin-weblinks-modal.js index 35f7133..66fe802 100644 --- a/src/media/com_weblinks/js/admin-weblinks-modal.js +++ b/src/media/com_weblinks/js/admin-weblinks-modal.js @@ -14,8 +14,8 @@ var hreflang = '', editor, tag; if (!Joomla.getOptions('xtd-weblinks')) { - // Something went wrong! - window.parent.jModalClose(); + // Something went wrong + window.parent.Joomla.Modal.getCurrent().close(); return false; } @@ -28,14 +28,8 @@ tag = '' + title + ''; - /** Use the API, if editor supports it **/ - if (window.Joomla && window.Joomla.editors && Joomla.editors.instances && Joomla.editors.instances.hasOwnProperty(editor)) { - Joomla.editors.instances[editor].replaceSelection(tag) - } else { - window.parent.jInsertEditorText(tag, editor); - } - - window.parent.jModalClose(); + window.parent.Joomla.editors.instances[editor].replaceSelection(tag); + window.parent.Joomla.Modal.getCurrent().close(); }; document.addEventListener('DOMContentLoaded', function(){