Skip to content

Commit

Permalink
Add jQuery version check to existing jQuery presence check
Browse files Browse the repository at this point in the history
Fixes #14809.
Closes #14825.
  • Loading branch information
hnrch02 committed Oct 22, 2014
1 parent 60bb69a commit 4956ee3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
20 changes: 17 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,22 @@ module.exports = function (grunt) {
' * Copyright 2011-<%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' * Licensed under <%= pkg.license.type %> (<%= pkg.license.url %>)\n' +
' */\n',
// NOTE: This jqueryCheck code is duplicated in customizer.js; if making changes here, be sure to update the other copy too.
jqueryCheck: 'if (typeof jQuery === \'undefined\') { throw new Error(\'Bootstrap\\\'s JavaScript requires jQuery\') }\n\n',
// NOTE: This jqueryCheck/jqueryVersionCheck code is duplicated in customizer.js;
// if making changes here, be sure to update the other copy too.
jqueryCheck: [
'if (typeof jQuery === \'undefined\') {',
' throw new Error(\'Bootstrap\\\'s JavaScript requires jQuery\')',
'}\n'
].join('\n'),
jqueryVersionCheck: [
'+function ($) {',
' var versionString = $.fn.jquery.split(\' \')[0]',
' var version = versionString.match(/(\\d+)(?=\\.?)/g)',
' if ((version[0] < 2 && version[1] < 9) || /1\\.9\\.0rc1|1\\.9\\.0b1/.test(versionString)) {',
' throw new Error(\'Bootstrap\\\'s JavaScript requires jQuery version 1.9 or higher\')',
' }',
'}(jQuery);\n\n'
].join('\n'),

// Task configuration.
clean: {
Expand Down Expand Up @@ -93,7 +107,7 @@ module.exports = function (grunt) {

concat: {
options: {
banner: '<%= banner %>\n<%= jqueryCheck %>',
banner: '<%= banner %>\n<%= jqueryCheck %>\n<%= jqueryVersionCheck %>',
stripBanners: false
},
bootstrap: {
Expand Down
17 changes: 15 additions & 2 deletions docs/assets/js/src/customizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,20 @@ window.onload = function () { // wait for load in a dumb way because B-0

function generateJS(preamble) {
var $checked = $('#plugin-section input:checked')
var jqueryCheck = 'if (typeof jQuery === "undefined") { throw new Error("Bootstrap\'s JavaScript requires jQuery") }\n\n'
var jqueryCheck = [
'if (typeof jQuery === \'undefined\') {',
' throw new Error(\'Bootstrap\\\'s JavaScript requires jQuery\')',
'}\n'
].join('\n')
var jqueryVersionCheck = [
'+function ($) {',
' var versionString = $.fn.jquery.split(\' \')[0]',
' var version = versionString.match(/(\\d+)(?=\\.?)/g)',
' if ((version[0] < 2 && version[1] < 9) || /1\\.9\\.0rc1|1\\.9\\.0b1/.test(versionString)) {',
' throw new Error(\'Bootstrap\\\'s JavaScript requires jQuery version 1.9 or higher\')',
' }',
'}(jQuery);\n\n'
].join('\n')

if (!$checked.length) return false

Expand All @@ -329,7 +342,7 @@ window.onload = function () { // wait for load in a dumb way because B-0
.join('\n')

preamble = cw + preamble
js = jqueryCheck + js
js = jqueryCheck + jqueryVersionCheck + js

return {
'bootstrap.js': preamble + js,
Expand Down

0 comments on commit 4956ee3

Please sign in to comment.