2 lines
2.9 KiB
JavaScript
2 lines
2.9 KiB
JavaScript
(function(){for(var v=function(c){var m={init:function(a){var i=this;i.openEvent(a)},openEvent:function(a){var i=this;i.playEvent(a),i.durationEvent(a),i.volumeEvent(a),i.autoplayEvent(a)},playEvent:function(a){var i=this,r=a.find(".m-player");r.on("click",function(){a.find("audio")[0].paused?i.play(a):i.pause(a)})},volumeEvent:function(a){var i=this,r=a.find("audio")[0];a.find(".m-voice").on("click",function(){r.muted?r.muted=!1:r.muted=!0,i.muted(a)}),r.volume=.3,a.find(".m-voice-progress").on("click",function(t){var n=t.pageX,u=$(t.target).offset().left,o=n-u;r.volume=o>75?1:o<5?0:o/80,r.muted=!1,i.volume(!1,a),i.muted(a)}),i.volume(!1,a),i.muted(a)},durationEvent:function(a){var i=this,r=a.find(".musicPlayer"),t=r.find(".m-play-progress");t.on("click",function(n){var u=n.pageX,o=$(n.target).offset().left,s=u-o;i.currentTime(s,a)})},play:function(a){var i=this,r=a.find("audio")[0];r.play(),clearInterval(i.playTimeCount),i.playTimeCount=setInterval(function(){if(r.readyState==4&&!r.paused){clearInterval(i.playTimeCount),a.find("audio").removeAttr("autoplay");var t=a.find(".m-player").addClass("on");a.find(".m-disk").addClass("rotate_common"),a.find(".m-handle").addClass("on"),$(".function_left_btn.music").addClass("musiced"),i.duration(a),i.currentTime(!1,a)}},100)},pause:function(a){var i=this;a.find("audio")[0].pause();var r=a.find(".m-player").removeClass("on");a.find(".m-disk").removeClass("rotate_common"),a.find(".m-handle").removeClass("on"),$(".function_left_btn.music").removeClass("musiced"),clearInterval(i.currentInterval)},duration:function(a){var i=this,r=a.find("audio")[0];clearInterval(i.durationState),i.durationState=setInterval(function(){if(r.readyState==4){clearInterval(i.durationState);var t=i.getTime(parseInt(r.duration||0));a.find(".mp-right-time").text(t)}},300)},currentTime:function(a,i){var r=this,t=i.find("audio")[0],n=i.find(".mp-left-time"),u=i.find(".m-play-progress-bg");a&&(t.currentTime=t.duration*(a/405));var o=function(){n.text(r.getTime(parseInt(t.currentTime||0)));var s=parseInt(t.currentTime/t.duration*1e4)/100+"%";u.css({width:s})};o(),clearInterval(r.currentInterval),t.paused||(r.currentInterval=setInterval(function(){o()},300))},volume:function(a,i){var r=this,t=i.find("audio")[0],n=i.find(".m-voice-progress-bg");n.css({width:(a?0:t.volume*100)+"%"})},muted:function(a){var i=this,r=a.find("audio")[0],t=a.find(".m-voice"),n=r.muted;i.volume(n,a),n?t.addClass("on"):t.removeClass("on")},autoplayEvent:function(a){var i=this,r=a.find("audio");r.attr("autoplay")&&i.play(a),$(document).click(function(t){var n=a.find("audio");$(t.target).hasClass("m-player")||n.attr("autoplay")&&i.play(a)}),$(document).keydown(function(){var t=a.find("audio");t.attr("autoplay")&&i.play(a)})},getTime:function(a){var i=parseInt(a/60),r=parseInt(a%60);return(i<10?"0"+i:""+i)+":"+(r<10?"0"+r:""+r)}};m.init(c)},e=$(".module[data-type=MP3]"),d=0,f=e.length;d<f;d++)new v(e.eq(d))})();
|