Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
morrissinger committed Nov 29, 2013
0 parents commit e364af8
Show file tree
Hide file tree
Showing 12 changed files with 627 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.DS_Store
node_modules
*.sublime*
Binary file not shown.
133 changes: 133 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,133 @@
/* jshint node: true */

module.exports = function(grunt) {
'use strict';

// Project configuration.
grunt.initConfig({

// Metadata.
pkg: grunt.file.readJSON('package.json'),
banner: '/**\n' +
'* <%= pkg.name %>.js v<%= pkg.version %> by @morrissinger\n' +
'* Copyright <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
'* <%= _.pluck(pkg.licenses, "url").join(", ") %>\n' +
'*/\n',
jqueryCheck: 'if (!jQuery) { throw new Error(\"Bootstrap Tree Nav requires jQuery\"); }\n\n',

// Task configuration.
clean: {
dist: ['dist']
},

jshint: {
options: {
jshintrc: 'js/.jshintrc'
},
gruntfile: {
src: 'Gruntfile.js'
},
src: {
src: [
'js/lang/*/*.js',
'js/*.js'
]
}
},

concat: {
options: {
banner: '<%= banner %><%= jqueryCheck %>',
stripBanners: false
},
bootstraptreenav: {
src: [
'js/*.js'
],
dest: 'dist/js/<%= pkg.name %>.js'
}
},

uglify: {
options: {
banner: '<%= banner %>'
},
bootstraptreenav: {
src: ['<%= concat.bootstraptreenav.dest %>'],
dest: 'dist/js/<%= pkg.name %>.min.js'
}
},

copy: {
img: {
expand: true,
src: ['img/*'],
dest: 'dist/'
}
},
sass: {
src: {
options: {
style: 'expanded',
banner: '<%= banner %>'
},
files: {
'dist/css/bootstrap-treenav.css' : 'sass/bootstrap-treenav.scss'
}
},
dist: {
options: {
style: 'compressed',
banner: '<%= banner %>'
},
files: {
'dist/css/bootstrap-treenav.min.css' : 'sass/bootstrap-treenav.scss'
}
}
},
watch: {
src: {
files: '<%= jshint.src.src %>',
tasks: ['jshint:src']
},
css: {
files: '**/*.scss',
tasks: ['sass']
}
}
});


// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');

var testSubtasks = ['dist-css', 'jshint'];
// Only push to coveralls under Travis
if (process.env.TRAVIS) {
if ((process.env.TRAVIS_REPO_SLUG === 'morrissinger/BootstrapTreeNav' && process.env.TRAVIS_PULL_REQUEST === 'false')) {
testSubtasks.push('coveralls');
}
}
grunt.registerTask('test', testSubtasks);

// JS distribution task.
grunt.registerTask('dist-js', ['concat', 'uglify']);

// CSS distribution task.
grunt.registerTask('dist-css', ['sass']);

// Img distribution task.
grunt.registerTask('dist-img', ['copy']);

// Full distribution task.
grunt.registerTask('dist', ['clean', 'dist-css', 'dist-img', 'dist-js']);

// Default task.
grunt.registerTask('default', ['test', 'dist']);
};
39 changes: 39 additions & 0 deletions dist/css/bootstrap-treenav.css
@@ -0,0 +1,39 @@
/**
* bootstrap-treenav.js v1.0.0 by @morrissinger
* Copyright 2013 Morris Singer
* http://www.apache.org/licenses/LICENSE-2.0
*/

ul.nav-tree {
list-style: none;
margin-left: 20px;
}
ul.nav-tree ul.nav-tree {
margin-left: 45px;
}
ul.nav-tree li {
position: relative;
margin-left: -15px;
}
ul.nav-tree li a {
text-indent: 15px;
}
ul.nav-tree li span.opener {
position: absolute;
top: 5px;
left: 10px;
color: #444;
z-index: +1;
}
ul.nav-tree li span.opener.closed span.tree-icon-opened {
display: none;
}
ul.nav-tree li span.opener.closed span.tree-icon-closed {
display: block;
}
ul.nav-tree li span.opener.opened span.tree-icon-open {
display: block;
}
ul.nav-tree li span.opener.opened span.tree-icon-closed {
display: none;
}
7 changes: 7 additions & 0 deletions dist/css/bootstrap-treenav.min.css
@@ -0,0 +1,7 @@
/**
* bootstrap-treenav.js v1.0.0 by @morrissinger
* Copyright 2013 Morris Singer
* http://www.apache.org/licenses/LICENSE-2.0
*/

ul.nav-tree{list-style:none;margin-left:20px}ul.nav-tree ul.nav-tree{margin-left:45px}ul.nav-tree li{position:relative;margin-left:-15px}ul.nav-tree li a{text-indent:15px}ul.nav-tree li span.opener{position:absolute;top:5px;left:10px;color:#444;z-index:+1}ul.nav-tree li span.opener.closed span.tree-icon-opened{display:none}ul.nav-tree li span.opener.closed span.tree-icon-closed{display:block}ul.nav-tree li span.opener.opened span.tree-icon-open{display:block}ul.nav-tree li span.opener.opened span.tree-icon-closed{display:none}
122 changes: 122 additions & 0 deletions dist/js/bootstrap-treenav.js
@@ -0,0 +1,122 @@
/**
* bootstrap-treenav.js v1.0.0 by @morrissinger
* Copyright 2013 Morris Singer
* http://www.apache.org/licenses/LICENSE-2.0
*/
if (!jQuery) { throw new Error("Bootstrap Tree Nav requires jQuery"); }

/* ==========================================================
* bootstrap-treenav.js
* https://github.com/morrissinger/BootstrapTreeNav
* ==========================================================
* Copyright 2013 Morris Singer
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================== */

+function ($) {

'use strict';

$.fn.navTree = function(options) {

var defaults = {
navTreeExpanded: 'icon-collapse-alt',
navTreeCollapsed: 'icon-expand-alt'
};

options = $.extend(defaults, options);

if ($(this).prop('tagName') === 'LI') {
collapsible(this, options);
} else if ($(this).prop('tagName') === 'UL') {
collapsible(this, options);
}

};

var collapsible = function(element, options) {
var $childrenLi = $(element).find('li');
$childrenLi.each(function(index, li) {
collapsibleAll($(li), options);

// Expand the tree so that the active item is shown.
if ($(li).hasClass('active')) {
$(li).parents('ul').each(function(i, ul) {
$(ul).show();
$(ul).siblings('span.opener')
.removeClass('closed')
.addClass('opened');

// If there's a real target to this menu item link, then allow it to be
// clicked to go to that page, now that the menu has been expanded.
if ($(ul).siblings('a').attr('href') !== '#' && $(ul).siblings('a').attr('href') !== '') {
$(ul).siblings('a').off('click.bs.tree');
}

});
}
});
};

var collapsibleAll = function(element, options) {
var $childUl = $(element).children('ul');
if ( $childUl.length > 0 ) {
$childUl.hide();
$(element).prepend('<span class="opener closed"><span class="tree-icon-closed"><i class="' + options.navTreeCollapsed + '"></i></span><span class="tree-icon-opened"><i class="' + options.navTreeExpanded + '"></i></span></span>');
$(element).children('a').first().on('click.bs.tree', function(e) {
e.preventDefault();
var $opener = $(this).siblings('span.opener');
if ($opener.hasClass('closed')) {
expand(element);

// If there's a real target to this menu item link, then allow it to be
// clicked to go to that page, now that the menu has been expanded.
if (($(this).attr('href') !== '#') && ($(this).attr('href') !== '')) {
$(this).off('click.bs.tree');
}

} else {
collapse(element);
}
});
$(element).children('span.opener').first().on('click.bs.tree', function(e){
var $opener = $(this);
if ($opener.hasClass('closed')) {
expand(element);
} else {
collapse(element);
}
});
}
};

var expand = function(element) {
var $opener = $(element).children('span.opener');
$opener.removeClass('closed').addClass('opened');
$(element).children('ul').first().slideDown();
};

var collapse = function(element) {
var $opener = $(element).children('span.opener');
$opener.removeClass('opened').addClass('closed');
$(element).children('ul').first().slideUp();
};

$('ul[data-toggle=nav-tree]').each(function(){
var $tree;
$tree = $(this);
$tree.navTree($tree.data());
});

}(window.jQuery);
6 changes: 6 additions & 0 deletions dist/js/bootstrap-treenav.min.js

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

0 comments on commit e364af8

Please sign in to comment.