29 lines
10 KiB
JavaScript
29 lines
10 KiB
JavaScript
(function(t){t.jQueryPlugin=function(a){t.fn[a]=function(h){var i=Array.prototype.slice.call(arguments,1);if(this.length)return this.each(function(){var e=t.data(this,a)||t.data(this,a,new cyntax.plugins[a](this,h)._init());typeof h=="string"&&(h=h.replace(/^_/,""),e[h]&&e[h].apply(e,i))})}}})(jQuery);var cyntax={plugins:{}};/*!
|
|
* Pause jQuery plugin v0.1
|
|
*
|
|
* Copyright 2010 by Tobia Conforto <tobia.conforto@gmail.com>
|
|
*
|
|
* Based on Pause-resume-animation jQuery plugin by Joe Weitzel
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
* Software Foundation; either version 2 of the License, or(at your option)
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*/(function(){var t=jQuery,a="jQuery.pause",h=1,i=t.fn.animate,e={};function o(){return new Date().getTime()}t.fn.animate=function(r,p,d,c){var n=t.speed(p,d,c);return n.complete=n.old,this.each(function(){this[a]||(this[a]=h++);var s=t.extend({},n);i.apply(t(this),[r,t.extend({},s)]),e[this[a]]={run:!0,prop:r,opt:s,start:o(),done:0}})},t.fn.pause=function(){return this.each(function(){this[a]||(this[a]=h++);var r=e[this[a]];r&&r.run&&(r.done+=o()-r.start,r.done>r.opt.duration?delete e[this[a]]:(t(this).stop().stop().stop(),t(this).stop(),t(this).stop(),t(this).stop(),t(this).stop(),t(this).stop(),t(this).stop(),t(this).stop(),t(this).stop(),t(this).stop(),t(this).stop(),t(this).stop(),t(this).stop(),t(this).stop(),t(this).stop(),r.run=!1))})},t.fn.resume=function(){return this.each(function(){this[a]||(this[a]=h++);var r=e[this[a]];r&&!r.run&&(r.opt.duration-=r.done,r.done=0,r.run=!0,r.start=o(),i.apply(t(this),[r.prop,t.extend({},r.opt)]))})}})(),function(t){cyntax.plugins.timer=function(a,h){this.$this=t(a),this.options=t.extend({},this.defaults,h),this.timer_info={id:null,index:null,state:0}},cyntax.plugins.timer.prototype={defaults:{delay:1e3,repeat:!1,autostart:!0,callback:null,url:"",post:""},_init:function(){return this.options.autostart&&(this.timer_info.state=1,this.timer_info.id=setTimeout(t.proxy(this._timer_fn,this),this.options.delay)),this},_timer_fn:function(){typeof this.options.callback=="function"?t.proxy(this.options.callback,this.$this).call(this,++this.timer_info.index):typeof this.options.url=="string"&&(ajax_options={url:this.options.url,context:this,type:typeof this.options.post=="string"&&typeof this.options.post!=""==""?"POST":"GET",success:function(a,h,i){this.$this.html(a)}},typeof this.options.post=="string"&&typeof this.options.post!=""&&(ajax_options.data=this.options.post),t.ajax(ajax_options)),this.options.repeat&&this.timer_info.state==1&&(typeof this.options.repeat=="boolean"||parseInt(this.options.repeat)>this.timer_info.index)?this.timer_info.id=setTimeout(t.proxy(this._timer_fn,this),this.options.delay):this.timer_id=null},start:function(){this.timer_info.state==0&&(this.timer_info.index=0,this.timer_info.state=1,this.timer_id=setTimeout(t.proxy(this._timer_fn,this),this.options.delay))},stop:function(){this.timer_info.state==1&&this.timer_info.id&&(clearTimeout(this.timer_info.id),this.timer_id=null),this.timer_info.state=0},pause:function(){this.timer_info.state==1&&this.timer_info.id&&clearTimeout(this.timer_info.id),this.timer_info.state=0},resume:function(){this.timer_info.state=1,this.timer_id=setTimeout(t.proxy(this._timer_fn,this),this.options.delay)}},t.jQueryPlugin("timer")}(jQuery);/*!
|
|
*弹幕引擎核心
|
|
*
|
|
* Copyright 2015 by Ruiko Of AcGit.cc
|
|
* @license MIT
|
|
*
|
|
* 版本3.0 2015/08/12
|
|
*/(function(t){var a=function(i,e){this.$element=t(i),this.options=e,this.id=t(i).attr("id"),t(i).data("nowTime",0),t(i).data("danmuList",e.danmuList),t(i).data("opacity",e.opacity),t(i).data("paused",1),t(i).data("topSpace",0),t(i).data("bottomSpace",0),this.$element.css({position:"absolute",left:this.options.left,top:this.options.top,width:this.options.width,height:this.options.height,"z-index":this.options.zindex,color:e.defaultFontColor,overflow:"hidden"});var o=this;o.height=this.$element.height(),o.width=this.$element.width(),o.speed=1e3/e.speed,this.launched=[],this.preTime=0;var r=this.options.maxCountInScreen,p=this.options.maxCountPerSec,d=0,c=0;this.rowCount=parseInt(o.height/e.FontSizeBig),o.options.SubtitleProtection&&(o.rowCount=o.rowCount-3),this.rows=[],this.topRows=[],this.bottomRows=[],this.initRows=function(n){for(var s=0;s<n.rowCount;s++)n.rows[s]=0,n.topRows[s]=0,n.bottomRows[s]=0},this.initRows(this),o.getRow=function(n){for(var s=0;n.rows[s]!==0;)if(s=s+1,s>=n.rowCount){n.initRows(n),s=0;break}return s},o.getTopRow=function(n){for(var s=0;s<n.topRows.length;s++)if(n.topRows[s]==0)return s},o.getBottomRow=function(n){for(var s=0;s<n.bottomRows.length;s++)if(n.bottomRows[s]==0)return s},o.checkRow=function(n){for(var s in n.rows)n.rows[s]!==0&&typeof t("#"+n.rows[s]).position()!="undefined"&&t("#"+n.rows[s]).position().left<n.$element.width()-t("#"+n.rows[s]).width()&&(n.rows[s]=0)},t("<div class='danmakuTimer'></div>").appendTo(this.$element),this.$timer=t(".danmakuTimer"),this.$timer.timer({delay:100,repeat:e.sumTime,autostart:!1,callback:function(n){setTimeout(function(){o.options.danmuLoop&&t(i).data("nowTime")>=t(i).data("sumTime")&&t(i).data("nowTime",0),t(i).data("nowTime",t(i).data("nowTime")+1),o.height=t(i).height(),o.width=t(i).width(),Math.abs(t(i).data("nowTime")-(o.preTime+1))>10&&(o.launched=[]),o.preTime=t(i).data("nowTime");var s=o.rowCount;if(o.rowCount=parseInt(o.height/e.FontSizeBig),setTimeout(o.checkRow(o),0),o.options.SubtitleProtection&&(o.rowCount=o.rowCount-3),s!==0&&o.rowCount!==s&&o.initRows(o),c=0,t(i).data("danmuList")[t(i).data("nowTime")]&&o.launched.indexOf(t(i).data("nowTime"))<0){for(var g=t(i).data("nowTime"),l=t(i).data("danmuList")[g],w=l.length-1;w>=0;w--){setTimeout(o.checkRow(o),0);var u=l[w],R=u.color||"",Q=u.color<"#777777"?" 0px 0px 2px #FFFFFF":" 0px 0px 2px #000000",_=t(i).data("opacity"),F=u.size==0?e.fontSizeSmall:u.size==2?e.fontSizeMid:e.FontSizeBig,C=u.hasOwnProperty("isnew")?"border: 2px solid "+u.color+";":"";if(u.position==0){var v=o.id+"fly"+parseInt(new Date().getTime()).toString();if(d<=r&&c<=p){o.checkRow(o);var S=o.getRow(o);o.rows[S]=v,u.row=S;var f=S*e.FontSizeBig,E=t("#"+o.id).width(),T=u.xposition,b=Math.floor(Math.random()*3);if(T===1){var z=Math.floor(Math.random()*6),L=["35%","40%","45%","50%","55%","60%"];f=L[z]}else if(T===2){var M=Math.floor(Math.random()*7),j=["65%","70%","75%","80%","85%","90%","95%"];f=j[M]}else if(T===3){var b=Math.floor(Math.random()*3);switch(b){case 1:{var k=Math.floor(Math.random()*6),B=["35%","40%","45%","50%","55%","60%"];f=B[k];break}case 2:{var D=Math.floor(Math.random()*7),P=["65%","70%","75%","80%","85%","90%","95%"];f=P[D];break}default:break}}var A=(f+"").indexOf("%")>-1?f:f+"px",O="<span style='color: "+R+";-moz-opacity:"+_+";opacity:"+_+";white-space:nowrap; font-weight:bold;animation-duration:7s;font-family:SimHei; font-size:"+F+"px;top:"+A+";"+C+"' class='danmaku bullet-item-style' id='"+v+"'>"+u.text+"</span>";d++,c++,t(i).append(O),t("#"+v).one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend transitionend",function(){t(this).remove(),d--,c--})}else t("#"+v).remove()}else if(u.position==1){var y=o.id+"top"+parseInt(1e4*Math.random()).toString();t("#"+o.id+"tempDanmaku").attr("id",y);var m=o.getTopRow(o);t(i).data("topSpace",e.FontSizeBig*m),o.topRows[m]=1,t("#"+y).css({width:"100%","text-align":"center",position:"absolute",top:t(i).data("topSpace"),left:"0"}),t("#"+y).data("row",m),t("#"+y).fadeTo(e.topBottomDanmuTime,t(i).data("opacity"),function(){o.topRows[t(this).data("row")]=0,t(this).remove()})}else if(u.position==2){var x=o.id+"bottom"+parseInt(1e4*Math.random()).toString();t("#"+o.id+"tempDanmaku").attr("id",x);var m=o.getBottomRow(o);t(i).data("bottomSpace",e.FontSizeBig*m),o.bottomRows[m]=1,t("#"+x).css({width:e.width,left:"0","text-align":"center",position:"absolute",bottom:0+t(i).data("bottomSpace")}),t("#"+x).data("row",m),t("#"+x).fadeTo(e.topBottomDanmuTime,t(i).data("opacity"),function(){o.bottomRows[t(this).data("row")]=0,t(this).remove()})}l[w]=u}t(i).data("danmuList")[g]=l}o.launched.push(t(i).data("nowTime")),n==e.sumTime&&e.isLoop&&(o.$timer.timer("stop"),o.$timer.timer("start"))})}})};a.DEFAULTS={left:0,top:0,height:360,width:640,zindex:100,speed:8e3,sumTime:65535,danmuLoop:!1,danmuList:{},defaultFontColor:"#FFFFFF",fontSizeSmall:16,fontSizeMid:18,FontSizeBig:24,opacity:"0.9",topBottomDanmuTime:6e3,SubtitleProtection:!1,positionOptimize:!1,maxCountInScreen:40,maxCountPerSec:10},a.prototype.danmuStart=function(){this.$timer.timer("start"),this.$element.data("paused",0)},a.prototype.danmuStop=function(){this.$timer.timer("stop"),t("#"+this.id+" .danmaku").remove(),nowTime=0,this.$element.data("paused",1),this.$element.data("nowTime",0)},a.prototype.danmuPause=function(){this.$timer.timer("pause"),t("#"+this.id+" .danmaku").pause(),this.$element.data("paused",1)},a.prototype.danmuResume=function(){this.$timer.timer("resume"),t("#"+this.id+" .danmaku").resume(),this.$element.data("paused",0)},a.prototype.danmuHideAll=function(){t("#"+this.id+" .danmaku").css({opacity:0}),this.initRows(this)},a.prototype.setTime=function(i){t("#"+this.id+" .danmaku").remove(),this.$element.data("nowTime",i)},a.prototype.setOpacity=function(i){t("#"+this.id+" .danmaku").css("opacity",i),this.$element.data("opacity",i)},a.prototype.addDanmu=function(i){if(i instanceof Array)for(var e in i)this.$element.data("danmuList")[i[e].time]?this.$element.data("danmuList")[i[e].time].push(i[e]):(this.$element.data("danmuList")[i[e].time]=[],this.$element.data("danmuList")[i[e].time].push(i[e]));else this.$element.data("danmuList")[i.time]?this.$element.data("danmuList")[i.time].push(i):(this.$element.data("danmuList")[i.time]=[],this.$element.data("danmuList")[i.time].push(i))};function h(i,e){return this.each(function(){var o=t(this),r=t.extend({},a.DEFAULTS,typeof i=="object"&&i),p=o.data("danmu"),d=typeof i=="string"?i:NaN;p||o.data("danmu",p=new a(this,r)),d&&p[d](e)})}t.fn.danmu=h,t.fn.danmu.Constructor=a})(jQuery);
|