Skip to content

Commit

Permalink
fix(lory.js): call reset() *before* dispatching resize event
Browse files Browse the repository at this point in the history
This fixes a problem when trying to read the index
after a resize in an 'on.lory.resize' handler, where the
old index is returned instead of 0, as set in reset().

Ideally lory.js would not register the resize handler at all
and instead let the application register a resize handler
(maybe even debounced) that calls lory.reset().
  • Loading branch information
unstubbable committed Nov 17, 2015
1 parent 0bbfa33 commit f7a8942
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 45 deletions.
22 changes: 13 additions & 9 deletions demo/js/jquery.lory.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ return /******/ (function(modules) { // webpackBootstrap

'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /* globals jQuery */

Object.defineProperty(exports, "__esModule", {
value: true
Expand All @@ -100,8 +100,6 @@ return /******/ (function(modules) { // webpackBootstrap

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _instanceof(left, right) { if (right != null && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } } /* globals jQuery */

var slice = Array.prototype.slice;

function lory(slider, opts) {
Expand All @@ -126,7 +124,7 @@ return /******/ (function(modules) { // webpackBootstrap
/**
* if object is jQuery convert to native DOM element
*/
if (typeof jQuery !== 'undefined' && _instanceof(slider, jQuery)) {
if (typeof jQuery !== 'undefined' && slider instanceof jQuery) {
slider = slider[0];
}

Expand Down Expand Up @@ -353,7 +351,7 @@ return /******/ (function(modules) { // webpackBootstrap
slideContainer.addEventListener('click', onClick);
}

window.addEventListener('resize', onResize);
options.window.addEventListener('resize', onResize);

dispatchSliderEvent('after', 'init');
}
Expand Down Expand Up @@ -439,7 +437,7 @@ return /******/ (function(modules) { // webpackBootstrap
slideContainer.removeEventListener('mouseleave', onTouchend);
slideContainer.removeEventListener('click', onClick);

window.removeEventListener('resize', onResize);
options.window.removeEventListener('resize', onResize);

if (prevCtrl) {
prevCtrl.removeEventListener('click', prev);
Expand Down Expand Up @@ -588,11 +586,11 @@ return /******/ (function(modules) { // webpackBootstrap
}

function onResize(event) {
reset();

dispatchSliderEvent('on', 'resize', {
event: event
});

reset();
}

// trigger initial setup
Expand Down Expand Up @@ -851,7 +849,13 @@ return /******/ (function(modules) { // webpackBootstrap
* enables mouse events for swiping on desktop devices
* @enableMouseEvents {boolean}
*/
enableMouseEvents: false
enableMouseEvents: false,

/**
* window instance
* @window {object}
*/
window: window
};

/***/ }
Expand Down
2 changes: 1 addition & 1 deletion demo/js/jquery.lory.min.js

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

Loading

0 comments on commit f7a8942

Please sign in to comment.