1 ///////////////////////////////////////////////////////////////////////////////
\r
3 // Silverlight.js version 2.0.30523.6
\r
5 // This file is provided by Microsoft as a helper file for websites that
\r
6 // incorporate Silverlight Objects. This file is provided under the Microsoft
\r
7 // Public License available at
\r
8 // http://code.msdn.microsoft.com/silverlightjs/Project/License.aspx.
\r
9 // You may not use or distribute this file or the code in this file except as
\r
10 // expressly permitted under that license.
\r
12 // Copyright (c) Microsoft Corporation. All rights reserved.
\r
14 ///////////////////////////////////////////////////////////////////////////////
\r
16 if (!window.Silverlight)
\r
18 window.Silverlight = { };
\r
21 //////////////////////////////////////////////////////////////////
\r
23 // _silverlightCount:
\r
25 // Counter of globalized event handlers
\r
27 //////////////////////////////////////////////////////////////////
\r
28 Silverlight._silverlightCount = 0;
\r
30 //////////////////////////////////////////////////////////////////
\r
34 // Prefix for fwlink URL's
\r
36 //////////////////////////////////////////////////////////////////
\r
37 Silverlight.fwlinkRoot='http://go2.microsoft.com/fwlink/?LinkID=';
\r
39 //////////////////////////////////////////////////////////////////
\r
41 // onGetSilverlight:
\r
43 // Called by Silverlight.GetSilverlight to notify the page that a user
\r
44 // has requested the Silverlight installer
\r
46 //////////////////////////////////////////////////////////////////
\r
47 Silverlight.onGetSilverlight = null;
\r
49 //////////////////////////////////////////////////////////////////
\r
51 // onSilverlightInstalled:
\r
53 // Called by Silverlight.WaitForInstallCompletion when the page detects
\r
54 // that Silverlight has been installed. The event handler is not called
\r
55 // in upgrade scenarios.
\r
57 //////////////////////////////////////////////////////////////////
\r
58 Silverlight.onSilverlightInstalled = function () {window.location.reload(false);};
\r
60 //////////////////////////////////////////////////////////////////
\r
64 // Checks to see if the correct version is installed
\r
66 //////////////////////////////////////////////////////////////////
\r
67 Silverlight.isInstalled = function(version)
\r
69 var isVersionSupported=false;
\r
70 var container = null;
\r
78 control = new ActiveXObject('AgControl.AgControl');
\r
79 if ( version == null )
\r
81 isVersionSupported = true;
\r
83 else if ( control.IsVersionSupported(version) )
\r
85 isVersionSupported = true;
\r
91 var plugin = navigator.plugins["Silverlight Plug-In"] ;
\r
94 if ( version === null )
\r
96 isVersionSupported = true;
\r
100 var actualVer = plugin.description;
\r
101 if ( actualVer === "1.0.30226.2")
\r
102 actualVer = "2.0.30226.2";
\r
103 var actualVerArray =actualVer.split(".");
\r
104 while ( actualVerArray.length > 3)
\r
106 actualVerArray.pop();
\r
108 while ( actualVerArray.length < 4)
\r
110 actualVerArray.push(0);
\r
112 var reqVerArray = version.split(".");
\r
113 while ( reqVerArray.length > 4)
\r
118 var requiredVersionPart ;
\r
119 var actualVersionPart
\r
125 requiredVersionPart = parseInt(reqVerArray[index]);
\r
126 actualVersionPart = parseInt(actualVerArray[index]);
\r
129 while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);
\r
131 if ( requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart) )
\r
133 isVersionSupported = true;
\r
141 isVersionSupported = false;
\r
145 document.body.removeChild(container);
\r
148 return isVersionSupported;
\r
150 //////////////////////////////////////////////////////////////////
\r
152 // WaitForInstallCompletion:
\r
154 // Occasionally checks for Silverlight installation status. If it
\r
155 // detects that Silverlight has been installed then it calls
\r
156 // Silverlight.onSilverlightInstalled();. This is only supported
\r
157 // if Silverlight was not previously installed on this computer.
\r
159 //////////////////////////////////////////////////////////////////
\r
160 Silverlight.WaitForInstallCompletion = function()
\r
162 if ( ! Silverlight.isBrowserRestartRequired && Silverlight.onSilverlightInstalled )
\r
166 navigator.plugins.refresh();
\r
171 if ( Silverlight.isInstalled(null) )
\r
173 Silverlight.onSilverlightInstalled();
\r
177 setTimeout(Silverlight.WaitForInstallCompletion, 3000);
\r
181 //////////////////////////////////////////////////////////////////
\r
185 // Performs startup tasks
\r
186 //////////////////////////////////////////////////////////////////
\r
187 Silverlight.__startup = function()
\r
189 Silverlight.isBrowserRestartRequired = Silverlight.isInstalled(null);
\r
190 if ( !Silverlight.isBrowserRestartRequired)
\r
192 Silverlight.WaitForInstallCompletion();
\r
194 if (window.removeEventListener) {
\r
195 window.removeEventListener('load', Silverlight.__startup , false);
\r
198 window.detachEvent('onload', Silverlight.__startup );
\r
202 if (window.addEventListener)
\r
204 window.addEventListener('load', Silverlight.__startup , false);
\r
208 window.attachEvent('onload', Silverlight.__startup );
\r
211 ///////////////////////////////////////////////////////////////////////////////
\r
214 // Inserts a Silverlight <object> tag or installation experience into the HTML
\r
215 // DOM based on the current installed state of Silverlight.
\r
217 /////////////////////////////////////////////////////////////////////////////////
\r
219 Silverlight.createObject = function(source, parentElement, id, properties, events, initParams, userContext)
\r
221 var slPluginHelper = new Object();
\r
222 var slProperties = properties;
\r
223 var slEvents = events;
\r
225 slPluginHelper.version = slProperties.version;
\r
226 slProperties.source = source;
\r
227 slPluginHelper.alt = slProperties.alt;
\r
229 //rename properties to their tag property names. For bacwards compatibility
\r
230 //with Silverlight.js version 1.0
\r
232 slProperties.initParams = initParams;
\r
233 if ( slProperties.isWindowless && !slProperties.windowless)
\r
234 slProperties.windowless = slProperties.isWindowless;
\r
235 if ( slProperties.framerate && !slProperties.maxFramerate)
\r
236 slProperties.maxFramerate = slProperties.framerate;
\r
237 if ( id && !slProperties.id)
\r
238 slProperties.id = id;
\r
240 // remove elements which are not to be added to the instantiation tag
\r
241 delete slProperties.ignoreBrowserVer;
\r
242 delete slProperties.inplaceInstallPrompt;
\r
243 delete slProperties.version;
\r
244 delete slProperties.isWindowless;
\r
245 delete slProperties.framerate;
\r
246 delete slProperties.data;
\r
247 delete slProperties.src;
\r
248 delete slProperties.alt;
\r
251 // detect that the correct version of Silverlight is installed, else display install
\r
253 if (Silverlight.isInstalled(slPluginHelper.version))
\r
255 //move unknown events to the slProperties array
\r
256 for (var name in slEvents)
\r
258 if ( slEvents[name])
\r
260 if ( name == "onLoad" && typeof slEvents[name] == "function" && slEvents[name].length != 1 )
\r
262 var onLoadHandler = slEvents[name];
\r
263 slEvents[name]=function (sender){ return onLoadHandler(document.getElementById(id), userContext, sender)};
\r
265 var handlerName = Silverlight.__getHandlerName(slEvents[name]);
\r
266 if ( handlerName != null )
\r
268 slProperties[name] = handlerName;
\r
269 slEvents[name] = null;
\r
273 throw "typeof events."+name+" must be 'function' or 'string'";
\r
277 slPluginHTML = Silverlight.buildHTML(slProperties);
\r
279 //The control could not be instantiated. Show the installation prompt
\r
282 slPluginHTML = Silverlight.buildPromptHTML(slPluginHelper);
\r
285 // insert or return the HTML
\r
288 parentElement.innerHTML = slPluginHTML;
\r
292 return slPluginHTML;
\r
297 ///////////////////////////////////////////////////////////////////////////////
\r
301 // create HTML that instantiates the control
\r
303 ///////////////////////////////////////////////////////////////////////////////
\r
304 Silverlight.buildHTML = function( slProperties)
\r
306 var htmlBuilder = [];
\r
308 htmlBuilder.push('<object type=\"application/x-silverlight\" data="data:application/x-silverlight,"');
\r
309 if ( slProperties.id != null )
\r
311 htmlBuilder.push(' id="' + slProperties.id + '"');
\r
313 if ( slProperties.width != null )
\r
315 htmlBuilder.push(' width="' + slProperties.width+ '"');
\r
317 if ( slProperties.height != null )
\r
319 htmlBuilder.push(' height="' + slProperties.height + '"');
\r
321 htmlBuilder.push(' >');
\r
323 delete slProperties.id;
\r
324 delete slProperties.width;
\r
325 delete slProperties.height;
\r
327 for (var name in slProperties)
\r
329 if (slProperties[name])
\r
331 htmlBuilder.push('<param name="'+Silverlight.HtmlAttributeEncode(name)+'" value="'+Silverlight.HtmlAttributeEncode(slProperties[name])+'" />');
\r
334 htmlBuilder.push('<\/object>');
\r
335 return htmlBuilder.join('');
\r
340 //////////////////////////////////////////////////////////////////
\r
344 // takes a single parameter of all createObject
\r
345 // parameters enclosed in {}
\r
347 //////////////////////////////////////////////////////////////////
\r
349 Silverlight.createObjectEx = function(params)
\r
351 var parameters = params;
\r
352 var html = Silverlight.createObject(parameters.source, parameters.parentElement, parameters.id, parameters.properties, parameters.events, parameters.initParams, parameters.context);
\r
353 if (parameters.parentElement == null)
\r
359 ///////////////////////////////////////////////////////////////////////////////////////////////
\r
363 // Builds the HTML to prompt the user to download and install Silverlight
\r
365 ///////////////////////////////////////////////////////////////////////////////////////////////
\r
366 Silverlight.buildPromptHTML = function(slPluginHelper)
\r
368 var slPluginHTML = "";
\r
369 var urlRoot = Silverlight.fwlinkRoot;
\r
370 var shortVer = slPluginHelper.version ;
\r
371 if ( slPluginHelper.alt )
\r
373 slPluginHTML = slPluginHelper.alt;
\r
381 slPluginHTML = "<a href='javascript:Silverlight.getSilverlight(\"{1}\");' style='text-decoration: none;'><img src='{2}' alt='Get Microsoft Silverlight' style='border-style: none'/></a>";
\r
382 slPluginHTML = slPluginHTML.replace('{1}', shortVer );
\r
383 slPluginHTML = slPluginHTML.replace('{2}', urlRoot + '108181');
\r
386 return slPluginHTML;
\r
389 ///////////////////////////////////////////////////////////////////////////////////////////////
\r
393 // Navigates the browser to the appropriate Silverlight installer
\r
395 ///////////////////////////////////////////////////////////////////////////////////////////////
\r
396 Silverlight.getSilverlight = function(version)
\r
398 if (Silverlight.onGetSilverlight )
\r
400 Silverlight.onGetSilverlight();
\r
404 var reqVerArray = String(version).split(".");
\r
405 if (reqVerArray.length > 1)
\r
407 var majorNum = parseInt(reqVerArray[0] );
\r
408 if ( isNaN(majorNum) || majorNum < 2 )
\r
414 shortVer = reqVerArray[0]+'.'+reqVerArray[1];
\r
420 if (shortVer.match(/^\d+\056\d+$/) )
\r
422 verArg = "&v="+shortVer;
\r
425 Silverlight.followFWLink("114576" + verArg);
\r
429 ///////////////////////////////////////////////////////////////////////////////////////////////
\r
433 // Navigates to a url based on fwlinkid
\r
435 ///////////////////////////////////////////////////////////////////////////////////////////////
\r
436 Silverlight.followFWLink = function(linkid)
\r
438 top.location=Silverlight.fwlinkRoot+String(linkid);
\r
441 ///////////////////////////////////////////////////////////////////////////////////////////////
\r
443 // HtmlAttributeEncode:
\r
445 // Encodes special characters in input strings as charcodes
\r
447 ///////////////////////////////////////////////////////////////////////////////////////////////
\r
448 Silverlight.HtmlAttributeEncode = function( strInput )
\r
453 if(strInput == null)
\r
458 for(var cnt = 0; cnt < strInput.length; cnt++)
\r
460 c = strInput.charCodeAt(cnt);
\r
462 if (( ( c > 96 ) && ( c < 123 ) ) ||
\r
463 ( ( c > 64 ) && ( c < 91 ) ) ||
\r
464 ( ( c > 43 ) && ( c < 58 ) && (c!=47)) ||
\r
467 retVal = retVal + String.fromCharCode(c);
\r
471 retVal = retVal + '&#' + c + ';';
\r
477 ///////////////////////////////////////////////////////////////////////////////
\r
479 // default_error_handler:
\r
481 // Default error handling function
\r
483 ///////////////////////////////////////////////////////////////////////////////
\r
485 Silverlight.default_error_handler = function (sender, args)
\r
488 var errorType = args.ErrorType;
\r
490 iErrorCode = args.ErrorCode;
\r
492 var errMsg = "\nSilverlight error message \n" ;
\r
494 errMsg += "ErrorCode: "+ iErrorCode + "\n";
\r
497 errMsg += "ErrorType: " + errorType + " \n";
\r
498 errMsg += "Message: " + args.ErrorMessage + " \n";
\r
500 if (errorType == "ParserError")
\r
502 errMsg += "XamlFile: " + args.xamlFile + " \n";
\r
503 errMsg += "Line: " + args.lineNumber + " \n";
\r
504 errMsg += "Position: " + args.charPosition + " \n";
\r
506 else if (errorType == "RuntimeError")
\r
508 if (args.lineNumber != 0)
\r
510 errMsg += "Line: " + args.lineNumber + " \n";
\r
511 errMsg += "Position: " + args.charPosition + " \n";
\r
513 errMsg += "MethodName: " + args.methodName + " \n";
\r
518 ///////////////////////////////////////////////////////////////////////////////////////////////
\r
522 // Releases event handler resources when the page is unloaded
\r
524 ///////////////////////////////////////////////////////////////////////////////////////////////
\r
525 Silverlight.__cleanup = function ()
\r
527 for (var i = Silverlight._silverlightCount - 1; i >= 0; i--) {
\r
528 window['__slEvent' + i] = null;
\r
530 Silverlight._silverlightCount = 0;
\r
531 if (window.removeEventListener) {
\r
532 window.removeEventListener('unload', Silverlight.__cleanup , false);
\r
535 window.detachEvent('onunload', Silverlight.__cleanup );
\r
539 ///////////////////////////////////////////////////////////////////////////////////////////////
\r
541 // __getHandlerName:
\r
543 // Generates named event handlers for delegates.
\r
545 ///////////////////////////////////////////////////////////////////////////////////////////////
\r
546 Silverlight.__getHandlerName = function (handler)
\r
548 var handlerName = "";
\r
549 if ( typeof handler == "string")
\r
551 handlerName = handler;
\r
553 else if ( typeof handler == "function" )
\r
555 if (Silverlight._silverlightCount == 0)
\r
557 if (window.addEventListener)
\r
559 window.addEventListener('onunload', Silverlight.__cleanup , false);
\r
563 window.attachEvent('onunload', Silverlight.__cleanup );
\r
566 var count = Silverlight._silverlightCount++;
\r
567 handlerName = "__slEvent"+count;
\r
569 window[handlerName]=handler;
\r
573 handlerName = null;
\r
575 return handlerName;
\r