-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactionslide.min.js
27 lines (27 loc) · 5.28 KB
/
actionslide.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
* ----------------------------- ActionSlide -------------------------------------
* Simple animation library for action movie credits in JavaScript, supporting
* all major browsers - IE9+, Firefox, Safari, Chrome and Opera
* Prerequisite: JQuery
*
* Copyright (c) 2013 - 2014 Liron Aichel, work.liron@gmail.com
*
* Licensed under MIT-style license:
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
var ActionSlide=(function(c){function a(d,e){this.screen=d;this.slides=[];this.params=e;this.isPlaying=false;this.addSlide=function(f){if(f instanceof b){this.slides.push(f)}};this.preloadImageSlides=function(){for(var f in this.slides){if(typeof(this.slides[f].imageURL)!=="undefined"){c("<img/>")[0].src=this.slides[f].imageURL}}};this.events={play:"playing",end:"ended",slideIn:"slideIn",slideOut:"slideOut"}}a.prototype.play=function(){var g=this;c(g).trigger(g.events.play);g.isPlaying=true;if(g.params.animateBackground){var f=function(){var h=Math.floor((Math.random()*(g.screen.width()/2))+(g.screen.width()/5));var j=Math.floor((Math.random()*1000)+500);var m=Math.floor((Math.random()*g.screen.height())+1);var l=Math.floor((Math.random()*2)+1)==1?"ltr":"rtl";var k;var i=c("<div class='actionslide-bglines' style='position: absolute; top: "+m+"px; width: "+h+"px;'></div>");g.screen.prepend(i);if(l=="ltr"){i.css("left","-"+h+"px");k={left:g.screen.width()+50}}else{i.css("right","-"+h+"px");k={right:g.screen.width()+50}}i.animate(k).promise().done(function(){i.remove()});if(g.isPlaying){setTimeout(f,j)}};f()}g.preloadImageSlides();var d=c.Deferred();var e=function(n){var m=g.slides[n];var o=m.render();var p=c.Deferred();if(m.params.align){o.css("text-align",m.params.align)}o.css("opacity","0");g.screen.append(o);var i=(g.screen.width()/2)-(o.width()/2);o.css("top",(g.screen.height()/2-o.height()/2)+"px");if(m.params.animation=="fade"){o.css("left",i+"px")}if(m.params.direction=="rtl"){o.css("right","0px")}if(!m.params.easing){m.params.easing="linear"}var k=function(){var r;switch(m.params.animation){case"fade":r={opacity:0};break;default:if(m.params.direction=="rtl"){r={right:g.screen.width(),opacity:0}}else{r={left:g.screen.width(),opacity:0}}break}var q=o.animate(r,{duration:700,easing:m.params.easing}).promise();q.done(function(){c(g).trigger(g.events.slideOut,[n]);o.remove();p.resolve()})};var l=function(){var q;switch(m.params.animation){case"fade":q={opacity:1};break;default:if(m.params.direction=="rtl"){q={right:i-o.width()}}else{q={left:i-o.width()}}break}var r=o.animate(q,{duration:m.pauseDuration,easing:m.params.easing}).promise();r.done(k)};var h;switch(m.params.animation){case"fade":h={opacity:1};break;default:if(m.params.direction=="rtl"){h={right:i,opacity:1}}else{h={left:i,opacity:1}}break}c(g).trigger(g.events.slideIn,[n]);var j=o.animate(h,{duration:700,easing:m.params.easing}).promise();j.done(l);p.done(function(){if(n<g.slides.length-1){n++;e(n)}else{d.resolve();g.isPlaying=false;c(g).trigger(g.events.end)}})};e(0);return d};function b(g,e,d,f){this.title=g;this.html=e;this.pauseDuration=d;this.params=f;this.template='<div class="actionslide-container"> <div class="actionslide-title"> </div> <div class="actionslide-content"> </div> </div>'}b.prototype.render=function(){var d=c(this.template);d.find(".actionslide-title").html(this.title);d.find(".actionslide-content").html(this.html);return d};c.fn.actionSlide=function(e){if(this.length>1){var d=[];this.each(function(){d.push(c(this).actionSlide(e))});return d}if(this.data("actionSlide")){return this.data("actionSlide")}if(this&&this.is("ul")){var g={animationBG:this.attr("data-animate-background")};var f=new a(c(this).parent(),{animateBackground:g.animationBG?g.animationBG==="true":true});c(this).hide();c(this).find(">li").each(function(k,h){var l=c(h);var m={title:l.attr("data-title"),duration:l.attr("data-duration"),animation:l.attr("data-animation"),direction:l.attr("data-direction"),textAlign:l.attr("data-align"),easing:l.attr("data-easing")};var j=c.extend({title:"",duration:2000,animation:"slide",direction:"ltr",textAlign:"left",easing:"linear"},m,j);f.addSlide(new b(j.title,l.html(),parseInt(j.duration,10),{animation:j.animation,align:j.textAlign,direction:j.direction}))});this.data("actionSlide",f);setTimeout(function(){f.play()},200);return f}};c(document).ready(function(){c("body [data-role='actionSlide']").actionSlide()});return{Credits:a,Slide:b,version: "1.0.5"}}($));