(
function
($)
{
if
(!document.defaultView || !document.defaultView.getComputedStyle)
{
var
oldCurCSS = $.curCSS;
$.curCSS =
function
(elem, name, force)
{
if
(name ===
'background-position'
)
{
name =
'backgroundPosition'
;
}
if
(name !==
'backgroundPosition'
|| !elem.currentStyle || elem.currentStyle[name])
{
return
oldCurCSS.apply(this, arguments);
}
var
style = elem.style;
if
(!force && style && style[name])
{
return
style[name];
}
return
oldCurCSS(elem,
'backgroundPositionX'
, force) +
' '
+ oldCurCSS(elem,
'backgroundPositionY'
, force);
};
}
var
oldAnim = $.fn.animate;
$.fn.animate =
function
(prop)
{
if
(
'background-position'
in prop)
{
prop.backgroundPosition = prop[
'background-position'
];
delete
prop[
'background-position'
];
}
if
(
'backgroundPosition'
in prop)
{
prop.backgroundPosition =
'('
+ prop.backgroundPosition;
}
return
oldAnim.apply(this, arguments);
};
function
toArray(strg)
{
strg = strg.replace(/left|top/g,
'0px'
);
strg = strg.replace(/right|bottom/g,
'100%'
);
strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,
"$1px$2"
);
var
res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
return
[parseFloat(res[1], 10), res[2], parseFloat(res[3], 10), res[3]];
}
$.fx.step.backgroundPosition =
function
(fx)
{
if
(!fx.bgPosReady)
{
var
start = $.curCSS(fx.elem,
'backgroundPosition'
);
if
(!start)
{
start =
'0px 0px'
;
}
start = toArray(start);
fx.start = [start[0], start[2]];
var
end
= toArray(fx.
end
);
fx.
end
= [
end
[0],
end
[2]];
fx.unit = [
end
[1],
end
[3]];
fx.bgPosReady = true;
}
var
nowPosX = [];
nowPosX[0] = ((fx.
end
[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
nowPosX[1] = ((fx.
end
[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
fx.elem.style.backgroundPosition = nowPosX[0] +
' '
+ nowPosX[1];
};
})(jQuery);
;(
function
( $, window, document, undefined ){
function
generateNavigation(
$el
,
count
, config) {
var
i, html =
""
,
width =
count
* 24;
html +=
"<ol class='"
+ config.navigationClass +
"' style='margin-left: -"
+ width/2 +
"px; width: "
+ width +
"px'>"
;
for
(i = 0; i <
count
; i++) {
html +=
"<li><a "
+ (i === 0 ?
"class='selected'"
:
""
) +
" href='#"
+ (i) +
"'>slide</a></li>"
;
}
html +=
"</ol>"
;
$el
.append(html);
}
function
sweepOut(
$el
, windowWidth) {
var
dfr = $.Deferred(),
pos =
$el
.position(),
width =
$el
.width(),
delta,
final
,
options =
$el
.data(
"tlrkAnimOptions"
);
windowWidth = windowWidth || $(window).width();
delta = windowWidth - pos.left;
final
= -(delta);
setTimeout(
function
(){
$el
.animate({left:
final
, opacity:
"toggle"
}, options.speed, options.easing,
function
(){
dfr.resolve();
});
}, options.delay);
return
dfr.promise();
}
function
sweepIn(
$el
, windowWidth, frameLeft) {
var
dfr = $.Deferred(),
options =
$el
.data(
"tlrkAnimOptions"
),
positionData =
$el
.data(
"tlrkOriginalPos"
),
final
= positionData.position.left,
rightEdge;
windowWidth = windowWidth || $(window).width();
$el
.css({opacity: 0, display:
"block"
});
$el
.css(
"left"
,
function
(current){
return
current + windowWidth - frameLeft;
});
setTimeout(
function
(){
$el
.animate({left:
final
, opacity: 1}, options.speed, options.easing,
function
(){
dfr.resolve();
});
}, options.delay);
return
dfr.promise();
}
function
absolutize(
$elements
) {
$elements
.each(
function
(){
var
$t
= $(this);
if
(
$t
.data(
"tlrkOriginalPos"
))
return
$t
.data(
"tlrkOriginalPos"
, {
position:
$t
.position(),
width:
$t
.width(),
height:
$t
.height(),
css_pos:
$t
.css(
"position"
),
css_left:
$t
.css(
"left"
),
css_top:
$t
.css(
"top"
),
css_width:
$t
.css(
"width"
) ||
"auto"
,
css_height:
$t
.css(
"height"
) ||
"auto"
});
});
$elements
.each(
function
(){
var
$t
= $(this),
opos =
$t
.data(
"tlrkOriginalPos"
);
$t
.css({
position:
"absolute"
,
left: opos.position.left,
top: opos.position.top,
width: opos.width,
height: opos.height
});
});
}
function
restoreFrameElements(
$elements
) {
$elements
.each(
function
(){
var
$t
= $(this),
opos =
$t
.data(
"tlrkOriginalPos"
);
if
(!opos)
return
$t
.css({
position: opos.css_pos,
left: opos.css_left,
top: opos.css_top,
width: opos.css_width,
height: opos.css_height
});
});
}
var
TlrkSlider =
function
( elem, options ){
this.elem = elem;
this.
$elem
= $(elem);
this.options = options;
};
TlrkSlider.prototype = {
defaults: {
defaultElementOptions: {
speed: 1200,
easing:
"easeInOutBack"
,
delay: 100
},
disposeDelay: 100,
disposeSpeed: 1000,
delayBetweenTransition: 1000,
delayAnimation: 7000,
loop: true,
autoStart: true,
framesSelector:
"section"
,
elements: {
"p"
: {delay: 100, speed: 1000, easing:
"easeInOutBack"
}
},
navigation: true,
navigationClass:
"slider-nav"
,
animationStart: null,
animationEnd: null
},
init:
function
() {
var
c, e, element,
$element
,
that = this,
$firstFrame
;
c = this.config = $.extend({}, this.defaults, this.options);
this.elem.style.position =
"relative"
;
this.
$frames
= this.
$elem
.find(c.framesSelector);
this.framesCount = this.
$frames
.length;
this.currentFrame = 0;
this.queue = [];
this._
$elementsByFrame
= {};
this._
$disposeElementsByFrame
= {};
for
(i = 0; i < this.framesCount; i++) {
this._
$elementsByFrame
[i] = this._getFrameElements(i);
this._
$disposeElementsByFrame
[i] = this._getDisposeFrameElements(i);
}
if
(c.navigation) {
generateNavigation(this.
$elem
, this.framesCount, c);
this.
$navigation
= this.
$elem
.find(
"."
+c.navigationClass);
}
this.
$elem
.find(
".slider-nav"
).delegate(
"a"
,
"click"
,
function
(e){
var
frame = this.getAttribute(
"href"
).split(
"#"
)[1];
that.go.call(that, frame);
return
false;
});
this.
$elem
.bind(
"animationStart"
,
function
(){
if
($.isFunction(c.animationStart)) {c.animationStart.apply(that, arguments);}
})
.bind(
"animationEnd"
,
function
(){
if
($.isFunction(c.animationEnd)) {c.animationEnd.apply(that, arguments);}
})
;
if
(c.autoStart) {
this.start();
}
else
{
this.running = false;
}
return
this;
},
start:
function
(instant) {
var
that = this;
if
(this.timer) {
window.clearTimeout(this.timer);
}
this.running = true;
if
(instant) {
that.nextFrame();
}
else
{
this.timer = window.setTimeout(
function
(){ that.nextFrame.call(that) }, that.config.delayAnimation);
}
},
stop:
function
() {
if
(!this.running)
return
;
this.running = false;
window.clearTimeout(this.timer);
},
selectFrame:
function
(frame, dfr) {
var
c = this.config,
that = this,
dfr = dfr || $.Deferred(),
dFadeIn = $.Deferred(),
dFadeOut = $.Deferred();
if
(isNaN(frame) || frame < 0 || frame > this.framesCount || frame === this.currentFrame) {
dfr.reject();
return
dfr.promise();
}
if
(this.running && this.timer) {
window.clearTimeout(this.timer);
}
if
(this.animated && this.queue.length > 0) {
this.queue[this.queue.length-1].done(
function
(){
that.selectFrame(frame, dfr);
})
return
dfr.promise();
}
this.animated = true;
this.
$elem
.trigger(
"animationStart"
, [this, frame]);
this.queue.push(dfr);
dFadeOut = this._fadeOutFrame(this.currentFrame);
dFadeOut.done(
function
(){
that.
$frames
.eq(that.currentFrame).hide();
});
window.setTimeout(
function
(){
dFadeIn = that._fadeInFrame.call(that, frame).done(
function
(){
$.when(dFadeOut, dFadeIn).done(
function
(){
that.animated = false;
that.queue.shift();
that.
$elem
.trigger(
"animationEnd"
, [that]);
that.currentFrame = frame;
dfr.resolve();
});
});
}, c.delayBetweenTransition);
if
(this.config.navigation) {
this.
$navigation
.find(
".selected"
).removeClass(
"selected"
).
end
()
.find(
"a"
).eq(frame).addClass(
"selected"
);
}
dfr.done(
function
(){
if
(that.running) {
that.start();
}
});
return
dfr.promise();
},
_fadeFrame:
function
(frame, callback, direction) {
var
dfr = $.Deferred(),
$frame
= this.
$frames
.eq(frame),
$elements
= this._
$elementsByFrame
[frame],
windowWidth = $(window).width(),
i, len,
that = this,
elementAnimations = [],
$disposeElements
= this._
$disposeElementsByFrame
[frame],
$affectedElements
,
frameLeft =
$frame
.offset().left;
direction = direction ||
"out"
;
if
(!$.isFunction(callback))
return
;
$affectedElements
=
$elements
.add(
$disposeElements
);
absolutize(
$affectedElements
);
if
(
$disposeElements
.length > 0) {
window.setTimeout(
function
(){
$disposeElements
[direction ===
"out"
?
"fadeOut"
:
"fadeIn"
](that.config.disposeSpeed);
}, this.config.disposeDelay);
}
$elements
.each(
function
(){
elementAnimations.push( callback.call(that, $(this), windowWidth, frameLeft) );
});
$.when.apply(this, elementAnimations).done(
function
(){
dfr.resolve();
});
return
dfr.promise();
},
_fadeOutFrame:
function
(frame) {
var
dfr = $.Deferred(),
$frame
= this.
$frames
.eq(frame),
$disposeElements
= this._
$disposeElementsByFrame
[frame];
this._fadeFrame(frame, this._animationOut,
"out"
).done(
function
(){
dfr.resolve();
})
return
dfr.promise();
},
_fadeInFrame:
function
(frame) {
var
dfr = $.Deferred(),
$frame
= this.
$frames
.eq(frame),
$elements
= this._
$elementsByFrame
[frame];
this._restoreFrame(frame);
$frame
.show();
this._fadeFrame(frame, this._animationIn,
"in"
).done(
function
(){
dfr.resolve();
});
return
dfr.promise();
},
_restoreFrame:
function
(frame){
if
(!frame)
return
restoreFrameElements( this._
$elementsByFrame
[frame].add(this._
$disposeElementsByFrame
[frame]) );
},
nextFrame:
function
() {
var
frame = this.currentFrame+1,
dfr = $.Deferred();
if
(frame > this.framesCount-1) {
if
(this.config.loop) {
frame = 0;
}
else
{
dfr.reject();
}
};
this.selectFrame(frame).done(
function
(){
dfr.resolve();
});
return
dfr.promise();
},
prevFrame:
function
() {
var
frame = this.currentFrame-1,
dfr = $.Deferred();
if
(frame < 0) {
if
(this.config.loop) {
frame = this.framesCount-1;
}
else
{
dfr.reject();
return
dfr.promise();
}
}
this.selectFrame(frame).done(
function
(){
dfr.resolve();
});
return
dfr.promise();
},
go:
function
(str) {
switch
(str) {
case
"next"
:
case
"+1"
:
this.nextFrame();
break
;
case
"prev"
:
case
"-1"
:
this.prevFrame();
break
;
case
"first"
:
this.selectFrame(0);
break
;
case
"last"
:
this.selectFrame(this.framesCount-1);
break
;
default
:
if
(isNaN(str))
return
;
this.selectFrame(Number(str));
}
},
_getFrameElements:
function
(frame) {
var
$frame
= this.
$frames
.eq(frame),
elements = this.config.elements,
e, elementOptions,
$found
,
$frameElements
= $([]);
for
(e in elements) {
elementOptions = elements[e];
$found
=
$frame
.find(e);
$found
.addClass(
"t-frame-element"
).data(
"tlrkAnimOptions"
, $.extend({}, this.defaults.defaultElementOptions, elementOptions ));
$frameElements
=
$frameElements
.add(
$found
);
}
return
$frameElements
;
},
_getDisposeFrameElements:
function
(frame) {
var
$disposeElements
= $([]),
$frame
= this.
$frames
.eq(frame),
$elements
= this._
$elementsByFrame
[frame];
$elements
.each(
function
(){
var
$t
= $(this),
$siblings
=
$t
.siblings().not(
".t-frame-element"
);
$siblings
.each(
function
(){
var
$t
= $(this);
if
(!
$t
.hasClass(
"t-frame-dispose"
) &&
$t
.find(
".t-frame-element"
).length === 0) {
$t
.addClass(
"t-frame-dispose"
);
$disposeElements
=
$disposeElements
.add(
$t
);
}
});
});
return
$disposeElements
;
},
_animationIn: sweepIn,
_animationOut: sweepOut
}
TlrkSlider.defaults = TlrkSlider.prototype.defaults;
$.fn.tlrkSlider =
function
(options) {
var
otherArgs = Array.prototype.slice.call(arguments, 1);
return
this.each(
function
() {
var
$el
= $(this),
pluginData =
$el
.data(
"tlrkSlider"
);
if
(!pluginData) {
pluginData =
new
TlrkSlider(this, options).init();
$el
.data(
"tlrkSlider"
, pluginData);
return
;
}
if
(typeof options ===
"string"
) {
if
(options ===
"option"
) {
if
(typeof otherArgs[0] ===
"string"
&& typeof otherArgs[1] !==
"undefined"
) {
pluginData.config[otherArgs[0]] = otherArgs[1];
}
if
(typeof otherArgs[0] ===
"object"
) {
pluginData.config = $.extend(pluginData.config, otherArgs[0]);
}
}
else
{
try
{
pluginData[options].apply(pluginData, otherArgs);
}
catch
(ex) {
throw
"Error calling a plugin method ("
+ ex +
")"
;
}
}
}
});
};
window.TlrkSlider = TlrkSlider;
})( jQuery, window , document );