Файл: 3020.ru/design/js/muz/player_main.js
Строк: 668
<?php
if(!document.getElementsByClassName){document.getElementsByClassName=function(class_name){var elements=document.body.getElementsByTagName("*"),length=elements.length,out=[],i;for(i=0;i<length;i+=1){if(elements[i].className.indexOf(class_name)!==-1){out.push(elements[i]);}}return out;};}function removeClass(o,c){var re=new RegExp("(^|\s)"+c+"(\s|$)","g");o.className=o.className.replace(re,"$1").replace(/s+/g," ").replace(/(^ | $)/g,"");}function addClass(o,c){var re=new RegExp("(^|\s)"+c+"(\s|$)","g");if(re.test(o.className))return;o.className=(o.className+" "+c).replace(/s+/g," ").replace(/(^ | $)/g,"");}function hasClass(elem,className){return new RegExp("(^|\s)"+className+"(\s|$)").test(elem.className)}function isTouchSupported(){/*return'ontouchmove'in document.documentElement;*/}function supports_html5_storage(){try{return'localStorage'in window&&window['localStorage']!==null;}catch(e){return false;}}var MusicPlayer={musicFilesId:[],current:0,playing:true,duration:0,volume:function(){if(supports_html5_storage){if(localStorage["mobes_volume"]){return localStorage["mobes_volume"];}else{return 50;}}else{return 50;}},resetPlayers:function(){soundManager.stop('aSound');MusicPlayer.musicFilesId=[];MusicPlayer.current=0;MusicPlayer.playing=true;MusicPlayer.duration=0;MusicPlayer.playersList();},init:function(){soundManager.setup({url:'../js',flashVersion:9,preferFlash:false,onready:function(){var mySound=soundManager.createSound({id:'aSound',volume:MusicPlayer.volume(),onfinish:function(){MusicPlayer.nextFilePlay();},whileplaying:function(){var thisTime=((parseInt(this.position))/1000).toFixed();MusicPlayer.currenTime(thisTime);var thisDuration=((parseInt(this.durationEstimate))/1000).toFixed();MusicPlayer.progressbarPosition(thisTime,thisDuration);MusicPlayer.duration=this.durationEstimate;},whileloading:function(){MusicPlayer.loadedInfo(this.bytesLoaded,this.bytesTotal);}});}});MusicPlayer.playersList();},playersList:function(){var player_items=document.getElementsByClassName("player_item"),player_items_length=player_items.length;for(var i=0;i<player_items_length;i++){this.musicFilesId[i]={}
this.musicFilesId[i].id=player_items[i].id;this.musicFilesId[i].source=player_items[i].getAttribute('data-source');player_items[i].style.display="block";}},nextFilePlay:function(){var musicFilesId_length=MusicPlayer.musicFilesId.length;if(document.getElementById(MusicPlayer.current+"ct")){document.getElementById(MusicPlayer.current+"ct").innerHTML="";}if(document.getElementById(MusicPlayer.current+"dr")){document.getElementById(MusicPlayer.current+"dr").style.display="inline";}if(document.getElementById(MusicPlayer.current+"ll")){document.getElementById(MusicPlayer.current+"ll").style.width='0%';}if(document.getElementById(MusicPlayer.current+"pb")){document.getElementById(MusicPlayer.current+"pb").style.width='0%';}if(musicFilesId_length>1){for(i=0;i<musicFilesId_length;i++){if(MusicPlayer.musicFilesId[i].id==MusicPlayer.current){soundManager.stop('aSound');removeClass(document.getElementById(MusicPlayer.current),"playing");var j=i+1;if(MusicPlayer.musicFilesId[j]!==undefined){addClass(document.getElementById(MusicPlayer.musicFilesId[j].id),"playing");soundManager.play('aSound',{url:MusicPlayer.musicFilesId[j].source});MusicPlayer.current=MusicPlayer.musicFilesId[j].id;}else{addClass(document.getElementById(MusicPlayer.musicFilesId[0].id),"playing");soundManager.play('aSound',{url:MusicPlayer.musicFilesId[0].source});MusicPlayer.current=MusicPlayer.musicFilesId[0].id;}if(document.getElementById(MusicPlayer.current+"ct")){document.getElementById(MusicPlayer.current+"ct").innerHTML="0:00";}if(document.getElementById(MusicPlayer.current+"dr")){document.getElementById(MusicPlayer.current+"dr").style.display="none";}break;}}}else{soundManager.stop('aSound');removeClass(document.getElementById(MusicPlayer.current),"playing");MusicPlayer.current=0;}},play:function(fileId){if(fileId!=MusicPlayer.current){soundManager.stop('aSound');if(document.getElementById(MusicPlayer.current+"ct")){document.getElementById(MusicPlayer.current+"ct").innerHTML="";}if(document.getElementById(MusicPlayer.current+"dr")){document.getElementById(MusicPlayer.current+"dr").style.display="inline";}if(document.getElementById(MusicPlayer.current+"ll")){document.getElementById(MusicPlayer.current+"ll").style.width='0%';}if(document.getElementById(MusicPlayer.current+"pb")){document.getElementById(MusicPlayer.current+"pb").style.width='0%';}if(document.getElementById(this.current)){if(hasClass(document.getElementById(this.current),'playing')){removeClass(document.getElementById(this.current),"playing");}}addClass(document.getElementById(fileId),"playing");var musicFilesId_length=this.musicFilesId.length;var play_music_source=null;for(i=0;i<musicFilesId_length;i++){if(this.musicFilesId[i].id==fileId){play_music_source=this.musicFilesId[i].source;}}soundManager.play('aSound',{url:play_music_source});document.getElementById(fileId+"ct").innerHTML="0:00";document.getElementById(fileId+"dr").style.display="none";MusicPlayer.current=fileId;}else{if(hasClass(document.getElementById(this.current),'playing')){soundManager.pause('aSound');removeClass(document.getElementById(this.current),"playing");}else{soundManager.play('aSound');addClass(document.getElementById(this.current),"playing");}}},volumeChange:function(fileId,event,el){if(fileId==MusicPlayer.current){if(event==null){event=window.event}if(event.pageX==null&&event.clientX!=null){var html=document.documentElement
var body=document.body
event.pageX=event.clientX+(html&&html.scrollLeft||body&&body.scrollLeft||0)-(html.clientLeft||0)
event.pageY=event.clientY+(html&&html.scrollTop||body&&body.scrollTop||0)-(html.clientTop||0)}var volume_control_page_position2=0;var elem2=el;while(elem2){volume_control_page_position2+=elem2.offsetLeft;elem2=elem2.offsetParent;}var page_cursor_position2=event.pageX;var new_width2=page_cursor_position2-volume_control_page_position2;var setVolume=((new_width2/el.clientWidth)).toFixed(2);if(setVolume>1){setVolume=1;}if(setVolume<0){setVolume=0;}setVolume=setVolume*100;if(event==null){event=window.event}if(event.preventDefault){event.preventDefault();};var changeEl=document.getElementById(MusicPlayer.current+"vc"),oldMouseMove=null,oldMouseUp=null;oldMouseMove=document.onmousemove;oldMouseUp=document.onmouseup;var volume_control_page_position=0;var elem=el;while(elem){volume_control_page_position+=elem.offsetLeft;elem=elem.offsetParent;}function moveHandler(event){if(event==null){event=window.event}if(event.pageX==null&&event.clientX!=null){var html=document.documentElement
var body=document.body
event.pageX=event.clientX+(html&&html.scrollLeft||body&&body.scrollLeft||0)-(html.clientLeft||0)
event.pageY=event.clientY+(html&&html.scrollTop||body&&body.scrollTop||0)-(html.clientTop||0)}var page_cursor_position=event.pageX;var new_width=page_cursor_position-volume_control_page_position;new_width=(new_width/el.clientWidth).toFixed(2);if(new_width<0){new_width=0;}else if(new_width>1){new_width=1;}new_width=new_width*100;var changeEl2=document.getElementById(MusicPlayer.current+"vc");changeEl2.style.width=new_width+'%';soundManager.setVolume('aSound',new_width);if(supports_html5_storage){localStorage.setItem("mobes_volume",new_width);}return false;}function cleanupHandler(event){document.onmousemove=oldMouseMove;document.onmouseup=oldMouseUp;}document.onmousemove=moveHandler;document.onmouseup=cleanupHandler;soundManager.setVolume('aSound',setVolume);if(supports_html5_storage){localStorage.setItem("mobes_volume",setVolume);}document.getElementById(MusicPlayer.current+"vc").style.width=(setVolume)+"%";}},currenTime:function(time){var timeShow=MusicPlayer.timeFormatter(time);document.getElementById(MusicPlayer.current+"ct").innerHTML=timeShow;},timeFormatter:function(seconds){function zeroPad(str){if(str.length>2)return str
for(i=0;i<(2-str.length);i++){str="0"+str;}return str;}var minute=60;var hour=minute*60;hStr="";mStr="";sStr="";var h=Math.floor(seconds/hour);hStr=zeroPad(String(h));var m=Math.floor((seconds-(h*hour))/minute);mStr=String(m);var s=Math.floor((seconds-(h*hour))-(m*minute));sStr=zeroPad(String(s));if(hStr!=0){hStr=hStr+":";}else{hStr="";}return(hStr+mStr+":"+sStr);},loadedInfo:function(bytesLoaded,bytesTotal){var loadedpercents=((bytesLoaded/bytesTotal)*100).toFixed(2);document.getElementById(MusicPlayer.current+"ll").style.width=loadedpercents+'%';},progressbarPosition:function(time,duration){if(MusicPlayer.playing===true){var progressbar_percents=((time/duration)*100).toFixed(2);document.getElementById(MusicPlayer.current+"pb").style.width=progressbar_percents+'%';}},progressChange:function(fileId,event,el){MusicPlayer.playing=false;if(!isTouchSupported()){soundManager.pause('aSound');}if(fileId==MusicPlayer.current){if(event==null){event=window.event}if(event.pageX==null&&event.clientX!=null){var html=document.documentElement
var body=document.body
event.pageX=event.clientX+(html&&html.scrollLeft||body&&body.scrollLeft||0)-(html.clientLeft||0)
event.pageY=event.clientY+(html&&html.scrollTop||body&&body.scrollTop||0)-(html.clientTop||0)}var volume_control_page_position2=0;var elem2=el;while(elem2){volume_control_page_position2+=elem2.offsetLeft;elem2=elem2.offsetParent;}var cursor=event;if(isTouchSupported()){/*cursor=cursor.changedTouches[0];*/}var page_cursor_position2=cursor.pageX;var new_width2=page_cursor_position2-volume_control_page_position2;var setPosition=((new_width2/el.clientWidth)).toFixed(2);if(setPosition>1){setPosition=1;}if(setPosition<0){setPosition=0;}setPosition=setPosition*100;if(event==null){event=window.event}if(event.preventDefault){event.preventDefault();};var changeEl=document.getElementById(MusicPlayer.current+"pb"),oldMouseMove=null,oldMouseUp=null;if(isTouchSupported()){oldMouseMove=document.ontouchmove;oldMouseUp=document.ontouchend;}else{oldMouseMove=document.onmousemove;oldMouseUp=document.onmouseup;}var control_page_position=0;var elem=el;while(elem){control_page_position+=elem.offsetLeft;elem=elem.offsetParent;}function moveHandler(event){if(event==null){event=window.event}if(event.pageX==null&&event.clientX!=null){var html=document.documentElement;var body=document.body;event.pageX=event.clientX+(html&&html.scrollLeft||body&&body.scrollLeft||0)-(html.clientLeft||0)
event.pageY=event.clientY+(html&&html.scrollTop||body&&body.scrollTop||0)-(html.clientTop||0)}var cursor2=event;if(isTouchSupported()){cursor2=cursor2.changedTouches[0];}var page_cursor_position=cursor2.pageX;var new_width=page_cursor_position-control_page_position;new_width=(new_width/el.clientWidth).toFixed(2);if(new_width<0){new_width=0;}else if(new_width>1){new_width=1;}new_width=new_width*100;var changeEl2=document.getElementById(MusicPlayer.current+"pb");changeEl2.style.width=new_width+'%';var setNewPosition=((MusicPlayer.duration/100)*new_width).toFixed(2);soundManager.setPosition('aSound',setNewPosition);if(setNewPosition==0){document.getElementById(MusicPlayer.current+"ct").innerHTML='0:00';}return false;}function cleanupHandler(event){if(isTouchSupported()){document.ontouchmove=oldMouseMove;document.ontouchend=oldMouseUp;}else{document.onmousemove=oldMouseMove;document.onmouseup=oldMouseUp;}MusicPlayer.playing=true;soundManager.play('aSound');}if(isTouchSupported()){document.ontouchmove=moveHandler;document.ontouchend=cleanupHandler;}else{document.onmousemove=moveHandler;document.onmouseup=cleanupHandler;}var setNewPosition=((MusicPlayer.duration/100)*setPosition).toFixed(2);soundManager.setPosition('aSound',setNewPosition);document.getElementById(MusicPlayer.current+"pb").style.width=(setPosition)+"%";}},addNewPlayer:function(){var player_items=document.getElementsByClassName("player_item"),player_items_length=player_items.length;for(var i=0;i<player_items_length;i++){if(player_items[i].style.display!='block'){this.musicFilesId[i]={};this.musicFilesId[i].id=player_items[i].id;this.musicFilesId[i].source=player_items[i].getAttribute('data-source');player_items[i].style.display="block";}}},addNewPlayerToStart:function(){var player_items=document.getElementsByClassName("player_item"),player_items_length=player_items.length,tempArray=[],tempCounter=0;for(var i=0;i<player_items_length;i++){if(player_items[i].style.display!='block'){tempArray[tempCounter]={};tempArray[tempCounter].id=player_items[i].id;tempArray[tempCounter].source=player_items[i].getAttribute('data-source');player_items[i].style.display="block";tempCounter=tempCounter+1;}}this.musicFilesId=tempArray.concat(this.musicFilesId);}}
MusicPlayer.init();
?>