Skip to content

Commit

Permalink
Initialize tooltips when a new a row is added in a subform (#12996)
Browse files Browse the repository at this point in the history
* Initialize tooltips when a new a row is added in a subform

* Fix a test since the init function has changed

* Replace htaccess which was removed inexplicably
  • Loading branch information
okonomiyaki3000 authored and Michael Babker committed Apr 29, 2018
1 parent a6e20f9 commit 9780ed3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
10 changes: 8 additions & 2 deletions libraries/cms/html/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public static function tooltip($selector = '.hasTooltip', $params = array())
$options = JHtml::getJSObject($opt);

// Build the script.
$script = array('$(' . json_encode($selector) . ').tooltip(' . $options . ')');
$script = array('$(container).find(' . json_encode($selector) . ').tooltip(' . $options . ')');

if ($onShow)
{
Expand All @@ -488,8 +488,14 @@ public static function tooltip($selector = '.hasTooltip', $params = array())
$script[] = 'on("hidden.bs.tooltip", ' . $onHidden . ')';
}

$initFunction = 'function initTooltips (event, container) { ' .
'container = container || document;' .
implode('.', $script) . ';' .
'}';

// Attach tooltips to document
JFactory::getDocument()->addScriptDeclaration('jQuery(function($){ ' . implode('.', $script) . '; });');
JFactory::getDocument()
->addScriptDeclaration('jQuery(function($){ initTooltips(); $("body").on("subform-row-add", initTooltips); ' . $initFunction . ' });');

// Set static array
static::$loaded[__METHOD__][$selector] = true;
Expand Down
5 changes: 0 additions & 5 deletions media/system/js/subform-repeatable-uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,6 @@
$row.find('.field-media-wrapper').fieldMedia();
}

// bootstrap tooltips
if($.fn.tooltip){
$row.find('.hasTooltip').tooltip({html: true, container: "body"});
}

// bootstrap based User field
if($.fn.fieldUser){
$row.find('.field-user-wrapper').fieldUser();
Expand Down
3 changes: 2 additions & 1 deletion media/system/js/subform-repeatable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/unit/suites/libraries/cms/html/JHtmlBootstrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ public function testTooltip()
'Verify that the alert method initialises Bootstrap as well'
);

$this->assertEquals(
$this->assertContains(
'jQuery(function($){ initTooltips();',
$document->_script['text/javascript'],
'jQuery(function($){ $(".hasTooltip").tooltip({"html": true,"container": "body"}); });',
'Verify that the tooltip script is initialised'
);
}
Expand Down

0 comments on commit 9780ed3

Please sign in to comment.