Skip to content

Commit

Permalink
Removed jQuery dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jdan committed Aug 31, 2013
1 parent 87bc4cf commit 320ca8f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 51 deletions.
3 changes: 1 addition & 2 deletions lib/cleaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function Cleaver(file) {

this.resources = {
style: 'default.css',
jquery: 'jquery.min.js',
navigation: 'navigation.js'
};

Expand Down Expand Up @@ -89,7 +88,7 @@ Cleaver.prototype._renderSlideshow = function () {
controls: putControls,
style: this.resources.loaded.style,
externalStyle: this.external.loaded.style,
jquery: this.resources.loaded.jquery,
// TODO: uglify navigation.js?
navigation: this.resources.loaded.navigation
};

Expand Down
4 changes: 0 additions & 4 deletions resources/jquery.min.js

This file was deleted.

86 changes: 42 additions & 44 deletions resources/navigation.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,55 @@
$(function() {
$('section').each(function(i, v) {
if (i)
$(v).hide();
else
$(v).addClass('active');
});

// go back a slide
var go_back = function() {
var curr = $('section.active');
if (!curr.prev().length) {
$('section:last').show().addClass('active');
} else {
curr.prev().show().addClass('active');
}
curr.hide().removeClass('active');
};

// go forward a slide
var go_forward = function() {
var curr = $('section.active');
if (!curr.next().length) {
$('section:first').show().addClass('active');
} else {
curr.next().show().addClass('active');
}
curr.hide().removeClass('active');
};
/**
* Takes the last slide and places it at the front.
*/
function goBack() {
var wrapper = document.querySelector('#wrapper');
var lastSlide = wrapper.lastChild;
while (lastSlide != null && lastSlide.nodeType !== 1) {
lastSlide = lastSlide.previousSibling;
}

wrapper.removeChild(lastSlide);
wrapper.insertBefore(lastSlide, wrapper.firstChild);
}

/**
* Takes the first slide and places it at the end.
*/
function goForward() {
var wrapper = document.querySelector('#wrapper');
var firstSlide = wrapper.firstChild;
while (firstSlide != null && firstSlide.nodeType !== 1) {
firstSlide = firstSlide.nextSibling;
}

wrapper.removeChild(firstSlide);
wrapper.appendChild(firstSlide);
}

$(document).on('keydown', function(e) {
window.onload = function () {

document.onkeydown = function (e) {
var kc = e.keyCode;

// left, down, H, J, backspace - BACK
// up, right, K, L, space, enter - FORWARD
if (kc == 37 || kc == 40 || kc == 8 || kc == 72 || kc == 74) {
go_back();
goBack();
} else if (kc == 38 || kc == 39 || kc == 13 || kc == 32 || kc == 75 || kc == 76) {
go_forward();
goForward();
}
}

});

if ($('#next') && $('#prev')) {
// clicking the next box
$('#next').on('click', function(e) {
if (document.querySelector('#next') && document.querySelector('#prev')) {
document.querySelector('#next').onclick = function (e) {
e.preventDefault();
go_forward();
});
goForward();
}

// clicking the prev box
$('#prev').on('click', function(e) {
document.querySelector('#prev').onclick = function (e) {
e.preventDefault();
go_back();
});
goBack();
}
}
});

}
1 change: 0 additions & 1 deletion templates/layout.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
</div>
{{/controls}}
<script type="text/javascript">
{{{jquery}}}
{{{navigation}}}
</script>
</body>
Expand Down

0 comments on commit 320ca8f

Please sign in to comment.