Skip to content

Commit

Permalink
fix #103 (#105)
Browse files Browse the repository at this point in the history
* fix: polyfill Math.sign and Object.assign closes #103

* fix: add polyfill in docs
  • Loading branch information
logaretm authored Jun 26, 2019
1 parent 3555740 commit 26dda3e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 43 deletions.
64 changes: 29 additions & 35 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
module.exports = {
title: 'Hooper',
description: 'Vue.js carousel component',
base: '/hooper/',
serviceWorker: true,
head: [
['meta', { charset: 'utf-8' }],
['meta', { name: "theme-color", content: "#41b883" }],
['meta', { name: 'viewport', content: 'width=device-width, initial-scale=1' }],
['meta', { property: 'og:image', content: '/hooper/hooper.png' }],
],
themeConfig: {
repo: 'baianat/hooper',
docsRepo: 'baianat/hooper',
docsDir: 'docs',
docsBranch: 'master',
editLinks: true,
locales: {
'/': {
label: 'English',
selectText: 'Languages',
editLinkText: 'Help us improve this page!',
nav: [
{ text: 'API', link: '/api' },
{ text: 'Examples', link: '/examples' }
],
sidebar: [
'/getting-started',
'/examples',
'/api'
]
}
}
}
}
module.exports = {
title: 'Hooper',
description: 'Vue.js carousel component',
base: '/hooper/',
serviceWorker: true,
head: [
['meta', { charset: 'utf-8' }],
['meta', { name: 'theme-color', content: '#41b883' }],
['meta', { name: 'viewport', content: 'width=device-width, initial-scale=1' }],
['meta', { property: 'og:image', content: '/hooper/hooper.png' }],
['script', { src: 'https://polyfill.io/v3/polyfill.min.js', crossorigin: 'anonymous' }]
],
themeConfig: {
repo: 'baianat/hooper',
docsRepo: 'baianat/hooper',
docsDir: 'docs',
docsBranch: 'master',
editLinks: true,
locales: {
'/': {
label: 'English',
selectText: 'Languages',
editLinkText: 'Help us improve this page!',
nav: [{ text: 'API', link: '/api' }, { text: 'Examples', link: '/examples' }],
sidebar: ['/getting-started', '/examples', '/api']
}
}
}
};
16 changes: 8 additions & 8 deletions src/Hooper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<script>
import Vue from 'vue';
import { getInRange, now, Timer, normalizeSlideIndex, cloneSlide } from './utils';
import { getInRange, now, Timer, normalizeSlideIndex, cloneSlide, assign, sign } from './utils';
let EMITTER = new Vue();
Expand Down Expand Up @@ -282,8 +282,8 @@ export default {
},
initDefaults() {
this.breakpoints = this.settings.breakpoints;
this.defaults = Object.assign({}, this.$props, this.settings);
this.config = Object.assign({}, this.defaults);
this.defaults = assign({}, this.$props, this.settings);
this.config = assign({}, this.defaults);
},
initSlides() {
this.slides = this.filteredSlides();
Expand Down Expand Up @@ -344,12 +344,12 @@ export default {
breakpoints.some(breakpoint => {
matched = window.matchMedia(`(min-width: ${breakpoint}px)`).matches;
if (matched) {
this.config = Object.assign({}, this.config, this.defaults, this.breakpoints[breakpoint]);
this.config = assign({}, this.config, this.defaults, this.breakpoints[breakpoint]);
return true;
}
});
if (!matched) {
this.config = Object.assign(this.config, this.defaults);
this.config = assign(this.config, this.defaults);
}
},
restartTimer() {
Expand Down Expand Up @@ -402,10 +402,10 @@ export default {
if (this.config.vertical) {
const draggedSlides = Math.round(Math.abs(this.delta.y / this.slideHeight) + tolerance);
this.slideTo(this.currentSlide - Math.sign(this.delta.y) * draggedSlides);
this.slideTo(this.currentSlide - sign(this.delta.y) * draggedSlides);
}
if (!this.config.vertical) {
const direction = (this.config.rtl ? -1 : 1) * Math.sign(this.delta.x);
const direction = (this.config.rtl ? -1 : 1) * sign(this.delta.x);
const draggedSlides = Math.round(Math.abs(this.delta.x / this.slideWidth) + tolerance);
this.slideTo(this.currentSlide - direction * draggedSlides);
}
Expand Down Expand Up @@ -459,7 +459,7 @@ export default {
// get wheel direction
this.lastScrollTime = now();
const value = event.wheelDelta || -event.deltaY;
const delta = Math.sign(value);
const delta = sign(value);
if (delta === -1) {
this.slideNext();
}
Expand Down
39 changes: 39 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,42 @@ export function cloneSlide(vnode, indx) {

return h(tag, data, children);
}

// IE11 :)
function assignPoly(target) {
if (target === undefined || target === null) {
throw new TypeError('Cannot convert first argument to object');
}

var to = Object(target);
for (var i = 1; i < arguments.length; i++) {
var nextSource = arguments[i];
if (nextSource === undefined || nextSource === null) {
continue;
}
nextSource = Object(nextSource);

var keysArray = Object.keys(Object(nextSource));
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
var nextKey = keysArray[nextIndex];
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
if (desc !== undefined && desc.enumerable) {
to[nextKey] = nextSource[nextKey];
}
}
}

return to;
}

export const assign = Object.assign || assignPoly;

function signPoly(value) {
if (value < 0) {
return -1;
}

return value > 0 ? 1 : 0;
}

export const sign = Math.sign || signPoly;

0 comments on commit 26dda3e

Please sign in to comment.