Skip to content

Commit 13970f8

Browse files
committed
Removed Jquery as a dependancy
1 parent 3c5eff6 commit 13970f8

File tree

6 files changed

+43
-25
lines changed

6 files changed

+43
-25
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on and off the page.
99
# Dependencies
1010

1111
* Barba
12-
* Jquery
1312

1413
# Installation
1514

@@ -49,7 +48,6 @@ the ```data-transition``` attribute on each element that you wish to animate.
4948
</div>
5049
</div>
5150
52-
<script src="jquery.min.js" type="text/javascript"></script>
5351
<script src="barba.min.js" type="text/javascript"></script>
5452
<script src="barba.transitions.min.js" type="text/javascript"></script>
5553
<script src="main.js" type="text/javascript"></script>
@@ -69,9 +67,9 @@ the ```data-transition``` attribute on each element that you wish to animate.
6967
### JS
7068

7169
```
72-
$(function(){
70+
window.onload = function() {
7371
Barba.Pjax.start();
74-
});
72+
}
7573
```
7674

7775
# Setting a custom transition time

example/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
</div>
2222
</div>
2323

24-
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js" type="text/javascript"></script>
2524
<script src="https://rawgit.com/luruke/barba.js/master/dist/barba.min.js" type="text/javascript"></script>
2625
<script src="temp/barba.transitions.min.js" type="text/javascript"></script>
2726
<script src="main.js" type="text/javascript"></script>

example/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
$(function(){
1+
window.onload = function() {
22
Barba.Pjax.start();
3-
});
3+
}

example/post.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ <h2>My Post Title</h2>
2929
</div>
3030
</div>
3131

32-
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js" type="text/javascript"></script>
3332
<script src="https://rawgit.com/luruke/barba.js/master/dist/barba.min.js" type="text/javascript"></script>
3433
<script src="temp/barba.transitions.min.js" type="text/javascript"></script>
3534
<script src="main.js" type="text/javascript"></script>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "barba-transitions",
3-
"version": "1.0.4",
3+
"version": "1.1.0",
44
"description": "An addon to BarbaJS which makes it really easy to use css transitions for page transitions.",
55
"main": "barba.transitions.js",
66
"directories": {

src/transition.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var Transition = Barba.BaseTransition.extend({
99

1010
runTransition: function() {
1111

12-
$('body').css('overflow', 'hidden');
12+
document.body.style.overflow = 'hidden';
1313

1414
////////////////////////////
1515
// Setup
@@ -21,22 +21,40 @@ var Transition = Barba.BaseTransition.extend({
2121
////////////////////////////
2222

2323
// Set the animation time on all elements
24-
var allAnimationElements = $('[' + transitionSelector + ']');
25-
$.each(allAnimationElements, function() {
26-
$(this).css('animation-duration', transitionLengthSeconds).css('animation-delay', transitionLengthSeconds).css('animation-name', $(this).data('transition')).css('animation-fill-mode', 'forwards');
27-
})
24+
var allAnimationElements = document.querySelectorAll('[' + transitionSelector + ']');
25+
for (var i = 0; i < allAnimationElements.length; i++) {
26+
element = allAnimationElements[i];
27+
28+
// Set styles
29+
element.style.animationDuration = transitionLengthSeconds;
30+
element.style.animationDelay = transitionLengthSeconds;
31+
element.style.animationName = element.dataset.transition;
32+
element.style.animationFillMode = 'forwards';
33+
}
2834

2935
// Get all old elements with transitions
30-
var oldElements = $(this.oldContainer).find('[' + transitionSelector + ']');
31-
$.each(oldElements, function() {
32-
$(this).removeAttr('style');
33-
});
36+
var oldElements = this.oldContainer.querySelectorAll('[' + transitionSelector + ']');
37+
for (var i = 0; i < oldElements.length; i++) {
38+
element = oldElements[i];
3439

40+
// Remove style tag
41+
element.removeAttribute('style');
42+
}
43+
3544
// Trigger out transitions
3645
setTimeout(function(){
37-
$.each(oldElements, function() {
38-
$(this).css('animation-duration', transitionLengthSeconds).css('animation-delay', transitionLengthSeconds).css('animation-name', $(this).data('transition')).css('animation-direction', 'alternate-reverse').css('animation-delay', '0s').css('animation-fill-mode', 'forwards');
39-
});
46+
47+
for (var i = 0; i < oldElements.length; i++) {
48+
element = oldElements[i];
49+
50+
// Set styles
51+
element.style.animationDuration = transitionLengthSeconds;
52+
element.style.animationDelay = '0s';
53+
element.style.animationName = element.dataset.transition;
54+
element.style.animationFillMode = 'forwards';
55+
element.style.animationDirection = 'alternate-reverse';
56+
}
57+
4058
}, transitionTimeout);
4159

4260
var x = this;
@@ -45,11 +63,14 @@ var Transition = Barba.BaseTransition.extend({
4563
// Remove old container and add new one
4664
x.oldContainer.style.visibility = 'hidden';
4765
x.newContainer.style.visibility = 'visible';
66+
67+
// Remove style tag at the end of the animation
4868
setTimeout(function(){
49-
$('body').css('overflow', 'visible');
50-
$.each(allAnimationElements, function() {
51-
$(this).removeAttr('style');
52-
});
69+
document.body.style.overflow = 'visible';
70+
for (var i = 0; i < allAnimationElements.length; i++) {
71+
element = allAnimationElements[i];
72+
element.removeAttribute('style');
73+
}
5374
}, transitionLength);
5475

5576
// Scroll to top
@@ -60,6 +81,7 @@ var Transition = Barba.BaseTransition.extend({
6081

6182
}
6283

84+
// Mark as done
6385
setTimeout(function(){
6486
done(x);
6587
}, transitionLength + transitionTimeout);

0 commit comments

Comments
 (0)