/////////////////////////////////////////////////////////////////////////////// // // Silverlight.js version 1.0 // // This file is provided by Microsoft as a helper file for websites that // incorporate Silverlight Objects. This file is provided under the Silverlight // SDK 1.0 license available athttp://go.microsoft.com/fwlink/?linkid=94240. // You may not use or distribute this file or the code in this file except as // expressly permitted under that license. // // Copyright (c) 2007 Microsoft Corporation. All rights reserved. // /////////////////////////////////////////////////////////////////////////////// if (!window.Silverlight) { window.Silverlight = { }; } // Silverlight control instance counter for memory mgt Silverlight._silverlightCount = 0; // Container for User Agent information Silverlight.ua = null; Silverlight.available = false; Silverlight.fwlinkRoot='http://go.microsoft.com/fwlink/?LinkID='; Silverlight.tempfwlinkRoot='silverlight/installers_temp/'; Silverlight.StatusText='Get Microsoft Silverlight'; Silverlight.EmptyText=''; Silverlight.prev; // keep track of install buttons created Silverlight.bugCreated = false; /////////////////////////////////////////////////////////////////////////////// // detectUserAgent Parses UA string and stores relevant data in Silverlight.ua. /////////////////////////////////////////////////////////////////////////////// Silverlight.detectUserAgent = function() { var ua = window.navigator.userAgent; Silverlight.ua = {OS:'Unsupported',Browser:'Unsupported'}; //Silverlight does not support pre-Windows NT platforms if (ua.indexOf('Windows NT') >= 0) { Silverlight.ua.OS = 'Windows'; } else if (ua.indexOf('PPC Mac OS X') >= 0) { Silverlight.ua.OS = 'MacPPC'; } else if (ua.indexOf('Intel Mac OS X') >= 0) { Silverlight.ua.OS = 'MacIntel'; } if ( Silverlight.ua.OS != 'Unsupported' ) { if (ua.indexOf('MSIE') >= 0) { if (navigator.userAgent.indexOf('Win64') == -1) { if (parseInt(ua.split('MSIE')[1]) >= 6) { Silverlight.ua.Browser = 'MSIE'; } } } else if (ua.indexOf('Firefox') >= 0) { var version = ua.split('Firefox/')[1].split('.'); var major = parseInt(version[0]); if (major >= 2) { Silverlight.ua.Browser = 'Firefox'; } else { var minor = parseInt(version[1]); if ((major == 1) && (minor >= 5)) { Silverlight.ua.Browser = 'Firefox'; } } } else if (ua.indexOf('Safari') >= 0) { Silverlight.ua.Browser = 'Safari'; } } } // Detect the user agent at script. load time Silverlight.detectUserAgent(); ////////////////////////////////////////////////////////////////// // isInstalled, checks to see if the correct version is installed ////////////////////////////////////////////////////////////////// Silverlight.isInstalled = function(version) { var isVersionSupported=false; var container = null; try { var control = null; if (Silverlight.ua.Browser == 'MSIE') { control = new ActiveXObject('AgControl.AgControl'); } else { if ( navigator.plugins["Silverlight Plug-In"] ) { container = document.createElement('div'); document.body.appendChild(container); container.innerHTML= '<embed type="application/x-silverlight" />'; control = container.childNodes[0]; } } // prev version exists Silverlight.prev = ( control ) ? true : false; if ( control.IsVersionSupported(version) ) { isVersionSupported = true; } control = null; Silverlight.available = true; } catch (e) { isVersionSupported = false; } if (container) { document.body.removeChild(container); } return isVersionSupported; } /////////////////////////////////////////////////////////////////////////////// // createObject(); Params: // parentElement of type Element, the parent element of the Silverlight Control // source of type String // id of type string // properties of type String, object literal notation { name:value, name:value, name:value}, // current properties are: width, height, background, framerate, isWindowless, enableHtmlAccess, inplaceInstallPrompt: all are of type string // events of type String, object literal notation { name:value, name:value, name:value}, // current events are onLoad onError, both are type string // initParams of type Object or object literal notation { name:value, name:value, name:value} // userContext of type Object /////////////////////////////////////////////////////////////////////////////////
Silverlight.createObject = function(source, parentElement, id, properties, events, initParams, userContext) { var slPluginHelper = new Object(); var slProperties = properties; var slEvents = events; slProperties.source = source; slPluginHelper.parentElement = parentElement; slPluginHelper.id = Silverlight.HtmlAttributeEncode(id); slPluginHelper.width = Silverlight.HtmlAttributeEncode(slProperties.width); slPluginHelper.height = Silverlight.HtmlAttributeEncode(slProperties.height); slPluginHelper.ignoreBrowserVer = Boolean(slProperties.ignoreBrowserVer); slPluginHelper.inplaceInstallPrompt = Boolean(slProperties.inplaceInstallPrompt); var reqVerArray = slProperties.version.split("."); slPluginHelper.shortVer = reqVerArray[0]+'.'+reqVerArray[1]; slPluginHelper.version = slProperties.version; //rename properties to their tag property names slProperties.initParams = initParams; slProperties.windowless = slProperties.isWindowless; slProperties.maxFramerate = slProperties.framerate; //move unknown events to the slProperties array for (var name in slEvents) { if (slEvents[name] && name != "onLoad" && name != "onError") { slProperties[name] = slEvents[name]; slEvents[name] = null; } } // remove elements which are not to be added to the instantiation tag delete slProperties.width; delete slProperties.height; delete slProperties.id; delete slProperties.onLoad; delete slProperties.onError; delete slProperties.ignoreBrowserVer; delete slProperties.inplaceInstallPrompt; delete slProperties.version; delete slProperties.isWindowless; delete slProperties.framerate; // detect that the correct version of Silverlight is installed, else display install if (Silverlight.isInstalled(slPluginHelper.version)) { // initialize unload event one time if (Silverlight._silverlightCount == 0) { if (window.addEventListener) { window.addEventListener('onunload', Silverlight.__cleanup , false); } else { window.attachEvent('onunload', Silverlight.__cleanup ); } } var count = Silverlight._silverlightCount++; slProperties.onLoad = '__slLoad' + count; slProperties.onError = '__slError' + count; //add the onLoad handler if one exists window[slProperties.onLoad] = function(sender) { if ( slEvents.onLoad) { slEvents.onLoad(document.getElementById(slPluginHelper.id), userContext, sender); } }; //add the error handler if one exists. Otherwise, add the default error handler. window[slProperties.onError] = function(sender, e) { if (slEvents.onError) { slEvents.onError(sender, e); } else { Silverlight.default_error_handler(sender, e); } } slPluginHTML = Silverlight.buildHTML(slPluginHelper, slProperties); } //The control could not be instantiated. Show the installation prompt else { slPluginHTML = Silverlight.buildPromptHTML(slPluginHelper); } // insert or return the HTML if(slPluginHelper.parentElement) {// Not inplace //slPluginHelper.parentElement.innerHTML = slPluginHTML; /*================ hack-a-doodle-doo ===========================================*/ if( Silverlight.bugCreated != true && this.available == false ) { // Plugin is NOT available! if( document.getElementById('buggy-thing')!= null ) { document.getElementById('buggy-thing').innerHTML = slPluginHTML; Silverlight.bugCreated = true; } else { // redirect to non-silverlight home page window.location = "default_ns.aspx"; } } else if ( document.getElementById('buggy-thing')!= null || this.available == true ) { // Plugin is available! slPluginHelper.parentElement.innerHTML = slPluginHTML; } /*==============================================================================*/ } else {// inplace //return slPluginHTML; /*================ hack-a-doodle-doo ===========================================*/ if( this.available == false ) { // Plugin is NOT available! return ( Silverlight.bugCreated == true ) ? "" : slPluginHTML ; Silverlight.bugCreated = true; } else { // Plugin is available! return slPluginHTML; } /*==============================================================================*/ } } /////////////////////////////////////////////////////////////////////////////// // detect to see if this is a supported user agent /////////////////////////////////////////////////////////////////////////////// Silverlight.supportedUserAgent = function(version) { var ua = Silverlight.ua; //detect all unsupported platform. combinations (IE on Mac, Safari on Win) var noSupport = ( ua.OS == 'Unsupported' || //Unsupported OS ua.Browser == 'Unsupported' || //Unsupported Browser (ua.OS == 'Windows' && ua.Browser == 'Safari') || //Safari is not supported on Windows (ua.OS.indexOf('Mac') >= 0 && ua.Browser == 'IE') //IE is not supported on Mac ); return (!noSupport); } /////////////////////////////////////////////////////////////////////////////// // // create HTML that instantiates the control // /////////////////////////////////////////////////////////////////////////////// Silverlight.buildHTML = function(slPluginHelper, slProperties) { var htmlBuilder = []; var start ; var pre ; var dur ; var post ; var end ; if (Silverlight.ua.Browser=='Safari') { htmlBuilder.push('<embed '); start = ''; pre = ' '; dur = '="'; post = '"'; end = ' type="application/x-silverlight"/>' + "<iframe. style='visibility:hidden;height:0;width:0'/>"; } else { htmlBuilder.push('<object type=\"application/x-silverlight\"'); start = '>'; pre = ' <param name="'; dur = '" value="'; post = '" />'; end = '<\/object>'; } htmlBuilder.push(' id="' + slPluginHelper.id + '" width="' + slPluginHelper.width + '" height="' +slPluginHelper.height + '" '+start); for (var name in slProperties) { if (slProperties[name]) { htmlBuilder.push(pre+Silverlight.HtmlAttributeEncode(name)+dur+Silverlight.HtmlAttributeEncode(slProperties[name])+post); } } htmlBuilder.push(end); return htmlBuilder.join(''); } /////////////////////////////////////////////////////////////////////////////// // // Default error handling function to be used when a custom error handler is // not present // /////////////////////////////////////////////////////////////////////////////// Silverlight.default_error_handler = function (sender, args) { var iErrorCode; var errorType = args.ErrorType; iErrorCode = args.ErrorCode; var errMsg = "\nSilverlight error message \n" ; errMsg += "ErrorCode: "+ iErrorCode + "\n"; errMsg += "ErrorType: " + errorType + " \n"; errMsg += "Message: " + args.ErrorMessage + " \n";
if (errorType == "ParserError") { errMsg += "XamlFile: " + args.xamlFile + " \n"; errMsg += "Line: " + args.lineNumber + " \n"; errMsg += "Position: " + args.charPosition + " \n"; } else if (errorType == "RuntimeError") { if (args.lineNumber != 0) { errMsg += "Line: " + args.lineNumber + " \n"; errMsg += "Position: " + args.charPosition + " \n"; } errMsg += "MethodName: " + args.methodName + " \n"; } alert (errMsg); } // createObjectEx, takes a single parameter of all createObject parameters enclosed in {} Silverlight.createObjectEx = function(params) { var parameters = params; var html = Silverlight.createObject(parameters.source, parameters.parentElement, parameters.id, parameters.properties, parameters.events, parameters.initParams, parameters.context); if (parameters.parentElement == null) { return html; } }
/////////////////////////////////////////////////////////////////////////////////////////////// // Builds the HTML to prompt the user to download and install Silverlight /////////////////////////////////////////////////////////////////////////////////////////////// Silverlight.buildPromptHTML = function(slPluginHelper) { var slPluginHTML = null; var urlRoot=Silverlight.fwlinkRoot; var S = Silverlight.ua.OS; var target = '92822'; // 92822 is the 'unsupported platform' linkid var image; var homeLocation = ( window.location.pathname.indexOf( "default_ns" ) > -1 ) ? true : false; if (slPluginHelper.inplaceInstallPrompt) { var bottom; //upgrade image, when available if ( Silverlight.available ) { //image = '94376'; //bottom = '94382'; image = ( homeLocation == true ) ? '/silverlight/images/WebPromptDirect-W.png' : '/silverlight/images/WebPromptDirectRCsmall.png'; bottom = ( homeLocation == true ) ? '/silverlight/images/WebPromptDirectBlue-B.gif' : '/silverlight/images/WebPromptDirectBlueSm-B.gif'; } else { //image = '92802'; // bottom = '94381'; image = ( homeLocation == true ) ? '/silverlight/images/WebPromptDirect-W.png' : '/silverlight/images/WebPromptDirectRCsmall.png'; bottom = ( homeLocation == true ) ? '/silverlight/images/WebPromptDirectBlue-B.gif' : '/silverlight/images/WebPromptDirectBlueSm-B.gif'; } var EULA = '93481'; // unsupported platform. EULA linkid var Privacy = '93483'; // unsupported platform. Privacy LinkID if (OS=='Windows') { target = '92799'; //target = 'Silverlight.1.0.RC.exe'; EULA = '92803'; Privacy = '92805'; } else if (OS=='MacIntel') { target = '92808'; //target = 'Silverlight.1.0.RC.dmg'; EULA = '92804'; Privacy = '92806'; } else if (OS=='MacPPC') { target = '92807'; //target = 'Silverlight.1.0.RC.dmg'; EULA = '92815'; Privacy = '92816'; } //By clicking <b>"Get Microsoft Silverlight"</b> you accept the<br /><a title="Silverlight License Agreement" href="{2}" target="_top" style="text-decoration: underline; color: #96C5E1"><b>Silverlight license agreement</b></a>',j='Silverlight updates automatically, <a title="Silverlight Privacy Statement" href="{3}" target="_top" style="text-decoration: underline; color: #96C5E1"><b>learn more</b></a>';a='<table border="0" cellpadding="0" cellspacing="0" width="206px"><tr><td><img style="display: block; cursor: pointer; border= 0;" title="'+f+'" alt="'+f+'" nclick="javascript.:Silverlight.followFWLink({0});" src="{1}" /></td></tr><tr><td style="width: 206px; margin: 0px; background: #FFFFFF; color: C7C7C7; text-align: left; border-left-style. solid; border-right-style. solid; padding-left: 6px; padding-right: 6px; padding-top: 3px; padding-bottom: 0px; border-width: 2px; border-color: #c7c7bd; font-family: Verdana; font-size: 55%">'+k+'</td></tr><tr><td><img src="{5}" style="border: 0; cursor: pointer; display: block" /></td></tr><tr><td style="width: 206px; margin: 0px; background: #D8EFF9; color: C7C7C7; text-align: left; border-left-style. solid; border-right-style. solid; padding-left: 6px; padding-right: 6px; padding-top: 0px; padding-bottom: 2px; border-width: 2px; border-color: #c7c7bd; font-family: Verdana; font-size: 55%">'+j+'</td></tr><tr><td><img alt="" src="{4}" /></td></tr></table> //slPluginHTML = '<table border="0" cellpadding="0" cellspacing="0" width="205px"><tr><td><img title="Get Microsoft Silverlight" nclick="javascript.:Silverlight.followFWLink({0});" style="border:0; cursor:pointer" src="{1}"/></td></tr><tr><td style="background:#C7C7BD; text-align: center; color: black; font-family: Verdana; font-size: 9px; padding-bottom: 0.05cm; ;padding-top: 0.05cm" >By clicking <b>Get Microsoft Silverlight</b> you accept the <a title="Silverlight License Agreement" href="{2}" target="_top" style="text-decoration: underline; color: #36A6C6"><b>Silverlight license agreement</b></a>.</td></tr><tr><td style="border-left-style. solid; border-right-style. solid; border-width: 2px; border-color:#c7c7bd; background: #817d77; color: #FFFFFF; text-align: center; font-family: Verdana; font-size: 9px">Silverlight updates automatically, <a title="Silverlight Privacy Statement" href="{3}" target="_top" style="text-decoration: underline; color: #36A6C6"><b>learn more</b></a>.</td></tr><tr><td><img src="{4}"/></td></tr></table>'; slPluginHTML = '<table border="0" align="left" cellpadding="0" cellspacing="0" width="144px"><tr><td><img title="Get Microsoft Silverlight" nclick="javascript.:Silverlight.followFWLink({0});" style="border:0; cursor:pointer" src="{1}"/></td></tr><tr><td style="background: #ffffff; text-align: center; border-left-style. solid; border-right-style. solid; padding-left: 6px; padding-right: 6px; padding-top: 3px; padding-bottom: 0px; border-width: 2px; border-color: #c7c7bd; color: #c7c7c7; font-family: Verdana; font-size: 9px;" >By clicking <b>"Get Microsoft Silverlight"</b> you accept the <a title="Silverlight License Agreement" href="{2}" target="_top" style="text-decoration: underline; color: #36A6C6"><b>Silverlight license agreement</b></a>.</td></tr><tr><td><img src="/silverlight/images/WebPromptDirectBlueSm-M.gif" style="border: 0; cursor: pointer; display: block" /></td></tr><tr><td style="border-left-style. solid; border-right-style. solid; border-width: 2px; border-color:#c7c7bd; background: #D8EFF9; color: #96C5E1; padding-left: 6px; padding-right: 6px; padding-top: 3px; padding-bottom: 0px;text-align: center; font-family: Verdana; font-size: 9px">Silverlight updates automatically, <a title="Silverlight Privacy Statement" href="{3}" target="_top" style="text-decoration: underline; color: #96C5E1"><b>learn more</b></a>.</td></tr><tr><td><img src="{4}"/></td></tr><tr><td><p id="feedback" style="margin:4px;font-size:10pt;color:#96C5E1;text-align:left;"></p></td></tr></table></td></tr>'; slPluginHTML = slPluginHTML.replace('{2}', urlRoot+EULA); slPluginHTML = slPluginHTML.replace('{3}', urlRoot+Privacy); //slPluginHTML = slPluginHTML.replace('{4}', urlRoot+bottom); slPluginHTML = slPluginHTML.replace('{4}', bottom); if( homeLocation == true ) { /* replace background & text colors slPluginHTML = slPluginHTML.replace( 'background: #817d77; color: #FFFFFF;', 'background: #817d77; color: #96C5E1;' ); slPluginHTML = slPluginHTML.replace( 'background: #C7C7BD', 'background: #ffffff' ); slPluginHTML = slPluginHTML.replace( 'background: #817d77', 'background: #D8EFF9' ); slPluginHTML = slPluginHTML.replace( 'color: black;', 'color: C7C7C7;' ); slPluginHTML = slPluginHTML.replace( 'color: #36A6C6', 'color: #96C5E1' ); slPluginHTML = slPluginHTML.replace( '<b>Silverlight license agreement</b></a>.</td></tr>', '<b>Silverlight license agreement</b></a>.</td></tr><tr><td><img src="/silverlight/images/WebPromptDirectBlue-M.gif" style="border: 0; cursor: pointer; display: block" /></td></tr>' ); */ slPluginHTML = slPluginHTML.replace( '/silverlight/images/WebPromptDirectBlueSm-M.gif', '/silverlight/images/WebPromptDirectBlue-M.gif' ); slPluginHTML = slPluginHTML.replace( 'width="144px"', 'width="206px"' ); slPluginHTML = slPluginHTML.replace( /text-align: center;/gi, 'text-align: left;' ); slPluginHTML = slPluginHTML.replace( '<table border="0" align="left"', '<table border="0" align="center"' ); } } else { if ( Silverlight.available ) { //image = '94377'; image = '/silverlight/images/WebPromptIndirectRCsmall.png'; } else { //image = '92801'; image = '/silverlight/images/WebPromptIndirectRCsmall.png'; } if (OS=='Windows') { //target = 'Silverlight.1.0.RC.exe'; target = '92800'; } else if (OS=='MacIntel') { //target = 'Silverlight.1.0.RC.dmg'; target = '92812'; } else if (OS=='MacPPC') { //target = 'Silverlight.1.0.RC.dmg'; target = '92811'; } slPluginHTML = '<div style="width: 205px; height: 67px; background-color: #FFFFFF"><img nclick="javascript.:Silverlight.followFWLink({0});" style="border:0; cursor:pointer" src="{1}" alt="Get Microsoft Silverlight"/></div>'; } //slPluginHTML = slPluginHTML.replace('{0}', "'" + target + "'" ); slPluginHTML = slPluginHTML.replace('{0}', target ); //slPluginHTML = slPluginHTML.replace('{1}', urlRoot+image); slPluginHTML = slPluginHTML.replace('{1}', image); return slPluginHTML; } /////////////////////////////////////////////////////////////////////////////////////////////// /// Releases event handler resources when the page is unloaded /////////////////////////////////////////////////////////////////////////////////////////////// Silverlight.__cleanup = function () { for (var i = Silverlight._silverlightCount - 1; i >= 0; i--) { window['__slLoad' + i] = null; window['__slError' + i] = null; } if (window.removeEventListener) { window.removeEventListener('unload', Silverlight.__cleanup , false); } else { window.detachEvent('onunload', Silverlight.__cleanup ); } } /////////////////////////////////////////////////////////////////////////////////////////////// /// Navigates to a url based on fwlinkid /////////////////////////////////////////////////////////////////////////////////////////////// Silverlight.followFWLink = function( linkid ) { // report to webtrends DCSext.wt_evtid="Link: Download"; // update install progress for user if( Silverlight.ua.Browser != 'MSIE' ) { // firefox, safari message Silverlight.updateFeedback( "Silverlight is Installing. After installation completes, restart your browser to view the content in Silverlight." ); } else { if( Silverlight.prev ) { // outdated version exists - Explorer Silverlight.updateFeedback( "After installation, please press F5 to refresh the browser and view the content." ); } else { // no silverlight - Explorer Silverlight.updateFeedback( "Silverlight is Installing..." ); } } //top.location=Silverlight.fwlinkRoot+String(linkid); top.location=Silverlight.fwlinkRoot+linkid; } /////////////////////////////////////////////////////////////////////////////////////////////// /// Navigates to a url based on fwlinkid /////////////////////////////////////////////////////////////////////////////////////////////// Silverlight.updateFeedback = function( txt ) { // update install progress for user var progressDiv = document.getElementById( "buggy-thing" ); var progressP = document.getElementById( "feedback" ); progressP.innerHTML = txt; } /////////////////////////////////////////////////////////////////////////////////////////////// /// Encodes special characters in input strings as charcodes /////////////////////////////////////////////////////////////////////////////////////////////// Silverlight.HtmlAttributeEncode = function( strInput ) { var c; var retVal = ''; if(strInput == null) { return null; } for(var cnt = 0; cnt < strInput.length; cnt++) { c = strInput.charCodeAt(cnt); if (( ( c > 96 ) && ( c < 123 ) ) || ( ( c > 64 ) && ( c < 91 ) ) || ( ( c > 43 ) && ( c < 58 ) && (c!=47)) || ( c == 95 )) { retVal = retVal + String.fromCharCode(c); } else { retVal = retVal + '&#' + c + ';'; } } return retVal; } |