]> git.sesse.net Git - vlc/blobdiff - share/http/js/functions.js
URL encode fix
[vlc] / share / http / js / functions.js
index e1a0031852bd2972d2ad77e77219b04729b617b1..a04bb360ab5d20533d05c95b131d30673858c257 100644 (file)
@@ -130,12 +130,16 @@ function set_css( item, element, value )
 {
     for( var j = 0; j < document.styleSheets.length; j++ )
     {
-        cssRules = document.styleSheets[j].cssRules;
+        var cssRules = document.styleSheets[j].cssRules;
+        if( !cssRules ) cssRules = document.styleSheets[j].rules;
         for( var i = 0; i < cssRules.length; i++)
         {
             if( cssRules[i].selectorText == item )
             {
-                cssRules[i].style.setProperty( element, value, null );
+                if( cssRules[i].style.setProperty )
+                    cssRules[i].style.setProperty( element, value, null );
+                else
+                    cssRules[i].style.setAttribute( toCamelCase( element ), value );
                 return;
             }
         }
@@ -147,12 +151,16 @@ function get_css( item, element )
 {
     for( var j = 0; j < document.styleSheets.length; j++ )
     {
-        cssRules = document.styleSheets[j].cssRules;
+        var cssRules = document.styleSheets[j].cssRules;
+        if( !cssRules ) cssRules = document.styleSheets[j].rules;
         for( var i = 0; i < cssRules.length; i++)
         {
             if( cssRules[i].selectorText == item )
             {
-                return cssRules[i].style.getPropertyValue( element );
+                if( cssRules[i].style.getPropertyValue )
+                    return cssRules[i].style.getPropertyValue( element );
+                else
+                    return cssRules[i].style.getAttribute( toCamelCase( element ) );
             }
         }
     }
@@ -189,6 +197,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'; }
 
@@ -196,6 +205,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 );
@@ -211,15 +226,25 @@ 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 ) )
-        document.getElementById( id ).value = val;
+        return document.getElementById( id ).value = val;
+    return document.getElementById( id ).value;
 }
 
 function addslashes( str ){ return str.replace(/\'/g, '\\\''); }
-function escapebackslashes( str ){ return str.replace(/\\[^']/g, '\\\\'); }
+function escapebackslashes( str ){ return str.replace(/\\/g, '\\\\'); }
+
+function toCamelCase( str )
+{
+    str = str.split( '-' );
+    var cml = str[0];
+    for( var i=1; i<str.length; i++)
+        cml += str[i].charAt(0).toUpperCase()+str[i].substring(1);
+    return cml;
+}
 
 function disable( id ){ document.getElementById( id ).disabled = true; }
 
@@ -262,7 +287,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( input );
     loadXMLDoc( url, parse_status );
     setTimeout( 'update_playlist()', 1000 );
 }
@@ -271,7 +296,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( input );
     loadXMLDoc( url, parse_status );
     setTimeout( 'update_playlist()', 1000 );
 }
@@ -440,18 +465,23 @@ function parse_status()
                 document.getElementById( 'btn_pause' ).setAttribute( 'title', 'Play' );
             }
 
-            if( status.getElementsByTagName( 'random' )[0].firstChild.data == "1" )
-                document.getElementById( 'btn_shuffle').setAttribute( 'class', 'on' );
+            var randomtag = status.getElementsByTagName( 'random' );
+            if( randomtag.length > 0 ? randomtag[0].firstChild.data == "1" : 0)
+                setclass( document.getElementById( 'btn_shuffle'), 'on' );
             else
-                document.getElementById( 'btn_shuffle').setAttribute( 'class', 'off' );
-            if( status.getElementsByTagName( 'loop' )[0].firstChild.data == "1" )
-                document.getElementById( 'btn_loop').setAttribute( 'class', 'on' );
+                setclass( document.getElementById( 'btn_shuffle'), 'off' );
+               
+            var looptag = status.getElementsByTagName( 'loop' );
+            if( looptag.length > 0 ? looptag[0].firstChild.data == "1" : 0)
+                setclass( document.getElementById( 'btn_loop'), 'on' );
             else
-                document.getElementById( 'btn_loop').setAttribute( 'class', 'off' );
-            if( status.getElementsByTagName( 'repeat' )[0].firstChild.data == "1" )
-                document.getElementById( 'btn_repeat').setAttribute( 'class', 'on' );
+                setclass( document.getElementById( 'btn_loop'), 'off' );
+
+            var repeattag = status.getElementsByTagName( 'repeat' );
+            if( repeattag.length > 0 ? repeattag[0].firstChild.data == "1" : 0 )
+                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' );
@@ -534,7 +564,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 );
                 }
@@ -543,12 +573,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' ) ) );
@@ -623,14 +653,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 );
@@ -638,8 +668,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 );
                     }
@@ -665,6 +695,7 @@ function hide_input( )
     document.getElementById( 'input_file' ).style.display = 'none';
     document.getElementById( 'input_disc' ).style.display = 'none';
     document.getElementById( 'input_network' ).style.display = 'none';
+    document.getElementById( 'input_fake' ).style.display = 'none';
 }
 
 /* update the input MRL using data from the input file helper */
@@ -679,19 +710,14 @@ function update_input_file()
 /* update the input MRL using data from the input disc helper */
 function update_input_disc()
 {
-    var mrl = document.getElementById( 'input_mrl' );
-    var type = radio_value( "input_disc_type" );
-    var device = value( "input_disc_dev" );
-
-    check_and_replace_int( 'input_disc_title', 0 );
-    check_and_replace_int( 'input_disc_chapter', 0 );
-    check_and_replace_int( 'input_disc_subtrack', '' );
-    check_and_replace_int( 'input_disc_audiotrack', 0 );
+    var mrl     = document.getElementById( 'input_mrl' );
+    var type    = radio_value( "input_disc_type" );
+    var device  = value( "input_disc_dev" );
 
-    var title = value( 'input_disc_title' );
-    var chapter = value( 'input_disc_chapter' );
-    var subs = value( 'input_disc_subtrack' );
-    var audio = value( 'input_disc_audiotrack' );
+    var title   = check_and_replace_int( 'input_disc_title', 0 );
+    var chapter = check_and_replace_int( 'input_disc_chapter', 0 );
+    var subs    = check_and_replace_int( 'input_disc_subtrack', '' );
+    var audio   = check_and_replace_int( 'input_disc_audiotrack', 0 );
 
     mrl.value = "";
 
@@ -779,6 +805,22 @@ function update_input_net()
         mrl.value += " :access-filter=timeshift";
 }
 
+/* update the input MRL using data from the input fake helper */
+function update_input_fake()
+{
+    var mrl = document.getElementById( 'input_mrl' );
+
+    mrl.value = "fake:";
+    mrl.value += " :fake-file=" + value( "input_fake_filename" );
+
+    if( value( "input_fake_width" ) )
+        mrl.value += " :fake-width=" + value( "input_fake_width" );
+    if( value( "input_fake_height" ) )
+        mrl.value += " :fake-height=" + value( "input_fake_height" );
+    if( value( "input_fake_ar" ) )
+        mrl.value += " :fake-ar=" + value( "input_fake_ar" );
+}
+
 /**********************************************************************
  * Sout dialog functions
  *********************************************************************/
@@ -853,6 +895,8 @@ function update_sout()
             mrl.value += "scodec="+value( 'sout_scodec' );
             alot = true;
         }
+        mrl.value += value( 'sout_transcode_extra' );
+            
         mrl.value += "}";
     }
 
@@ -978,7 +1022,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 )
 {