Steam = { sm_bInitialized: false, sm_bUserInClient: false, sm_bUserInGameOverlay: false, sm_bUserInTenfootBrowser: false, BIsUserInSteamClient: function() { if ( !Steam.sm_bInitialized ) Steam.Init(); return Steam.sm_bUserInClient; }, BIsUserInGameOverlay: function() { if ( !Steam.sm_bInitialized ) Steam.Init(); return Steam.sm_bUserInGameOverlay }, BIsUserInSteamTenfootBrowser: function() { if ( !Steam.sm_bInitialized ) Steam.Init(); return Steam.sm_bUserInTenfootBrowser; }, BIsUserInClientOrOverlay: function() { if ( !Steam.sm_bInitialized ) Steam.Init(); return Steam.sm_bUserInClient || Steam.sm_bUserInGameOverlay; }, GetClientPackageVersion: function() { if ( !Steam.BIsUserInClientOrOverlay() ) return 0; if ( typeof navigator != 'undefined' && navigator.userAgent ) { var matches = navigator.userAgent.match( /Valve Steam [^\/]*\/([0-9]*)/ ); if ( matches && matches.length == 2 ) return matches[1]; } return 0; }, Init: function() { var fnCheckAgent = function( strUAMatch, strURLParam ) { if ( window.location.href.match( '[?&]' + strURLParam + '=' ) ) return true; if ( typeof navigator != 'undefined' && navigator.userAgent && navigator.userAgent.indexOf( strUAMatch ) != -1 ) return true; return false; }; Steam.sm_bUserInTenfootBrowser = fnCheckAgent( 'Valve Steam Tenfoot', 'force_tenfoot_client_view' ); Steam.sm_bUserInGameOverlay = fnCheckAgent( 'Valve Steam GameOverlay', 'force_overlay_view' ); Steam.sm_bUserInClient = Steam.sm_bUserInTenfootBrowser || fnCheckAgent( 'Valve Steam Client', 'force_client_view' ); Steam.sm_bInitialized = true; }, LinkInNewWindow: function( $A ) { if ( Steam.BIsUserInSteamClient() && !Steam.BIsUserInSteamTenfootBrowser() ) $A.attr( 'href', 'steam://openurl_external/' + $A.attr('href') ); else $A.attr( 'target', '_blank' ); } }; // proto functions used to accept an id or an element. // This can be used to migrate them to returning jquery instead of proto-wrapped element function $JFromIDOrElement( elem ) { if ( elem instanceof jQuery ) return elem; else if ( typeof elem == 'string' ) return $J('#' + elem.replace( /\./, '\\.' ) ); else return $J( elem ); } /** Show a popup dialog like confirm(), with two buttons. Clicking ok resolves with done(), cancel or closing the window resolves with fail() * * @param strTitle Title bar text * @param strDescription Message text * @param strOKButton Text to show on OK button (default "OK") * @param strCancelButton Text to show on Cancel button (default "Cancel") * @param strSecondaryActionButton Add a secondary ok button (three buttons total). Resolves with done() like OK but passes 'SECONDARY' as argument to handler * @returns CModal */ function ShowConfirmDialog( strTitle, strDescription, strOKButton, strCancelButton, strSecondaryActionButton ) { if ( !strOKButton ) strOKButton = 'OK'; if ( !strCancelButton ) strCancelButton = 'Cancel'; var deferred = new jQuery.Deferred(); var fnOK = function() { deferred.resolve( 'OK' ); }; var fnSecondary = function() { deferred.resolve( 'SECONDARY' ); }; var fnCancel = function( bWasCancelButton ) { deferred.reject( bWasCancelButton ); }; var rgButtons = []; var $OKButton = _BuildDialogButton( strOKButton, true ); $OKButton.click( fnOK ); rgButtons.push( $OKButton ); if ( strSecondaryActionButton ) { var $SecondaryActionButton = _BuildDialogButton( strSecondaryActionButton, false, {strClassName: ' btn_darkblue_white_innerfade btn_medium' } ); $SecondaryActionButton.click( fnSecondary ); rgButtons.push( $SecondaryActionButton ); } var $CancelButton = _BuildDialogButton( strCancelButton ); $CancelButton.click( function() { fnCancel( true ); } ); rgButtons.push( $CancelButton ); var Modal = _BuildDialog( strTitle, strDescription, rgButtons, fnCancel ); Modal.Show(); _BindOnEnterKeyPressForDialog( Modal, deferred, fnOK ); deferred.always( function() { Modal.Dismiss(); } ); // attach the deferred's events to the modal deferred.promise( Modal ); return Modal; } /** Show a dialog with a single button, like alert(). Button click or closing the modal resolve deferred with done(). * * @param strTitle Title bar text * @param strDescription Message text * @param strOKButton Text on the OK button ("OK" by default) * @returns CModal */ function ShowAlertDialog( strTitle, strDescription, strOKButton ) { if ( !strOKButton ) strOKButton = 'OK'; var deferred = new jQuery.Deferred(); var fnOK = function( bWasCancelButton ) { deferred.resolve( bWasCancelButton ); }; var $OKButton = _BuildDialogButton( strOKButton ); $OKButton.click( function() { fnOK( true ); } ); var Modal = _BuildDialog( strTitle, strDescription, [ $OKButton ], fnOK ); deferred.always( function() { Modal.Dismiss(); } ); Modal.Show(); _BindOnEnterKeyPressForDialog( Modal, deferred, fnOK ); // attach the deferred's events to the modal deferred.promise( Modal ); return Modal; } /** Show a popup dialog. Has no buttons. Closing the dialog resolves deferred with done(). * * @param strTitle Title bar text * @param strDescription Message text * @param rgModalParams See CModal * @returns CModal */ function ShowDialog( strTitle, strDescription, rgModalParams ) { var deferred = new jQuery.Deferred(); var fnOK = function() { deferred.resolve(); }; var Modal = _BuildDialog( strTitle, strDescription, [], fnOK, rgModalParams ); deferred.always( function() { Modal.Dismiss(); } ); Modal.Show(); // attach the deferred's events to the modal deferred.promise( Modal ); return Modal; } /** * @returns CModal */ function ShowPromptDialog( strTitle, strDescription, strOKButton, strCancelButton ) { if ( !strOKButton ) strOKButton = 'OK'; if ( !strCancelButton ) strCancelButton = 'Cancel'; var $Body = $J('
'); var $Input = $J('', {type: 'text', 'class': '' } ); $Body.append( $J('
', {'class': 'newmodal_prompt_description' } ).append( strDescription ) ); $Body.append( $J('
', {'class': 'newmodal_prompt_input gray_bevel for_text_input fullwidth' } ).append( $Input ) ); var deferred = new jQuery.Deferred(); var fnOK = function() { deferred.resolve( $Input.val() ); }; var fnCancel = function() { deferred.reject(); }; $Body.submit( function( event ) { event.preventDefault(); fnOK(); } ); var elButtonLabel = $J( '' ).text( strOKButton ); var $OKButton = $J('