' .$html . implode('',$button).'
';
- }
- }
- return $html;
- }
-
/**
* Method to get a list of options for a list input.
*
diff --git a/admin/src/Helper/ComponentbuilderHelper.php b/admin/src/Helper/ComponentbuilderHelper.php
index 107a93502..e4e971aab 100644
--- a/admin/src/Helper/ComponentbuilderHelper.php
+++ b/admin/src/Helper/ComponentbuilderHelper.php
@@ -1772,7 +1772,7 @@ abstract class ComponentbuilderHelper
public static function getFieldTypeProperties($value, $type, $settings = [], $xml = null, bool $dbDefaults = false): ?array
{
// Get a db connection.
- $db = Factory::getDbo();
+ $db = Factory::getContainer()->get(DatabaseInterface::class);
// Create a new query object.
$query = $db->getQuery(true);
@@ -1935,7 +1935,6 @@ abstract class ComponentbuilderHelper
{
return FieldHelper::getValue($xml, $get, $confirmation);
}
-
/**
* Retrieves field type properties from the database.
@@ -1967,7 +1966,7 @@ abstract class ComponentbuilderHelper
string $operator = 'IN'
) {
// Get a database connection
- $db = Factory::getDbo();
+ $db = Factory::getContainer()->get(DatabaseInterface::class);
try {
// Create a new query object
@@ -3752,7 +3751,7 @@ abstract class ComponentbuilderHelper
if (is_int($serverID) && is_int($protocol))
{
// Get a db connection
- $db = Factory::getDbo();
+ $db = Factory::getContainer()->get(DatabaseInterface::class);
// start the query
$query = $db->getQuery(true);
// select based to protocol
diff --git a/admin/src/Model/Admin_fields_relationsModel.php b/admin/src/Model/Admin_fields_relationsModel.php
index 4298ee451..1499ea398 100644
--- a/admin/src/Model/Admin_fields_relationsModel.php
+++ b/admin/src/Model/Admin_fields_relationsModel.php
@@ -119,6 +119,14 @@ class Admin_fields_relationsModel extends AdminModel
}
+ /**
+ * The VDM view key
+ *
+ * @var string
+ * @since 3.0.13
+ */
+ protected string $vastDevMod;
+
/**
* Retrieves or generates a Vast Development Method (VDM) key for the current item.
*
@@ -132,8 +140,9 @@ class Admin_fields_relationsModel extends AdminModel
* 7. Returns the VDM key.
*
* @return string The VDM key for the current item.
+ * @since 3.0.13
*/
- public function getVDM()
+ public function getVDM(): string
{
if (!isset($this->vastDevMod))
{
@@ -148,7 +157,7 @@ class Admin_fields_relationsModel extends AdminModel
$id = $_id;
}
// set the id and view name to session
- if (($vdm = SessionHelper::get('admin_fields_relations__'.$id)) !== null)
+ if (($vdm = SessionHelper::get('admin_fields_relations__' . $id)) !== null)
{
$this->vastDevMod = $vdm;
}
@@ -156,10 +165,10 @@ class Admin_fields_relationsModel extends AdminModel
{
// set the vast development method key
$this->vastDevMod = UtilitiesStringHelper::random(50);
- SessionHelper::set($this->vastDevMod, 'admin_fields_relations__'.$id);
- SessionHelper::set('admin_fields_relations__'.$id, $this->vastDevMod);
+ SessionHelper::set($this->vastDevMod, 'admin_fields_relations__' . $id);
+ SessionHelper::set('admin_fields_relations__' . $id, $this->vastDevMod);
// set a return value if found
- $app = Factory::getApplication();
+ $app = $this->app ?? Factory::getApplication();
$input = method_exists($app, 'getInput') ? $app->getInput() : $app->input;
$return = $input->get('return', null, 'base64');
SessionHelper::set($this->vastDevMod . '__return', $return);
@@ -171,9 +180,9 @@ class Admin_fields_relationsModel extends AdminModel
}
}
}
+
return $this->vastDevMod;
- }
-
+ }
/**
* Method to get a single record.
@@ -221,7 +230,7 @@ class Admin_fields_relationsModel extends AdminModel
$id = $item->id;
}
// set the id and view name to session
- if (($vdm = SessionHelper::get('admin_fields_relations__'.$id)) !== null)
+ if (($vdm = SessionHelper::get('admin_fields_relations__' . $id)) !== null)
{
$this->vastDevMod = $vdm;
}
@@ -229,10 +238,10 @@ class Admin_fields_relationsModel extends AdminModel
{
// set the vast development method key
$this->vastDevMod = UtilitiesStringHelper::random(50);
- SessionHelper::set($this->vastDevMod, 'admin_fields_relations__'.$id);
- SessionHelper::set('admin_fields_relations__'.$id, $this->vastDevMod);
+ SessionHelper::set($this->vastDevMod, 'admin_fields_relations__' . $id);
+ SessionHelper::set('admin_fields_relations__' . $id, $this->vastDevMod);
// set a return value if found
- $app = Factory::getApplication();
+ $app = $this->app ?? Factory::getApplication();
$input = method_exists($app, 'getInput') ? $app->getInput() : $app->input;
$return = $input->get('return', null, 'base64');
SessionHelper::set($this->vastDevMod . '__return', $return);
diff --git a/admin/src/Model/Admin_viewModel.php b/admin/src/Model/Admin_viewModel.php
index 7e27f6193..faed41a8a 100644
--- a/admin/src/Model/Admin_viewModel.php
+++ b/admin/src/Model/Admin_viewModel.php
@@ -255,6 +255,14 @@ class Admin_viewModel extends AdminModel
}
+ /**
+ * The VDM view key
+ *
+ * @var string
+ * @since 3.0.13
+ */
+ protected string $vastDevMod;
+
/**
* Retrieves or generates a Vast Development Method (VDM) key for the current item.
*
@@ -268,8 +276,9 @@ class Admin_viewModel extends AdminModel
* 7. Returns the VDM key.
*
* @return string The VDM key for the current item.
+ * @since 3.0.13
*/
- public function getVDM()
+ public function getVDM(): string
{
if (!isset($this->vastDevMod))
{
@@ -284,7 +293,7 @@ class Admin_viewModel extends AdminModel
$id = $_id;
}
// set the id and view name to session
- if (($vdm = SessionHelper::get('admin_view__'.$id)) !== null)
+ if (($vdm = SessionHelper::get('admin_view__' . $id)) !== null)
{
$this->vastDevMod = $vdm;
}
@@ -292,10 +301,10 @@ class Admin_viewModel extends AdminModel
{
// set the vast development method key
$this->vastDevMod = UtilitiesStringHelper::random(50);
- SessionHelper::set($this->vastDevMod, 'admin_view__'.$id);
- SessionHelper::set('admin_view__'.$id, $this->vastDevMod);
+ SessionHelper::set($this->vastDevMod, 'admin_view__' . $id);
+ SessionHelper::set('admin_view__' . $id, $this->vastDevMod);
// set a return value if found
- $app = Factory::getApplication();
+ $app = $this->app ?? Factory::getApplication();
$input = method_exists($app, 'getInput') ? $app->getInput() : $app->input;
$return = $input->get('return', null, 'base64');
SessionHelper::set($this->vastDevMod . '__return', $return);
@@ -307,9 +316,9 @@ class Admin_viewModel extends AdminModel
}
}
}
+
return $this->vastDevMod;
- }
-
+ }
/**
* Method to get a single record.
@@ -591,7 +600,7 @@ class Admin_viewModel extends AdminModel
$id = $item->id;
}
// set the id and view name to session
- if (($vdm = SessionHelper::get('admin_view__'.$id)) !== null)
+ if (($vdm = SessionHelper::get('admin_view__' . $id)) !== null)
{
$this->vastDevMod = $vdm;
}
@@ -599,10 +608,10 @@ class Admin_viewModel extends AdminModel
{
// set the vast development method key
$this->vastDevMod = UtilitiesStringHelper::random(50);
- SessionHelper::set($this->vastDevMod, 'admin_view__'.$id);
- SessionHelper::set('admin_view__'.$id, $this->vastDevMod);
+ SessionHelper::set($this->vastDevMod, 'admin_view__' . $id);
+ SessionHelper::set('admin_view__' . $id, $this->vastDevMod);
// set a return value if found
- $app = Factory::getApplication();
+ $app = $this->app ?? Factory::getApplication();
$input = method_exists($app, 'getInput') ? $app->getInput() : $app->input;
$return = $input->get('return', null, 'base64');
SessionHelper::set($this->vastDevMod . '__return', $return);
diff --git a/admin/src/Model/Admin_viewsModel.php b/admin/src/Model/Admin_viewsModel.php
index 8383c4a37..d80c99698 100644
--- a/admin/src/Model/Admin_viewsModel.php
+++ b/admin/src/Model/Admin_viewsModel.php
@@ -120,20 +120,20 @@ class Admin_viewsModel extends ListModel
$form = parent::getFilterForm($data, $loadData);
// Create the "joomla_component" filter
- $attributes = array(
+ $attributes = [
'name' => 'joomla_component',
'type' => 'list',
'onchange' => 'this.form.submit();',
- );
- $options = array(
+ ];
+ $options = [
'' => '- ' . Text::_('COM_COMPONENTBUILDER_NO_COMPONENTS_FOUND') . ' -'
- );
+ ];
// check if we have joomla components
if (($joomla_components = JCBFilterHelper::names('joomla_component')) !== null)
{
- $options = array(
+ $options = [
'' => '- ' . Text::_('COM_COMPONENTBUILDER_SELECT_COMPONENT') . ' -'
- );
+ ];
// make sure we do not lose the key values in normal merge
$options = $options + $joomla_components;
}
diff --git a/admin/src/Model/AjaxModel.php b/admin/src/Model/AjaxModel.php
index dbd5a8896..f74c17390 100644
--- a/admin/src/Model/AjaxModel.php
+++ b/admin/src/Model/AjaxModel.php
@@ -1757,7 +1757,7 @@ class AjaxModel extends ListModel
// load the values form params
$xml = json_decode($result->xml);
- $xmlOptions = GetHelper::between($xml,'option="','"');
+ $xmlOptions = GetHelper::between($xml, 'option="', '"');
$optionSet = '';
if (strpos($xmlOptions,',') !== false)
@@ -1800,7 +1800,7 @@ class AjaxModel extends ListModel
{
return "keywords=\"\"\nlength=\"\"";
}
- elseif (ComponentbuilderHelper::fieldCheck($result->name,'dynamic'))
+ elseif (ComponentbuilderHelper::fieldCheck($result->name, 'dynamic'))
{
return 'dynamic_list';
}
@@ -1830,7 +1830,7 @@ class AjaxModel extends ListModel
public function getTableColumns(string $tableName): ?string
{
// get the columns
- $columns = $this->_db->getTableColumns("#__".$tableName);
+ $columns = $this->_db->getTableColumns("#__" . $tableName);
if (UtilitiesArrayHelper::check($columns))
{
// build the return string
@@ -2187,7 +2187,7 @@ class AjaxModel extends ListModel
/**
* The view persistence details
*
- * @var array
+ * @var array
* @since 3.0.13
*/
protected array $viewid = [];
@@ -2195,18 +2195,20 @@ class AjaxModel extends ListModel
/**
* Get the view details via the session
*
- * @input string $call The persistence key
+ * @input string $call The persistence key
*
* @return array
- * @since 3.0.13
+ * @since 3.0.13
*/
protected function getViewID(string $call = 'table'): array
{
if (!isset($this->viewid[$call]))
{
// get the vdm key
- $input = Factory::getApplication()->getInput();
+ $app = $this->app ?? Factory::getApplication();
+ $input = $this->input ?? (method_exists($app, 'getInput') ? $app->getInput() : $app->input);
$vdm = $input->get('vdm', null, 'WORD');
+
if ($vdm)
{
// set view and id
@@ -2250,317 +2252,498 @@ class AjaxModel extends ListModel
return [];
}
-
- public function getButton($type, $size)
+ /**
+ * Generate a new-item creation button for a specific type and size.
+ *
+ * @param string $type The item type (view name) for which to create the button.
+ * @param int $size The button size: 1 = large, 2 = medium, 3 = small.
+ *
+ * @return string The generated HTML button markup, an empty string if unauthorized, or false if type not found.
+ * @since 3.0.0
+ */
+ public function getButton(string $type, int $size): string
{
- if (isset($this->buttonArray[$type]))
+ // Ensure the type exists in the button definition array
+ if (!isset($this->buttonArray[$type]))
{
- $user = Factory::getUser();
- // only add if user allowed to create
- if ($user->authorise($type.'.create', 'com_componentbuilder'))
- {
- // get the view name & id
- $values = $this->getViewID();
- // check if new item
- $ref = '';
- if (!empty($values['a_id']) && !empty($values['a_view']))
- {
- // check if we have a return value
- $return_url = 'index.php?option=com_componentbuilder&view=' . (string) $values['a_view'] . '&layout=edit&id=' . (int) $values['a_id'];
- if (isset($values['a_return']))
- {
- $return_url .= '&return=' . (string) $values['a_return'];
- }
-
- // load the return url
- $ref = '&return=' . urlencode(base64_encode($return_url));
-
- // check if we have a GUID
- if (isset($values['a_guid']))
- {
- $ref .= '&init_defaults=' . urlencode(json_encode([$values['a_view'] => $values['a_guid']]));
- }
- }
- // build url (A tag)
- $startAtag = 'onclick="UIkit2.modal.confirm(\''.Text::_('COM_COMPONENTBUILDER_ALL_UNSAVED_WORK_ON_THIS_PAGE_WILL_BE_LOST_ARE_YOU_SURE_YOU_WANT_TO_CONTINUE').'\', function(){ window.location.href = \'index.php?option=com_componentbuilder&view=' . $type . '&layout=edit' . $ref . '\' })" href="javascript:void(0)" title="'.Text::sprintf('COM_COMPONENTBUILDER_CREATE_NEW_S', StringHelper::safe($type, 'W')).'">';
- // build the smallest button
- if (3 == $size)
- {
- $button = '' . Text::sprintf('COM_COMPONENTBUILDER_BUTTON_TO_CREATE_S_WILL_SHOW_ONCE_S_IS_SAVED_FOR_THE_FIRST_TIME', StringHelper::safe($type, 'w'), StringHelper::safe($values['a_view'], 'w')) . '
';
- }
+ // Add GUID initialization if available
+ if (!empty($values['a_guid']))
+ {
+ $ref .= '&init_defaults=' . urlencode(json_encode([
+ $values['a_view'] => $values['a_guid']
+ ]));
}
}
- return '';
+
+ // Confirmation text
+ $confirmText = Text::_('COM_COMPONENTBUILDER_ALL_UNSAVED_WORK_ON_THIS_PAGE_WILL_BE_LOST_ARE_YOU_SURE_YOU_WANT_TO_CONTINUE');
+
+ // Safe label for title
+ $safeType = StringHelper::safe($type, 'W');
+ $title = Text::sprintf('COM_COMPONENTBUILDER_CREATE_NEW_S', $safeType);
+
+ // Build onclick A tag
+ $startATag = sprintf(
+ 'onclick="UIkit2.modal.confirm(\'%s\', function(){ window.location.href = \'index.php?option=com_componentbuilder&view=%s&layout=edit%s\' })" href="javascript:void(0)" title="%s"',
+ addslashes($confirmText),
+ htmlspecialchars($type, ENT_QUOTES, 'UTF-8'),
+ $ref,
+ htmlspecialchars($title, ENT_QUOTES, 'UTF-8')
+ );
+
+ // Build button markup based on size
+ return match ($size) {
+ 3 => sprintf(
+ '' . implode('
', $result) . '
';
+ $result[] = $table;
}
}
- return '' . implode('
', $result) . '
';
+
+ return $html;
}
/**
@@ -3398,7 +3581,7 @@ class AjaxModel extends ListModel
protected function validateViewRequest(int $id): ?array
{
$view = $this->getViewID();
- if (isset($view['a_id'], $view['a_view']) && (int)$view['a_id'] === $id)
+ if (isset($view['a_id'], $view['a_view']) && (int) $view['a_id'] === $id)
{
$target = $this->getCodeSearchKeys($view['a_view'], 'customcode', 'query_');
if ($target !== null)
@@ -3423,11 +3606,9 @@ class AjaxModel extends ListModel
*/
protected function buildReturnUrl(array $view, int $id): string
{
- $jinput = Factory::getApplication()->getInput();
- $returnHere = $jinput->get('return_here', null, 'base64');
- if (StringHelper::check($returnHere))
+ if (!empty($view['a_return']))
{
- return '&return=' . $returnHere;
+ return '&return=' . (string) $view['a_return'];
}
return '&ref=' . $view['a_view'] . '&refid=' . $id;
}
@@ -4646,39 +4827,39 @@ class AjaxModel extends ListModel
// start building the subform field XML
$subformXML = new \SimpleXMLElement('
SuccessMessage)): ?>
@@ -258,7 +330,8 @@ function JRouter(link) {
?>
return url+link;
}
-
+
+
diff --git a/admin/tmpl/compiler/default_nocomponentstocompile.php b/admin/tmpl/compiler/default_nocomponentstocompile.php
new file mode 100644
index 000000000..004adf02b
--- /dev/null
+++ b/admin/tmpl/compiler/default_nocomponentstocompile.php
@@ -0,0 +1,42 @@
+
+ * @git Joomla Component Builder
+ * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+use Joomla\CMS\Language\Text;
+use Joomla\CMS\Router\Route;
+use Joomla\CMS\Layout\LayoutHelper;
+use Joomla\CMS\HTML\HTMLHelper as Html;
+
+// No direct access to this file
+defined('_JEXEC') or die;
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $this->dankie]); ?>
+
+
diff --git a/admin/tmpl/componentbuilder/default_notice_board_vast_development_method.php b/admin/tmpl/componentbuilder/default_notice_board_vast_development_method.php
index a8ea495d6..a5289faf6 100644
--- a/admin/tmpl/componentbuilder/default_notice_board_vast_development_method.php
+++ b/admin/tmpl/componentbuilder/default_notice_board_vast_development_method.php
@@ -11,8 +11,8 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
-use Joomla\CMS\HTML\HTMLHelper as Html;
use Joomla\CMS\Layout\LayoutHelper;
+use Joomla\CMS\HTML\HTMLHelper as Html;
// No direct access to this file
defined('_JEXEC') or die;
diff --git a/admin/tmpl/componentbuilder/default_readme_information.php b/admin/tmpl/componentbuilder/default_readme_information.php
index 2bad44b97..1d29e8c43 100644
--- a/admin/tmpl/componentbuilder/default_readme_information.php
+++ b/admin/tmpl/componentbuilder/default_readme_information.php
@@ -11,6 +11,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
+use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\HTML\HTMLHelper as Html;
// No direct access to this file
diff --git a/admin/tmpl/componentbuilder/default_wiki_tutorials.php b/admin/tmpl/componentbuilder/default_wiki_tutorials.php
index bf41cd55e..2dfec6090 100644
--- a/admin/tmpl/componentbuilder/default_wiki_tutorials.php
+++ b/admin/tmpl/componentbuilder/default_wiki_tutorials.php
@@ -11,6 +11,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
+use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\HTML\HTMLHelper as Html;
// No direct access to this file
diff --git a/admin/tmpl/custom_admin_view/default.php b/admin/tmpl/custom_admin_view/default.php
index 3a8b7b182..5dd697408 100644
--- a/admin/tmpl/custom_admin_view/default.php
+++ b/admin/tmpl/custom_admin_view/default.php
@@ -370,19 +370,38 @@ var select_a_snippet = '';
-HTMLElement.prototype.selText = function() {
- var obj = this;
+/**
+ * Select all text content within an HTMLElement.
+ *
+ * Adds a convenient `selText()` method to all HTMLElements.
+ * Works across modern browsers and gracefully handles errors.
+ *
+ * @return {HTMLElement} Returns the element itself for chaining.
+ * @since 5.1.3
+ */
+HTMLElement.prototype.selText = function () {
+ try {
+ const selection = window.getSelection();
+ if (!selection) {
+ console.warn('selText: window.getSelection() not supported in this environment.');
+ return this;
+ }
- // For modern browsers, handle the selection
- var selection = window.getSelection();
- var range = document.createRange();
+ const range = document.createRange();
+ range.selectNodeContents(this);
- // Select the content of the element
- range.selectNodeContents(obj);
- selection.removeAllRanges(); // Clear any previous selections
- selection.addRange(range); // Add the new selection range
+ selection.removeAllRanges(); // clear any prior selections
+ selection.addRange(range); // select the element's text content
- return this;
+ // Optionally bring the element into view if it's outside viewport
+ if (typeof this.scrollIntoView === 'function') {
+ this.scrollIntoView({ behavior: 'smooth', block: 'center' });
+ }
+ } catch (error) {
+ console.error('selText failed:', error);
+ }
+
+ return this;
};
document.addEventListener("DOMContentLoaded", function() {
diff --git a/admin/tmpl/field/default.php b/admin/tmpl/field/default.php
index 614f8f921..6f01ced6a 100644
--- a/admin/tmpl/field/default.php
+++ b/admin/tmpl/field/default.php
@@ -308,19 +308,38 @@ jQuery('#adminForm').on('change', '#jform_fieldtype',function (e) {
});
-HTMLElement.prototype.selText = function() {
- var obj = this;
+/**
+ * Select all text content within an HTMLElement.
+ *
+ * Adds a convenient `selText()` method to all HTMLElements.
+ * Works across modern browsers and gracefully handles errors.
+ *
+ * @return {HTMLElement} Returns the element itself for chaining.
+ * @since 5.1.3
+ */
+HTMLElement.prototype.selText = function () {
+ try {
+ const selection = window.getSelection();
+ if (!selection) {
+ console.warn('selText: window.getSelection() not supported in this environment.');
+ return this;
+ }
- // For modern browsers, handle the selection
- var selection = window.getSelection();
- var range = document.createRange();
+ const range = document.createRange();
+ range.selectNodeContents(this);
- // Select the content of the element
- range.selectNodeContents(obj);
- selection.removeAllRanges(); // Clear any previous selections
- selection.addRange(range); // Add the new selection range
+ selection.removeAllRanges(); // clear any prior selections
+ selection.addRange(range); // select the element's text content
- return this;
+ // Optionally bring the element into view if it's outside viewport
+ if (typeof this.scrollIntoView === 'function') {
+ this.scrollIntoView({ behavior: 'smooth', block: 'center' });
+ }
+ } catch (error) {
+ console.error('selText failed:', error);
+ }
+
+ return this;
};
';
-HTMLElement.prototype.selText = function() {
- var obj = this;
+/**
+ * Select all text content within an HTMLElement.
+ *
+ * Adds a convenient `selText()` method to all HTMLElements.
+ * Works across modern browsers and gracefully handles errors.
+ *
+ * @return {HTMLElement} Returns the element itself for chaining.
+ * @since 5.1.3
+ */
+HTMLElement.prototype.selText = function () {
+ try {
+ const selection = window.getSelection();
+ if (!selection) {
+ console.warn('selText: window.getSelection() not supported in this environment.');
+ return this;
+ }
- // For modern browsers, handle the selection
- var selection = window.getSelection();
- var range = document.createRange();
+ const range = document.createRange();
+ range.selectNodeContents(this);
- // Select the content of the element
- range.selectNodeContents(obj);
- selection.removeAllRanges(); // Clear any previous selections
- selection.addRange(range); // Add the new selection range
+ selection.removeAllRanges(); // clear any prior selections
+ selection.addRange(range); // select the element's text content
- return this;
+ // Optionally bring the element into view if it's outside viewport
+ if (typeof this.scrollIntoView === 'function') {
+ this.scrollIntoView({ behavior: 'smooth', block: 'center' });
+ }
+ } catch (error) {
+ console.error('selText failed:', error);
+ }
+
+ return this;
};
';
var create_a_snippet = '';
-HTMLElement.prototype.selText = function() {
- var obj = this;
+/**
+ * Select all text content within an HTMLElement.
+ *
+ * Adds a convenient `selText()` method to all HTMLElements.
+ * Works across modern browsers and gracefully handles errors.
+ *
+ * @return {HTMLElement} Returns the element itself for chaining.
+ * @since 5.1.3
+ */
+HTMLElement.prototype.selText = function () {
+ try {
+ const selection = window.getSelection();
+ if (!selection) {
+ console.warn('selText: window.getSelection() not supported in this environment.');
+ return this;
+ }
- // For modern browsers, handle the selection
- var selection = window.getSelection();
- var range = document.createRange();
+ const range = document.createRange();
+ range.selectNodeContents(this);
- // Select the content of the element
- range.selectNodeContents(obj);
- selection.removeAllRanges(); // Clear any previous selections
- selection.addRange(range); // Add the new selection range
+ selection.removeAllRanges(); // clear any prior selections
+ selection.addRange(range); // select the element's text content
- return this;
+ // Optionally bring the element into view if it's outside viewport
+ if (typeof this.scrollIntoView === 'function') {
+ this.scrollIntoView({ behavior: 'smooth', block: 'center' });
+ }
+ } catch (error) {
+ console.error('selText failed:', error);
+ }
+
+ return this;
};
saveOrder)