From 45b476bdbff7ac38518deb7898529bb9510f648f Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 1 Mar 2014 18:19:50 +0200 Subject: [PATCH 1/2] JS: remove unused variables. --- docs/assets/js/_src/application.js | 5 +---- docs/assets/js/_src/customizer.js | 5 +++-- grunt/.jshintrc | 3 ++- js/.jshintrc | 1 + js/scrollspy.js | 3 ++- js/tests/unit/affix.js | 6 +++--- js/tests/unit/button.js | 1 - js/tests/unit/collapse.js | 16 ++++++++-------- js/tests/unit/scrollspy.js | 2 +- js/tests/unit/tooltip.js | 20 ++++++++++---------- js/tooltip.js | 1 - 11 files changed, 31 insertions(+), 32 deletions(-) diff --git a/docs/assets/js/_src/application.js b/docs/assets/js/_src/application.js index 678c6eace4..9ebba13fe5 100644 --- a/docs/assets/js/_src/application.js +++ b/docs/assets/js/_src/application.js @@ -31,11 +31,8 @@ var $window = $(window) var $body = $(document.body) - var navHeight = $('.navbar').outerHeight(true) + 10 - $body.scrollspy({ - target: '.bs-docs-sidebar', - // offset: navHeight + target: '.bs-docs-sidebar' }) $window.on('load', function () { diff --git a/docs/assets/js/_src/customizer.js b/docs/assets/js/_src/customizer.js index c2dcba73f4..ac314dc733 100644 --- a/docs/assets/js/_src/customizer.js +++ b/docs/assets/js/_src/customizer.js @@ -231,7 +231,9 @@ window.onload = function () { // wait for load in a dumb way because B-0 paths: ['variables.less', 'mixins.less'], optimization: 0, filename: baseFilename + '.css' - }).parse(lessSource, function (err, tree) { + }) + + parser.parse(lessSource, function (err, tree) { if (err) { return showError('Ruh roh! Could not parse less files.', err) } @@ -331,7 +333,6 @@ window.onload = function () { // wait for load in a dumb way because B-0 }) var $compileBtn = $('#btn-compile') - var $downloadBtn = $('#btn-download') $compileBtn.on('click', function (e) { var configData = getCustomizerData() diff --git a/grunt/.jshintrc b/grunt/.jshintrc index 8d402b53c2..d9dce889b1 100644 --- a/grunt/.jshintrc +++ b/grunt/.jshintrc @@ -6,5 +6,6 @@ "node" : true, "nonbsp": true, "strict": true, - "undef" : true + "undef" : true, + "unused": true } diff --git a/js/.jshintrc b/js/.jshintrc index e1ead322ea..c6104dc931 100644 --- a/js/.jshintrc +++ b/js/.jshintrc @@ -8,5 +8,6 @@ "eqnull" : true, "expr" : true, "laxbreak" : true, + "unused" : true, "validthis": true } diff --git a/js/scrollspy.js b/js/scrollspy.js index 137bd373fc..c77a9fbed7 100644 --- a/js/scrollspy.js +++ b/js/scrollspy.js @@ -43,7 +43,8 @@ this.targets = $([]) var self = this - var $targets = this.$body + + this.$body .find(this.selector) .map(function () { var $el = $(this) diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index b348ecf2b5..673026b8c1 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -28,14 +28,14 @@ $(function () { var template = $('
') template.appendTo('body') - var affixer = $('#affixTarget').affix({ + $('#affixTarget').affix({ offset: $('#affixTarget ul').position() }) $('#affixTarget') - .on('affix.bs.affix', function (e) { + .on('affix.bs.affix', function () { ok(true, 'affix event triggered') - }).on('affixed.bs.affix', function (e) { + }).on('affixed.bs.affix', function () { ok(true,'affixed event triggered') $('#affixTarget').remove() $('#affixAfter').remove() diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 73420863ce..ea12364788 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -98,7 +98,6 @@ $(function () { var btn1 = $(group.children()[0]) var btn2 = $(group.children()[1]) - var btn3 = $(group.children()[2]) group.appendTo($('#qunit-fixture')) diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index 7948b3ab49..bead36f91d 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -64,7 +64,7 @@ $(function () { var target = $('') .appendTo($('#qunit-fixture')) - var collapsible = $('
') + $('
') .appendTo($('#qunit-fixture')) .on('show.bs.collapse', function () { ok(!target.hasClass('collapsed')) @@ -81,7 +81,7 @@ $(function () { var target = $('') .appendTo($('#qunit-fixture')) - var collapsible = $('
') + $('
') .appendTo($('#qunit-fixture')) .on('hide.bs.collapse', function () { ok(target.hasClass('collapsed')) @@ -101,19 +101,19 @@ $(function () { var target1 = $('') .appendTo(accordion.find('.accordion-group').eq(0)) - var collapsible1 = $('
') + $('
') .appendTo(accordion.find('.accordion-group').eq(0)) var target2 = $('') .appendTo(accordion.find('.accordion-group').eq(1)) - var collapsible2 = $('
') + $('
') .appendTo(accordion.find('.accordion-group').eq(1)) var target3 = $('') .appendTo(accordion.find('.accordion-group').eq(2)) - var collapsible3 = $('
') + $('
') .appendTo(accordion.find('.accordion-group').eq(2)) .on('show.bs.collapse', function () { ok(target1.hasClass('collapsed')) @@ -136,19 +136,19 @@ $(function () { var target1 = $('') .appendTo(accordion.find('.accordion-group').eq(0)) - var collapsible1 = $('
') + $('
') .appendTo(accordion.find('.accordion-group').eq(0)) var target2 = $('') .appendTo(accordion.find('.accordion-group').eq(1)) - var collapsible2 = $('
') + $('
') .appendTo(accordion.find('.accordion-group').eq(1)) var target3 = $('') .appendTo(accordion.find('.accordion-group').eq(2)) - var collapsible3 = $('
') + $('
') .appendTo(accordion.find('.accordion-group').eq(2)) .on('show.bs.collapse', function () { ok(target1.hasClass('collapsed')) diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index d91b6b3131..670735a468 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -18,7 +18,6 @@ $(function () { test('should switch active class on scroll', function () { var sectionHTML = '
', - $section = $(sectionHTML).append('#qunit-fixture'), topbarHTML = '
' + '
' + '
' + @@ -30,6 +29,7 @@ $(function () { '
', $topbar = $(topbarHTML).scrollspy() + $(sectionHTML).append('#qunit-fixture') ok($topbar.find('.active', true)) }) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index e670883e35..e6ae119930 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -68,7 +68,7 @@ $(function () { test('should fire show event', function () { stop() - var tooltip = $('
') + $('
') .on('show.bs.tooltip', function () { ok(true, 'show was called') start() @@ -78,7 +78,7 @@ $(function () { test('should fire shown event', function () { stop() - var tooltip = $('
') + $('
') .on('shown.bs.tooltip', function () { ok(true, 'shown was called') start() @@ -88,7 +88,7 @@ $(function () { test('should not fire shown event when default prevented', function () { stop() - var tooltip = $('
') + $('
') .on('show.bs.tooltip', function (e) { e.preventDefault() ok(true, 'show was called') @@ -102,7 +102,7 @@ $(function () { test('should fire hide event', function () { stop() - var tooltip = $('
') + $('
') .on('shown.bs.tooltip', function () { $(this).tooltip('hide') }) @@ -115,7 +115,7 @@ $(function () { test('should fire hidden event', function () { stop() - var tooltip = $('
') + $('
') .on('shown.bs.tooltip', function () { $(this).tooltip('hide') }) @@ -128,7 +128,7 @@ $(function () { test('should not fire hidden event when default prevented', function () { stop() - var tooltip = $('
') + $('
') .on('shown.bs.tooltip', function () { $(this).tooltip('hide') }) @@ -272,14 +272,14 @@ $(function () { test('should show tooltip with delegate selector on click', function () { var div = $('
') - var tooltip = div.appendTo('#qunit-fixture') + div.appendTo('#qunit-fixture') .tooltip({ selector: 'a[rel=tooltip]', trigger: 'click' }) div.find('a').trigger('click') ok($('.tooltip').is('.fade.in'), 'tooltip is faded in') }) test('should show tooltip when toggle is called', function () { - var tooltip = $('') + $('') .appendTo('#qunit-fixture') .tooltip({trigger: 'manual'}) .tooltip('toggle') @@ -298,8 +298,8 @@ $(function () { test('should place tooltip inside window', function () { var container = $('
').appendTo('body') - .css({position: 'absolute', width: 200, height: 200, bottom: 0, left: 0}), - tooltip = $('Hover me') + .css({position: 'absolute', width: 200, height: 200, bottom: 0, left: 0}) + $('Hover me') .css({position: 'absolute', top: 0, left: 0}) .appendTo(container) .tooltip({placement: 'top', animate: false}) diff --git a/js/tooltip.js b/js/tooltip.js index f27beacc6d..bb47d43365 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -195,7 +195,6 @@ } Tooltip.prototype.applyPlacement = function (offset, placement) { - var replace var $tip = this.tip() var width = $tip[0].offsetWidth var height = $tip[0].offsetHeight From 2f0f8ec6d13129cad43e710a3886e59214367c89 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 8 Mar 2014 09:10:35 +0200 Subject: [PATCH 2/2] Run `grunt dist`. --- dist/js/bootstrap.js | 4 ++-- dist/js/bootstrap.min.js | 2 +- docs/assets/js/customize.min.js | 2 +- docs/assets/js/docs.min.js | 2 +- docs/dist/js/bootstrap.min.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/js/bootstrap.js b/dist/js/bootstrap.js index d85a7514c0..0cc5c8ca61 100644 --- a/dist/js/bootstrap.js +++ b/dist/js/bootstrap.js @@ -1243,7 +1243,6 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re } Tooltip.prototype.applyPlacement = function (offset, placement) { - var replace var $tip = this.tip() var width = $tip[0].offsetWidth var height = $tip[0].offsetHeight @@ -1626,7 +1625,8 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re this.targets = $([]) var self = this - var $targets = this.$body + + this.$body .find(this.selector) .map(function () { var $el = $(this) diff --git a/dist/js/bootstrap.min.js b/dist/js/bootstrap.min.js index 705bb5e642..dbd6a9e3de 100644 --- a/dist/js/bootstrap.min.js +++ b/dist/js/bootstrap.min.js @@ -3,4 +3,4 @@ * Copyright 2011-2014 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) */ -if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one(a.support.transition.end,function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b()})}(jQuery),+function(a){"use strict";var b='[data-dismiss="alert"]',c=function(c){a(c).on("click",b,this.close)};c.prototype.close=function(b){function c(){f.trigger("closed.bs.alert").remove()}var d=a(this),e=d.attr("data-target");e||(e=d.attr("href"),e=e&&e.replace(/.*(?=#[^\s]*$)/,""));var f=a(e);b&&b.preventDefault(),f.length||(f=d.hasClass("alert")?d:d.parent()),f.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(f.removeClass("in"),a.support.transition&&f.hasClass("fade")?f.one(a.support.transition.end,c).emulateTransitionEnd(150):c())};var d=a.fn.alert;a.fn.alert=function(b){return this.each(function(){var d=a(this),e=d.data("bs.alert");e||d.data("bs.alert",e=new c(this)),"string"==typeof b&&e[b].call(d)})},a.fn.alert.Constructor=c,a.fn.alert.noConflict=function(){return a.fn.alert=d,this},a(document).on("click.bs.alert.data-api",b,c.prototype.close)}(jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d),this.isLoading=!1};b.DEFAULTS={loadingText:"loading..."},b.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",f.resetText||d.data("resetText",d[e]()),d[e](f[b]||this.options[b]),setTimeout(a.proxy(function(){"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c))},this),0)},b.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")&&(c.prop("checked")&&this.$element.hasClass("active")?a=!1:b.find(".active").removeClass("active")),a&&c.prop("checked",!this.$element.hasClass("active")).trigger("change")}a&&this.$element.toggleClass("active")};var c=a.fn.button;a.fn.button=function(c){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof c&&c;e||d.data("bs.button",e=new b(this,f)),"toggle"==c?e.toggle():c&&e.setState(c)})},a.fn.button.Constructor=b,a.fn.button.noConflict=function(){return a.fn.button=c,this},a(document).on("click.bs.button.data-api","[data-toggle^=button]",function(b){var c=a(b.target);c.hasClass("btn")||(c=c.closest(".btn")),c.button("toggle"),b.preventDefault()})}(jQuery),+function(a){"use strict";var b=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=this.sliding=this.interval=this.$active=this.$items=null,"hover"==this.options.pause&&this.$element.on("mouseenter",a.proxy(this.pause,this)).on("mouseleave",a.proxy(this.cycle,this))};b.DEFAULTS={interval:5e3,pause:"hover",wrap:!0},b.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},b.prototype.getActiveIndex=function(){return this.$active=this.$element.find(".item.active"),this.$items=this.$active.parent().children(".item"),this.$items.index(this.$active)},b.prototype.to=function(b){var c=this,d=this.getActiveIndex();return b>this.$items.length-1||0>b?void 0:this.sliding?this.$element.one("slid.bs.carousel",function(){c.to(b)}):d==b?this.pause().cycle():this.slide(b>d?"next":"prev",a(this.$items[b]))},b.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},b.prototype.next=function(){return this.sliding?void 0:this.slide("next")},b.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},b.prototype.slide=function(b,c){var d=this.$element.find(".item.active"),e=c||d[b](),f=this.interval,g="next"==b?"left":"right",h="next"==b?"first":"last",i=this;if(!e.length){if(!this.options.wrap)return;e=this.$element.find(".item")[h]()}if(e.hasClass("active"))return this.sliding=!1;var j=a.Event("slide.bs.carousel",{relatedTarget:e[0],direction:g});return this.$element.trigger(j),j.isDefaultPrevented()?void 0:(this.sliding=!0,f&&this.pause(),this.$indicators.length&&(this.$indicators.find(".active").removeClass("active"),this.$element.one("slid.bs.carousel",function(){var b=a(i.$indicators.children()[i.getActiveIndex()]);b&&b.addClass("active")})),a.support.transition&&this.$element.hasClass("slide")?(e.addClass(b),e[0].offsetWidth,d.addClass(g),e.addClass(g),d.one(a.support.transition.end,function(){e.removeClass([b,g].join(" ")).addClass("active"),d.removeClass(["active",g].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger("slid.bs.carousel")},0)}).emulateTransitionEnd(1e3*d.css("transition-duration").slice(0,-1))):(d.removeClass("active"),e.addClass("active"),this.sliding=!1,this.$element.trigger("slid.bs.carousel")),f&&this.cycle(),this)};var c=a.fn.carousel;a.fn.carousel=function(c){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c),g="string"==typeof c?c:f.slide;e||d.data("bs.carousel",e=new b(this,f)),"number"==typeof c?e.to(c):g?e[g]():f.interval&&e.pause().cycle()})},a.fn.carousel.Constructor=b,a.fn.carousel.noConflict=function(){return a.fn.carousel=c,this},a(document).on("click.bs.carousel.data-api","[data-slide], [data-slide-to]",function(b){var c,d=a(this),e=a(d.attr("data-target")||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"")),f=a.extend({},e.data(),d.data()),g=d.attr("data-slide-to");g&&(f.interval=!1),e.carousel(f),(g=d.attr("data-slide-to"))&&e.data("bs.carousel").to(g),b.preventDefault()}),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var b=a(this);b.carousel(b.data())})})}(jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d),this.transitioning=null,this.options.parent&&(this.$parent=a(this.options.parent)),this.options.toggle&&this.toggle()};b.DEFAULTS={toggle:!0},b.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},b.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b=a.Event("show.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.$parent&&this.$parent.find("> .panel > .in");if(c&&c.length){var d=c.data("bs.collapse");if(d&&d.transitioning)return;c.collapse("hide"),d||c.data("bs.collapse",null)}var e=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[e](0),this.transitioning=1;var f=function(a){a&&a.target!=this.$element[0]||(this.$element.removeClass("collapsing").addClass("collapse in")[e]("auto"),this.transitioning=0,this.$element.trigger("shown.bs.collapse"))};if(!a.support.transition)return f.call(this);var g=a.camelCase(["scroll",e].join("-"));this.$element.one(a.support.transition.end,a.proxy(f,this)).emulateTransitionEnd(350)[e](this.$element[0][g])}}},b.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse").removeClass("in"),this.transitioning=1;var d=function(a){a&&a.target!=this.$element[0]||(this.transitioning=0,this.$element.trigger("hidden.bs.collapse").removeClass("collapsing").addClass("collapse"))};return a.support.transition?void this.$element[c](0).one(a.support.transition.end,a.proxy(d,this)).emulateTransitionEnd(350):d.call(this)}}},b.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()};var c=a.fn.collapse;a.fn.collapse=function(c){return this.each(function(){var d=a(this),e=d.data("bs.collapse"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c);!e&&f.toggle&&"show"==c&&(c=!c),e||d.data("bs.collapse",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.collapse.Constructor=b,a.fn.collapse.noConflict=function(){return a.fn.collapse=c,this},a(document).on("click.bs.collapse.data-api",'[data-toggle="collapse"]',function(b){var c,d=a(this),e=d.attr("data-target")||b.preventDefault()||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,""),f=a(e),g=f.data("bs.collapse"),h=g?"toggle":d.data(),i=d.attr("data-parent"),j=i&&a(i);g&&g.transitioning||(j&&j.find('[data-toggle="collapse"][data-parent="'+i+'"]').not(d).addClass("collapsed"),d[f.hasClass("in")?"addClass":"removeClass"]("collapsed")),f.collapse(h)})}(jQuery),+function(a){"use strict";function b(b){a(d).remove(),a(e).each(function(){var d=c(a(this)),e={relatedTarget:this};d.hasClass("open")&&(d.trigger(b=a.Event("hide.bs.dropdown",e)),b.isDefaultPrevented()||d.removeClass("open").trigger("hidden.bs.dropdown",e))})}function c(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}var d=".dropdown-backdrop",e='[data-toggle="dropdown"]',f=function(b){a(b).on("click.bs.dropdown",this.toggle)};f.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=c(e),g=f.hasClass("open");if(b(),!g){"ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a('