diff --git a/libraries/cms/html/bootstrap.php b/libraries/cms/html/bootstrap.php index 8cae47d06c000..cf7a006919089 100644 --- a/libraries/cms/html/bootstrap.php +++ b/libraries/cms/html/bootstrap.php @@ -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) { @@ -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; diff --git a/media/system/js/subform-repeatable-uncompressed.js b/media/system/js/subform-repeatable-uncompressed.js index 28ba80a770667..1db67997ba525 100644 --- a/media/system/js/subform-repeatable-uncompressed.js +++ b/media/system/js/subform-repeatable-uncompressed.js @@ -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(); diff --git a/media/system/js/subform-repeatable.js b/media/system/js/subform-repeatable.js index 5410427d14ac1..3890ea678c921 100644 --- a/media/system/js/subform-repeatable.js +++ b/media/system/js/subform-repeatable.js @@ -1 +1,2 @@ -(function($){"use strict";$.subformRepeatable=function(container,options){this.$container=$(container);if(this.$container.data("subformRepeatable")){return self}this.$container.data("subformRepeatable",self);this.options=$.extend({},$.subformRepeatable.defaults,options);this.template="";this.prepareTemplate();this.$containerRows=this.options.rowsContainer?this.$container.find(this.options.rowsContainer):this.$container;this.lastRowNum=this.$containerRows.find(this.options.repeatableElement).length;var self=this;this.$container.on("click",this.options.btAdd,function(e){e.preventDefault();var after=$(this).parents(self.options.repeatableElement);if(!after.length){after=null}self.addRow(after)});this.$container.on("click",this.options.btRemove,function(e){e.preventDefault();var $row=$(this).parents(self.options.repeatableElement);self.removeRow($row)});if(this.options.btMove){this.$containerRows.sortable({items:this.options.repeatableElement,handle:this.options.btMove,tolerance:"pointer"})}this.$container.trigger("subform-ready")};$.subformRepeatable.prototype.prepareTemplate=function(){if(this.options.rowTemplateSelector){var tmplElement=this.$container.find(this.options.rowTemplateSelector)[0]||{};this.template=$.trim(tmplElement.text||tmplElement.textContent)}else{var row=this.$container.find(this.options.repeatableElement).get(0),$row=$(row).clone();try{this.clearScripts($row)}catch(e){if(window.console){console.log(e)}}this.template=$row.prop("outerHTML")}};$.subformRepeatable.prototype.addRow=function(after){var count=this.$containerRows.find(this.options.repeatableElement).length;if(count>=this.options.maximum){return null}var row=$.parseHTML(this.template);if(after){$(after).after(row)}else{this.$containerRows.append(row)}var $row=$(row);$row.attr("data-new","true");this.fixUniqueAttributes($row,count);try{this.fixScripts($row)}catch(e){if(window.console){console.log(e)}}this.$container.trigger("subform-row-add",$row);return $row};$.subformRepeatable.prototype.removeRow=function($row){var count=this.$containerRows.find(this.options.repeatableElement).length;if(count<=this.options.minimum){return}this.$container.trigger("subform-row-remove",$row);$row.remove()};$.subformRepeatable.prototype.fixUniqueAttributes=function($row,count){this.lastRowNum++;var group=$row.attr("data-group"),basename=$row.attr("data-base-name"),count=count||0,countnew=Math.max(this.lastRowNum,count+1),groupnew=basename+countnew;this.lastRowNum=countnew;$row.attr("data-group",groupnew);var haveName=$row.find("[name]"),ids={};for(var i=0,l=haveName.length;i=this.options.maximum)return null;var o=e.parseHTML(this.template);t?e(t).after(o):this.$containerRows.append(o);var r=e(o);r.attr("data-new","true"),this.fixUniqueAttributes(r,a);try{this.fixScripts(r)}catch(e){window.console&&console.log(e)}return this.$container.trigger("subform-row-add",r),r},e.subformRepeatable.prototype.removeRow=function(e){this.$containerRows.find(this.options.repeatableElement).length<=this.options.minimum||(this.$container.trigger("subform-row-remove",e),e.remove())},e.subformRepeatable.prototype.fixUniqueAttributes=function(t,a){this.lastRowNum++;var o=t.attr("data-group"),r=t.attr("data-base-name"),i=(a=a||0,Math.max(this.lastRowNum,a+1)),n=r+i;this.lastRowNum=i,t.attr("data-group",n);for(var s=t.find("[name]"),l={},p=0,f=s.length;passertEquals( + $this->assertContains( + 'jQuery(function($){ initTooltips();', $document->_script['text/javascript'], - 'jQuery(function($){ $(".hasTooltip").tooltip({"html": true,"container": "body"}); });', 'Verify that the tooltip script is initialised' ); }