Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(){
- var hasFrame = window.parent!=window,
- scripts = document.getElementsByTagName('script'),
- current = scripts[scripts.length-1],
- config = current.getAttribute('data-config'),
- head = document.getElementsByTagName("head")[0],
- dest = location.href.replace(/rhinplayer\=true/g, 'rhinplayer=false'),
- destHost = dest.substr(0,dest.indexOf('/',10)),
- rhin = current.getAttribute('src').replace(/script\.js.*/g,'rhin.html')+'#'+dest,
- rhinHost = rhin.substr(0,rhin.indexOf('/',10)),
- isOutside = !hasFrame || location.href.indexOf("rhinplayer=true")>0,
- postMessage = function(msg){
- return window.top.document.getElementById('rhinframe')
- .contentWindow.postMessage(msg,rhinHost);
- },
- postFactory = function(obj,keys){
- var keys = keys.split(','),
- post = function(key){
- return function(arg){
- var argStr = '';
- if(typeof(arg)!='undefined')
- argStr = (key.match(/(play|queue)/) ? 'new Song(':'(') +
- JSON.stringify(arg)+')';
- postMessage('rhin.'+key+'('+argStr+')');
- }
- };
- for(var i=0;i<keys.length;i++){
- var key = keys[i];
- obj[key] = post(key);
- }
- },
- postConfig = function(config){
- if(!isOutside)
- postMessage('rhin.config('+config+')');
- },
- addEvent = function(elm, evType, fn) {
- if(elm.addEventListener)
- elm.addEventListener(evType, fn);
- else if (elm.attachEvent)
- elm.attachEvent('on' + evType, fn);
- else
- elm['on' + evType] = fn;
- },
- isIE = (function(){
- var undef,v = 3,div = document.createElement('div'),
- all = div.getElementsByTagName('i');
- while (div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',all[0] );
- return v > 4 ? v : undef;
- })(),
- isMobile = navigator.userAgent.match(/iPad|iPhone|Android|Blackberry/i),
- isIPad= navigator.userAgent.match(/iPad/i),
- init = function(){
- if(!document.body){
- setTimeout(init,10);
- return;
- }
- if(isOutside) outside(); else inside();
- },
- outside = function(){
- var css = 'html,body{overflow:hidden;} body{margin:0;padding:0;border:0;} img,a,embed,object,div,address,table,iframe,p,span,form,header,section,footer{ display:none;border:0;margin:0;padding:0; } #tumblr_controls{display:none;} #rhinframe{display:block; background-color:transparent; position:fixed; top:0px; left:0px; width:100%; height:100%; z-index:1667;} ';
- var style = document.createElement('style');
- style.type = 'text/css';
- style.id = 'rhincss';
- if(style.styleSheet) style.styleSheet.cssText = css;
- else style.appendChild(document.createTextNode(css));
- head.appendChild(style);
- /*
- while(head.firstChild.id!="rhincss")
- head.removeChild(head.firstChild);
- */
- var rhinframe = document.createElement('iframe');
- rhinframe.frameBorder = 0;
- rhinframe.id = "rhinframe";
- rhinframe.allowTransparency = true;
- rhinframe.src = rhin;
- document.body.insertBefore(rhinframe,document.body.firstChild);
- var resize = function(){
- rhinframe.style.height = (function(){
- if( typeof( window.innerHeight ) == 'number' )
- return window.innerHeight;
- else if( document.documentElement && document.documentElement.clientHeight )
- return document.documentElement.clientHeight;
- else if( document.body && document.body.clientHeight )
- return document.body.clientHeight;
- })();
- };
- addEvent(window,'load',function() {
- setTimeout(function(){
- while(document.body.firstChild!=rhinframe)
- document.body.removeChild(document.body.firstChild);
- while(document.body.lastChild!=rhinframe)
- document.body.removeChild(document.body.lastChild);
- resize();
- },0);
- });
- //fix frame height in IE
- addEvent(window,'resize',resize);
- //pushState and hash change detection
- var getPath = function(){
- return location.href.replace(/#.*/,'');
- },
- path = getPath(),
- hash = location.hash;
- setInterval(function(){
- if(getPath()!=path){
- path = getPath();
- window.rhininside.location.replace(path);
- }
- if(location.hash != hash){
- hash = location.hash;
- window.rhininside.location.hash = hash;
- }
- },100);
- },
- inside = function(){
- //change title
- window.top.document.title = document.title;
- //fix links
- var filter = function(host){
- host = host.replace(/blogspot.[a-z.]*/i,'blogspot.com');
- host = host.replace(/^(http(s)?:\/\/)?(www.)?/i,'');
- return host;
- };
- addEvent(document.body,'click',function(e){
- var tar = e.target;
- while(!tar.tagName.match(/^(a|area)$/i) && tar!=document.body)
- tar = tar.parentNode;
- if(tar.tagName.match(/^(a|area)$/i) &&
- !tar.href.match(/.(jpg|png)$/i) && //ignore picture link
- !tar.href.match(/^javascript:/) //ignore javascript link
- ){
- if(tar.href.indexOf('#')==0){
- //hash
- if(tar.href != "#"){
- window.top.rhininside = window;
- window.top.location.hash = location.hash;
- e.preventDefault();
- }
- }else if(tar.title.match(/^(rhin:|\[rhin\])/i)){
- //rhin Play link
- var title = tar.title.replace(/^(rhin:|\[rhin\])( )?/i,'');
- var url = tar.href;
- rhin.play({title:title,url:url});
- e.preventDefault();
- }else if(tar.href.match(/\.css$/)){
- //auto add skin
- window.open('http://rhinplayer.co/#skin='+tar.href,'_blank');
- window.focus();
- e.preventDefault();
- }else if(filter(tar.href).indexOf(filter(location.host))==-1 ){
- if(tar.href.match(/^http(s)?/)){
- //external links
- window.open(tar.href,'_blank');
- window.focus();
- e.preventDefault();
- }
- }else if(history.pushState){
- //internal link & has pushState
- //change address bar href
- var url = filter(tar.href).replace(filter(destHost),'');
- window.top.rhininside = window;
- window.top.history.pushState(null,null,url);
- e.preventDefault();
- }
- }
- });
- };
- //rhin interface
- var rhin = {};
- postFactory(rhin,
- 'queue,play,pause,next,previous,volume,skin,placement,'+
- 'loadPlaylist,repeatMode,isShuffle,showPlaylist,'+
- 'togglePlaylist,toggleShuffle,changeRepeatMode');
- if(window.rhin && window.rhinMusicPlayer) return;
- if (!isMobile) {
- init();
- }
- //send config
- if(config) postConfig(config);
- rhin.init = postConfig;
- window.rhinMusicPlayer = window.rhinMusicPlayer || rhin;
- window.rhin = window.rhin || rhin;
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement