diff --git a/popcorn.js b/popcorn.js index fb6cb938c..9d31bc6d3 100644 --- a/popcorn.js +++ b/popcorn.js @@ -1462,54 +1462,54 @@ // HH:MM:SS;FF // Hours and minutes are optional. They default to 0 toSeconds: function( timeStr, framerate ) { - // Hours and minutes are optional - // Seconds must be specified - // Seconds can be followed by milliseconds OR by the frame information - var validTimeFormat = /^([0-9]+:){0,2}[0-9]+([.;][0-9]+)?$/, - errorMessage = "Invalid time format", - digitPairs, lastIndex, lastPair, firstPair, - frameInfo, frameTime; - - if ( typeof timeStr === "number" ) { - return timeStr; - } - - if ( typeof timeStr === "string" && - !validTimeFormat.test( timeStr ) ) { - Popcorn.error( errorMessage ); - } + // Hours and minutes are optional + // Seconds must be specified + // Seconds can be followed by milliseconds OR by the frame information + var validTimeFormat = /^([0-9]+:){0,2}[0-9]+([.;][0-9]+)?$/, + errorMessage = "Invalid time format", + digitPairs, lastIndex, lastPair, firstPair, + frameInfo, frameTime; + + if ( typeof timeStr === "number" ) { + return timeStr; + } - digitPairs = timeStr.split( ":" ); - lastIndex = digitPairs.length - 1; - lastPair = digitPairs[ lastIndex ]; + if ( typeof timeStr === "string" && + !validTimeFormat.test( timeStr ) ) { + Popcorn.error( errorMessage ); + } - // Fix last element: - if ( lastPair.indexOf( ";" ) > -1 ) { + digitPairs = timeStr.split( ":" ); + lastIndex = digitPairs.length - 1; + lastPair = digitPairs[ lastIndex ]; - frameInfo = lastPair.split( ";" ); - frameTime = 0; + // Fix last element: + if ( lastPair.indexOf( ";" ) > -1 ) { - if ( framerate && ( typeof framerate === "number" ) ) { - frameTime = parseFloat( frameInfo[ 1 ], 10 ) / framerate; - } + frameInfo = lastPair.split( ";" ); + frameTime = 0; - digitPairs[ lastIndex ] = parseInt( frameInfo[ 0 ], 10 ) + frameTime; + if ( framerate && ( typeof framerate === "number" ) ) { + frameTime = parseFloat( frameInfo[ 1 ], 10 ) / framerate; } - firstPair = digitPairs[ 0 ]; + digitPairs[ lastIndex ] = parseInt( frameInfo[ 0 ], 10 ) + frameTime; + } + + firstPair = digitPairs[ 0 ]; - return { + return { - 1: parseFloat( firstPair, 10 ), + 1: parseFloat( firstPair, 10 ), - 2: ( parseInt( firstPair, 10 ) * 60 ) + - parseFloat( digitPairs[ 1 ], 10 ), + 2: ( parseInt( firstPair, 10 ) * 60 ) + + parseFloat( digitPairs[ 1 ], 10 ), - 3: ( parseInt( firstPair, 10 ) * 3600 ) + - ( parseInt( digitPairs[ 1 ], 10 ) * 60 ) + - parseFloat( digitPairs[ 2 ], 10 ) + 3: ( parseInt( firstPair, 10 ) * 3600 ) + + ( parseInt( digitPairs[ 1 ], 10 ) * 60 ) + + parseFloat( digitPairs[ 2 ], 10 ) - }[ digitPairs.length || 1 ]; + }[ digitPairs.length || 1 ]; } };