home *** CD-ROM | disk | FTP | other *** search
/ ftp.novell.com / 2014.06.ftp.novell.com.tar / ftp.novell.com / forge / camtasia.msi / Cabs.w1.cab / realembed.js < prev    next >
Text File  |  2009-08-17  |  5KB  |  210 lines

  1. /**
  2.  * @author Brooks Andrus 
  3.  * October 30, 2006
  4.  *
  5.  * Real Player JavaScript detection and embed script
  6.  * Inspired by Geoff Stern's SWFObject http://blog.deconcept.com/swfobject/
  7.  *
  8.  * Tested and found to work on:
  9.  *    - Windows XP, IE 6, Firefox 1.5
  10.  *    - Mac OS X, Firefox 1.5, Firefox 2.0, Safari 2.0.4
  11.  *
  12.  * Known Issues
  13.  *    - Opera & Real Media fail on all platforms
  14.  */
  15.  
  16.  
  17.  
  18. /**
  19.  * Here's our JavaScript constructor function.
  20.  * 
  21.  * @param src - the file name / path
  22.  * @param id  - the object id for the embedded wmp
  23.  * @param w   - the width of the object / embed area
  24.  * @param h   - the height of the object / embed area
  25.  */
  26. RealEmbed = function( src, id, w , h )
  27. {
  28.     this.params     = new Object();
  29.     this.attributes = new Array();
  30.     
  31.     if ( id  )  { this.setAttribute('id'    , id  ); }
  32.     if ( src )  { this.setAttribute( 'src'  , src ); }
  33.     if ( w   )  { this.setAttribute('width' , w   ); }
  34.     if ( h   )  { this.setAttribute('height', h   ); }
  35. }
  36.  
  37. /**
  38.  * Stuffs attributes array with name value pairs.
  39.  *
  40.  */
  41. RealEmbed.prototype.setAttribute = function( name, value )
  42. {
  43.     this.attributes[name] = value;
  44. }
  45.  
  46. /**
  47.  * Returns value for a given attribute array key.
  48.  *
  49.  */
  50. RealEmbed.prototype.getAttribute = function( name )
  51. {
  52.     return this.attributes[name];
  53. }
  54.  
  55. /**
  56.  * Allows name / value parameter tags to be chained onto the
  57.  * RealEmbed object - keeps the constructor from being enormous
  58.  *
  59.  */
  60. RealEmbed.prototype.addParam = function( name, value )
  61. {
  62.     this.params[name] = value;
  63. }
  64.  
  65. /**
  66.  * Returns a keyed array of name / value parameters
  67.  *
  68.  */
  69. RealEmbed.prototype.getParams = function()
  70. {
  71.     return this.params;
  72.  
  73. /**
  74.  * Returns a string of html param tags with name / value pairs set.
  75.  *
  76.  */
  77. RealEmbed.prototype.getParamTags = function( ie )
  78. {
  79.     var params = "";
  80.     if ( ie )
  81.     {
  82.         var paramObj = this.getParams();
  83.         
  84.         for ( var i in paramObj )
  85.         {
  86.             params += '<param name="' + i + '" value="' + paramObj[i] + '" />'
  87.         }
  88.     }
  89.     else
  90.     {
  91.         var paramObj = this.getParams();
  92.         for ( var i in this.getParams() )
  93.         {
  94.             params += ' ' + i + '="' +  paramObj[i] + '"';
  95.         }
  96.     }
  97.     return params;
  98. }
  99.  
  100. RealEmbed.prototype.getFormattedName = function()
  101. {
  102.     var videofile =  this.getAttribute( 'src' );
  103.     // this will be the final video link (absolute path)
  104.     var videolink = location.href;
  105.             
  106.     // remove the file:// because windows media doesn't understand that
  107.     var file = videolink.indexOf( "file://");
  108.  
  109.     if ( file > -1 )
  110.     {
  111.         // this is a local path
  112.         videolink = videolink.substring( file + 8 );
  113.         // remove the %20 because media player doesn't understand those
  114.         while( videolink.lastIndexOf( "%20" ) != -1 )
  115.         {
  116.             videolink = videolink.replace( "%20", " " );
  117.         }
  118.         //remove the html file name now
  119.         var lastslash = videolink.lastIndexOf( "/");
  120.         if ( lastslash > -1 )
  121.         {
  122.             videolink = videolink.substring( 0, lastslash );
  123.         }
  124.         //add the video file name
  125.         videolink = videolink + "/" + videofile;
  126.     }
  127.     if ( navigator && navigator.userAgent.substr( 0, navigator.userAgent.indexOf( "/" ) ) == "Opera" )
  128.     {
  129.         videolink = videofile;
  130.     }
  131.     else
  132.     {
  133.         videolink = videofile;
  134.     }
  135.     return videolink;
  136. }
  137.  
  138. /**
  139.  * Creates the object and embed tags needed to display Real Player
  140.  * in a web page. 
  141.  *
  142.  */
  143. RealEmbed.prototype.getHTML = function()
  144. {    
  145.     var node;
  146.     if ( navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length )
  147.     {
  148.         node  = '<embed name="' + this.getAttribute( 'id' ) + '"'    
  149.                 + ' id="' + this.getAttribute( 'id' ) + '"'
  150.                 + ' width="' + this.getAttribute( 'width' ) + '"'
  151.                 + ' height="' + this.getAttribute( 'height' ) + '"'
  152.                 + ' src="' + this.getFormattedName() + '"'
  153.                 + ' type="audio/x-pn-realaudio-plugin"'
  154.                 + this.getParamTags( false )
  155.         node += ' />';
  156.     }
  157.     else
  158.     {
  159.         node  = '<object id="' + this.getAttribute( 'id' ) + '"'
  160.                 + ' classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"'
  161.                 + ' width="' + this.getAttribute( 'width' ) + '"'
  162.                 + ' height="' + this.getAttribute( 'height' ) 
  163.                 + ' type="audio/x-pn-realaudio-plugin"'
  164.                 + '">'
  165.                 + '<param name="src" value="' + this.getAttribute( 'src' ) + '" />'
  166.                 + this.getParamTags( true )
  167.                 + '</object>';
  168.     }
  169.     return node
  170. }
  171.  
  172. /**
  173.  * Responsible for writing out the innerHTML for the element identified
  174.  *
  175.  */
  176. RealEmbed.prototype.write = function( elementId )
  177. {
  178.     var n = ( typeof elementId == 'string' ) ? document.getElementById( elementId ) : elementId;
  179.     n.innerHTML = this.getHTML();
  180.     return true;
  181. }
  182.  
  183. /**
  184.  * Returns boolean value indicating whether Real Player 
  185.  * plugin is installed for the browser in use. A touch of vb 
  186.  * script is actually used when IE is the browser.
  187.  */
  188. function isRealInstalled() 
  189. {
  190.     var installed = false;
  191.     realObj = false;
  192.     if ( navigator.mimeTypes && navigator.mimeTypes.length )
  193.     {    
  194.         for ( var i = 0; i < navigator.mimeTypes.length; i++ )
  195.         {
  196.             var mt = navigator.mimeTypes[i];
  197.             if ( mt.type == "audio/x-pn-realaudio-plugin" )
  198.             {
  199.                 installed = true;
  200.             }
  201.         }
  202.     }
  203.     else 
  204.     {
  205.         execScript( 'on error resume next: realObj = IsObject( CreateObject( "rmocx.RealPlayer G2 Control.1" ) )','VBScript' );
  206.         installed = realObj;
  207.     }
  208.     return installed;
  209. }