Skip to content

Commit

Permalink
Stop sliding when only having 1 image? #158
Browse files Browse the repository at this point in the history
  • Loading branch information
jedrzejchalubek committed Aug 6, 2016
1 parent b6ff6ad commit db9d1fb
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 56 deletions.
16 changes: 6 additions & 10 deletions dist/css/glide.theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
background-color: transparent;
border: 2px solid rgba(255, 255, 255, 0.5);
border-radius: 4px;
-webkit-transition: border 300ms ease-in-out;
transition: border 300ms ease-in-out;
opacity: 1;
-webkit-transition: opacity 150ms ease, border 300ms ease-in-out;
transition: opacity 150ms ease, border 300ms ease-in-out;
}
.glide__arrow.disabled {
opacity: 0.33;
}
.glide__arrow:focus {
outline: none;
Expand Down Expand Up @@ -102,11 +106,3 @@
border: 2px solid white;
background-color: rgba(255, 255, 255, 0.5);
}
.glide--slider .glide__arrow {
opacity: 1;
-webkit-transition: opacity 150ms ease;
transition: opacity 150ms ease;
}
.glide--slider .glide__arrow.disabled {
opacity: 0.33;
}
2 changes: 1 addition & 1 deletion dist/css/glide.theme.min.css

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

74 changes: 65 additions & 9 deletions dist/glide.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var Animation = function(Glide, Core) {
* Animation constructor.
*/
function Animation() {

}

/**
Expand All @@ -37,6 +38,11 @@ var Animation = function(Glide, Core) {
* @return {self}
*/
Animation.prototype.make = function(displacement) {
// Do not run if we have only one slide.
if (! Core.Run.canProcess()) {
return Core.Arrows.disable();
}

// Parse displacement to integer before use.
offset = (typeof displacement !== 'undefined') ? parseInt(displacement) : 0;

Expand Down Expand Up @@ -226,6 +232,7 @@ var Api = function(Glide, Core) {
* Api constructor.
*/
function Api() {

}

/**
Expand Down Expand Up @@ -356,6 +363,8 @@ var Api = function(Glide, Core) {
Core.Arrows.unbind();
Core.Bullets.unbind();

Glide.destroyed = true;

delete Glide.slider;
delete Glide.track;
delete Glide.slides;
Expand Down Expand Up @@ -421,14 +430,18 @@ var Arrows = function(Glide, Core) {


/**
* Disable next/previous arrow.
* Disable next/previous arrow and enable another.
*
* @param {String} type
* @return {Void}
*/
Arrows.prototype.disable = function(type) {
var classes = Glide.options.classes;

if (!type) {
return this.disableBoth();
}

this.items.filter('.' + classes['arrow' + Core.Helper.capitalise(type)])
.unbind('click.glide touchstart.glide')
.addClass(classes.disabled)
Expand All @@ -439,6 +452,17 @@ var Arrows = function(Glide, Core) {
.removeClass(classes.disabled);
};

/**
* Disable both arrows.
*
* @return {Void}
*/
Arrows.prototype.disableBoth = function() {
this.items
.unbind('click.glide touchstart.glide')
.addClass(Glide.options.classes.disabled);
};


/**
* Show both arrows.
Expand Down Expand Up @@ -1049,12 +1073,14 @@ var Events = function(Glide, Core) {
Events.prototype.resize = function() {

$(window).on('resize.glide.' + Glide.uuid, Core.Helper.throttle(function() {
Core.Transition.jumping = true;
Glide.setup();
Core.Build.init();
Core.Run.make('=' + Glide.current, false);
Core.Run.play();
Core.Transition.jumping = false;
if(!Glide.destroyed) {
Core.Transition.jumping = true;
Glide.setup();
Core.Build.init();
Core.Run.make('=' + Glide.current, false);
Core.Run.play();
Core.Transition.jumping = false;
}
}, Glide.options.throttle));

};
Expand Down Expand Up @@ -1421,6 +1447,10 @@ var Run = function(Glide, Core) {

var that = this;

if (! this.canProcess()) {
return;
}

if (Glide.options.autoplay || this.running) {

if (typeof this.interval === 'undefined') {
Expand Down Expand Up @@ -1508,6 +1538,11 @@ var Run = function(Glide, Core) {
// Extract move steps.
this.steps = (move.substr(1)) ? move.substr(1) : 0;

// Do not run if we have only one slide.
if (! this.canProcess()) {
return this.stop();
}

// Stop autoplay until hoverpause is not set.
if (!Glide.options.hoverpause) {
this.pause();
Expand Down Expand Up @@ -1600,6 +1635,24 @@ var Run = function(Glide, Core) {

};

/**
* Stop slider from running.
*
* @return {void}
*/
Run.prototype.stop = function() {
this.pause();
};

/**
* Stop slider from running.
*
* @return {void}
*/
Run.prototype.canProcess = function() {
return Glide.slides.length > 1;
};

// Return class.
return new Run();

Expand Down Expand Up @@ -2043,6 +2096,9 @@ var Glide = function(element, options) {
this.collect();
this.setup();

// Mark the glide as not destroyed
this.destroyed = false;

// Call before init callback.
this.options.beforeInit({
index: this.current,
Expand All @@ -2060,11 +2116,11 @@ var Glide = function(element, options) {
Helper: Helper,
Translate: Translate,
Transition: Transition,
Arrows: Arrows,
Bullets: Bullets,
Run: Run,
Animation: Animation,
Clones: Clones,
Arrows: Arrows,
Bullets: Bullets,
Height: Height,
Build: Build,
Events: Events,
Expand Down
2 changes: 1 addition & 1 deletion dist/glide.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/glide.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@
</script>

</body>
</html>
</html>
4 changes: 2 additions & 2 deletions src/Glide.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ var Glide = function(element, options) {
Helper: Helper,
Translate: Translate,
Transition: Transition,
Arrows: Arrows,
Bullets: Bullets,
Run: Run,
Animation: Animation,
Clones: Clones,
Arrows: Arrows,
Bullets: Bullets,
Height: Height,
Build: Build,
Events: Events,
Expand Down
22 changes: 7 additions & 15 deletions src/less/glide.theme.less
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@
background-color: transparent;
border: 2px solid rgba(255, 255, 255, 0.5);
border-radius: 4px;
transition: border 300ms ease-in-out;
opacity: 1;
transition: opacity 150ms ease, border 300ms ease-in-out;

&.disabled {
opacity: 0.33;
}

&:focus { outline: none; }
&:hover { border-color: white; }
Expand Down Expand Up @@ -110,22 +115,9 @@
}


&--slider {

@{that}__arrow {
opacity: 1;
transition: opacity 150ms ease;

&.disabled {
opacity: 0.33;
}
}

}

&--slider {}

&--carousel {}


&--slideshow {}
}
6 changes: 6 additions & 0 deletions src/modules/Animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var Animation = function(Glide, Core) {
* Animation constructor.
*/
function Animation() {

}

/**
Expand All @@ -27,6 +28,11 @@ var Animation = function(Glide, Core) {
* @return {self}
*/
Animation.prototype.make = function(displacement) {
// Do not run if we have only one slide.
if (! Core.Run.canProcess()) {
return Core.Arrows.disable();
}

// Parse displacement to integer before use.
offset = (typeof displacement !== 'undefined') ? parseInt(displacement) : 0;

Expand Down
1 change: 1 addition & 0 deletions src/modules/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var Api = function(Glide, Core) {
* Api constructor.
*/
function Api() {

}

/**
Expand Down
17 changes: 16 additions & 1 deletion src/modules/Arrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ var Arrows = function(Glide, Core) {


/**
* Disable next/previous arrow.
* Disable next/previous arrow and enable another.
*
* @param {String} type
* @return {Void}
*/
Arrows.prototype.disable = function(type) {
var classes = Glide.options.classes;

if (!type) {
return this.disableBoth();
}

this.items.filter('.' + classes['arrow' + Core.Helper.capitalise(type)])
.unbind('click.glide touchstart.glide')
.addClass(classes.disabled)
Expand All @@ -47,6 +51,17 @@ var Arrows = function(Glide, Core) {
.removeClass(classes.disabled);
};

/**
* Disable both arrows.
*
* @return {Void}
*/
Arrows.prototype.disableBoth = function() {
this.items
.unbind('click.glide touchstart.glide')
.addClass(Glide.options.classes.disabled);
};


/**
* Show both arrows.
Expand Down
27 changes: 27 additions & 0 deletions src/modules/Run.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ var Run = function(Glide, Core) {

var that = this;

if (! this.canProcess()) {
return;
}

if (Glide.options.autoplay || this.running) {

if (typeof this.interval === 'undefined') {
Expand Down Expand Up @@ -119,6 +123,11 @@ var Run = function(Glide, Core) {
// Extract move steps.
this.steps = (move.substr(1)) ? move.substr(1) : 0;

// Do not run if we have only one slide.
if (! this.canProcess()) {
return this.stop();
}

// Stop autoplay until hoverpause is not set.
if (!Glide.options.hoverpause) {
this.pause();
Expand Down Expand Up @@ -211,6 +220,24 @@ var Run = function(Glide, Core) {

};

/**
* Stop slider from running.
*
* @return {void}
*/
Run.prototype.stop = function() {
this.pause();
};

/**
* Stop slider from running.
*
* @return {void}
*/
Run.prototype.canProcess = function() {
return Glide.slides.length > 1;
};

// Return class.
return new Run();

Expand Down
Loading

0 comments on commit db9d1fb

Please sign in to comment.