Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     MP3-jPlayer 1.8.8
  3.     www.sjward.org
  4. */
  5.  
  6. var MP3_JPLAYER = {
  7.    
  8.     tID:            '',
  9.     state:          '',
  10.     pl_info:        [],
  11.     load_pc:        0, 
  12.     played_t:       0, 
  13.     dl_dialogs:     [],
  14.     timeoutIDs:     [],
  15.     intervalIDs:    [],
  16.     dl_domain:      '',
  17.     jp_audio:       {},
  18.     jp_seekable:    0,
  19.     sliding:        false,
  20.     launched_ID:    null,
  21.     jpID:           '#mp3_jplayer_1_8',
  22.     plugin_path:    '',
  23.  
  24.     vars: {
  25.         play_f:             false,     
  26.         stylesheet_url:     '',
  27.         dload_text:         'DOWNLOAD MP3',
  28.         pp_width:           280,
  29.         pp_maxheight:       350,
  30.         pp_bodycolour:      '#fff',
  31.         pp_bodyimg:         '',
  32.         pp_fixedcss:        false,
  33.         pp_windowheight:    600,
  34.         pp_playerheight:    100+142,
  35.         force_dload:        false,
  36.         message_interval:   '<h2>Download MP3</h2><p style="margin-top:34px !important;">Your download should start in a second!</p>',
  37.         message_ok:         '',
  38.         message_indark:     '<h2>Download MP3</h2><p>Your download should start in a second!</p>',
  39.         message_promtlink:  '<h2>Download MP3</h2><p>Link to the file:</p><h3><a target="_blank" href="#1">#2</a></h3><p>Depending on your browser settings, you may need to right click the link to save it.</p>',
  40.         message_fail:       '<h2>Download Failed</h2><p>Sorry, something went wrong!</p>',
  41.         message_timeout:    '<h2>Download<br />Unavailable</h2><p>please try again later!</p>',
  42.         dl_remote_path:     ''
  43.     },
  44.  
  45.     eID: {
  46.         play:       '#playpause_mp3j_',
  47.         playW:      '#playpause_wrap_mp3j_',
  48.         stp:        '#stop_mp3j_',
  49.         prev:       '#Prev_mp3j_',
  50.         next:       '#Next_mp3j_',
  51.         vol:        '#vol_mp3j_',
  52.         loader:     '#load_mp3j_',
  53.         pos:        '#posbar_mp3j_',
  54.         poscol:     '#poscol_mp3j_',
  55.         title:      '#T_mp3j_',
  56.         caption:    '#C_mp3j_',
  57.         pT:         '#P-Time-MI_',
  58.         tT:         '#T-Time-MI_',
  59.         dload:      '#download_mp3j_',
  60.         plwrap:     '#L_mp3j_',
  61.         ul:         '#UL_mp3j_',
  62.         a:          'mp3j_A_', //No hash!
  63.         indiM:      '#statusMI_',
  64.         toglist:    '#playlist-toggle_',
  65.         lPP:        '#lpp_mp3j_',
  66.         pplink:     '#mp3j_popout_',
  67.         img:        '#MI_image_'
  68.     },
  69.  
  70.     init: function () {
  71.         var plpath, that = this;
  72.                
  73.         plpath = this.plugin_path.split('/');
  74.         this.dl_domain = plpath[2].replace(/^www./i, "");
  75.        
  76.         this.unwrap();
  77.         this.write_controls();
  78.         jQuery(this.jpID).jPlayer({
  79.             ready: function () {
  80.                 that.startup();
  81.             },
  82.             //swfPath: that.plugin_path + '/js',
  83.             swfPath: that.plugin_path + '/js/Jplayer2-6-0.swf',
  84.             volume: 1,
  85.             supplied: "mp3",
  86.             wmode: "window",
  87.             solution:"html, flash",
  88.             preload: "none"
  89.         });
  90.         jQuery(this.jpID).bind(jQuery.jPlayer.event.ended, function(event) {
  91.             that.E_complete(that.tID);
  92.         });
  93.         jQuery(this.jpID).bind(jQuery.jPlayer.event.timeupdate, function(event) {
  94.             var lp = that.get_loaded(event);
  95.             var ppA = event.jPlayer.status.currentPercentAbsolute;
  96.             var pt = event.jPlayer.status.currentTime;
  97.             var tt = event.jPlayer.status.duration;
  98.             that.E_update(that.tID, lp, ppA, pt, tt);
  99.         });
  100.         jQuery(this.jpID).bind(jQuery.jPlayer.event.ready, function(event) {
  101.             if(event.jPlayer.html.used && event.jPlayer.html.audio.available) {
  102.                 that.jp_audio = jQuery(that.jpID).data("jPlayer").htmlElement.audio;
  103.             } else {
  104.                 that.jp_audio = 'flash';
  105.             }
  106.         });
  107.         jQuery(this.jpID).bind(jQuery.jPlayer.event.progress, function(event) {
  108.             var lp = that.get_loaded(event);
  109.             var pt = event.jPlayer.status.currentTime;
  110.             var tt = event.jPlayer.status.duration;
  111.             that.E_loading( that.tID, lp, tt, pt );
  112.         });
  113.     },
  114.    
  115.     get_loaded: function (event) {
  116.         var lp;
  117.         if ( typeof this.jp_audio.buffered === "object" ) {
  118.             if( this.jp_audio.buffered.length > 0 && this.jp_audio.duration > 0 ) {
  119.                     lp = 100 * this.jp_audio.buffered.end(this.jp_audio.buffered.length-1) / this.jp_audio.duration;
  120.             } else {
  121.                 lp = 0;
  122.             }
  123.         } else {
  124.             lp = event.jPlayer.status.seekPercent;
  125.         }
  126.         this.jp_seekable = event.jPlayer.status.seekPercent; //use this for slider calcs for both html/flash solution
  127.         this.load_pc = lp;
  128.         return lp;
  129.     },
  130.    
  131.     Tformat: function ( sec ) {
  132.         var t = sec,
  133.             s = Math.floor((t)%60),
  134.             m = Math.floor((t/60)%60),
  135.             h = Math.floor(t/3600);
  136.         return ((h > 0) ? h+':' : '') + ((m > 9) ? m : '0'+m) + ':' + ((s > 9) ? s : '0'+s);
  137.     },
  138.  
  139.     E_loading: function ( j, lp, tt, pt ) {
  140.         if (j !== '') {    
  141.             jQuery(this.eID.loader + j).css( "width", lp + '%' );
  142.             if (this.pl_info[j].type === 'MI') {
  143.                 if (tt > 0 && this.played_t > 0) {
  144.                     jQuery(this.eID.tT + j).text(this.Tformat(tt));
  145.                 }
  146.             }
  147.             if ( this.jp_audio !== 'flash' && lp < 100 ) {
  148.                 if ( pt === this.played_t && this.state === 'playing' && pt > 0 && !this.sliding ) {
  149.                     if (this.pl_info[j].type === 'MI') {
  150.                         jQuery(this.eID.indiM + j).empty().append('<span class="mp3-finding"></span><span class="mp3-tint"></span>Buffering');
  151.                     }
  152.                     if (this.pl_info[j].type === 'single' ) {
  153.                         jQuery(this.eID.indiM + j).empty().append('<span class="Smp3-finding"></span><span class="mp3-gtint"></span> ' + this.Tformat(pt));
  154.                     }
  155.                 }
  156.                 this.played_t = pt;
  157.             }
  158.         }
  159.     },
  160.    
  161.     E_update: function (j, lp, ppA, pt, tt) {
  162.         if (j !== '') {    
  163.             jQuery(this.eID.loader + j).css( "width", lp + '%' );
  164.             jQuery(this.eID.poscol + j).css( "width", ppA + '%' );
  165.             if ( jQuery(this.eID.pos + j + ' div.ui-widget-header').length > 0 ) {
  166.                 jQuery(this.eID.pos + j).slider('option', 'value', 10*ppA);
  167.             }
  168.             if (pt > 0) {
  169.                 jQuery(this.eID.pos + j).css( 'visibility', 'visible' );
  170.             }
  171.             if (this.pl_info[j].type === 'MI') {
  172.                 jQuery(this.eID.pT + j).text(this.Tformat(pt));
  173.             }
  174.             if ('playing' === this.state) {
  175.                 if ('MI' === this.pl_info[j].type) {
  176.                     if (tt > 0 && this.played_t === pt && lp < 100 && !this.sliding ) {
  177.                         jQuery(this.eID.indiM + j).empty().append('<span class="mp3-finding"></span><span class="mp3-tint"></span>Buffering');
  178.                         jQuery(this.eID.tT + j).text(this.Tformat(tt));
  179.                     } else if (pt > 0) {
  180.                         jQuery(this.eID.indiM + j).empty().append('Playing');
  181.                         jQuery(this.eID.tT + j).text(this.Tformat(tt));
  182.                     }
  183.                 }
  184.                 if ('single' === this.pl_info[j].type){
  185.                     if (pt > 0 ) {
  186.                         if (this.played_t === pt && lp < 100 && !this.sliding ) {
  187.                             jQuery(this.eID.indiM + j).empty().append('<span class="Smp3-finding"></span><span class="mp3-gtint"></span> ' + this.Tformat(pt));
  188.                         } else {
  189.                             jQuery(this.eID.indiM + j).empty().append('<span class="mp3-tint tintmarg"></span> ' + this.Tformat(pt));
  190.                         }
  191.                     }
  192.                 }
  193.             }
  194.             this.played_t = pt;
  195.         }
  196.     },
  197.    
  198.     E_complete: function (j) {
  199.         var p = this.pl_info[j];
  200.         if ('MI' === p.type) {
  201.             if (p.loop || p.tr+1 < p.list.length) {
  202.                 this.E_change_track(j, 'next');
  203.             } else {
  204.                 this.E_dblstop(j);
  205.                 this.startup();
  206.             }
  207.         }
  208.         if ('single' === p.type) {
  209.             if (p.loop) {
  210.                 this.E_change_track(j, 'next');
  211.             } else {
  212.                 this.E_stop(j);
  213.                 this.startup();
  214.             }
  215.         }
  216.     },
  217.    
  218.     write_controls: function () {
  219.         var j;
  220.         for (j = 0; j < this.pl_info.length; j += 1) {
  221.             this.setup_a_player(j);
  222.         }
  223.     },
  224.    
  225.     startup: function () {
  226.         var j;
  227.         for (j = 0; j < this.pl_info.length; j += 1) {
  228.             //if (this.pl_info[j].autoplay) {
  229.             if ( this.pl_info[j].autoplay && (this.pl_info[j].type === 'single' || this.pl_info[j].type === 'MI') ) {
  230.                 this.pl_info[j].autoplay = false;
  231.                 this.E_change_track(j, this.pl_info[j].tr);
  232.                 return;
  233.             }
  234.         }
  235.     },
  236.    
  237.     setup_a_player: function (j) {
  238.         var i, li, sel, that = this, p = this.pl_info[j];
  239.        
  240.     //PLAYLISTERS and SINGLES
  241.         if ('MI' === p.type || 'single' === p.type) {
  242.            
  243.             jQuery(this.eID.vol + j).slider({
  244.                 value : p.vol,
  245.                 max: 100,
  246.                 range: 'min',
  247.                 animate: false,
  248.                 slide: function (event, ui) {
  249.                     p.vol = ui.value;
  250.                     if (j === that.tID) {
  251.                         jQuery(that.jpID).jPlayer("volume", ui.value/100);
  252.                     }
  253.                 }
  254.             });
  255.            
  256.             jQuery(this.eID.pos + j).mouseup(function (e) { //for posbar
  257.                 that.sliding = false;
  258.             });
  259.            
  260.             sel = ('MI' === p.type) ? this.eID.play : this.eID.playW;
  261.             jQuery(sel + j).click(function () { //play-pause click
  262.                 that.E_change_track(j, p.tr);
  263.                 jQuery(this).blur();
  264.             });
  265.             jQuery(sel + j).dblclick(function () { //play-pause dbl click
  266.                 if (that.state !== "playing") {
  267.                     that.E_change_track(j, p.tr);
  268.                 }
  269.                 jQuery(this).blur();
  270.             });
  271.                
  272.             this.titles(j, p.tr);
  273.         }
  274.        
  275.     //PLAYLISTERS
  276.         if ('MI' === p.type) {
  277.             jQuery(this.eID.pT + j).text('00:00');
  278.             jQuery(this.eID.indiM + j).text('Ready');
  279.             jQuery(this.eID.stp + j).click(function () {
  280.                 that.E_stop(j);
  281.             });
  282.             jQuery(this.eID.stp + j).dblclick(function () {
  283.                 that.E_dblstop(j);
  284.             });
  285.            
  286.             jQuery(this.eID.plwrap + j).hide();
  287.             if (p.list.length > 1) {
  288.                 jQuery(this.eID.next + j).click(function () {
  289.                     that.E_change_track(j, 'next');
  290.                 });
  291.                 jQuery(this.eID.prev + j).click(function () {
  292.                     that.E_change_track(j, 'prev');
  293.                 });
  294.                 jQuery(this.eID.ul + j).empty();
  295.                 for (i = 0; i < p.list.length; i += 1) {
  296.                     li = '<li>';
  297.                     li += '<a href="#" id="' + this.eID.a + j + '_' + i + '">' + p.list[i].name + '</a></li>';
  298.                     jQuery(this.eID.ul + j).append(li);
  299.                     this.add_ul_click(j, i);
  300.                 }
  301.                 jQuery('#' + this.eID.a + j + '_' + p.tr).addClass('mp3j_A_current');
  302.                 jQuery(this.eID.toglist + j).click(function () {
  303.                     that.togglelist(j);
  304.                 });
  305.                 if (p.lstate === true) {
  306.                     jQuery(this.eID.plwrap + j).show();
  307.                 }  
  308.             }
  309.            
  310.             this.writedownload(j, p.tr);   
  311.             if ( this.vars.force_dload === true ) {
  312.                 this.dl_closeinfo_click(j);
  313.             }
  314.            
  315.             jQuery(this.eID.lPP + j).click(function () {
  316.                 return that.E_launchPP(j);
  317.             });
  318.         }
  319.        
  320.     //POPOUT LINKS
  321.         if ('popout' === p.type) {
  322.             jQuery(this.eID.pplink + j).click(function () {
  323.                 return that.E_launchPP(j);
  324.             });
  325.         }
  326.     },
  327.    
  328.     add_ul_click: function (j, i) { //playlist item click
  329.         var that = this;
  330.         jQuery('#' + this.eID.a + j + "_" + i).click(function (e) {
  331.             that.E_change_track(j, i);
  332.             e.preventDefault();
  333.         });
  334.     },
  335.        
  336.     unwrap: function () {
  337.         var i, j, arr;
  338.         if (this.vars.play_f === true && typeof this.lists !== "undefined" && this.lists.length > 0) {
  339.             for (i = 0; i < this.lists.length; i += 1) {
  340.                 arr = this.lists[i];
  341.                 for (j = 0; j < arr.length; j += 1) {
  342.                     arr[j].mp3 = this.f_undo.f_con(arr[j].mp3);
  343.                 }
  344.             }
  345.         }
  346.     },
  347.    
  348.     f_undo: {
  349.         keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  350.         f_con : function (input) {
  351.             var output = "", i = 0, chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  352.             input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  353.             while (i < input.length) {
  354.                 enc1 = this.keyStr.indexOf(input.charAt(i++)); enc2 = this.keyStr.indexOf(input.charAt(i++));
  355.                 enc3 = this.keyStr.indexOf(input.charAt(i++)); enc4 = this.keyStr.indexOf(input.charAt(i++));
  356.                 chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4;
  357.                 output = output + String.fromCharCode(chr1);
  358.                 if (enc3 !== 64) { output = output + String.fromCharCode(chr2); }
  359.                 if (enc4 !== 64) { output = output + String.fromCharCode(chr3); }
  360.             }
  361.             output = this.utf8_f_con(output);
  362.             return output;
  363.         },
  364.         utf8_f_con : function (utftext) {
  365.             var string = "", i = 0, c, c1, c2, c3;
  366.             while (i < utftext.length) {
  367.                 c = utftext.charCodeAt(i);
  368.                 if (c < 128) {
  369.                     string += String.fromCharCode(c); i++;
  370.                 } else if ((c > 191) && (c < 224)) {
  371.                     c2 = utftext.charCodeAt(i + 1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2;
  372.                 } else {
  373.                     c2 = utftext.charCodeAt(i + 1); c3 = utftext.charCodeAt(i + 2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3;
  374.                 }
  375.             }
  376.             return string;
  377.         }
  378.     },
  379.    
  380.  
  381.     E_stop: function (j) {
  382.         if (j === this.tID && j !== '') {
  383.             this.clearit();
  384.             if ( jQuery(this.eID.pos + j + ' div.ui-widget-header').length > 0 ) {
  385.                 jQuery(this.eID.pos + j).slider('destroy');
  386.             }
  387.             jQuery(this.eID.loader + j).css( "width", '0%' );
  388.             this.button(j, 'play');
  389.             if (this.pl_info[j].type === 'MI') {
  390.                 jQuery(this.eID.poscol + j).css( "width", '0%' );
  391.                 jQuery(this.eID.tT + j).empty();
  392.                 jQuery(this.eID.indiM + j).text('Stopped');
  393.                 jQuery(this.eID.pT + j).text(this.Tformat(0));
  394.             } else {
  395.                 jQuery(this.eID.indiM + j).empty();
  396.             }
  397.             this.load_pc = 0;
  398.             this.played_t = 0;
  399.         }
  400.     },
  401.    
  402.     E_dblstop: function (j) {
  403.         this.listclass(j, this.pl_info[j].tr, 0);
  404.         if ( this.pl_info[j].tr !== 0 ) {
  405.             this.titles(j, 0);
  406.         }
  407.         this.writedownload(j, 0);
  408.         this.E_stop(j);
  409.         jQuery(this.eID.indiM + j).text('Ready');
  410.         this.pl_info[j].tr = 0;
  411.     },
  412.    
  413.     E_change_track: function (j, change) {
  414.         var track, txt, p = this.pl_info[j];
  415.         if (j === this.tID && change === p.tr) {
  416.             if ('playing' === this.state) {
  417.                 if (this.load_pc === 0) {
  418.                     this.E_stop(j);
  419.                 } else {
  420.                     this.pauseit();
  421.                     this.button(j, 'play');
  422.                     if ('MI' === p.type) {
  423.                         jQuery(this.eID.indiM + j).text('Paused');
  424.                     }
  425.                 }
  426.                 return;
  427.             } else if ('paused' === this.state || 'set' === this.state) {
  428.                 this.playit();
  429.                 this.button(j, 'pause');
  430.                 return;
  431.             }
  432.         }
  433.         this.E_stop(this.tID);
  434.         if ('prev' === change) {
  435.             track = (p.tr-1 < 0) ? p.list.length-1 : p.tr-1;
  436.         } else if ('next' === change) {
  437.             track = (p.tr+1 < p.list.length) ? p.tr+1 : 0;
  438.         } else {
  439.             track = change;
  440.         }
  441.         jQuery(this.jpID).jPlayer("volume", 1 ); //Vol scaling fix
  442.         this.setit(p.list[track].mp3);
  443.         this.playit();
  444.         jQuery(this.jpID).jPlayer("volume", p.vol/100 ); //Reset to correct vol
  445.         txt = ('MI' === p.type) ? '<span class="mp3-finding"></span><span class="mp3-tint"></span>Connecting' : '<span class="Smp3-finding"></span><span class="mp3-gtint"></span>';
  446.         jQuery(this.eID.indiM + j).empty().append(txt);
  447.         this.button(j, 'pause');
  448.         this.makeslider(j);
  449.         if ('MI' === p.type) {
  450.             this.listclass(j, p.tr, track);
  451.             if ( p.tr !== track ) {
  452.                 this.titles(j, track);
  453.             }
  454.             if (p.download) {
  455.                 this.writedownload(j, track);
  456.                 jQuery(this.eID.dload + j).hide().addClass('whilelinks').fadeIn(400);
  457.             }
  458.         }
  459.         p.tr = track;
  460.         this.tID = j;
  461.     },
  462.    
  463.     E_launchPP: function (j) {
  464.         var li_height = 28;
  465.         if ( this.pl_info[j].height !== false ) {
  466.             this.vars.pp_playerheight = 100 + this.pl_info[j].height;
  467.         }
  468.         this.vars.pp_windowheight = ( this.pl_info[j].list.length > 1 ) ? this.vars.pp_playerheight + ( this.pl_info[j].list.length * li_height) : this.vars.pp_playerheight;
  469.         if ( this.vars.pp_windowheight > this.vars.pp_maxheight ) {
  470.             this.vars.pp_windowheight = this.vars.pp_maxheight;
  471.         }
  472.         this.launched_ID = j;
  473.         this.was_playing = ( this.state === "playing" ) ? true : false;
  474.        
  475.         this.E_stop(this.tID);
  476.         this.setit(this.plugin_path + '/mp3/silence.mp3');
  477.         this.playit(); //make chrome let go of last track (incase it didn't finish loading)
  478.         this.clearit();
  479.        
  480.         var newwindow = window.open(this.plugin_path + '/popout.php', 'mp3jpopout', 'height=300, width=600, location=1, status=1, scrollbars=1, resizable=1, left=25, top=25');
  481.         if ( this.pl_info[j].lstate === true ) {
  482.             newwindow.resizeTo( this.vars.pp_width, this.vars.pp_windowheight );
  483.         } else {
  484.             newwindow.resizeTo( this.vars.pp_width, this.vars.pp_playerheight );
  485.         }
  486.         if (window.focus) {
  487.             newwindow.focus();
  488.         }
  489.         return false;
  490.     },
  491.    
  492.     setit: function (file) {
  493.         this.state = 'set';
  494.         jQuery(this.jpID).jPlayer("setMedia", {mp3: file});
  495.     },
  496.     playit: function () {
  497.         this.state = 'playing';
  498.         jQuery(this.jpID).jPlayer("play");
  499.     },
  500.     pauseit: function () {
  501.         this.state = 'paused';
  502.         jQuery(this.jpID).jPlayer("pause");
  503.     },
  504.     clearit: function () {
  505.         this.state = '';
  506.         jQuery(this.jpID).jPlayer("clearMedia");
  507.     },
  508.            
  509.     button: function (j, type) {
  510.         if (j === '') { return; }
  511.         if ('pause' === type) {
  512.             if (this.pl_info[j].play_txt === '#USE_G#') {
  513.                 jQuery(this.eID.play + j).removeClass('buttons_mp3j').addClass('buttons_mp3jpause');
  514.             } else {
  515.                 jQuery(this.eID.play + j).text(this.pl_info[j].pause_txt);
  516.             }
  517.         }
  518.         if ('play' === type) {
  519.             if (this.pl_info[j].play_txt === '#USE_G#') {
  520.                 jQuery(this.eID.play + j).removeClass('buttons_mp3jpause').addClass('buttons_mp3j');
  521.             } else {
  522.                 jQuery(this.eID.play + j).text(this.pl_info[j].play_txt);
  523.             }
  524.         }
  525.     },
  526.    
  527.     listclass: function ( j, rem, add ) {
  528.         jQuery('#'+ this.eID.a + j +'_'+ rem).removeClass('mp3j_A_current');
  529.         jQuery('#'+ this.eID.a + j +'_'+ add).addClass('mp3j_A_current');
  530.     },
  531.    
  532.     titles: function ( j, track ) {
  533.         var p = this.pl_info[j], Olink = '', Clink = '';   
  534.         if (p.type === "MI") {
  535.             jQuery(this.eID.title + j).empty().append(p.list[track].name).append('<br /><span>' + p.list[track].artist + '</span>');
  536.             if (p.list[track].image !== '') {
  537.                 if (p.list[track].imgurl !== '') {
  538.                     Olink = '<a href="' + p.list[track].imgurl + '">';
  539.                     Clink = '</a>';
  540.                 }
  541.                 jQuery(this.eID.img + j).empty().hide().append(Olink + '<img src="' + p.list[track].image + '" />' + Clink).fadeIn(300);
  542.             }
  543.         }
  544.     },
  545.    
  546.     writedownload: function ( j, track ) {
  547.         var p = this.pl_info[j];
  548.         if (p.download) {
  549.             jQuery(this.eID.dload + j).empty().removeClass('whilelinks').append('<a id="mp3j_dlanchor_' + j + '" href="' + p.list[track].mp3 + '" target="_blank">' + this.vars.dload_text + '</a>');
  550.             if ( this.vars.force_dload === true ) {
  551.                 this.dl_button_click( j );
  552.             }
  553.         }
  554.     },
  555.    
  556.     togglelist: function ( j ) {
  557.         if (this.pl_info[j].lstate === true) {
  558.             jQuery(this.eID.plwrap + j).fadeOut(300);
  559.             jQuery(this.eID.toglist + j).text('SHOW');
  560.             this.pl_info[j].lstate = false;
  561.         } else if (this.pl_info[j].lstate === false) {
  562.             jQuery(this.eID.plwrap + j).fadeIn("slow");
  563.             jQuery(this.eID.toglist + j).text('HIDE');
  564.             this.pl_info[j].lstate = true;
  565.         }
  566.     },
  567.        
  568.     makeslider: function (j) {
  569.         var phmove, cssmove, that = this;
  570.         jQuery(this.eID.pos + j).css( 'visibility', 'hidden' );
  571.         jQuery(this.eID.pos + j).slider({
  572.             max: 1000,
  573.             range: 'min',
  574.             animate: false,
  575.             slide: function (event, ui) {
  576.                 if ((ui.value/10) < that.load_pc) {
  577.                     cssmove = ui.value/10;
  578.                     phmove = ui.value*(10.0/that.jp_seekable);
  579.                 } else {
  580.                     cssmove = 0.99*that.load_pc;
  581.                     phmove = (9.9*that.load_pc)*(10.0/that.jp_seekable);
  582.                 }
  583.                 jQuery(that.eID.poscol + j).css('width', cssmove + '%');
  584.                 jQuery(that.jpID).jPlayer("playHead", phmove );
  585.                 if (that.state === 'paused') {
  586.                     that.button(j, 'pause');
  587.                     that.playit();
  588.                 }
  589.                 that.state = 'playing';
  590.                 that.sliding = true;
  591.             }
  592.         });
  593.     }
  594.    
  595. };
  596.  
  597. // Force browser download
  598. MP3_JPLAYER.dl_button_click = function ( j ) {
  599.     var that = this, p = this.pl_info[j];
  600.     jQuery('#mp3j_dlanchor_' + j).click(function (e) {
  601.         that.dl_runinfo( p.list[p.tr].mp3, j, e );
  602.         e.preventDefault();
  603.     });
  604. };
  605.  
  606. MP3_JPLAYER.dl_closeinfo_click = function ( j ) {
  607.     var that = this;
  608.     jQuery('#mp3j_finfo_close_' + j).click(function () {
  609.         that.dl_dialogue( j, '', 'close');
  610.         that.clear_timers( j );
  611.     });
  612. }; 
  613.  
  614. MP3_JPLAYER.dl_runinfo = function ( get, j, e ) {
  615.     var can_write,  
  616.         dlpath,
  617.         message,
  618.         that = this,
  619.         dlframe = false,
  620.         p = this.pl_info[j],
  621.         is_local = this.is_local_dload( get );
  622.    
  623.     var enc_get;
  624.    
  625.     if ( !this.intervalIDs[ j ] && !this.timeoutIDs[ j ] ) { //if timers not already running for this player
  626.         can_write = this.write_cookie('mp3Download' + j, 'waiting', '');
  627.         if ( is_local ) {
  628.             if ( can_write !== false ) {
  629.                 this.dl_dialogue( j, this.vars.message_interval, 'check');
  630.             } else {
  631.                 this.dl_dialogue( j, this.vars.message_indark, 'indark');
  632.             }
  633.             this.intervalIDs[ j ] = setInterval( function(){ that.dl_interval_check( j, can_write ); }, 500);
  634.             this.timeoutIDs[ j ] = setTimeout( function(){ that.dl_timeout( j, can_write ); }, 7000);
  635.             dlframe = true;
  636.         } else {
  637.             if ( this.vars.dl_remote_path === '' ) {
  638.                 message = this.vars.message_promtlink.replace('#1', get);
  639.                 message = message.replace('#2', p.list[p.tr].name);
  640.                 this.dl_dialogue( j, message, 'indark');
  641.             } else {
  642.                 message = this.vars.message_indark.replace('#1', get);
  643.                 message = message.replace('#2', p.list[p.tr].name);
  644.                 this.dl_dialogue( j, message, 'indark');
  645.                 dlframe = true;
  646.             }
  647.         }
  648.         this.dl_dialogs[ j ] = 'false';
  649.         if ( dlframe ) {
  650.             dlpath = this.get_dloader_path( get );
  651.             enc_get = encodeURIComponent( get );
  652.             //jQuery('#mp3j_dlf_' + j).empty().append('<iframe id="mp3j_dlframe_' + j + '" name="mp3j_dlframe_' + j + '" class="mp3j-dlframe" src="' + dlpath + '?mp3=loc' + get + '&pID=' + j + '" style="display:none;"></iframe>');
  653.             jQuery('#mp3j_dlf_' + j).empty().append('<iframe id="mp3j_dlframe_' + j + '" name="mp3j_dlframe_' + j + '" class="mp3j-dlframe" src="' + dlpath + '?mp3=loc' + enc_get + '&pID=' + j + '" style="display:none;"></iframe>');
  654.         }  
  655.     }
  656. };
  657.  
  658. MP3_JPLAYER.dl_interval_check = function  ( j, can_write ) {
  659.     if ( can_write !== false && this.read_cookie('mp3Download' + j) === 'true' ) {  //got cookie back, all should be good  
  660.         this.dl_dialogue( j, this.vars.message_ok, 'hide');
  661.         //jQuery('#debug').append('<br />check: cookie '+j+' true');
  662.         this.clear_timers( j );
  663.     } else if ( this.dl_dialogs[ j ] !== 'false' ) { //got a message back
  664.         this.dl_dialogue( j, this.dl_dialogs[ j ], 'add');     
  665.         //jQuery('#debug').append('<br />check: dialog'+j+' true');
  666.         this.clear_timers( j );
  667.     } //else {
  668.         //jQuery('#debug').append('<br />check: neither '+j+'...# ');
  669.     //}                                                                    
  670. };
  671.  
  672. MP3_JPLAYER.dl_timeout = function ( j, can_write  ) {
  673.     this.clear_timers( j );
  674.     if ( can_write !== false ) {
  675.         this.dl_dialogue( j, this.vars.message_timeout, 'add');
  676.     }
  677.     //jQuery('#debug').append('<br />no responses ('+j+' timed out) ');
  678. };
  679.  
  680. MP3_JPLAYER.clear_timers = function ( j ) {
  681.     if ( this.intervalIDs[ j ] !== null && this.timeoutIDs[ j ] !== null ) {
  682.         clearInterval( this.intervalIDs[j] );
  683.         clearTimeout( this.timeoutIDs[j] );
  684.         this.intervalIDs[ j ] = null;
  685.         this.timeoutIDs[j] = null;
  686.     }
  687.     jQuery('#mp3j_dlf_' + j).empty(); //ditch iframe
  688.     this.write_cookie('mp3Download' + j, '', -1); //clear any cookie
  689.     //jQuery('#debug').append('<br />cookie/frame '+j+' cleared');
  690. };
  691.  
  692. MP3_JPLAYER.dl_dialogue = function ( j, text, state ) {
  693.     if ( 'check' === state ) {
  694.         jQuery('#mp3j_finfo_gif_' + j).show();
  695.         jQuery('#mp3j_finfo_txt_' + j).empty().append(text).show();
  696.         jQuery('#mp3j_finfo_' + j).show();
  697.     } else if ( 'add' === state ) {
  698.         jQuery('#mp3j_finfo_gif_' + j).hide();
  699.         jQuery('#mp3j_finfo_txt_' + j).empty().append(text).show();
  700.     } else if ( 'indark' === state ) {
  701.         jQuery('#mp3j_finfo_gif_' + j).hide();
  702.         jQuery('#mp3j_finfo_txt_' + j).empty().append(text).show();
  703.         jQuery('#mp3j_finfo_' + j).fadeIn(100);
  704.     } else if ( 'close' === state ) {
  705.         jQuery('#mp3j_finfo_gif_' + j).hide();
  706.         jQuery('#mp3j_finfo_' + j).hide();
  707.     } else {
  708.         jQuery('#mp3j_finfo_gif_' + j).hide();
  709.         if ( text !== '' ) {
  710.             jQuery('#mp3j_finfo_txt_' + j).empty().append(text).show();
  711.         }
  712.         jQuery('#mp3j_finfo_' + j).fadeOut(1000);
  713.     }
  714. };
  715.  
  716. MP3_JPLAYER.read_cookie = function ( name ) {
  717.     var i, cookie, allCookies = document.cookie.split('; ');
  718.     if ( allCookies.length > 0 ) {
  719.         for ( i = 0; i < allCookies.length; i += 1 ) {
  720.             cookie = allCookies[i].split( '=' );
  721.             if ( cookie[0] === name ) {
  722.                 return cookie[1];
  723.             }
  724.         }
  725.     }
  726.     return false;
  727. };
  728.  
  729. MP3_JPLAYER.write_cookie = function ( name, value, days ) {
  730.     var date, expires = "";
  731.     if ( days ) {
  732.         date = new Date();
  733.         date.setTime( date.getTime() + (days*24*60*60*1000) );
  734.         expires = "; expires=" + date.toGMTString();
  735.     }
  736.     document.cookie = name + "=" + value + expires + "; path=/";
  737.     return this.read_cookie( name );
  738. };
  739.  
  740. MP3_JPLAYER.get_dloader_path = function ( loc ) {
  741.     var k, path = "", file = "", chunks;
  742.     chunks = loc.split('/');
  743.     file = chunks[chunks.length-1];
  744.     //jQuery('#debug').append('<br />');
  745.     //for ( k = 0; k < chunks.length; k += 1 ) {
  746.     //  jQuery('#debug').append('<br />[' + k + '] ' + chunks[k]);
  747.     //}
  748.     //jQuery('#debug').append('<br />file:' + file);
  749.     if ( loc.charAt(0) === '/' ) {
  750.         path = this.plugin_path + '/download.php';
  751.     } else {
  752.         path = chunks[2].replace(/^www./i, "");
  753.         if ( path === this.dl_domain ) {
  754.             path = this.plugin_path + '/download.php';
  755.         } else {
  756.             path = chunks[0] + '//' + chunks[2] + this.vars.dl_remote_path;
  757.         }
  758.     }
  759.     //jQuery('#debug').append('<br />path:' + path);
  760.     return path;
  761. };
  762.  
  763. MP3_JPLAYER.is_local_dload = function ( loc ) {
  764.     var domain = "", file = "", chunks, is_local = false;
  765.     chunks = loc.split('/');
  766.     file = chunks[chunks.length-1];
  767.     if ( loc.charAt(0) === '/' ) {
  768.         is_local = true;
  769.     } else {
  770.         domain = chunks[2].replace(/^www./i, "");
  771.         if ( domain === this.dl_domain ) {
  772.             is_local = true;
  773.         }
  774.     }
  775.     return is_local;
  776. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement