Skip to content

Commit

Permalink
Update bgzy.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ninocamdzic committed Feb 21, 2016
1 parent 7f0cdde commit 03fa01e
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions bgzy.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@
}
}

function _getImageUrl(image) {
if(image instanceof Array) {
return image[0];
}

return image;
}

function _getImageFx(image) {
if(image instanceof Array) {
return image[1];
}

return self.conf.fx;
}

function _startTicker() {
tickerElement.style.opacity = "1.0";
tickerElement.style.transitionDuration = self.conf.timeout + "ms";
Expand Down Expand Up @@ -101,16 +117,9 @@
// Preload images before playing.
for(var i = 0; i < images.length; i++) {
var img = document.createElement("img"),
url = images[i];
url = _getImageUrl(images[i]);

img.addEventListener("load", cb);

// If we are dealing with an array we retrieve the image url from
// the first element of the array.
if(url instanceof Array) {
url = images[i][0];
}

img.src = url;
}
}
Expand All @@ -130,8 +139,12 @@

// Determine the background index of the loaded image.
for(var i = 0; i < images.length; i++) {
if(this.src.indexOf(images[i])) {
var imageUrl = _getImageUrl(images[i]);

if(this.src.indexOf(imageUrl) > -1) {
console.log(this.src + " - " + imageUrl);
backgroundImageIndex = i;
console.log("Found at: " + i);
break;
}
}
Expand Down Expand Up @@ -169,17 +182,10 @@

var activeElement = elements[activeElementIndex],
nextElement = elements[nextElementIndex],
image = images[backgroundImageIndex],
imageFx = self.conf.fx;

// If we are dealing with an array we retrieve the image url from the
// first array element and the used animation from the second.
if(image instanceof Array) {
image = images[backgroundImageIndex][0];
imageFx = images[currentbackgroundImageIndex][1];
}
imageUrl = _getImageUrl(images[backgroundImageIndex]),
imageFx = _getImageFx(images[currentbackgroundImageIndex]);

nextElement.style.backgroundImage = "url(" + image + ")";
nextElement.style.backgroundImage = "url(" + imageUrl + ")";
fx = self.fx[imageFx](activeElement, nextElement, self.conf);
backgroundElementTransitionEndCount = 0;
fx.run();
Expand Down

0 comments on commit 03fa01e

Please sign in to comment.