//----------------------------------------------------------
// Copyright (C) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------
// SilverlightControl.js
Type.registerNamespace("Sys.UI.Silverlight"); Sys.UI.Silverlight.Control = function(a) { Sys.UI.Silverlight.Control.initializeBase(this, [this._findObject(a) || a]); this._scaleMode = Sys.UI.Silverlight.ScaleMode.none }; Sys.UI.Silverlight.Control.prototype = { _source: null, _splashScreenSource: null, _loaded: false, _boundEvents: null, _setOnLoad: false, _setOnFullScreenChange: false, _setOnResize: false, _setOnError: false, add_pluginError: function(a) { this.get_events().addHandler("pluginError", a) }, remove_pluginError: function(a) { this.get_events().removeHandler("pluginError", a) }, add_pluginSourceDownloadComplete: function(a) { this.get_events().addHandler("pluginSourceDownloadComplete", a) }, remove_pluginSourceDownloadComplete: function(a) { this.get_events().removeHandler("pluginSourceDownloadComplete", a) }, add_pluginSourceDownloadProgressChanged: function(a) { this.get_events().addHandler("pluginSourceDownloadProgressChanged", a) }, remove_pluginSourceDownloadProgressChanged: function(a) { this.get_events().removeHandler("pluginSourceDownloadProgressChanged", a) }, add_pluginFullScreenChanged: function(a) { this.get_events().addHandler("pluginFullScreenChanged", a) }, remove_pluginFullScreenChanged: function(a) { this.get_events().removeHandler("pluginFullScreenChanged", a) }, add_pluginLoaded: function(a) { this.get_events().addHandler("pluginLoaded", a) }, remove_pluginLoaded: function(a) { this.get_events().removeHandler("pluginLoaded", a) }, add_pluginResized: function(a) { this.get_events().addHandler("pluginResized", a) }, remove_pluginResized: function(a) { this.get_events().removeHandler("pluginResized", a) }, get_scaleMode: function() { return this._scaleMode }, set_scaleMode: function(a) { if (a !== this.get_scaleMode()) { this._scaleMode = a; if (this._loaded) this._ensureTransform() } }, get_source: function() { return this._source || "" }, set_source: function(a) { this._source = a; if (a && this._setOnLoad) this.get_element().Source = a }, get_splashScreenSource: function() { return this._splashScreenSource || "" }, set_splashScreenSource: function(a) { this._splashScreenSource = a; if (this._setOnLoad) this.get_element().SplashScreenSource = a }, addEventListener: function(b, a, e) { var d = b.addEventListener(a, e), c = this._getEventsForElement(b, true); c[c.length] = { eventName: a, token: d }; return d }, dispose: function() { if (this._loaded) { this.pluginDispose(); this._loaded = false } var a = this.get_element(); if (a) { if (this._setOnLoad) { a.OnLoad = null; a.OnSourceDownloadProgressChanged = null; a.OnSourceDownloadComplete = null } if (this._setOnError) a.OnError = null; if (this._setOnFullScreenChange) a.content.OnFullScreenChange = null; if (this._setOnResize) a.content.OnResize = null } var b = this._boundEvents; if (b) { for (var c = 0, i = b.length; c < i; c++) { var g = b[c], h = g.element, e = g.events; for (var d = 0, j = e.length; d < j; d++) { var f = e[d]; h.removeEventListener(f.eventName, f.token) } } this._boundEvents = null } this._doCheck = null; Sys.UI.Silverlight.Control.callBaseMethod(this, "dispose") }, _ensureTransform: function() { var b = this.get_element().content.root, a = Sys.UI.Silverlight.Control._computeScale(b, this.get_scaleMode()); Sys.UI.Silverlight.Control._applyMatrix(b, a.horizontal, a.vertical, 0, 0) }, _findObject: function(d) { if (this._isSilverlight(d)) return d; var a, e, b, c = d.getElementsByTagName("object"); for (a = 0, e = c.length; a < e; a++) { b = c[a]; if (this._isSilverlight(b)) return b } c = d.getElementsByTagName("embed"); for (a = 0, e = c.length; a < e; a++) { b = c[a]; if (this._isSilverlight(b)) return b } return null }, _getEventsForElement: function(d, e) { var b, a = this._boundEvents; if (!a) this._boundEvents = a = []; for (var c = 0, f = a.length; c < f; c++) { b = a[c]; if (b.element === d) return b.events } if (!e) return null; b = { element: d, events: [] }; a[a.length] = b; return b.events }, initialize: function() { Sys.UI.Silverlight.Control.callBaseMethod(this, "initialize"); var a = this.get_element(); if (this._isSilverlight(a)) { if (!a.OnError) { a.OnError = Function.createDelegate(this, this._pluginError); this._setOnError = true } if (a.IsLoaded) this._pluginLoaded(); else { a.OnLoad = Function.createDelegate(this, this._pluginLoaded); a.OnSourceDownloadProgressChanged = Function.createDelegate(this, this._pluginSourceProgress); a.OnSourceDownloadComplete = Function.createDelegate(this, this._pluginSourceComplete); this._setOnLoad = true; if (!a.Source) { if (!a.SplashScreenSource) { var c = this.get_splashScreenSource(); if (c) a.SplashScreenSource = c } var b = this.get_source(); if (b) { a.Source = b; if (Sys.Browser.agent === Sys.Browser.Firefox && Sys.Browser.version >= 3 && Sys.Browser.version < 3.1) if (!this._doCheck) this._ensureSet(); else this._doCheck = null } } } } }, _ensureSet: function() { this._doCheck = Function.createDelegate(this, this._checkSet); window.setTimeout(this._doCheck, 50) }, _checkSet: function() { if (!this._doCheck) return; if (!this.get_element().Source) { this.initialize(); return } window.setTimeout(this._doCheck, 200) }, _isSilverlight: function(a) { if (!a) return false; var b = a.tagName.toLowerCase(); if (b === "object" || b === "embed") { var c = a.type ? a.type.toLowerCase() : ""; if (c.indexOf("application/x-silverlight") === 0 || c.indexOf("application/silverlight") === 0) { a.innerHTML; return !!a.settings } } return false }, _onFullScreen: function() { if (!this.get_element()) return; this.onPluginFullScreenChanged(Sys.EventArgs.Empty); this._raiseEvent("pluginFullScreenChanged") }, onPluginError: function() { }, onPluginFullScreenChanged: function() { }, onPluginLoaded: function() { }, onPluginResized: function() { if (this.get_scaleMode() !== Sys.UI.Silverlight.ScaleMode.none) this._ensureTransform() }, onPluginSourceDownloadComplete: function() { }, onPluginSourceDownloadProgressChanged: function() { }, _onResize: function() { if (!this.get_element()) return; this.onPluginResized(Sys.EventArgs.Empty); this._raiseEvent("pluginResized") }, pluginDispose: function() { }, _pluginError: function(c, b) { if (!this.get_element()) return; var a = new Sys.UI.Silverlight.ErrorEventArgs(b); this.onPluginError(a); this._doCheck = null; if (!a.get_cancel()) this._raiseEvent("pluginError", a) }, _pluginLoaded: function() { var a = this.get_element(); if (a) { if (!a.content.OnFullScreenChange) { a.content.OnFullScreenChange = Function.createDelegate(this, this._onFullScreen); this._setOnFullScreenChange = true } if (!a.content.OnResize) { a.content.OnResize = Function.createDelegate(this, this._onResize); this._setOnResize = true } this._doCheck = null; this._raisepluginLoaded(); this._onResize() } }, _pluginSourceProgress: function(c, b) { var a = new Sys.UI.Silverlight.DownloadProgressEventArgs(b.progress); this.onPluginSourceDownloadProgressChanged(a); this._raiseEvent("pluginSourceDownloadProgressChanged", a) }, _pluginSourceComplete: function() { this.onPluginSourceDownloadComplete(Sys.EventArgs.Empty); this._raiseEvent("pluginSourceDownloadComplete") }, _raiseEvent: function(c, b) { var a = this.get_events().getHandler(c); if (a) a(this, b || Sys.EventArgs.Empty) }, _raisepluginLoaded: function() { this._loaded = true; this.onPluginLoaded(Sys.EventArgs.Empty); this._raiseEvent("pluginLoaded") }, removeEventListener: function(d, c, e) { d.removeEventListener(c, e); var a = this._getEventsForElement(d, false); if (!a) return; for (var b = 0, g = a.length; b < g; b++) { var f = a[b]; if (f.token === e && f.eventName === c) { Array.removeAt(a, b); return } } } }; Sys.UI.Silverlight.Control._computeScale = function(b, c) { if (c === Sys.UI.Silverlight.ScaleMode.none) return { horizontal: 1, vertical: 1 }; var e = b.width, d = b.height, f = b.getHost(), a = { horizontal: e ? f.content.ActualWidth / e : 0, vertical: d ? f.content.ActualHeight / d : 0 }; if (c === Sys.UI.Silverlight.ScaleMode.zoom) a.horizontal = a.vertical = Math.min(a.horizontal, a.vertical); return a }; Sys.UI.Silverlight.Control._applyMatrix = function(b, f, g, d, e) { var a = b.RenderTransform; if (!a) b.RenderTransform = a = b.getHost().content.createFromXaml('<MatrixTransform Matrix="1,0 0,1 0,0"/>'); var c = { horizontal: a.Matrix.M11, vertical: a.Matrix.M22 }; a.Matrix.M11 = f; a.Matrix.M22 = g; a.Matrix.OffsetX = d; a.Matrix.OffsetY = e; return c }; Sys.UI.Silverlight.Control.createObject = function(a, b) { document.getElementById(a).innerHTML = b }; Sys.UI.Silverlight.Control.registerClass("Sys.UI.Silverlight.Control", Sys.UI.Control); Sys.UI.Silverlight.ErrorEventArgs = function(a) { this._error = a; Sys.UI.Silverlight.ErrorEventArgs.initializeBase(this) }; Sys.UI.Silverlight.ErrorEventArgs.prototype = { get_error: function() { return this._error } }; Sys.UI.Silverlight.ErrorEventArgs.registerClass("Sys.UI.Silverlight.ErrorEventArgs", Sys.CancelEventArgs); Sys.UI.Silverlight.DownloadProgressEventArgs = function(a) { this._progress = a; Sys.UI.Silverlight.DownloadProgressEventArgs.initializeBase(this) }; Sys.UI.Silverlight.DownloadProgressEventArgs.prototype = { get_progress: function() { return this._progress } }; Sys.UI.Silverlight.DownloadProgressEventArgs.registerClass("Sys.UI.Silverlight.DownloadProgressEventArgs", Sys.EventArgs); Sys.UI.Silverlight.ScaleMode = function() { throw Error.notImplemented() }; Sys.UI.Silverlight.ScaleMode.prototype = { none: 0, zoom: 1, stretch: 2 }; Sys.UI.Silverlight.ScaleMode.registerEnum("Sys.UI.Silverlight.ScaleMode");
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();