X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=share%2Fhttp%2Fjs%2Ffunctions.js;h=895a7ee2ef17816b10b6ffd4796e0b9f0d328fd4;hb=96246bfd5317091034152684a7753d5988d5231e;hp=d4542b3c0e906e21761e34bbe468c1fb1512f01a;hpb=4348289aa68aa69466b012d1454a419a35160223;p=vlc diff --git a/share/http/js/functions.js b/share/http/js/functions.js index d4542b3c0e..895a7ee2ef 100644 --- a/share/http/js/functions.js +++ b/share/http/js/functions.js @@ -21,9 +21,12 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -/* global variables */ +/********************************************************************** + * Global variables + *********************************************************************/ var old_time = 0; +var pl_cur_id; /********************************************************************** * Slider functions @@ -127,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; } } @@ -144,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 ) ); } } } @@ -212,10 +223,21 @@ function check_and_replace_int( id, val ) 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 toCamelCase( str ) +{ + str = str.split( '-' ); + var cml = str[0]; + for( var i=1; i 0 ) + { + var new_time = timetag[0].firstChild.data; + } + else { - slider_position = ( status.getElementsByTagName( 'position' )[0] - .firstChild.data * 4 ) + "px"; + new_time = old_time; + } + var lengthtag = status.getElementsByTagName( 'length' ); + var length; + if( lengthtag.length > 0 ) + { + length = lengthtag[0].firstChild.data; } else + { + length = 0; + } + var slider_position; + positiontag = status.getElementsByTagName( 'position' ); + if( length < 100 && positiontag.length > 0 ) + { + slider_position = ( positiontag[0].firstChild.data * 4 ) + "px"; + } + else if( length > 0 ) { /* this is more precise if length > 100 */ slider_position = Math.floor( ( new_time * 400 ) / length ) + "px"; } + else + { + slider_position = 0; + } if( old_time > new_time ) setTimeout('update_playlist()',50); old_time = new_time; @@ -373,12 +431,21 @@ function parse_status() set_text( 'length', format_time( length ) ); if( status.getElementsByTagName( 'volume' ).length != 0 ) set_text( 'volume', Math.floor(status.getElementsByTagName( 'volume' )[0].firstChild.data/5.12)+'%' ); - set_text( 'state', status.getElementsByTagName( 'state' )[0].firstChild.data ); + var statetag = status.getElementsByTagName( 'state' ); + if( statetag.length > 0 ) + { + set_text( 'state', statetag[0].firstChild.data ); + } + else + { + set_text( 'state', '(?)' ); + } if( slider_mouse_down == 0 ) { document.getElementById( 'main_slider_point' ).style.left = slider_position; } - if( status.getElementsByTagName( 'state' )[0].firstChild.data == "playing" ) + var statustag = status.getElementsByTagName( 'state' ); + if( statustag.length > 0 ? statustag[0].firstChild.data == "playing" : 0 ) { document.getElementById( 'btn_pause_img' ).setAttribute( 'src', 'images/pause.png' ); document.getElementById( 'btn_pause_img' ).setAttribute( 'alt', 'Pause' ); @@ -390,6 +457,54 @@ function parse_status() document.getElementById( 'btn_pause_img' ).setAttribute( 'alt', 'Play' ); document.getElementById( 'btn_pause' ).setAttribute( 'title', 'Play' ); } + + var randomtag = status.getElementsByTagName( 'random' ); + if( randomtag.length > 0 ? randomtag[0].firstChild.data == "1" : 0) + document.getElementById( 'btn_shuffle').setAttribute( 'class', 'on' ); + else + document.getElementById( 'btn_shuffle').setAttribute( 'class', 'off' ); + + var looptag = status.getElementsByTagName( 'loop' ); + if( looptag.length > 0 ? looptag[0].firstChild.data == "1" : 0) + document.getElementById( 'btn_loop').setAttribute( 'class', 'on' ); + else + document.getElementById( 'btn_loop').setAttribute( 'class', 'off' ); + + var repeattag = status.getElementsByTagName( 'repeat' ); + if( repeattag.length > 0 ? repeattag[0].firstChild.data == "1" : 0 ) + document.getElementById( 'btn_repeat').setAttribute( 'class', 'on' ); + else + document.getElementById( 'btn_repeat').setAttribute( 'class', 'off' ); + + var tree = document.createElement( "ul" ); + var categories = status.getElementsByTagName( 'category' ); + var i; + for( i = 0; i < categories.length; i++ ) + { + var item = document.createElement( "li" ); + item.appendChild( document.createTextNode( categories[i].getAttribute( 'name' ) ) ); + var subtree = document.createElement( "dl" ); + var infos = categories[i].getElementsByTagName( 'info' ); + var j; + for( j = 0; j < infos.length; j++ ) + { + var subitem = document.createElement( "dt" ); + subitem.appendChild( document.createTextNode( infos[j].getAttribute( 'name' ) ) ); + subtree.appendChild( subitem ); + if( infos[j].hasChildNodes() ) + { + var subitem = document.createElement( "dd" ); + subitem.appendChild( document.createTextNode( infos[j].firstChild.data ) ); + subtree.appendChild( subitem ); + } + } + item.appendChild( subtree ); + tree.appendChild( item ); + } + var infotree = document.getElementById('infotree' ); + clear_children( infotree ); + infotree.appendChild( tree ); + } else { @@ -410,6 +525,9 @@ function parse_playlist() var pos = document.createElement( "div" ); var pos_top = pos; var elt = answer.firstChild; + + pl_cur_id = 0; /* changed to the current id is there actually + * is a current id */ while( elt ) { if( elt.nodeName == "node" ) @@ -417,44 +535,67 @@ function parse_playlist() if( pos.hasChildNodes() ) pos.appendChild( document.createElement( "br" ) ); var nda = document.createElement( 'a' ); - pos.appendChild( nda ); nda.setAttribute( 'href', 'javascript:toggle_show_node(\''+elt.getAttribute( 'id' )+'\');' ); var ndai = document.createElement( 'img' ); - nda.appendChild( ndai ); ndai.setAttribute( 'src', 'images/minus.png' ); ndai.setAttribute( 'alt', '[-]' ); ndai.setAttribute( 'id', 'pl_img_'+elt.getAttribute( 'id' ) ); + nda.appendChild( ndai ); + pos.appendChild( nda ); pos.appendChild( document.createTextNode( ' ' + elt.getAttribute( 'name' ) ) ); + + if( elt.getAttribute( 'ro' ) == 'rw' ) + { + pos.appendChild( document.createTextNode( ' ' ) ); + var del = document.createElement( "a" ); + del.setAttribute( 'href', 'javascript:pl_delete('+elt.getAttribute( 'id' )+')' ); + var delimg = document.createElement( "img" ); + delimg.setAttribute( 'src', 'images/delete_small.png' ); + delimg.setAttribute( 'alt', '(delete)' ); + del.appendChild( delimg ); + pos.appendChild( del ); + } + var nd = document.createElement( "div" ); - pos.appendChild( nd ); nd.setAttribute( 'class', 'pl_node' ); nd.setAttribute( 'id', 'pl_'+elt.getAttribute( 'id' ) ); + pos.appendChild( nd ); } else if( elt.nodeName == "leaf" ) { if( pos.hasChildNodes() ) pos.appendChild( document.createElement( "br" ) ); var pl = document.createElement( "a" ); - pos.appendChild( pl ); pl.setAttribute( 'class', '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;' ); - document.getElementById( 'nowplaying' ).textContent - = elt.getAttribute( 'name' ); + var nowplaying = document.getElementById( 'nowplaying' ); + clear_children( nowplaying ); + nowplaying.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) ); + pl.appendChild( document.createTextNode( '* ')); + pl_cur_id = elt.getAttribute( 'id' ); } pl.setAttribute( 'title', elt.getAttribute( 'uri' )); pl.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) ); - pos.appendChild( document.createTextNode( ' ' ) ); - var del = document.createElement( "a" ); - pos.appendChild( del ); - del.setAttribute( 'href', 'javascript:pl_delete('+elt.getAttribute( 'id' )+')' ); - del.appendChild( document.createElement( "img" ) ); - del = del.lastChild; - del.setAttribute( 'src', 'images/delete_small.png' ); - del.setAttribute( 'alt', '(delete)' ); + var duration = elt.getAttribute( 'duration' ); + if( duration > 0 ) + pl.appendChild( document.createTextNode( " (" + format_time( elt.getAttribute( 'duration' ) / 1000000 ) + ")" ) ); + pos.appendChild( pl ); + + if( elt.getAttribute( 'ro' ) == 'rw' ) + { + pos.appendChild( document.createTextNode( ' ' ) ); + var del = document.createElement( "a" ); + del.setAttribute( 'href', 'javascript:pl_delete('+elt.getAttribute( 'id' )+')' ); + var delimg = document.createElement( "img" ); + delimg.setAttribute( 'src', 'images/delete_small.png' ); + delimg.setAttribute( 'alt', '(delete)' ); + del.appendChild( delimg ); + pos.appendChild( del ); + } } if( elt.firstChild ) { @@ -468,12 +609,17 @@ function parse_playlist() } else { + while( ! elt.parentNode.nextSibling ) + { + elt = elt.parentNode; + if( ! elt.parentNode ) break; + } + if( ! elt.parentNode ) break; elt = elt.parentNode.nextSibling; pos = pos.parentNode; } } - while( playtree.hasChildNodes() ) - playtree.removeChild( playtree.firstChild ); + clear_children( playtree ); playtree.appendChild( pos_top ); } else @@ -491,6 +637,7 @@ function parse_browse_dir( ) if( req.status == 200 ) { var answer = req.responseXML.documentElement; + if( !answer ) return; var browser = document.getElementById( 'browser' ); var pos = document.createElement( "div" ); var elt = answer.firstChild; @@ -498,31 +645,32 @@ function parse_browse_dir( ) { if( elt.nodeName == "element" ) { - pos.appendChild( document.createElement( "a" ) ); - pos.lastChild.setAttribute( 'class', 'browser' ); + var item = document.createElement( "a" ); + item.setAttribute( 'class', 'browser' ); if( elt.getAttribute( 'type' ) == 'directory' ) { - pos.lastChild.setAttribute( 'href', 'javascript:browse_dir(\''+addslashes(elt.getAttribute( 'path' ))+'\');'); + item.setAttribute( 'href', 'javascript:browse_dir(\''+escapebackslashes(addslashes(elt.getAttribute( 'path' )))+'\');'); } else { - pos.lastChild.setAttribute( 'href', 'javascript:browse_path(\''+addslashes(elt.getAttribute( 'path' ))+'\');' ); + item.setAttribute( 'href', 'javascript:browse_path(\''+escapebackslashes(addslashes(elt.getAttribute( 'path' )))+'\');' ); } - pos.lastChild.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) ); + item.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) ); + pos.appendChild( item ); if( elt.getAttribute( 'type' ) == 'directory' ) { pos.appendChild( document.createTextNode( ' ' ) ); - pos.appendChild( document.createElement( "a" ) ); - pos.lastChild.setAttribute( 'class', 'browser' ); - pos.lastChild.setAttribute( 'href', 'javascript:browse_path(\''+addslashes(elt.getAttribute( 'path' ))+'\');'); - pos.lastChild.appendChild( document.createTextNode( '(select)' ) ); + var item = document.createElement( "a" ); + item.setAttribute( 'class', 'browser' ); + item.setAttribute( 'href', 'javascript:browse_path(\''+escapebackslashes(addslashes(elt.getAttribute( 'path' )))+'\');'); + item.appendChild( document.createTextNode( '(select)' ) ); + pos.appendChild( item ); } pos.appendChild( document.createElement( "br" ) ); } elt = elt.nextSibling; } - while( browser.hasChildNodes() ) - browser.removeChild( browser.firstChild ); + clear_children( browser ); browser.appendChild( pos ); } else @@ -554,19 +702,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 = ""; @@ -728,6 +871,8 @@ function update_sout() mrl.value += "scodec="+value( 'sout_scodec' ); alot = true; } + mrl.value += value( 'sout_extra' ); + mrl.value += "}"; } @@ -846,13 +991,14 @@ function save_sout() function browse( dest ) { document.getElementById( 'browse_dest' ).value = dest; + document.getElementById( 'browse_lastdir' ).value; browse_dir( document.getElementById( 'browse_lastdir' ).value ); show( 'browse' ); } function browse_dir( dir ) { document.getElementById( 'browse_lastdir' ).value = dir; - loadXMLDoc( 'requests/browse.xml?dir='+dir, parse_browse_dir ); + loadXMLDoc( 'requests/browse.xml?dir='+escape(dir), parse_browse_dir ); } function browse_path( p ) {