Hi there,

i've created an subtheme by using method 1 from the "subtheming how to".
I have included all js files from 'my_theme/bootstrap/' instead of using cdn, compiled the less-file.

Now there's an JS Error all the times, because of bootstrap/js/bootstrap.js is included all the time from themes/bootstrap/theme/alter.inc:

TypeError: $(...).find(...).once is not a function

I have to exclude this file in my own .info-file to get rid of the error:

exclude[js][] = 'sites/all/themes/bootstrap/js/bootstrap.js'

I've edited the howto, but please confirm this is really needed.

Comments

stephen.punwasi’s picture

Isn't this a very specific case scenario? If you're not using the bootstrap.js, you might as well just add the bootstrap.css to another theme.

You could also just comment it out of the .info file with a ";"

stephen.punwasi’s picture

Category: Task » Feature request
jehu’s picture

hm, i think if i include the bootstrap-files manually like in method 1 described, then the bootstrap.js is not needed. Why do you mean method 1 from howto is a specific scenario?
I don't want to use CDN, so i have to provide the files in my subtheme (so it's written in the how to).
that's the case, where i have to exclude bootstrap.js from the base theme, don't you think so?

andregriffin’s picture

The bootstrap_subtheme.info.starterkit (should be renamed to bootstrap_subtheme.info) already has the js declared under the section of "Method 1". You just have to take off one semicolin from each line so that your "Method 1" looks like this.

;;;;;;;;;;;;;;;;;;;;;
;; Scripts
;;;;;;;;;;;;;;;;;;;;;

scripts[] = 'bootstrap/js/affix.js'
scripts[] = 'bootstrap/js/alert.js'
scripts[] = 'bootstrap/js/button.js'
scripts[] = 'bootstrap/js/carousel.js'
scripts[] = 'bootstrap/js/collapse.js'
scripts[] = 'bootstrap/js/dropdown.js'
scripts[] = 'bootstrap/js/modal.js'
scripts[] = 'bootstrap/js/tooltip.js'
scripts[] = 'bootstrap/js/popover.js'
scripts[] = 'bootstrap/js/scrollspy.js'
scripts[] = 'bootstrap/js/tab.js'
scripts[] = 'bootstrap/js/transition.js'
; Disable BootstrapCDN if using Bootstrap source files in your sub-theme.
settings[bootstrap_cdn] = ''

When you turn on js aggregation, these files become equivalent to bootstrap.js. But here, you can comment out individual js features that you may not need.

jehu’s picture

Yes, this is extactly the case where we have to exclude bootstrap.js from base theme, i think.

krystalcode’s picture

Hi,

It doesn't look like this is the case, the file in the base theme sites/all/themes/bootstrap/js/bootstrap.js says:

"Provides general enhancements and fixes to Bootstrap's JS files."

It is not a file that belongs to the bootstrap library but it is a Drupal specific file from the boostrap module. It therefore is not the same with what you get from aggregating the sites/all/themes/bootstrap_subtheme/bootstrap/* files as these files are the original bootstrap library that has nothing to do with bootstrap.

markhalliwell’s picture

Title: js/bootstrap.js should not be included all the time » Ensure jquery.once library is loaded when theme's bootstrap.js file is loaded
Version: 7.x-3.0 » 7.x-3.x-dev
Category: Feature request » Bug report

@dimboz in #6 is correct. This is an enhancement JS file for Bootstrap -> Drupal integration. You're receiving this error because it sounds like the jquery.once library isn't loaded (for whatever reason). We'll likely need to patch the JS alter. Also it probably wouldn't hurt to rename the bootstrap.js file to drupal.bootstrap.js or something for clarity here.

markhalliwell’s picture

Status: Active » Fixed

Committed d0b92f9 to 7.x-3.x:

Issue #2149561 by Mark Carver | Jehu: Ensure jquery.once library is loaded when theme's bootstrap.js file is loaded.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

  • Commit d0b92f9 on 7.x-3.x, 8.x-3.x by Mark Carver:
    Issue #2149561 by Mark Carver | Jehu: Ensure jquery.once library is...
ryan.armstrong’s picture

Version: 7.x-3.x-dev » 8.x-3.x-dev
Assigned: Unassigned » ryan.armstrong
Status: Closed (fixed) » Needs review

Moving this to the 8.x-3.x branch as it has been committed to that branch. Making sure the fix gets tested in the Drupal 8 release.

  • Mark Carver committed d0b92f9 on 8.x-3.x.x
    Issue #2149561 by Mark Carver | Jehu: Ensure jquery.once library is...
markhalliwell’s picture

Version: 8.x-3.x-dev » 7.x-3.x-dev
Assigned: ryan.armstrong » Unassigned
Status: Needs review » Closed (fixed)

I'm just moving this back to 7.x. If this needs re-evaluation in 8.x, create a new issue.

bennyzen’s picture

While moving the call for scripts-inclusion out of head in html.tpl.php, bootstrap.js is included too early, causing a JS error. I've been trying to patch bootstrap_js_alter in alter.inc, since this seems the culprit for this misbehavior, but miserably failing at it. Maybe someone can point me into the right direction to avoid the inclusion from happening too early.

bennyzen’s picture

ok, i found a solution for you guys using method 1: you do not really need the inclusion of bootstrap.js, like mentioned before by others. so i patched bootstrap_js_alter(), simply disabling the inclusion of bootstrap.js. Everything works great now.

gisle’s picture

Title: Ensure jquery.once library is loaded when theme's bootstrap.js file is loaded » The theme's bootstrap.js file should not be included if the "less" starterkit is used
Status: Closed (fixed) » Needs work

This just bit me when using the latest snapshot of 7.x-3.x to create a sub-theme of Bootstrap, so it does not look like it has been fixed.

I am using the "less" starter kit (previously known as "method 1").

It looks like jquery.once.js is loaded on my site:

<script src="http://.../misc/jquery.once.js?v=1.2">

but that does not seem to be enough - so I am changing the title.

Patching bootstrap_js_alter() to not include bootstrap.js (as suggested in #15) fixed it for me.

I also think the Drupal theme's bootstrap.js should be renamed drupal.bootstrap.js (as suggested in #7) for clarity. It is awkward for debugging that it has the same file name as the main bootstrap library.

markhalliwell’s picture

Title: The theme's bootstrap.js file should not be included if the "less" starterkit is used » Ensure jquery.once library is loaded when theme's bootstrap.js file is loaded
Status: Needs work » Closed (fixed)

@gisle, please create a new issue and reference closed ones. Hi-jacking existing closed issues makes it difficult to track when something has already been committed.

basvredeling’s picture

The += operator doesn't work reliably on all configurations. The attached patch proposes using array_replace() instead. If there are other users running into the following error, let's reopen this and rework the committed patch.

PHP Fatal error: Unsupported operand types in /sites/all/themes/bootstrap/includes/alter.inc on line 330

schiavone’s picture

Similar issue with Bootstrap 7.x-3.6 js errors "TypeError: $context.find(...).once is not a function" causing other js not to load. Loading jquery 1.9 with jquery_update (1.9 or higher required). Load order looked fine. Added...

exclude[js][] = 'sites/all/themes/bootstrap/js/misc/_vertical-tabs.js'

to .info file to remove error. A blunt solution until this issue gets sorted.

tamnv’s picture

I have same issue and my solution is exclude bootstrap.js on my custom theme.