Reputation: 5023
Working with Joomla 30 which has Mootools, jQuery and Twitter Bootstrap but each can be turned off.
I need to check if bootstrap is present.
For moo and jq we can do
if (typeof jQuery != 'undefined') {
// do stuff
}
But how do we check if Bootstrap is present? And how do we check it with mootools or pure js no libs?
Upvotes: 2
Views: 1208
Reputation: 5023
I think I fund a solution if anyone has better one please advise
this is within mootools domready
if((typeof jQuery == 'function' && typeof jQuery.fn.popover == 'undefined') || (typeof jQuery == 'undefined')){
// BS is not here
}
we can check for other bootstrap function like
jQuery.fn.tooltip
, like said this is particular to Joomla 3.0 version of bootstrap since all its plugins are in 1 min file ,
Upvotes: 0
Reputation: 973
Can you edit your body-tag? Then you could add a data-attribute like data-bootstrap="1"
and check if it is present, or even change the value to 0
if needed.
Upvotes: 0
Reputation: 507
This will be quite a bit harder with Bootstrap (than, say, checking for jQuery) because bootstrap doesn't leak a definitive variable into the global namespace. What you could do is to (a) first check for jQuery (as bootstrap seems to depend on it) and then either:
a) iterate over $("link") to check for attr("href").indexOf("/bootstrap.")>=0 and/or iterate over *$("script") to check attr("src").indexOf("/bootstrap.")>=0. Now this is of course a very non-scientific way to check for this. (Note: this check uses jQuery, but this should be ok as per the jQuery-dependency of bootstrap)
b) Another - maybe more scientific - idea would be to check for the presence of individual features. Say, check for ($.fn.modal && $.fn.affix && $.fn.typeahead && ...). This might yield false positives (if the developer uses other plugins with the same names) or even false negatives if the developer has used a custom combination of bootstrap features.
Another option would be to check for typical CSS classes like ".form-horizontal" and ".pre-scrollable" by assigning them to a temporary element and programmatically checking their runtime style. But this might be a bit harder and could also result in false positives/negatives if a developer has customized the styles.
So I guess there is no simple answer ...
Upvotes: 2