├── .gitignore ├── LICENSE ├── README.md ├── bootstrap-hover-dropdown.js ├── bootstrap-hover-dropdown.min.js ├── bower.json ├── composer.json ├── demo.html ├── gulpfile.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2012-2014 Cameron Spear http://cameronspear.com 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Bootstrap Hover Dropdown Plugin 2 | =============================== 3 | 4 | [![Join the chat at https://gitter.im/CWSpear/bootstrap-hover-dropdown](https://badges.gitter.im/CWSpear/bootstrap-hover-dropdown.svg)](https://gitter.im/CWSpear/bootstrap-hover-dropdown?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 5 | 6 | ![Current Version](http://img.shields.io/github/tag/cwspear/bootstrap-hover-dropdown.svg?style=flat) 7 | 8 | #### Name Change 9 | 10 | *Twitter Bootstrap* is now just *Bootstrap*, and I've renamed this repo, **renamed the files** and change all references from *Twitter Bootstrap* to just *Bootstrap* in the docs/example to reflect that. 11 | 12 | No actual code changed, so I am keeping the current version (`2.0.1` at the time of this writing), but be aware of the lack of *twitter-* from the beginning of the JS files and how that might affect you. 13 | 14 | Sorry for any inconvenience! 15 | 16 | #### Updated for Bootstrap 3 17 | 18 | I updated the demo with Bootstrap 3, as well as removed code associated to submenus ([not supported in Bootstrap 3](https://github.com/twbs/bootstrap/pull/6342#issuecomment-11594010)) and touch devices (just make sure you have `data-toggle="dropdown"` to let Mobile do its thing and my plugin won't interfere). 19 | 20 | ## Introduction 21 | 22 | A simple plugin to enable Bootstrap dropdowns to activate on hover and provide a nice user experience. 23 | 24 | The dropdowns are dismissed after a configurable delay. This fixes an issue that can instantly close your nav because of a 1px gap between the button/nav item that activated the dropdown and the actual dropdown. It is also generally a better user experience, as users are not punished by going 1 pixel outside of the dropdown, which would instantly close the nav without a delay. 25 | 26 | **Note:** The HTML markup is the same as with any other Bootstrap dropdown. This will not interfere with Bootstrap's default activate-on-click method (i.e. this plugin combined with Bootstrap's default behavior work well to support both the ideal experience on desktop and mobile). 27 | 28 | ## Installation 29 | 30 | You can simply download and extract the package downloaded from GitHub. Alternatively, you can download the files via [Bower](http://bower.io/) (a JavaScript package management system): 31 | 32 | ``` 33 | bower install bootstrap-hover-dropdown 34 | ``` 35 | 36 | which will also automatically install Bootstrap and jQuery if needed. 37 | 38 | Once you have the files downloaded, link to the files in your code *after* you include the main Bootstrap JS file(s): 39 | 40 | ```html 41 | 42 | 43 | 44 | 45 | ``` 46 | 47 | ## Usage 48 | 49 | Just like in Bootstrap you can activate it without any JavaScript, just by adding a data-attribute, you can make it automatically work. 50 | 51 | Add `data-hover="dropdown"` in addition (or in place of) Bootstrap's `data-toggle="dropdown"`. 52 | 53 | You can set options via data-attributes, too, via `data-delay` and `data-close-others`. Here's an example of markup: 54 | 55 | ```html 56 | 69 | ``` 70 | 71 | Alternatively, you can initialize via JavaScript: 72 | 73 | ```javascript 74 | $('.dropdown-toggle').dropdownHover(options); 75 | ``` 76 | 77 | This also works with submenus without any other configuring since Bootstrap already supports this feature. Just use the markup like you were using before. Only the top level anchor tag needs any special markup for my plugin to work (see demo for proper markup). 78 | 79 | ## Options 80 | 81 | * **delay**: *(optional)* The delay in miliseconds. This is the time to wait before closing a dropdown when the mouse is no longer over the dropdown or the button/nav item that activated it. Defaults to `500`. 82 | * **instantlyCloseOthers**: *(optional)* A boolean value that when true, will instantly close all other dropdowns matched by the selector used when you activate a new navigation. This is nice for when you have dropdowns close together that may overlap. Default is `true`. 83 | * **hoverDelay**: *(optional)* A delay *before opening* in miliseconds. Some people argue this improves user experience as it decreases the number of accidental menu openings. Defaults to `0`. 84 | 85 | ## Demo 86 | 87 | You can view a demo for this plugin on my site: http://cameronspear.com/demos/bootstrap-hover-dropdown/ 88 | 89 | ### A Note on Choosing a Selector 90 | 91 | This plugin purposedly lets you choose a selector (as opposed to apply this to everything with the class of `.dropdown-toggle`). This is so that you can selectively apply it where you want. Maybe you only want to use it for the main nav, and not have it activate for dropdown buttons in the main content. You can add a class to the item that normally gets `.dropdown-toggle` and use that class with this plugin to easily achieve that, or use a selector such as `.main-nav .dropdown-toggle`. 92 | 93 | **Important:** Bootstrap relies on styles associated with the class `.dropdown-toggle` (for stuff like the caret color), and it is recommended you leave that class alone. 94 | 95 | ## Changes/Bug Fixes 96 | 97 | I'm a slacker and only started keeping track of changes/bug fixes starting in March of 2013. 98 | 99 | * **2015-12-01** *[v2.2.1]* Update README 100 | * **2015-12-01** *[v2.2.0]* New logic: don't do anything when the navbar is collapsed 101 | * **2015-02-07** *[v2.1.3]* Update version in JS files 102 | * **2015-02-07** *[v2.1.2]* Forgot to minify the last couple updates... 103 | * **2015-02-07** *[v2.1.1]* Merged another PR: `browserify` compatibility [#100](/../../issues/100). 104 | * **2015-02-07** *[v2.1.0]* Merged a couple PRs: ARIA support [#95](/../../issues/95) and hover delay support [#99](/../../issues/99). 105 | * **2014-06-16** Added package to composer. 106 | * **2014-05-12** Fixed an issue where you could click a parent menu item to close it, but moving away from it would re-open the menu. Also cleaned up some code, removed some redundency. 107 | * **2014-01-27** Fixed an issue where chaining could break on mobile and cleaned up the the way the plugin triggered events. Also cleaned up the demo (fixed navbar appearance). 108 | * **2013-12-05** Change all references of *Twitter Bootstrap* to *Bootstrap* to reflect Bootstrap's name change. 109 | * **2013-11-09** Disable this plugin for devices that support touch. The plugin was causing issues with some mobile devices, and it's not necessary for them. 110 | * **2013-08-02** Add support for Bootstrap 3. For Bootstrap 2.x.x, use the `bootstrap-2.x.x` branch. 111 | * **2013-06-10** Always instantly close submenu siblings when opening a new one. Issue #19. 112 | * **2013-06-10** A fix for my last fix that would sometimes cause the correct item to not trigger when it should. Issue #18. 113 | * **2013-05-08** Fix issue where a sibling could open a drop down that wasn't theirs. Issue #18. 114 | * **2013-04-29** Added support for submenus: Submenus should now honor the delay option and way before closing. They do not abide by the `instantlyCloseOthers` option, as it's not really relevant. 115 | * **2013-04-19** Fixed an issue where the conditional rule to disable hover on mobile wasn't working if you included the script in the header. 116 | * **2013-04-03** Made it so if you're using the responsive CSS and in tablet/mobile view, disable the hover. 117 | * **2013-03-16** Fixed an issue where the options you passed in via the method call were completely ignored. 118 | 119 | ## Contributions 120 | 121 | Thanks to all of you who have contributed to this project, whether by code or by filing an issue to help improve it. But of course, especially the [ones that contribute code](/../../graphs/contributors) =) 122 | 123 | A special thanks to [Mattia Larentis](https://github.com/nostalgiaz). He isn't in the contributor list, but he helped me with the idea for the data-attributes and doing the options via an object. 124 | 125 | I will also issue a very special thanks in the README for help with setting up a [testing suite](/../../issues/69)! 126 | 127 | ## Roadmap 128 | 129 | As this plugin, in its simplicity, is pretty much exactly what I intend it to be, I don't plan to implement any new features. ~~**One exception:** I would like to tweak it so that when you're in a submenu, it doesn't instantly close when you hover outside of it.~~ **Update:** I added this in late April 2013. 130 | 131 | If you have ideas for a new feature or something along those lines, you're welcome to share them with me, but I am not likely to implement it/merge your pull without a very compelling reason. You are absolutely free to create a fork and implement the feature yourself for your and others' use. 132 | 133 | This, of course, does not speak for bugs. If you have a bug, please bring it to my attention, and I will try and fix it. Note that 93.7% of people's issues are caused by incorrect markup, so please double check that first. 134 | 135 | ## Me 136 | 137 | Follow me on Twitter: [@CWSpear](https://twitter.com/CWSpear) or check out my [blog](http://cameronspear.com/blog/). 138 | -------------------------------------------------------------------------------- /bootstrap-hover-dropdown.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve 3 | * Project: Bootstrap Hover Dropdown 4 | * Author: Cameron Spear 5 | * Version: v2.2.1 6 | * Contributors: Mattia Larentis 7 | * Dependencies: Bootstrap's Dropdown plugin, jQuery 8 | * Description: A simple plugin to enable Bootstrap dropdowns to active on hover and provide a nice user experience. 9 | * License: MIT 10 | * Homepage: http://cameronspear.com/blog/bootstrap-dropdown-on-hover-plugin/ 11 | */ 12 | ;(function ($, window, undefined) { 13 | // outside the scope of the jQuery plugin to 14 | // keep track of all dropdowns 15 | var $allDropdowns = $(); 16 | 17 | // if instantlyCloseOthers is true, then it will instantly 18 | // shut other nav items when a new one is hovered over 19 | $.fn.dropdownHover = function (options) { 20 | // don't do anything if touch is supported 21 | // (plugin causes some issues on mobile) 22 | if('ontouchstart' in document) return this; // don't want to affect chaining 23 | 24 | // the element we really care about 25 | // is the dropdown-toggle's parent 26 | $allDropdowns = $allDropdowns.add(this.parent()); 27 | 28 | return this.each(function () { 29 | var $this = $(this), 30 | $parent = $this.parent(), 31 | defaults = { 32 | delay: 500, 33 | hoverDelay: 0, 34 | instantlyCloseOthers: true 35 | }, 36 | data = { 37 | delay: $(this).data('delay'), 38 | hoverDelay: $(this).data('hover-delay'), 39 | instantlyCloseOthers: $(this).data('close-others') 40 | }, 41 | showEvent = 'show.bs.dropdown', 42 | hideEvent = 'hide.bs.dropdown', 43 | // shownEvent = 'shown.bs.dropdown', 44 | // hiddenEvent = 'hidden.bs.dropdown', 45 | settings = $.extend(true, {}, defaults, options, data), 46 | timeout, timeoutHover; 47 | 48 | $parent.hover(function (event) { 49 | // so a neighbor can't open the dropdown 50 | if(!$parent.hasClass('open') && !$this.is(event.target)) { 51 | // stop this event, stop executing any code 52 | // in this callback but continue to propagate 53 | return true; 54 | } 55 | 56 | openDropdown(event); 57 | }, function () { 58 | // clear timer for hover event 59 | window.clearTimeout(timeoutHover) 60 | timeout = window.setTimeout(function () { 61 | $this.attr('aria-expanded', 'false'); 62 | $parent.removeClass('open'); 63 | $this.trigger(hideEvent); 64 | }, settings.delay); 65 | }); 66 | 67 | // this helps with button groups! 68 | $this.hover(function (event) { 69 | // this helps prevent a double event from firing. 70 | // see https://github.com/CWSpear/bootstrap-hover-dropdown/issues/55 71 | if(!$parent.hasClass('open') && !$parent.is(event.target)) { 72 | // stop this event, stop executing any code 73 | // in this callback but continue to propagate 74 | return true; 75 | } 76 | 77 | openDropdown(event); 78 | }); 79 | 80 | // handle submenus 81 | $parent.find('.dropdown-submenu').each(function (){ 82 | var $this = $(this); 83 | var subTimeout; 84 | $this.hover(function () { 85 | window.clearTimeout(subTimeout); 86 | $this.children('.dropdown-menu').show(); 87 | // always close submenu siblings instantly 88 | $this.siblings().children('.dropdown-menu').hide(); 89 | }, function () { 90 | var $submenu = $this.children('.dropdown-menu'); 91 | subTimeout = window.setTimeout(function () { 92 | $submenu.hide(); 93 | }, settings.delay); 94 | }); 95 | }); 96 | 97 | function openDropdown(event) { 98 | if($this.parents(".navbar").find(".navbar-toggle").is(":visible")) { 99 | // If we're inside a navbar, don't do anything when the 100 | // navbar is collapsed, as it makes the navbar pretty unusable. 101 | return; 102 | } 103 | 104 | // clear dropdown timeout here so it doesnt close before it should 105 | window.clearTimeout(timeout); 106 | // restart hover timer 107 | window.clearTimeout(timeoutHover); 108 | 109 | // delay for hover event. 110 | timeoutHover = window.setTimeout(function () { 111 | $allDropdowns.find(':focus').blur(); 112 | 113 | if(settings.instantlyCloseOthers === true) 114 | $allDropdowns.removeClass('open'); 115 | 116 | // clear timer for hover event 117 | window.clearTimeout(timeoutHover); 118 | $this.attr('aria-expanded', 'true'); 119 | $parent.addClass('open'); 120 | $this.trigger(showEvent); 121 | }, settings.hoverDelay); 122 | } 123 | }); 124 | }; 125 | 126 | $(document).ready(function () { 127 | // apply dropdownHover to all elements with the data-hover="dropdown" attribute 128 | $('[data-hover="dropdown"]').dropdownHover(); 129 | }); 130 | })(jQuery, window); 131 | -------------------------------------------------------------------------------- /bootstrap-hover-dropdown.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve 3 | * Project: Bootstrap Hover Dropdown 4 | * Author: Cameron Spear 5 | * Version: v2.2.1 6 | * Contributors: Mattia Larentis 7 | * Dependencies: Bootstrap's Dropdown plugin, jQuery 8 | * Description: A simple plugin to enable Bootstrap dropdowns to active on hover and provide a nice user experience. 9 | * License: MIT 10 | * Homepage: http://cameronspear.com/blog/bootstrap-dropdown-on-hover-plugin/ 11 | */ 12 | !function(e,n){var o=e();e.fn.dropdownHover=function(t){return"ontouchstart"in document?this:(o=o.add(this.parent()),this.each(function(){function r(){d.parents(".navbar").find(".navbar-toggle").is(":visible")||(n.clearTimeout(a),n.clearTimeout(i),i=n.setTimeout(function(){o.find(":focus").blur(),v.instantlyCloseOthers===!0&&o.removeClass("open"),n.clearTimeout(i),d.attr("aria-expanded","true"),s.addClass("open"),d.trigger(h)},v.hoverDelay))}var a,i,d=e(this),s=d.parent(),u={delay:500,hoverDelay:0,instantlyCloseOthers:!0},l={delay:e(this).data("delay"),hoverDelay:e(this).data("hover-delay"),instantlyCloseOthers:e(this).data("close-others")},h="show.bs.dropdown",c="hide.bs.dropdown",v=e.extend(!0,{},u,t,l);s.hover(function(e){return s.hasClass("open")||d.is(e.target)?void r(e):!0},function(){n.clearTimeout(i),a=n.setTimeout(function(){d.attr("aria-expanded","false"),s.removeClass("open"),d.trigger(c)},v.delay)}),d.hover(function(e){return s.hasClass("open")||s.is(e.target)?void r(e):!0}),s.find(".dropdown-submenu").each(function(){var o,t=e(this);t.hover(function(){n.clearTimeout(o),t.children(".dropdown-menu").show(),t.siblings().children(".dropdown-menu").hide()},function(){var e=t.children(".dropdown-menu");o=n.setTimeout(function(){e.hide()},v.delay)})})}))},e(document).ready(function(){e('[data-hover="dropdown"]').dropdownHover()})}(jQuery,window); -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bootstrap-hover-dropdown", 3 | "version": "2.2.1", 4 | "description": "An unofficial Bootstrap plugin to enable Bootstrap dropdowns to activate on hover and provide a nice user experience.", 5 | "main": "./bootstrap-hover-dropdown.js", 6 | "keywords": [ 7 | "twitter", 8 | "bootstrap", 9 | "hover", 10 | "dropdowns" 11 | ], 12 | "homepage": "https://github.com/CWSpear/bootstrap-hover-dropdown", 13 | "dependencies": { 14 | "bootstrap": "^3.0.0", 15 | "jquery": ">= 1.9.0" 16 | }, 17 | "author": { 18 | "name": "Cameron Spear", 19 | "web": "http://cameronspear.com" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cwspear/bootstrap-hover-dropdown", 3 | "version": "2.2.1", 4 | "type": "component", 5 | "description": "An unofficial Bootstrap plugin to enable Bootstrap dropdowns to activate on hover and provide a nice user experience.", 6 | "keywords": [ 7 | "twitter", 8 | "bootstrap", 9 | "hover", 10 | "dropdowns" 11 | ], 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Cameron Spear", 16 | "email": "cam@cameronspear.com", 17 | "homepage": "http://cameronspear.com", 18 | "role": "Developer" 19 | } 20 | ], 21 | "require": { 22 | "components/jquery": ">=1.9", 23 | "components/bootstrap": "~3.0" 24 | }, 25 | "extra": { 26 | "component": { 27 | "name": "bootstrap-hover-dropdown", 28 | "files": [ 29 | "bootstrap-hover-dropdown.js" 30 | ] 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /demo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Bootstrap: Dropdown on Hover Plugin Demo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 16 | 17 | 20 | 21 | 22 | 111 | 112 |
113 |
114 |
115 | Please note that Bootstrap 3 does not support submenus. See this comment from one of the original authors. 116 |
117 | 118 |

Bootstrap: Dropdown on Hover Plugin Demo

119 |

Hover over the nav items to see that they activate on hover. I'm setting the instantlyCloseOthers flag to true, so when you hover over a new nav item, the other ones instantly close (instead of waiting for their timeouts). See cameronspear.com/blog/bootstrap-dropdown-on-hover-plugin/ for more.

120 | 121 |

New! Try it with data-attributes

122 | 123 |
124 |
125 | 126 | 131 |
132 |
133 | 134 | 142 |
143 |
144 | 145 | 152 |
153 |
154 | 155 |

It also works with buttons and tabs

156 |

Just add data-hover="dropdown" where you'd put data-toggle="dropdown"

157 | 158 |
159 |
160 | 161 | 168 |
169 |
170 | 171 | 178 |
179 |
180 | 181 | 188 |
189 |
190 | 191 | 198 |
199 |
200 | 201 | 208 |
209 |
210 | 211 | 218 |
219 |
220 | 221 | 228 |
229 |
230 | 231 |

Works with button groups

232 |

This was trickier than you might think!

233 | 234 |
235 | 236 | 237 | 238 | 239 |
240 | 244 | 249 |
250 |
251 | 252 |
253 | 254 |
255 | 266 |
267 |
268 |

Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.

269 |
270 |
271 |

Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.

272 |
273 | 276 | 279 |
280 |
281 |
282 |
283 | 284 | 285 | 286 | 287 | 288 | 289 | 295 | 296 | 297 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var uglify = require('gulp-uglify'); 3 | var rename = require('gulp-rename'); 4 | 5 | gulp.task('default', function() { 6 | return gulp.src('bootstrap-hover-dropdown.js') 7 | 8 | // minifiy preserving preserved comments 9 | .pipe(uglify({ 10 | preserveComments: 'some' 11 | })) 12 | 13 | // rename to .min. 14 | .pipe(rename('bootstrap-hover-dropdown.min.js')) 15 | 16 | .pipe(gulp.dest('.')); 17 | }); 18 | 19 | 20 | var fs = require('fs'); 21 | var bump = require('gulp-bump'); 22 | var filter = require('gulp-filter'); 23 | var git = require('gulp-git'); 24 | var tagVersion = require('gulp-tag-version'); 25 | var replace = require('gulp-replace'); 26 | var streamqueue = require('streamqueue'); 27 | 28 | /** 29 | * Bumping version number and tagging the repository with it. 30 | * Please read http://semver.org/ 31 | * 32 | * You can use the commands 33 | * 34 | * gulp patch # makes v0.1.0 → v0.1.1 35 | * gulp feature # makes v0.1.1 → v0.2.0 36 | * gulp release # makes v0.2.1 → v1.0.0 37 | * 38 | * To bump the version numbers accordingly after you did a patch, 39 | * introduced a feature or made a backwards-incompatible release. 40 | */ 41 | function increment(importance) { 42 | var packages = ['package.json', 'bower.json', 'composer.json']; 43 | var currentVersion = JSON.parse(fs.readFileSync('bower.json')).version; 44 | 45 | // get all the files to bump version in 46 | gulp.src(packages) 47 | 48 | // bump the version number in those files 49 | .pipe(bump({ type: importance })) 50 | 51 | // save it back to filesystem 52 | .pipe(gulp.dest('.')) 53 | 54 | .on('end', function () { 55 | var newVersion = JSON.parse(fs.readFileSync('bower.json')).version; 56 | 57 | var packagesStream = gulp.src(packages); 58 | 59 | var jsStream = gulp.src(['bootstrap-hover-dropdown.js', 'bootstrap-hover-dropdown.min.js']) 60 | 61 | // replace version # in the JS files 62 | .pipe(replace('Version: v' + currentVersion, 'Version: v' + newVersion)) 63 | 64 | // save it back to filesystem 65 | .pipe(gulp.dest('.')); 66 | 67 | // merge the streams together to commit 68 | streamqueue({ objectMode: true }, jsStream, packagesStream) 69 | 70 | // commit the changed version number 71 | .pipe(git.commit('bump packages\' version')) 72 | 73 | // read only one file to get the version number 74 | .pipe(filter('package.json')) 75 | 76 | // **tag it in the repository** 77 | .pipe(tagVersion()) 78 | 79 | // run npm publish 80 | .on('end', function () { 81 | var spawn = require('child_process').spawn; 82 | spawn('npm', ['publish'], { stdio: 'inherit' }); 83 | }); 84 | }); 85 | } 86 | 87 | gulp.task('patch', ['default'], function() { return increment('patch'); }); 88 | gulp.task('feature', ['default'], function() { return increment('minor'); }); 89 | gulp.task('release', ['default'], function() { return increment('major'); }); 90 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bootstrap-hover-dropdown", 3 | "version": "2.2.1", 4 | "description": "An unofficial Bootstrap plugin to enable Bootstrap dropdowns to activate on hover and provide a nice user experience.", 5 | "main": "bootstrap-hover-dropdown.js", 6 | "dependencies": { 7 | "streamqueue": "^0.1.1" 8 | }, 9 | "devDependencies": { 10 | "gulp": "^3.8.10", 11 | "gulp-bump": "^0.1.13", 12 | "gulp-filter": "^2.0.0", 13 | "gulp-git": "^0.5.6", 14 | "gulp-rename": "^1.2.0", 15 | "gulp-tag-version": "^1.2.1", 16 | "gulp-uglify": "^1.1.0", 17 | "streamqueue": "^0.1.1" 18 | }, 19 | "scripts": { 20 | "test": "echo \"Error: no test specified\" && exit 1" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/CWSpear/bootstrap-hover-dropdown.git" 25 | }, 26 | "keywords": [ 27 | "twitter", 28 | "bootstrap", 29 | "hover", 30 | "dropdowns" 31 | ], 32 | "author": { 33 | "name": "Cameron Spear", 34 | "url": "https://cameronspear.com" 35 | }, 36 | "license": "MIT", 37 | "bugs": { 38 | "url": "https://github.com/CWSpear/bootstrap-hover-dropdown/issues" 39 | }, 40 | "homepage": "https://github.com/CWSpear/bootstrap-hover-dropdown" 41 | } 42 | --------------------------------------------------------------------------------