]> git.sesse.net Git - vlc/blobdiff - share/http/js/functions.js
s,fake:,fake://,g
[vlc] / share / http / js / functions.js
index fe767914753a2c8dffcc3152572eb7da7d1d797f..fcd6c7a1677b9b7879ef6964be5802b9277c4dbe 100644 (file)
@@ -27,6 +27,7 @@
 
 var old_time = 0;
 var pl_cur_id;
+var albumart_id = -1;
 
 /**********************************************************************
  * Slider functions
@@ -197,6 +198,7 @@ function toggle_show_node( id )
 }
 
 function show( id ){ document.getElementById( id ).style.display = 'block'; }
+function showinline( id ){ document.getElementById( id ).style.display = 'inline'; }
 
 function hide( id ){ document.getElementById( id ).style.display = 'none'; }
 
@@ -204,6 +206,12 @@ function checked( id ){ return document.getElementById( id ).checked; }
 
 function value( id ){ return document.getElementById( id ).value; }
 
+function setclass( obj, value )
+{
+    obj.setAttribute( 'class', value ); /* Firefox */
+    obj.setAttribute( 'className', value ); /* IE */
+}
+
 function radio_value( name )
 {
     var radio = document.getElementsByName( name );
@@ -219,7 +227,7 @@ function radio_value( name )
 
 function check_and_replace_int( id, val )
 {
-    var objRegExp = /^\d\d*$/;
+    var objRegExp = /^\d+$/;
     if( value( id ) != ''
         && ( !objRegExp.test( value( id ) )
              || parseInt( value( id ) ) < 1 ) )
@@ -228,7 +236,7 @@ function check_and_replace_int( id, val )
 }
 
 function addslashes( str ){ return str.replace(/\'/g, '\\\''); }
-function escapebackslashes( str ){ return str.replace(/\\[^']/g, '\\\\'); }
+function escapebackslashes( str ){ return str.replace(/\\/g, '\\\\'); }
 
 function toCamelCase( str )
 {
@@ -280,7 +288,7 @@ function in_play()
     var input = value('input_mrl');
     if( value('sout_mrl') != '' )
         input += ' '+value('sout_mrl');
-    var url = 'requests/status.xml?command=in_play&input='+escape( input );
+    var url = 'requests/status.xml?command=in_play&input='+encodeURIComponent( addslashes(escapebackslashes(input)) );
     loadXMLDoc( url, parse_status );
     setTimeout( 'update_playlist()', 1000 );
 }
@@ -289,7 +297,7 @@ function in_enqueue()
     var input = value('input_mrl');
     if( value('sout_mrl') != '' )
         input += ' '+value('sout_mrl');
-    var url = 'requests/status.xml?command=in_enqueue&input='+escape( input );
+    var url = 'requests/status.xml?command=in_enqueue&input='+encodeURIComponent( addslashes(escapebackslashes(input)) );
     loadXMLDoc( url, parse_status );
     setTimeout( 'update_playlist()', 1000 );
 }
@@ -370,6 +378,15 @@ function fullscreen()
 {
     loadXMLDoc( 'requests/status.xml?command=fullscreen', parse_status );
 }
+function snapshot()
+{
+    loadXMLDoc( 'requests/status.xml?command=snapshot', parse_status );
+}
+function hotkey( str )
+{
+    /* Use hotkey name (without the "key-" part) as the argument to simulate a hotkey press */
+    loadXMLDoc( 'requests/status.xml?command=key&val='+str, parse_status );
+}
 function update_status()
 {
     loadXMLDoc( 'requests/status.xml', parse_status );
@@ -460,21 +477,21 @@ function parse_status()
 
             var randomtag = status.getElementsByTagName( 'random' );
             if( randomtag.length > 0 ? randomtag[0].firstChild.data == "1" : 0)
-                document.getElementById( 'btn_shuffle').setAttribute( 'class', 'on' );
+                setclass( document.getElementById( 'btn_shuffle'), 'on' );
             else
-                document.getElementById( 'btn_shuffle').setAttribute( 'class', 'off' );
+                setclass( document.getElementById( 'btn_shuffle'), 'off' );
                
             var looptag = status.getElementsByTagName( 'loop' );
             if( looptag.length > 0 ? looptag[0].firstChild.data == "1" : 0)
-                document.getElementById( 'btn_loop').setAttribute( 'class', 'on' );
+                setclass( document.getElementById( 'btn_loop'), 'on' );
             else
-                document.getElementById( 'btn_loop').setAttribute( 'class', 'off' );
+                setclass( document.getElementById( 'btn_loop'), 'off' );
 
             var repeattag = status.getElementsByTagName( 'repeat' );
             if( repeattag.length > 0 ? repeattag[0].firstChild.data == "1" : 0 )
-                document.getElementById( 'btn_repeat').setAttribute( 'class', 'on' );
+                setclass( document.getElementById( 'btn_repeat'), 'on' );
             else
-                document.getElementById( 'btn_repeat').setAttribute( 'class', 'off' );
+                setclass( document.getElementById( 'btn_repeat'), 'off' );
 
             var tree = document.createElement( "ul" );
             var categories = status.getElementsByTagName( 'category' );
@@ -557,7 +574,7 @@ function parse_playlist()
                     }
 
                     var nd = document.createElement( "div" );
-                    nd.setAttribute( 'class', 'pl_node' );
+                    setclass( nd, 'pl_node' );
                     nd.setAttribute( 'id', 'pl_'+elt.getAttribute( 'id' ) );
                     pos.appendChild( nd );
                 }
@@ -566,12 +583,12 @@ function parse_playlist()
                     if( pos.hasChildNodes() )
                     pos.appendChild( document.createElement( "br" ) );
                     var pl = document.createElement( "a" );
-                    pl.setAttribute( 'class', 'pl_leaf' );
+                    setclass( pl, 'pl_leaf' );
                     pl.setAttribute( 'href', 'javascript:pl_play('+elt.getAttribute( 'id' )+');' );
                     pl.setAttribute( 'id', 'pl_'+elt.getAttribute( 'id' ) );
                     if( elt.getAttribute( 'current' ) == 'current' )
                     {
-                        pl.setAttribute( 'style', 'font-weight: bold;' );
+                        pl.style.fontWeight = 'bold';
                         var nowplaying = document.getElementById( 'nowplaying' );
                         clear_children( nowplaying );
                         nowplaying.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) );
@@ -613,6 +630,7 @@ function parse_playlist()
                     {
                         elt = elt.parentNode;
                         if( ! elt.parentNode ) break;
+                        pos = pos.parentNode;
                     }
                     if( ! elt.parentNode ) break;
                     elt = elt.parentNode.nextSibling;
@@ -646,14 +664,14 @@ function parse_browse_dir( )
                 if( elt.nodeName == "element" )
                 {
                     var item = document.createElement( "a" );
-                    item.setAttribute( 'class', 'browser' );
+                    setclass( item, 'browser' );
                     if( elt.getAttribute( 'type' ) == 'directory' )
                     {
-                        item.setAttribute( 'href', 'javascript:browse_dir(\''+escapebackslashes(addslashes(elt.getAttribute( 'path' )))+'\');');
+                        item.setAttribute( 'href', 'javascript:browse_dir(\''+addslashes(escapebackslashes(elt.getAttribute( 'path' )))+'\');');
                     }
                     else
                     {
-                        item.setAttribute( 'href', 'javascript:browse_path(\''+escapebackslashes(addslashes(elt.getAttribute( 'path' )))+'\');' );
+                        item.setAttribute( 'href', 'javascript:browse_path(\''+addslashes(escapebackslashes(elt.getAttribute( 'path' )))+'\');' );
                     }
                     item.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) );
                     pos.appendChild( item );
@@ -661,8 +679,8 @@ function parse_browse_dir( )
                     {
                         pos.appendChild( document.createTextNode( ' ' ) );
                         var item = document.createElement( "a" );
-                        item.setAttribute( 'class', 'browser' );
-                        item.setAttribute( 'href', 'javascript:browse_path(\''+escapebackslashes(addslashes(elt.getAttribute( 'path' )))+'\');');
+                        setclass( item, 'browser' );
+                        item.setAttribute( 'href', 'javascript:browse_path(\''+addslashes(escapebackslashes(elt.getAttribute( 'path' )))+'\');');
                         item.appendChild( document.createTextNode( '(select)' ) );
                         pos.appendChild( item );
                     }
@@ -803,7 +821,7 @@ function update_input_fake()
 {
     var mrl = document.getElementById( 'input_mrl' );
 
-    mrl.value = "fake:";
+    mrl.value = "fake://";
     mrl.value += " :fake-file=" + value( "input_fake_filename" );
 
     if( value( "input_fake_width" ) )
@@ -1015,7 +1033,7 @@ function browse( dest )
 function browse_dir( dir )
 {
     document.getElementById( 'browse_lastdir' ).value = dir;
-    loadXMLDoc( 'requests/browse.xml?dir='+escape(dir), parse_browse_dir );
+    loadXMLDoc( 'requests/browse.xml?dir='+encodeURIComponent(dir), parse_browse_dir );
 }
 function browse_path( p )
 {
@@ -1023,7 +1041,16 @@ function browse_path( p )
     hide( 'browse' );
     document.getElementById( value( 'browse_dest' ) ).focus();
 }
-
+function refresh_albumart( force )
+{
+    if( albumart_id != pl_cur_id || force )
+    {
+        var now = new Date();
+        var albumart = document.getElementById( 'albumart' );
+        albumart.src = '/art?timestamp=' + now.getTime();
+        albumart_id = pl_cur_id;
+    }
+}
 /**********************************************************************
  * Periodically update stuff in the interface
  *********************************************************************/
@@ -1037,9 +1064,15 @@ function loop_refresh_playlist()
     /* setTimeout( 'loop_refresh_playlist()', 10000 ); */
     update_playlist();
 }
+function loop_refresh_albumart()
+{
+    setTimeout( 'loop_refresh_albumart()', 1000 );
+    refresh_albumart( false );
+}
 function loop_refresh()
 {
     setTimeout( 'loop_refresh_status()', 1 );
     setTimeout( 'loop_refresh_playlist()', 1 );
+    setTimeout( 'loop_refresh_albumart()', 1 );
 }