Skip to content

Commit

Permalink
Auto-scroll when out of viewport (option)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzos committed Mar 1, 2012
1 parent 0e0367e commit 5d7df41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Docs
- **showText**: If `TRUE` (default) keeps text in the dropdown menu.
- **showImages**: If `TRUE` (default) show images in the dropdown menu.
- **className**: A class name for CSS styling, default `'fancy-select'`.
- **autoScrollWindow**: If `TRUE`, auto-scroll browser window when FancySelect is out of viewport.
- **animateFade**: If `TRUE` (default) animate the dropdown menu appearance.
- **fx**: An object for additional `Fx` options (default `{'duration': 'short'}`).

Expand Down
11 changes: 11 additions & 0 deletions Source/FancySelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,30 @@ var FancySelect = new Class({
showImages: true,
className: 'fancy-select',
offset: { x: 0, y: 0 },
autoScrollWindow: false,
animateFade: true,
animateSlide: true,
fx: { 'duration': 'short' }
},

initialize: function(element, options) {

this.setOptions(options);
/*if (!Fx.Slide)*/ this.options.animateSlide = false; // Need review
this.element = document.id(element);
this.element.store('fancyselect_object', this);
this._create();
this.attach();

// Auto-scroll when FancySelect is out of viewport
if (this.options.autoScrollWindow) this.addEvent('show', function() {
var windowScroll = window.getScroll();
var overflow = this.ul.getPosition().y + this.ul.getSize().y - window.getSize().y - windowScroll.y;
if (overflow > 0) window.scrollTo(windowScroll.x, windowScroll.y + overflow + 10);
});

return this;

},

attach: function() {
Expand Down

0 comments on commit 5d7df41

Please sign in to comment.