Skip to content

Commit

Permalink
Merge pull request #2 from xysense/master
Browse files Browse the repository at this point in the history
expose current frame and playing state and fixes
  • Loading branch information
nterms authored Nov 18, 2016
2 parents 99da6a9 + c1ea9b9 commit 75f2a8b
Showing 1 changed file with 53 additions and 28 deletions.
81 changes: 53 additions & 28 deletions src/jquery.imgplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
var playTimer = null;

plugin.settings = {};

plugin.controls = {
play: null,
pause: null,
Expand Down Expand Up @@ -63,16 +63,26 @@
resize();
};

plugin.isPlaying = function() {
return playing;
};

plugin.getCurrentFrame = function() {
return index;
};

plugin.play = function() {
playing = true;
direction = 'forward';
drawFrame();

plugin.controls.play.addClass('active');
plugin.controls.stop.removeClass('active');
plugin.controls.pause.removeClass('active');
plugin.controls.rewind.removeClass('active');
plugin.controls.forward.removeClass('active');
if (plugin.settings.controls) {
plugin.controls.play.addClass('active');
plugin.controls.stop.removeClass('active');
plugin.controls.pause.removeClass('active');
plugin.controls.rewind.removeClass('active');
plugin.controls.forward.removeClass('active');
}
};

plugin.pause = function() {
Expand All @@ -81,22 +91,26 @@
clearTimeout(playTimer);
}

plugin.controls.pause.addClass('active');
plugin.controls.play.removeClass('active');
plugin.controls.stop.removeClass('active');
plugin.controls.rewind.removeClass('active');
plugin.controls.forward.removeClass('active');
if (plugin.settings.controls) {
plugin.controls.pause.addClass('active');
plugin.controls.play.removeClass('active');
plugin.controls.stop.removeClass('active');
plugin.controls.rewind.removeClass('active');
plugin.controls.forward.removeClass('active');
}
};

plugin.stop = function() {
playing = false;
index = 0;

plugin.controls.stop.addClass('active');
plugin.controls.play.removeClass('active');
plugin.controls.pause.removeClass('active');
plugin.controls.rewind.removeClass('active');
plugin.controls.forward.removeClass('active');
if (plugin.settings.controls) {
plugin.controls.stop.addClass('active');
plugin.controls.play.removeClass('active');
plugin.controls.pause.removeClass('active');
plugin.controls.rewind.removeClass('active');
plugin.controls.forward.removeClass('active');
}
};

plugin.rewind = function(frames) {
Expand All @@ -107,11 +121,13 @@
drawFrame();
}

plugin.controls.rewind.addClass('active');
plugin.controls.forward.removeClass('active');
plugin.controls.stop.removeClass('active');
plugin.controls.play.removeClass('active');
plugin.controls.pause.removeClass('active');
if (plugin.settings.controls) {
plugin.controls.rewind.addClass('active');
plugin.controls.forward.removeClass('active');
plugin.controls.stop.removeClass('active');
plugin.controls.play.removeClass('active');
plugin.controls.pause.removeClass('active');
}
};

plugin.forward = function(frames) {
Expand All @@ -122,11 +138,13 @@
drawFrame();
}

plugin.controls.forward.addClass('active');
plugin.controls.rewind.removeClass('active');
plugin.controls.stop.removeClass('active');
plugin.controls.play.removeClass('active');
plugin.controls.pause.removeClass('active');
if (plugin.settings.controls) {
plugin.controls.forward.addClass('active');
plugin.controls.rewind.removeClass('active');
plugin.controls.stop.removeClass('active');
plugin.controls.play.removeClass('active');
plugin.controls.pause.removeClass('active');
}
};

plugin.fastRewind = function(rate) {
Expand Down Expand Up @@ -188,7 +206,9 @@
} else if (el.webkitRequestFullscreen) {
el.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
plugin.controls.fullscreen.addClass('active');
if (plugin.settings.controls) {
plugin.controls.fullscreen.addClass('active');
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
Expand All @@ -199,7 +219,9 @@
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
plugin.controls.fullscreen.removeClass('active');
if (plugin.settings.controls) {
plugin.controls.fullscreen.removeClass('active');
}
}

setTimeout(function() {
Expand All @@ -208,6 +230,9 @@
};

var initControls = function() {
if (!plugin.settings.controls) {
return;
}
if($el.find('.imgplay-controls').length == 0) {
var controls = $('<div class="imgplay-controls"></div>');
var progress = $('<div class="imgplay-progress">');
Expand Down

0 comments on commit 75f2a8b

Please sign in to comment.