Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize tooltips when a new a row is added in a subform #12996

Merged
merged 3 commits into from
Apr 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions libraries/cms/html/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,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 @@ -484,8 +484,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"});
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Quy This right here is what I'm talking about.

// 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