~ubuntu-branches/ubuntu/karmic/moon/karmic

« back to all changes in this revision

Viewing changes to test/xaml/enums/Silverlight.js

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-14 12:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20090214120108-06539vb25vhbd8bn
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
ļ»æ///////////////////////////////////////////////////////////////////////////////
 
2
//
 
3
//  Silverlight.js                      version 2.0.30523.6
 
4
//
 
5
//  This file is provided by Microsoft as a helper file for websites that
 
6
//  incorporate Silverlight Objects. This file is provided under the Microsoft
 
7
//  Public License available at 
 
8
//  http://code.msdn.microsoft.com/silverlightjs/Project/License.aspx.  
 
9
//  You may not use or distribute this file or the code in this file except as 
 
10
//  expressly permitted under that license.
 
11
// 
 
12
//  Copyright (c) Microsoft Corporation. All rights reserved.
 
13
//
 
14
///////////////////////////////////////////////////////////////////////////////
 
15
 
 
16
if (!window.Silverlight)
 
17
{
 
18
    window.Silverlight = { };
 
19
}
 
20
 
 
21
//////////////////////////////////////////////////////////////////
 
22
//
 
23
// _silverlightCount:
 
24
//
 
25
// Counter of globalized event handlers
 
26
//
 
27
//////////////////////////////////////////////////////////////////
 
28
Silverlight._silverlightCount = 0;
 
29
 
 
30
//////////////////////////////////////////////////////////////////
 
31
//
 
32
// fwlinkRoot:
 
33
//
 
34
// Prefix for fwlink URL's
 
35
//
 
36
//////////////////////////////////////////////////////////////////
 
37
Silverlight.fwlinkRoot='http://go2.microsoft.com/fwlink/?LinkID=';
 
38
 
 
39
//////////////////////////////////////////////////////////////////
 
40
//  
 
41
// onGetSilverlight:
 
42
//
 
43
// Called by Silverlight.GetSilverlight to notify the page that a user
 
44
// has requested the Silverlight installer
 
45
//
 
46
//////////////////////////////////////////////////////////////////
 
47
Silverlight.onGetSilverlight = null;
 
48
 
 
49
//////////////////////////////////////////////////////////////////
 
50
//
 
51
// onSilverlightInstalled:
 
52
//
 
53
// Called by Silverlight.WaitForInstallCompletion when the page detects
 
54
// that Silverlight has been installed. The event handler is not called
 
55
// in upgrade scenarios.
 
56
//
 
57
//////////////////////////////////////////////////////////////////
 
58
Silverlight.onSilverlightInstalled = function () {window.location.reload(false);};
 
59
 
 
60
//////////////////////////////////////////////////////////////////
 
61
//
 
62
// isInstalled:
 
63
//
 
64
// Checks to see if the correct version is installed
 
65
//
 
66
//////////////////////////////////////////////////////////////////
 
67
Silverlight.isInstalled = function(version)
 
68
{
 
69
    var isVersionSupported=false;
 
70
    var container = null;
 
71
    
 
72
    try 
 
73
    {
 
74
        var control = null;
 
75
        
 
76
        try
 
77
        {
 
78
            control = new ActiveXObject('AgControl.AgControl');
 
79
            if ( version == null )
 
80
            {
 
81
                isVersionSupported = true;
 
82
            }
 
83
            else if ( control.IsVersionSupported(version) )
 
84
            {
 
85
                isVersionSupported = true;
 
86
            }
 
87
            control = null;
 
88
        }
 
89
        catch (e)
 
90
        {
 
91
            var plugin = navigator.plugins["Silverlight Plug-In"] ;
 
92
            if ( plugin )
 
93
            {
 
94
                if ( version === null )
 
95
                {
 
96
                    isVersionSupported = true;
 
97
                }
 
98
                else
 
99
                {
 
100
                    var actualVer = plugin.description;
 
101
                    if ( actualVer === "1.0.30226.2")
 
102
                        actualVer = "2.0.30226.2";
 
103
                    var actualVerArray =actualVer.split(".");
 
104
                    while ( actualVerArray.length > 3)
 
105
                    {
 
106
                        actualVerArray.pop();
 
107
                    }
 
108
                    while ( actualVerArray.length < 4)
 
109
                    {
 
110
                        actualVerArray.push(0);
 
111
                    }
 
112
                    var reqVerArray = version.split(".");
 
113
                    while ( reqVerArray.length > 4)
 
114
                    {
 
115
                        reqVerArray.pop();
 
116
                    }
 
117
                    
 
118
                    var requiredVersionPart ;
 
119
                    var actualVersionPart
 
120
                    var index = 0;
 
121
                    
 
122
                    
 
123
                    do
 
124
                    {
 
125
                        requiredVersionPart = parseInt(reqVerArray[index]);
 
126
                        actualVersionPart = parseInt(actualVerArray[index]);
 
127
                        index++;
 
128
                    }
 
129
                    while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);
 
130
                    
 
131
                    if ( requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart) )
 
132
                    {
 
133
                        isVersionSupported = true;
 
134
                    }
 
135
                }
 
136
            }
 
137
        }
 
138
    }
 
139
    catch (e) 
 
140
    {
 
141
        isVersionSupported = false;
 
142
    }
 
143
    if (container) 
 
144
    {
 
145
        document.body.removeChild(container);
 
146
    }
 
147
    
 
148
    return isVersionSupported;
 
149
}
 
150
//////////////////////////////////////////////////////////////////
 
151
//
 
152
// WaitForInstallCompletion:
 
153
//
 
154
// Occasionally checks for Silverlight installation status. If it
 
155
// detects that Silverlight has been installed then it calls
 
156
// Silverlight.onSilverlightInstalled();. This is only supported
 
157
// if Silverlight was not previously installed on this computer.
 
158
//
 
159
//////////////////////////////////////////////////////////////////
 
160
Silverlight.WaitForInstallCompletion = function()
 
161
{
 
162
    if ( ! Silverlight.isBrowserRestartRequired && Silverlight.onSilverlightInstalled )
 
163
    {
 
164
        try
 
165
        {
 
166
            navigator.plugins.refresh();
 
167
        }
 
168
        catch(e)
 
169
        {
 
170
        }
 
171
        if ( Silverlight.isInstalled(null) )
 
172
        {
 
173
            Silverlight.onSilverlightInstalled();
 
174
        }
 
175
        else
 
176
        {
 
177
              setTimeout(Silverlight.WaitForInstallCompletion, 3000);
 
178
        }    
 
179
    }
 
180
}
 
181
//////////////////////////////////////////////////////////////////
 
182
//
 
183
// __startup:
 
184
//
 
185
// Performs startup tasks
 
186
//////////////////////////////////////////////////////////////////
 
187
Silverlight.__startup = function()
 
188
{
 
189
    Silverlight.isBrowserRestartRequired = Silverlight.isInstalled(null);
 
190
    if ( !Silverlight.isBrowserRestartRequired)
 
191
    {
 
192
        Silverlight.WaitForInstallCompletion();
 
193
    }
 
194
    if (window.removeEventListener) { 
 
195
       window.removeEventListener('load', Silverlight.__startup , false);
 
196
    }
 
197
    else { 
 
198
        window.detachEvent('onload', Silverlight.__startup );
 
199
    }
 
200
}
 
201
 
 
202
if (window.addEventListener) 
 
203
{
 
204
    window.addEventListener('load', Silverlight.__startup , false);
 
205
}
 
206
else 
 
207
{
 
208
    window.attachEvent('onload', Silverlight.__startup );
 
209
}
 
210
 
 
211
///////////////////////////////////////////////////////////////////////////////
 
212
// createObject:
 
213
//
 
214
// Inserts a Silverlight <object> tag or installation experience into the HTML
 
215
// DOM based on the current installed state of Silverlight. 
 
216
//
 
217
/////////////////////////////////////////////////////////////////////////////////
 
218
 
 
219
Silverlight.createObject = function(source, parentElement, id, properties, events, initParams, userContext)
 
220
{
 
221
    var slPluginHelper = new Object();
 
222
    var slProperties = properties;
 
223
    var slEvents = events;
 
224
    
 
225
    slPluginHelper.version = slProperties.version;
 
226
    slProperties.source = source;    
 
227
    slPluginHelper.alt = slProperties.alt;
 
228
    
 
229
    //rename properties to their tag property names. For bacwards compatibility
 
230
    //with Silverlight.js version 1.0
 
231
    if ( initParams )
 
232
        slProperties.initParams = initParams;
 
233
    if ( slProperties.isWindowless && !slProperties.windowless)
 
234
        slProperties.windowless = slProperties.isWindowless;
 
235
    if ( slProperties.framerate && !slProperties.maxFramerate)
 
236
        slProperties.maxFramerate = slProperties.framerate;
 
237
    if ( id && !slProperties.id)
 
238
        slProperties.id = id;
 
239
    
 
240
    // remove elements which are not to be added to the instantiation tag
 
241
    delete slProperties.ignoreBrowserVer;
 
242
    delete slProperties.inplaceInstallPrompt;
 
243
    delete slProperties.version;
 
244
    delete slProperties.isWindowless;
 
245
    delete slProperties.framerate;
 
246
    delete slProperties.data;
 
247
    delete slProperties.src;
 
248
    delete slProperties.alt;
 
249
 
 
250
 
 
251
    // detect that the correct version of Silverlight is installed, else display install
 
252
 
 
253
    if (Silverlight.isInstalled(slPluginHelper.version))
 
254
    {
 
255
        //move unknown events to the slProperties array
 
256
        for (var name in slEvents)
 
257
        {
 
258
            if ( slEvents[name])
 
259
            {
 
260
                if ( name == "onLoad" && typeof slEvents[name] == "function" && slEvents[name].length != 1 )
 
261
                {
 
262
                    var onLoadHandler = slEvents[name];
 
263
                    slEvents[name]=function (sender){ return onLoadHandler(document.getElementById(id), userContext, sender)};
 
264
                }
 
265
                var handlerName = Silverlight.__getHandlerName(slEvents[name]);
 
266
                if ( handlerName != null )
 
267
                {
 
268
                    slProperties[name] = handlerName;
 
269
                    slEvents[name] = null;
 
270
                }
 
271
                else
 
272
                {
 
273
                    throw "typeof events."+name+" must be 'function' or 'string'";
 
274
                }
 
275
            }
 
276
        }
 
277
        slPluginHTML = Silverlight.buildHTML(slProperties);
 
278
    }
 
279
    //The control could not be instantiated. Show the installation prompt
 
280
    else 
 
281
    {
 
282
        slPluginHTML = Silverlight.buildPromptHTML(slPluginHelper);
 
283
    }
 
284
 
 
285
    // insert or return the HTML
 
286
    if(parentElement)
 
287
    {
 
288
        parentElement.innerHTML = slPluginHTML;
 
289
    }
 
290
    else
 
291
    {
 
292
        return slPluginHTML;
 
293
    }
 
294
 
 
295
}
 
296
 
 
297
///////////////////////////////////////////////////////////////////////////////
 
298
//
 
299
//  buildHTML:
 
300
//
 
301
//  create HTML that instantiates the control
 
302
//
 
303
///////////////////////////////////////////////////////////////////////////////
 
304
Silverlight.buildHTML = function( slProperties)
 
305
{
 
306
    var htmlBuilder = [];
 
307
 
 
308
    htmlBuilder.push('<object type=\"application/x-silverlight\" data="data:application/x-silverlight,"');
 
309
    if ( slProperties.id != null )
 
310
    {
 
311
        htmlBuilder.push(' id="' + slProperties.id + '"');
 
312
    }
 
313
    if ( slProperties.width != null )
 
314
    {
 
315
        htmlBuilder.push(' width="' + slProperties.width+ '"');
 
316
    }
 
317
    if ( slProperties.height != null )
 
318
    {
 
319
        htmlBuilder.push(' height="' + slProperties.height + '"');
 
320
    }
 
321
    htmlBuilder.push(' >');
 
322
    
 
323
    delete slProperties.id;
 
324
    delete slProperties.width;
 
325
    delete slProperties.height;
 
326
    
 
327
    for (var name in slProperties)
 
328
    {
 
329
        if (slProperties[name])
 
330
        {
 
331
            htmlBuilder.push('<param name="'+Silverlight.HtmlAttributeEncode(name)+'" value="'+Silverlight.HtmlAttributeEncode(slProperties[name])+'" />');
 
332
        }
 
333
    }
 
334
    htmlBuilder.push('<\/object>');
 
335
    return htmlBuilder.join('');
 
336
}
 
337
 
 
338
 
 
339
 
 
340
//////////////////////////////////////////////////////////////////
 
341
//
 
342
// createObjectEx:
 
343
//
 
344
// takes a single parameter of all createObject 
 
345
// parameters enclosed in {}
 
346
//
 
347
//////////////////////////////////////////////////////////////////
 
348
 
 
349
Silverlight.createObjectEx = function(params)
 
350
{
 
351
    var parameters = params;
 
352
    var html = Silverlight.createObject(parameters.source, parameters.parentElement, parameters.id, parameters.properties, parameters.events, parameters.initParams, parameters.context);
 
353
    if (parameters.parentElement == null)
 
354
    {
 
355
        return html;
 
356
    }
 
357
}
 
358
 
 
359
///////////////////////////////////////////////////////////////////////////////////////////////
 
360
//
 
361
// buildPromptHTML
 
362
//
 
363
// Builds the HTML to prompt the user to download and install Silverlight
 
364
//
 
365
///////////////////////////////////////////////////////////////////////////////////////////////
 
366
Silverlight.buildPromptHTML = function(slPluginHelper)
 
367
{
 
368
    var slPluginHTML = "";
 
369
    var urlRoot = Silverlight.fwlinkRoot;
 
370
    var shortVer = slPluginHelper.version ;
 
371
    if ( slPluginHelper.alt )
 
372
    {
 
373
        slPluginHTML = slPluginHelper.alt;
 
374
    }
 
375
    else
 
376
    {
 
377
        if (! shortVer )
 
378
        {
 
379
            shortVer="";
 
380
        }
 
381
        slPluginHTML = "<a href='javascript:Silverlight.getSilverlight(\"{1}\");' style='text-decoration: none;'><img src='{2}' alt='Get Microsoft Silverlight' style='border-style: none'/></a>";
 
382
        slPluginHTML = slPluginHTML.replace('{1}', shortVer );
 
383
        slPluginHTML = slPluginHTML.replace('{2}', urlRoot + '108181');
 
384
    }
 
385
    
 
386
    return slPluginHTML;
 
387
}
 
388
 
 
389
///////////////////////////////////////////////////////////////////////////////////////////////
 
390
//
 
391
// getSilverlight:
 
392
//
 
393
// Navigates the browser to the appropriate Silverlight installer
 
394
//
 
395
///////////////////////////////////////////////////////////////////////////////////////////////
 
396
Silverlight.getSilverlight = function(version)
 
397
{
 
398
    if (Silverlight.onGetSilverlight )
 
399
    {
 
400
        Silverlight.onGetSilverlight();
 
401
    }
 
402
    
 
403
    var shortVer = "";
 
404
    var reqVerArray = String(version).split(".");
 
405
    if (reqVerArray.length > 1)
 
406
    {
 
407
        var majorNum = parseInt(reqVerArray[0] );
 
408
        if ( isNaN(majorNum) || majorNum < 2 )
 
409
        {
 
410
            shortVer = "1.0";
 
411
        }
 
412
        else
 
413
        {
 
414
            shortVer = reqVerArray[0]+'.'+reqVerArray[1];
 
415
        }
 
416
    }
 
417
    
 
418
    var verArg = "";
 
419
    
 
420
    if (shortVer.match(/^\d+\056\d+$/) )
 
421
    {
 
422
        verArg = "&v="+shortVer;
 
423
    }
 
424
    
 
425
    Silverlight.followFWLink("114576" + verArg);
 
426
}
 
427
 
 
428
 
 
429
///////////////////////////////////////////////////////////////////////////////////////////////
 
430
//
 
431
// followFWLink:
 
432
//
 
433
// Navigates to a url based on fwlinkid
 
434
//
 
435
///////////////////////////////////////////////////////////////////////////////////////////////
 
436
Silverlight.followFWLink = function(linkid)
 
437
{
 
438
    top.location=Silverlight.fwlinkRoot+String(linkid);
 
439
}
 
440
 
 
441
///////////////////////////////////////////////////////////////////////////////////////////////
 
442
//
 
443
// HtmlAttributeEncode:
 
444
//
 
445
// Encodes special characters in input strings as charcodes
 
446
//
 
447
///////////////////////////////////////////////////////////////////////////////////////////////
 
448
Silverlight.HtmlAttributeEncode = function( strInput )
 
449
{
 
450
      var c;
 
451
      var retVal = '';
 
452
 
 
453
    if(strInput == null)
 
454
      {
 
455
          return null;
 
456
    }
 
457
      
 
458
      for(var cnt = 0; cnt < strInput.length; cnt++)
 
459
      {
 
460
            c = strInput.charCodeAt(cnt);
 
461
 
 
462
            if (( ( c > 96 ) && ( c < 123 ) ) ||
 
463
                  ( ( c > 64 ) && ( c < 91 ) ) ||
 
464
                  ( ( c > 43 ) && ( c < 58 ) && (c!=47)) ||
 
465
                  ( c == 95 ))
 
466
            {
 
467
                  retVal = retVal + String.fromCharCode(c);
 
468
            }
 
469
            else
 
470
            {
 
471
                  retVal = retVal + '&#' + c + ';';
 
472
            }
 
473
      }
 
474
      
 
475
      return retVal;
 
476
}
 
477
///////////////////////////////////////////////////////////////////////////////
 
478
//
 
479
//  default_error_handler:
 
480
//
 
481
//  Default error handling function 
 
482
//
 
483
///////////////////////////////////////////////////////////////////////////////
 
484
 
 
485
Silverlight.default_error_handler = function (sender, args)
 
486
{
 
487
    var iErrorCode;
 
488
    var errorType = args.ErrorType;
 
489
 
 
490
    iErrorCode = args.ErrorCode;
 
491
 
 
492
    var errMsg = "\nSilverlight error message     \n" ;
 
493
 
 
494
    errMsg += "ErrorCode: "+ iErrorCode + "\n";
 
495
 
 
496
 
 
497
    errMsg += "ErrorType: " + errorType + "       \n";
 
498
    errMsg += "Message: " + args.ErrorMessage + "     \n";
 
499
 
 
500
    if (errorType == "ParserError")
 
501
    {
 
502
        errMsg += "XamlFile: " + args.xamlFile + "     \n";
 
503
        errMsg += "Line: " + args.lineNumber + "     \n";
 
504
        errMsg += "Position: " + args.charPosition + "     \n";
 
505
    }
 
506
    else if (errorType == "RuntimeError")
 
507
    {
 
508
        if (args.lineNumber != 0)
 
509
        {
 
510
            errMsg += "Line: " + args.lineNumber + "     \n";
 
511
            errMsg += "Position: " +  args.charPosition + "     \n";
 
512
        }
 
513
        errMsg += "MethodName: " + args.methodName + "     \n";
 
514
    }
 
515
    alert (errMsg);
 
516
}
 
517
 
 
518
///////////////////////////////////////////////////////////////////////////////////////////////
 
519
//
 
520
// __cleanup:
 
521
//
 
522
// Releases event handler resources when the page is unloaded
 
523
//
 
524
///////////////////////////////////////////////////////////////////////////////////////////////
 
525
Silverlight.__cleanup = function ()
 
526
{
 
527
    for (var i = Silverlight._silverlightCount - 1; i >= 0; i--) {
 
528
        window['__slEvent' + i] = null;
 
529
    }
 
530
    Silverlight._silverlightCount = 0;
 
531
    if (window.removeEventListener) { 
 
532
       window.removeEventListener('unload', Silverlight.__cleanup , false);
 
533
    }
 
534
    else { 
 
535
        window.detachEvent('onunload', Silverlight.__cleanup );
 
536
    }
 
537
}
 
538
 
 
539
///////////////////////////////////////////////////////////////////////////////////////////////
 
540
//
 
541
// __getHandlerName:
 
542
//
 
543
// Generates named event handlers for delegates.
 
544
//
 
545
///////////////////////////////////////////////////////////////////////////////////////////////
 
546
Silverlight.__getHandlerName = function (handler)
 
547
{
 
548
    var handlerName = "";
 
549
    if ( typeof handler == "string")
 
550
    {
 
551
        handlerName = handler;
 
552
    }
 
553
    else if ( typeof handler == "function" )
 
554
    {
 
555
        if (Silverlight._silverlightCount == 0)
 
556
        {
 
557
            if (window.addEventListener) 
 
558
            {
 
559
                window.addEventListener('onunload', Silverlight.__cleanup , false);
 
560
            }
 
561
            else 
 
562
            {
 
563
                window.attachEvent('onunload', Silverlight.__cleanup );
 
564
            }
 
565
        }
 
566
        var count = Silverlight._silverlightCount++;
 
567
        handlerName = "__slEvent"+count;
 
568
        
 
569
        window[handlerName]=handler;
 
570
    }
 
571
    else
 
572
    {
 
573
        handlerName = null;
 
574
    }
 
575
    return handlerName;
 
576
}
 
 
b'\\ No newline at end of file'