
PK 
/*!
* Marquee - JS for Debug
* @licence Marquee - v1.0 (2015-01-20)
*/
/*
* @name pluginName
* @Rely jQuery v1.7+
* @License MIT
*
*
* usage as:
* m1. $.fn.pluginName({...});
* m2. $(...).pluginName({...});
*
* author: repar
*/
;(function($, window, document, undefined){
// Create the defaults once
var pluginName = "marquee",
defaults = {
enable : true, //plug-in is enabled
direction: 'vertical', //Movement direction. vertical : horizontal
itemSelecter : 'li', //Child node selector
delay: 3000, //Animation rendering delay time
speed: 1, //Animation rendering distance.
timing: 1, //Animation rendering rate.
mouse: true //Move the mouse to stop the animation
};
function Widget(element, options) {
this.element = element;
this.settings = $.extend({}, defaults, options);
this._defaults = defaults;
this._name = pluginName;
this.version = 'v1.0';
this.$element = $(this.element);
this.$wrapper = this.$element.parent();
this.$items = this.$element.children(this.settings.itemSelecter);
this.next = 0;
this.timeoutHandle;
this.intervalHandle
if(!this.settings.enable)return; //Check whether the plug-in is on.
this.init();
}
Widget.prototype = {
init:function(){
var that = this;
//The child node occupies the total height.
var totalSize = 0;
$.each(this.$items, function(index, element){
totalSize += that.isHorizontal()
? parseInt($(element).outerWidth())
: parseInt($(element).outerHeight());
});
//The actual height of the parent node
var elmentTotalSize = this.isHorizontal()
? this.$element.outerWidth
: this.$element.outerHeight;
//Determine whether the total height of the child node is greater than the parent node height, Otherwise the plug-in stops running.
if(totalSize < elmentTotalSize)return;
//Sets the CSS style required for animation rendering.
this.$wrapper.css({
position : 'relative',
overflow : 'hidden'
});
this.$element.css({
position : 'absolute',
top : 0,
left: 0
});
this.$element.css(this.isHorizontal() ? 'width' : 'height', '1000%');
//Clone a child node.
this.cloneAllItems();
//Mouse monitor
if(this.settings.mouse)
this.addHoverEvent(this);
this.timer(this);
},
/**
* Timer.
*/
timer : function(that){
this.timeoutHandle = setTimeout(function(){that.play(that)}, this.settings.delay);
},
/**
* Play.
*/
play : function(that){
this.clearTimeout();
var target = 0;
for(var i = 0; i <= this.next; i++){
target -= this.isHorizontal()
? parseInt($(this.$items.get(this.next)).outerWidth())
: parseInt($(this.$items.get(this.next)).outerHeight());
}
this.intervalHandle = setInterval(function(){that.animate(target)},this.settings.timing);
},
/**
* Animation rendering.
*/
animate : function(target){
var mark = this.isHorizontal() ? 'left' : 'top';
var present = parseInt(this.$element.css(mark));
if(present > target)
{
if(present - this.settings.speed <= target)
{
this.$element.css(mark, target);
}else
this.$element.css(mark, present - this.settings.speed);
}else{
this.clearInterval();
if(this.next + 1 < this.$items.length){
this.next++;
}else{
this.next = 0;
this.$element.css(mark,0);
}
this.timer(this);
}
},
isHorizontal : function(){
return this.settings.direction == 'horizontal';
},
/**
* Clone a child node
*/
cloneAllItems: function(){
this.$element.append(this.$items.clone());
},
/**
* Cancel the clock queue.
*/
clearTimeout : function(){
clearTimeout(this.timeoutHandle);
},
/**
* Cancel the timer queue.
*/
clearInterval : function(){
clearInterval(this.intervalHandle);
},
/**
* Pause animation rendering.
* @return {[type]} [description]
*/
addHoverEvent : function(that){
this.$wrapper
.mouseenter(function(){
that.clearInterval()
that.clearTimeout();
})
.mouseleave(function(){
that.play(that);
});
}
}//prototype
$.fn[pluginName] = function(options) {
// chain jQuery functions
return this.each(function() {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName, new Widget(this, options));
}
});
};
})(jQuery, window, document);


PK 99