Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orientation event #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions flickable.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ var Flickable = function(elementSelector, options) {
nextButtonClass: 'nextSlideButton',
prevButtonClass: 'prevSlideButton',
nextButtonText: 'Next',
prevButtonText: 'Previous'
prevButtonText: 'Previous',
orientationEvent: 'orientationchange'
},
orientationEvent = 'resize',
orientationTimeout;

if (elementMatches[1] === '.') {
Expand All @@ -28,10 +28,6 @@ var Flickable = function(elementSelector, options) {
elements = [document.getElementsById(elementMatches[2])];
}

if ('onorientationchange' in window) {
orientationEvent = 'orientationchange';
}

// Extend settings with options from parameter
if (options) {
for (i in options) {
Expand All @@ -41,6 +37,16 @@ var Flickable = function(elementSelector, options) {
}
}

// 'onorientationchange' could be disabled by passing 'resize' option.
// Default option is 'orientationchange' if supported by browser.
var orientationEvent;
if(settings.orientationEvent === 'orientationchange'
&& 'onorientationchange' in window) {
orientationEvent = 'orientationchange';
} else {
orientationEvent = 'resize';
}

if (settings.itemWidth) {
settings.width = settings.itemWidth;
}
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ Settings reference
- `indicatorClass`: The class name for the indicator wrapper element. **Default:** `'flickableIndicator'`
- `activeIndicatorClass`: The class name for the active indicator element. **Default:** `'flickableIndicatorActive'`
- `callback`: A function to be called each time the slide changes. The function will be passed the slide number (zero-indexed) as a parameter.
- `orientationEvent`: Window event which should determine when to change images width. **Default:** `'orientationchange'`

_Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php_