Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
5115ed3
Merge branches 'require-shim', 'standard-event-functions' and 'variab…
stutrek Jan 24, 2013
c5a0ebe
Merge branch 'standard-event-functions'
stutrek Jan 24, 2013
5a01e68
Merge branch 'require-shim'
stutrek Jan 24, 2013
b91dcca
change "page" to "tile"
stutrek Jan 24, 2013
47339fc
more "page" to "tile"
stutrek Jan 24, 2013
ad7d837
next/previous page buttons
stutrek Jan 24, 2013
764b420
added tilesPerPage to tests
stutrek Jan 24, 2013
315f018
made tossing automatically turn on for mutiple tiles per page
stutrek Jan 24, 2013
84d70cc
renamed items slides
stutrek Jan 25, 2013
bb49a0e
renamed thin-frames to thin-slides
stutrek Jan 25, 2013
a05a5b8
put position: relative on the sliding element
stutrek Jan 25, 2013
ba8e4d3
added slider.next/previous/nextPage/previousPage
stutrek Feb 5, 2013
9273961
added autoplay extension
stutrek Feb 5, 2013
5e565b2
added getSlideData method to lectirc, made autoplay use it to get dur…
stutrek Feb 5, 2013
ab3bd42
clear timeout when landing on a new frame
stutrek Feb 5, 2013
a3f23ea
clear timeout when starting transition
stutrek Feb 5, 2013
6eb29f5
navigation dot select the appropriate dot when created
stutrek Feb 5, 2013
7baf080
simple looping
stutrek Feb 5, 2013
65d7572
added XofY extension
stutrek Feb 6, 2013
6f2a1f0
typo
stutrek Feb 6, 2013
578f144
added automatic lazy loading
stutrek Feb 6, 2013
5c127e3
sometimes `this` is the right thing.
stutrek Feb 6, 2013
1359e69
clicks on next/prev buttons still animate when they are inside the sl…
stutrek Feb 13, 2013
d7f4ae6
made lectric advance slides if you swipe more than 20px instead of 50%
stutrek Feb 13, 2013
9fb126f
auto play stops when you start a touch
stutrek Feb 13, 2013
8addf08
check for left margins too
stutrek Mar 4, 2013
d6affb9
fixed bug getting CSS values when they have no numbers.
stutrek Mar 5, 2013
2d25f12
changed bind to on
stutrek Mar 5, 2013
bc36ba9
adding enable and disable functions for touch
Mar 7, 2013
d51dabb
comments on new functions
stutrek Mar 8, 2013
8e649c9
changed bind to on and unbind to off
stutrek Mar 8, 2013
3fe38cd
added events
stutrek Mar 8, 2013
bcb940a
lectric allows passing arguments to events, moved slide change events…
stutrek Mar 8, 2013
b08ad13
Frankenslide
stutrek Mar 8, 2013
60d0553
more renaming
stutrek Mar 15, 2013
36000de
autoplay now has a default duration of 12 seconds
stutrek Mar 15, 2013
9b67df1
added itemSelector option, element option that makes it work without …
stutrek Mar 15, 2013
a7e7251
fixes to last commits
stutrek Mar 15, 2013
7cadcd5
Frankenslide is responsive!
stutrek Mar 19, 2013
e65d895
use percentages instead of a resize listener, much better.
stutrek Mar 19, 2013
56be394
use pixel sizes when animating, percent sizes when just hanging out.
stutrek Mar 20, 2013
0712322
currentSlide never goes below zero or above the number of slides minu…
stutrek Mar 20, 2013
75c3178
navigationDots are now responsive too.
stutrek Mar 22, 2013
563aa45
reverted responsive changes that used percentages
stutrek Mar 22, 2013
6226b4f
fixed a bug where it would prevent scrolling
stutrek Mar 22, 2013
92c034c
no hiccups when changing frames
stutrek Mar 25, 2013
fb7c495
event fixes for nav dots
stutrek Mar 25, 2013
ba473aa
slow swipes throw events
stutrek Mar 26, 2013
177b636
changes the order of events calls on slide transitions
stevekoller Mar 27, 2013
2ecc17c
don't mess with css when you don't have to
stutrek Mar 27, 2013
24892bc
remove console.log
stutrek Mar 27, 2013
f9d751e
when tossing, limit x bounds after rounding to the nearest frame.
stutrek Apr 2, 2013
16d42b4
Frankenslide doesn't round tosses to the nearest frame unless only on…
stutrek Apr 3, 2013
e45fb22
frankenslide throws events for next/prev slides
stutrek Apr 22, 2013
ef57d49
don't cancel clicks when they're not moves
stutrek Apr 22, 2013
4b7d366
fixed bug in last commits when sliding slowly
stutrek Apr 22, 2013
4c039db
linting
stutrek Apr 30, 2013
ec1819f
fixed tests
stutrek Apr 30, 2013
82fe176
size the container element to the size of the content
stutrek Apr 30, 2013
06192b3
fix easing on touch
stutrek May 2, 2013
1f34abe
navigation dots get a count class
stutrek May 2, 2013
ef87703
reorganized navb dot code, fixed bug that left dot count classes on c…
stutrek May 8, 2013
0e9179a
adding controls extension for hiding / showing controls at start and …
May 8, 2013
b1c0882
adding option to frankenslide for "snapToNearest" in touchSlider
May 8, 2013
e3b9a29
made snapToNearest use the same codepath as not snapping to nearest.
stutrek May 9, 2013
20bb166
always set currentSlide to a positive number
stutrek May 9, 2013
e66c0a3
nab dots highlight when you're at a fractional slide
stutrek May 9, 2013
62ce358
remove slide start events because they can be too slow, increased ani…
stutrek May 9, 2013
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
44 changes: 22 additions & 22 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
# Lectric Slider
# Frankenslide slider

Lectric is a JavaScript slider that is touch-enabled and takes advantage of hardware acceleration. It looks awesome on Apple touch devices. You can see an early version of this software implemented on [mckinney.com](http://mckinney.com).

It's Electric!
Frankenslide is a JavaScript slider that is touch-enabled and takes advantage of hardware acceleration. It looks awesome on Apple touch devices. You can see an early version of this software implemented on [mckinney.com](http://mckinney.com).

**Requires:** [jQuery](http://github.com/jquery/jquery)

## Installation

Put this in your `<head>`:

<link href="/path/to/css/lectric.css" rel="stylesheet" type="text/css" media="screen">
<link href="/path/to/css/frankenslide.css" rel="stylesheet" type="text/css" media="screen">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="/path/to/js/lectric.js" type="text/javascript"></script>
<script src="/path/to/js/frankenslide.js" type="text/javascript"></script>

## Usage

HTML:

<div id="slider">
<div class="item">Page 1</div>
<div class="item">Page 2</div>
<div class="item">Page 3</div>
<div class="item">Page 4</div>
<div class="item">Slide 1</div>
<div class="item">Slide 2</div>
<div class="item">Slide 3</div>
<div class="item">Slide 4</div>
</div>

JavaScript:

var slider = new Lectric();
var slider = new Frankenslide();
slider.init('#slider');

## Optional Parameters

You can specify a few extra parameters when you call the `init` method. Those include:

- `next` *(selector)*: Next button
- `previous` *(selector)*: Previous button
- `next` *(selector)*: Next slide button
- `previous` *(selector)*: Previous slide button
- `nextPage` *(selector)*: Next page button. This will advance as many slides as fit in the viewport.
- `previousPage` *(selector)*: Previous tile button. This will go back as many slides as fit in the viewport.
- `limitLeft` *(boolean)*: Prohibits the slider from moving left
- `limitRight` *(boolean)*: Prohibits the slider from moving right
- `itemClassName` *(string)*: Class name of the individual pages of the slider (defaults to "item")
- `itemClassName` *(string)*: Class name of the individual slides of the slider (defaults to "item")
- `itemWrapperClassName` *(string)*: Class name of the container that wraps all items (defaults to "items")
- `animateEasing` *(string)*: A string indicating which easing function to use for the transition (non-mobile only).
- `animateDuration` *(integer or string)*: A string (e.g. "fast" or "slow") or number (in milliseconds) determining how long a slide animation will run.
Expand All @@ -49,36 +49,36 @@ You can specify a few extra parameters when you call the `init` method. Those in

For example, let's provide a slider with next/previous buttons:

var slider = new Lectric();
var slider = new frankenslide();
slider.init('#slider', {next: '.next', previous: '.previous'});

## Hook System

Lectric is designed to give you a great deal of visibility of its insides. To help you extend Lectric, we've provided a simple hook system for you to tap into. Hooks have specific names and are invoked at specific times in the execution of the slider's timeline.
Frankenslide is designed to give you a great deal of visibility of its insides. To help you extend frankenslide, we've provided a simple hook system for you to tap into. Hooks have specific names and are invoked at specific times in the execution of the slider's timeline.

Subscribing to a hook looks something like this:

slider.subscribe('slide', function(s, event) {
slider.on('move', function(s, event) {
console.log('We just moved! Our current position is:' + s.position.x);
});

Unsubscribing from a hook looks like this:

var handler = slider.subscribe('slide', function(s, event) {
var handler = slider.on('move', function(s, event) {
console.log('We just moved! Our current position is:' + s.position.x);
});
slider.unsubscribe('slide', handler); // Unsubscribe handler from slider
slider.off('move', handler); // Unsubscribe handler from slider

The hooks available to you are:

- `init`: Triggered when after the slider is initialized
- `init`: Triggered after the slider is initialized
- `start`: Triggered when the user puts her finger down on the slider
- `slide`: Triggered when the position of the slider is moved
- `move`: Triggered when the position of the slider is moved
- `firstSlide`: Triggered the first time the position of the slider is moved (for a single touch event)
- `end`: Triggered when the user lifts her finger off of the slider
- `endNoSlide`: Triggered when the user lifts her finger off of the slider and did not move the slider
- `animationEnd`: Triggered when the slide animation has completed
- `nextButton`: Triggered when the next button is pressed
- `previousButton`: Triggered when the previous button is pressed

The callback function that you provide the `subscribe` function will pass your callback two parameters: slider controller instance you are manipulating and the jQuery event object that was triggered. Having a reference to the controller object will allow you to augment the behaviour of the slider itself.
The callback function that you provide the `on` function will pass your callback two parameters: slider controller instance you are manipulating and the jQuery event object that was triggered. Having a reference to the controller object will allow you to augment the behaviour of the slider itself.
26 changes: 13 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ require 'jslint'
require 'webrick'

prefix = File.dirname(__FILE__)
lectric = File.join(prefix, 'js', 'lectric.js')
lectric_min = File.join(prefix, 'js', 'lectric.min.js')
frankenslide = File.join(prefix, 'js', 'frankenslide.js')
frankenslide_min = File.join(prefix, 'js', 'frankenslide.min.js')
version = File.join(prefix, 'VERSION')

task :default => :build

desc "Build and minify Lectric."
desc "Build and minify frankenslide."
task :build => [:lint, :stamp_version, :minify] do
puts "Lectric build complete."
puts "frankenslide build complete."
end

desc "Stamp the library with the current version"
task :stamp_version => :version do
contents = File.read(lectric)
file = File.open(lectric, 'w')
file.puts contents.gsub(/(Lectric v)([\d\w\.-]+)/, "\\1#{@version}")
contents = File.read(frankenslide)
file = File.open(frankenslide, 'w')
file.puts contents.gsub(/(frankenslide v)([\d\w\.-]+)/, "\\1#{@version}")
file.close
end

Expand All @@ -35,22 +35,22 @@ end

desc "Compress the library using Google's Closure Compiler"
task :minify => :version do
puts "Minifying Lectric..."
puts "Minifying frankenslide..."
comments = <<-EOS
/*!
* Lectric v#{@version}
* http://github.com/mckinney/lectric
* frankenslide v#{@version}
* http://github.com/mckinney/frankenslide
*
* Copyright 2011, McKinney
* Licensed under the MIT license.
* http://github.com/mckinney/lectric/blob/master/LICENSE
* http://github.com/mckinney/frankenslide/blob/master/LICENSE
*
* Author: Brett C. Buddin
*/
EOS

file = File.open(lectric_min, 'w')
file.puts comments + Closure::Compiler.new.compile(File.open(lectric, 'r'))
file = File.open(frankenslide_min, 'w')
file.puts comments + Closure::Compiler.new.compile(File.open(frankenslide, 'r'))
file.close
end

Expand Down
10 changes: 5 additions & 5 deletions css/lectric.css → css/frankenslide.css
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
.lectric-slider,.lectric-slider .items {
.frankenslide-slider,.frankenslide-slider .items {
position: relative;
}
.lectric-slider .items {
.frankenslide-slider .items {
left: 0;
width: 100000px;
}
.lectric-slider-touch {
.frankenslide-slider-touch {
-webkit-transform: translate3d(0, 0, 0);
}
.lectric-slider-touch .items {
.frankenslide-slider-touch .items {
-webkit-transition-timing-function: cubic-bezier(0, 0, 0.2, 1);
-webkit-font-smoothing: antialiased;
}
.lectric-slider-touch .item {
.frankenslide-slider-touch .item {
-webkit-transform: translate3d(0, 0, 0);
}
6 changes: 3 additions & 3 deletions examples/autoplay.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>

<link href="../css/lectric.css" rel="stylesheet" media="screen" type="text/css">
<script src="../js/lectric.js" type="text/javascript"></script>
<link href="../css/frankenslide.css" rel="stylesheet" media="screen" type="text/css">
<script src="../js/frankenslide.js" type="text/javascript"></script>

<style>
* {
Expand Down Expand Up @@ -86,7 +86,7 @@
<script type="text/javascript">
$(function() {
// Initialize the slider
var slider = new Lectric();
var slider = new frankenslide();
slider.init('#slider', {next: '.next', previous: '.previous'});

var count = 0;
Expand Down
8 changes: 4 additions & 4 deletions examples/scrubber.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>

<link href="../css/lectric.css" rel="stylesheet" media="screen" type="text/css">
<script src="../js/lectric.js" type="text/javascript"></script>
<link href="../css/frankenslide.css" rel="stylesheet" media="screen" type="text/css">
<script src="../js/frankenslide.js" type="text/javascript"></script>

<style>
* {
Expand Down Expand Up @@ -86,11 +86,11 @@
<script type="text/javascript">
$(function() {
// Initialize the slider
var slider = new Lectric();
var slider = new frankenslide();
slider.init('#slider', {next: '.next', previous: '.previous'});

// Initialize the scrubber
var scrubber = new Lectric();
var scrubber = new frankenslide();
scrubber.init('#scrubber', {reverse: true});

// Get the relative scale between the two sliders
Expand Down
6 changes: 3 additions & 3 deletions examples/simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>

<link href="../css/lectric.css" rel="stylesheet" media="screen" type="text/css">
<script src="../js/lectric.js" type="text/javascript"></script>
<link href="../css/frankenslide.css" rel="stylesheet" media="screen" type="text/css">
<script src="../js/frankenslide.js" type="text/javascript"></script>

<style>
#slider {
Expand Down Expand Up @@ -46,7 +46,7 @@
<script type="text/javascript">
$(function() {
// Initialize the slider
var slider = new Lectric();
var slider = new frankenslide();
slider.init('#slider', {next: '.next', previous: '.previous'});

// Keyboard shortcuts for left and right arrows
Expand Down
83 changes: 83 additions & 0 deletions examples/thin-slides.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!doctype html>
<html>
<head>
<title>Simple</title>
<meta name="viewport" content="width=600, initial-scale=1.0">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>

<link href="../css/frankenslide.css" rel="stylesheet" media="screen" type="text/css">
<script src="../js/frankenslide.js" type="text/javascript"></script>

<style>
#slider {
height: 300px;
width: 500px;
margin-bottom: 1em;
}
#slider .item {
height: 300px;
width: 100px;
margin-right: 10px;
padding: 10px;
background-color: #ccc;
}
.next,.previous, .nextPage, .previousPage {
display: block;
padding: 1em;
float: left;
color: #fff;
background-color: #000;
margin-right: 0.5em;
}
</style>
</head>
<body>
<div id="slider">
<div class="item">Hello world 1</div>
<div class="item">Hello world 2</div>
<div class="item">Hello world 3</div>
<div class="item">Hello world 4</div>
<div class="item">Hello world 5</div>
<div class="item">Hello world 6</div>
<div class="item">Hello world 7</div>
<div class="item">Hello world 8</div>
<div class="item">Hello world 9</div>
<div class="item">Hello world 10</div>
<div class="item">Hello world 11</div>
<div class="item">Hello world 12</div>
<div class="item">Hello world 13</div>
<div class="item">Hello world 14</div>
<div class="item">Hello world 15</div>
<div class="item">Hello world 16</div>
<div class="item">Hello world 17</div>
<div class="item">Hello world 18</div>
</div>

<a href="" class="previous">Previous</a>
<a href="" class="next">Next</a>
<a href="" class="previousPage">Previous Page</a>
<a href="" class="nextPage">Next Page</a>

<script type="text/javascript">
$(function() {
// Initialize the slider
var slider = new frankenslide();
slider.init('#slider', {next: '.next', previous: '.previous', nextPage: '.nextPage', previousPage: '.previousPage'});

// Keyboard shortcuts for left and right arrows
$(document).keydown(function(e) {
if (e.keyCode === 39) {
e.preventDefault();
var previous = slider.page();
slider.to(previous + 1);
} else if (e.keyCode === 37) {
e.preventDefault();
var previous = slider.page();
slider.to(previous - 1);
}
});
});
</script>
</body>
</html>
47 changes: 47 additions & 0 deletions extensions/XofY.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*!
* Autoplay for frankenslide
* Copyright 2013 Stu Kabakoff
* Licensed under the MIT license.
*/
(function( factory ) {
//AMD
if(typeof define === 'function' && define.amd) {
define(['jquery'], factory);

//NODE
} else if(typeof module === 'object' && module.exports) {
var jquery = require('jquery');
module.exports = factory(jquery);

//GLOBAL
} else {
window.frankenslideXofY = factory(jQuery);
}
})(function($) {

function XofY() {
var self = this;

this.update = function() {
var slideIndex = self.slider.currentSlide+1;
var totalSlides = self.slider.slideCount();
var newText = self.beforeText+' '+slideIndex+' '+self.of+' '+totalSlides+' '+self.afterText;
self.$container.html( $.trim(newText) );
}
}

XofY.prototype = {
of: 'of',
beforeText: '',
afterText: '',
init: function( container, slider ) {
this.$container = $(container);
this.slider = slider;

slider.on('animationEnd', this.update);
this.update()
}
};

return XofY;
});
Loading