Skip to content

Commit

Permalink
Added grunt-jscs and updated style to match
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Karg committed Oct 3, 2014
1 parent 02bc9e2 commit a94c947
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"immed": true,
"noarg": true,
"onevar": false,
"quotmark": "single",
"quotmark": "double",
"smarttabs": true,
"trailing": true,
"unused": true,
Expand Down
25 changes: 17 additions & 8 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = function (grunt) {
module.exports = function(grunt) {
"use strict";

grunt.initConfig({

Expand All @@ -20,17 +21,25 @@ module.exports = function (grunt) {
// Concat definitions
concat: {
js: {
src: ["src/jquery.bootstrap-autohidingnavbar.js"],
src: [ "src/jquery.bootstrap-autohidingnavbar.js" ],
dest: "dist/jquery.bootstrap-autohidingnavbar.js"
},
options: {
banner: "<%= meta.banner %>"
}
},

// Style checker definitions
jscs: {
src: [ "src/jquery.bootstrap-autohidingnavbar.js" ],
options: {
preset: "jquery"
}
},

// Lint definitions
jshint: {
files: ["src/jquery.bootstrap-autohidingnavbar.js"],
files: [ "src/jquery.bootstrap-autohidingnavbar.js" ],
options: {
jshintrc: ".jshintrc"
}
Expand All @@ -39,21 +48,21 @@ module.exports = function (grunt) {
// Minify definitions
uglify: {
js: {
src: ["dist/jquery.bootstrap-autohidingnavbar.js"],
src: [ "dist/jquery.bootstrap-autohidingnavbar.js" ],
dest: "dist/jquery.bootstrap-autohidingnavbar.min.js"
},
options: {
banner: "<%= meta.banner %>"
}
},

}
});

grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-jscs");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-uglify");

grunt.registerTask("default", ["jshint", "concat", "uglify"]);
grunt.registerTask("travis", ["jshint"]);
grunt.registerTask("default", [ "jshint", "jscs", "concat", "uglify" ]);
grunt.registerTask("travis", [ "jshint", "jscs" ]);

};
53 changes: 27 additions & 26 deletions dist/jquery.bootstrap-autohidingnavbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Made by István Ujj-Mészáros
* Under Apache License v2.0 License
*/
;(function($, window, document, undefined) {
var pluginName = 'autoHidingNavbar',
(function($, window, document, undefined) {
var pluginName = "autoHidingNavbar",
$window = $(window),
$document = $(document),
_scrollThrottleTimer = null,
Expand All @@ -22,7 +22,7 @@
disableAutohide: false,
showOnUpscroll: true,
showOnBottom: true,
hideOffset: 'auto', // "auto" means the navbar height
hideOffset: "auto", // "auto" means the navbar height
animationDuration: 200
};

Expand All @@ -40,22 +40,22 @@
}

var align = {};
if (autoHidingNavbar.element.hasClass('navbar-fixed-top')) {
if (autoHidingNavbar.element.hasClass("navbar-fixed-top")) {
align = {
top: -autoHidingNavbar.element.height()
};
} else if (autoHidingNavbar.element.hasClass('navbar-fixed-bottom')) {
} else if (autoHidingNavbar.element.hasClass("navbar-fixed-bottom")) {
align = {
bottom: -autoHidingNavbar.element.height()
};
}

autoHidingNavbar.element.addClass('navbar-hidden').animate(align, {
autoHidingNavbar.element.addClass("navbar-hidden").animate(align, {
queue: false,
duration: autoHidingNavbar.settings.animationDuration
});

$('.dropdown.open .dropdown-toggle', autoHidingNavbar.element).dropdown('toggle');
$(".dropdown.open .dropdown-toggle", autoHidingNavbar.element).dropdown("toggle");

_visible = false;
}
Expand All @@ -66,17 +66,17 @@
}

var align = {};
if (autoHidingNavbar.element.hasClass('navbar-fixed-top')) {
if (autoHidingNavbar.element.hasClass("navbar-fixed-top")) {
align = {
top: 0
};
} else if (autoHidingNavbar.element.hasClass('navbar-fixed-bottom')) {
} else if (autoHidingNavbar.element.hasClass("navbar-fixed-bottom")) {
align = {
bottom: 0
};
}

autoHidingNavbar.element.removeClass('navbar-hidden').animate(align, {
autoHidingNavbar.element.removeClass("navbar-hidden").animate(align, {
queue: false,
duration: autoHidingNavbar.settings.animationDuration
});
Expand All @@ -99,7 +99,8 @@
}
} else if (scrollDelta > 0) {
if (!_visible) {
if (autoHidingNavbar.settings.showOnBottom && scrollTop + _windowHeight === $document.height()) {
if (autoHidingNavbar.settings.showOnBottom &&
scrollTop + _windowHeight === $document.height()) {
show(autoHidingNavbar);
}
return;
Expand All @@ -123,7 +124,7 @@
}

function bindEvents(autoHidingNavbar) {
$document.on('scroll.' + pluginName, function() {
$document.on("scroll." + pluginName, function() {
if (new Date().getTime() - _lastScrollHandlerRun > _throttleDelay) {
scrollHandler(autoHidingNavbar);
} else {
Expand All @@ -134,7 +135,7 @@
}
});

$window.on('resize.' + pluginName, function() {
$window.on("resize." + pluginName, function() {
clearTimeout(_resizeThrottleTimer);
_resizeThrottleTimer = setTimeout(function() {
_windowHeight = $window.height();
Expand All @@ -143,9 +144,9 @@
}

function unbindEvents() {
$document.off('.' + pluginName);
$document.off("." + pluginName);

$window.off('.' + pluginName);
$window.off("." + pluginName);
}

AutoHidingNavbar.prototype = {
Expand All @@ -160,7 +161,8 @@
this.setHideOffset(this.settings.hideOffset);
this.setAnimationDuration(this.settings.animationDuration);

_hideOffset = this.settings.hideOffset === 'auto' ? this.element.height() : this.settings.hideOffset;
_hideOffset = this.settings.hideOffset === "auto" ?
this.element.height() : this.settings.hideOffset;
bindEvents(this);

return this.element;
Expand Down Expand Up @@ -196,27 +198,26 @@
destroy: function() {
unbindEvents(this);
show(this);
$.data(this, 'plugin_' + pluginName, null);
$.data(this, "plugin_" + pluginName, null);
return this.element;
}
};

$.fn[pluginName] = function(options) {
var args = arguments;
var args = arguments,
returns;

if (options === undefined || typeof options === 'object') {
if (options === undefined || typeof options === "object") {
return this.each(function() {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new AutoHidingNavbar(this, options));
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName, new AutoHidingNavbar(this, options));
}
});
} else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
var returns;

} else if (typeof options === "string" && options[0] !== "_" && options !== "init") {
this.each(function() {
var instance = $.data(this, 'plugin_' + pluginName);
var instance = $.data(this, "plugin_" + pluginName);

if (instance instanceof AutoHidingNavbar && typeof instance[options] === 'function') {
if (instance instanceof AutoHidingNavbar && typeof instance[options] === "function") {
returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
}
});
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.bootstrap-autohidingnavbar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"name": "István Ujj-Mészáros",
"url": "https://github.com/istvan-ujjmeszaros"
},
"contributors": [
],
"contributors": [],
"repository": {
"type": "git",
"url": "http://github.com/istvan-ujjmeszaros/bootstrap-autohidingnavbar.git"
Expand All @@ -17,10 +16,11 @@
"devDependencies": {
"grunt": "~0.4.1",
"grunt-cli": "~0.1.13",
"grunt-contrib-jshint": "~0.8.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-cssmin": "~0.9.0",
"grunt-contrib-jshint": "~0.8.0",
"grunt-contrib-uglify": "~0.3.2",
"grunt-contrib-cssmin": "~0.9.0"
"grunt-jscs": "^0.7.1"
},
"scripts": {
"test": "grunt travis --verbose"
Expand Down
Loading

0 comments on commit a94c947

Please sign in to comment.