Feature #44: Image capture WebRTC & HTML5 FileIO
Silverlight was previously used to capture webcam pictures and upload file attachments. HTML5 FileIO is now used for all attachment uploading - including drag-drop support. WebRTC is used to capture webcam images - this falls back to a Flash polyfill when WebRTC isn't supported.
This commit is contained in:
1 parent
d040ab094c
commit
b64ac3b16f
40 files changed
+3221
-2444
No files matched your search
@@ -0,0 +1,675 @@
|
||||
///#source 1 1 /ClientSource/Scripts/Modules/Disco-AttachmentUploader/webcam.js
|
||||
// WebcamJS v1.0
|
||||
// Webcam library for capturing JPEG/PNG images in JavaScript
|
||||
// Attempts getUserMedia, falls back to Flash
|
||||
// Author: Joseph Huckaby: http://github.com/jhuckaby
|
||||
// Based on JPEGCam: http://code.google.com/p/jpegcam/
|
||||
// Copyright (c) 2012 Joseph Huckaby
|
||||
// Licensed under the MIT License
|
||||
|
||||
/* Usage:
|
||||
<div id="my_camera" style="width:320px; height:240px;"></div>
|
||||
<div id="my_result"></div>
|
||||
|
||||
<script language="JavaScript">
|
||||
Webcam.attach( '#my_camera' );
|
||||
|
||||
function take_snapshot() {
|
||||
var data_uri = Webcam.snap();
|
||||
document.getElementById('my_result').innerHTML =
|
||||
'<img src="'+data_uri+'"/>';
|
||||
}
|
||||
</script>
|
||||
|
||||
<a href="javascript:void(take_snapshot())">Take Snapshot</a>
|
||||
*/
|
||||
|
||||
var Webcam = {
|
||||
version: '1.0.0',
|
||||
|
||||
// globals
|
||||
protocol: location.protocol.match(/https/i) ? 'https' : 'http',
|
||||
swfURL: '', // URI to webcam.swf movie (defaults to cwd)
|
||||
loaded: false, // true when webcam movie finishes loading
|
||||
live: false, // true when webcam is initialized and ready to snap
|
||||
userMedia: true, // true when getUserMedia is supported natively
|
||||
|
||||
params: {
|
||||
width: 0,
|
||||
height: 0,
|
||||
dest_width: 0, // size of captured image
|
||||
dest_height: 0, // these default to width/height
|
||||
image_format: 'jpeg', // image format (may be jpeg or png)
|
||||
jpeg_quality: 90, // jpeg image quality from 0 (worst) to 100 (best)
|
||||
force_flash: false // force flash mode
|
||||
},
|
||||
|
||||
hooks: {
|
||||
load: null,
|
||||
live: null,
|
||||
uploadcomplete: null,
|
||||
uploadprogress: null,
|
||||
error: function(msg) { alert("Webcam.js Error: " + msg); }
|
||||
}, // callback hook functions
|
||||
|
||||
init: function() {
|
||||
// initialize, check for getUserMedia support
|
||||
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
|
||||
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
|
||||
|
||||
this.userMedia = this.userMedia && !!navigator.getUserMedia && !!window.URL;
|
||||
|
||||
// Older versions of firefox (< 21) apparently claim support but user media does not actually work
|
||||
if (navigator.userAgent.match(/Firefox\D+(\d+)/)) {
|
||||
if (parseInt(RegExp.$1, 10) < 21) this.userMedia = null;
|
||||
}
|
||||
},
|
||||
|
||||
attach: function(elem) {
|
||||
// create webcam preview and attach to DOM element
|
||||
// pass in actual DOM reference, ID, or CSS selector
|
||||
if (typeof(elem) == 'string') {
|
||||
elem = document.getElementById(elem) || document.querySelector(elem);
|
||||
}
|
||||
if (!elem) {
|
||||
return this.dispatch('error', "Could not locate DOM element to attach to.");
|
||||
}
|
||||
|
||||
this.container = elem;
|
||||
if (!this.params.width) this.params.width = elem.offsetWidth;
|
||||
if (!this.params.height) this.params.height = elem.offsetHeight;
|
||||
|
||||
// set defaults for dest_width / dest_height if not set
|
||||
if (!this.params.dest_width) this.params.dest_width = this.params.width;
|
||||
if (!this.params.dest_height) this.params.dest_height = this.params.height;
|
||||
|
||||
// if force_flash is set, disable userMedia
|
||||
if (this.params.force_flash) this.userMedia = null;
|
||||
|
||||
if (this.userMedia) {
|
||||
// setup webcam video container
|
||||
var video = document.createElement('video');
|
||||
video.setAttribute('autoplay', 'autoplay');
|
||||
video.style.width = '' + this.params.dest_width + 'px';
|
||||
video.style.height = '' + this.params.dest_height + 'px';
|
||||
|
||||
// adjust scale if dest_width or dest_height is different
|
||||
var scaleX = this.params.width / this.params.dest_width;
|
||||
var scaleY = this.params.height / this.params.dest_height;
|
||||
|
||||
if ((scaleX != 1.0) || (scaleY != 1.0)) {
|
||||
elem.style.overflow = 'visible';
|
||||
video.style.webkitTransformOrigin = '0px 0px';
|
||||
video.style.mozTransformOrigin = '0px 0px';
|
||||
video.style.msTransformOrigin = '0px 0px';
|
||||
video.style.oTransformOrigin = '0px 0px';
|
||||
video.style.transformOrigin = '0px 0px';
|
||||
video.style.webkitTransform = 'scaleX('+scaleX+') scaleY('+scaleY+')';
|
||||
video.style.mozTransform = 'scaleX('+scaleX+') scaleY('+scaleY+')';
|
||||
video.style.msTransform = 'scaleX('+scaleX+') scaleY('+scaleY+')';
|
||||
video.style.oTransform = 'scaleX('+scaleX+') scaleY('+scaleY+')';
|
||||
video.style.transform = 'scaleX('+scaleX+') scaleY('+scaleY+')';
|
||||
}
|
||||
|
||||
// add video element to dom
|
||||
elem.appendChild( video );
|
||||
this.video = video;
|
||||
|
||||
// create offscreen canvas element to hold pixels later on
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = this.params.dest_width;
|
||||
canvas.height = this.params.dest_height;
|
||||
var context = canvas.getContext('2d');
|
||||
this.context = context;
|
||||
this.canvas = canvas;
|
||||
|
||||
// ask user for access to their camera
|
||||
var self = this;
|
||||
navigator.getUserMedia({
|
||||
"audio": false,
|
||||
"video": true
|
||||
},
|
||||
function(stream) {
|
||||
// got access, attach stream to video
|
||||
video.src = window.URL.createObjectURL( stream ) || stream;
|
||||
Webcam.stream = stream;
|
||||
Webcam.loaded = true;
|
||||
Webcam.live = true;
|
||||
Webcam.dispatch('load');
|
||||
Webcam.dispatch('live');
|
||||
},
|
||||
function(err) {
|
||||
return self.dispatch('error', "Could not access webcam.");
|
||||
});
|
||||
}
|
||||
else {
|
||||
// flash fallback
|
||||
elem.innerHTML = this.getSWFHTML();
|
||||
}
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
// shutdown camera, reset to potentially attach again
|
||||
if (this.userMedia) {
|
||||
try { this.stream.stop(); } catch (e) {;}
|
||||
delete this.stream;
|
||||
delete this.canvas;
|
||||
delete this.context;
|
||||
delete this.video;
|
||||
}
|
||||
|
||||
this.container.innerHTML = '';
|
||||
delete this.container;
|
||||
|
||||
this.loaded = false;
|
||||
this.live = false;
|
||||
},
|
||||
|
||||
set: function() {
|
||||
// set one or more params
|
||||
// variable argument list: 1 param = hash, 2 params = key, value
|
||||
if (arguments.length == 1) {
|
||||
for (var key in arguments[0]) {
|
||||
this.params[key] = arguments[0][key];
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.params[ arguments[0] ] = arguments[1];
|
||||
}
|
||||
},
|
||||
|
||||
on: function(name, callback) {
|
||||
// set callback hook
|
||||
// supported hooks: onLoad, onError, onLive
|
||||
name = name.replace(/^on/i, '').toLowerCase();
|
||||
|
||||
if (typeof(this.hooks[name]) == 'undefined')
|
||||
throw "Event type not supported: " + name;
|
||||
|
||||
this.hooks[name] = callback;
|
||||
},
|
||||
|
||||
dispatch: function() {
|
||||
// fire hook callback, passing optional value to it
|
||||
var name = arguments[0].replace(/^on/i, '').toLowerCase();
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
if (this.hooks[name]) {
|
||||
if (typeof(this.hooks[name]) == 'function') {
|
||||
// callback is function reference, call directly
|
||||
this.hooks[name].apply(this, args);
|
||||
}
|
||||
else if (typeof(this.hooks[name]) == 'array') {
|
||||
// callback is PHP-style object instance method
|
||||
this.hooks[name][0][this.hooks[name][1]].apply(this.hooks[name][0], args);
|
||||
}
|
||||
else if (window[this.hooks[name]]) {
|
||||
// callback is global function name
|
||||
window[ this.hooks[name] ].apply(window, args);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false; // no hook defined
|
||||
},
|
||||
|
||||
setSWFLocation: function(url) {
|
||||
// set location of SWF movie (defaults to webcam.swf in cwd)
|
||||
this.swfURL = url;
|
||||
},
|
||||
|
||||
getSWFHTML: function() {
|
||||
// Return HTML for embedding flash based webcam capture movie
|
||||
var html = '';
|
||||
|
||||
// make sure we aren't running locally (flash doesn't work)
|
||||
if (location.protocol.match(/file/)) {
|
||||
return '<h1 style="color:red">Sorry, the Webcam.js Flash fallback does not work from local disk. Please upload it to a web server first.</h1>';
|
||||
}
|
||||
|
||||
// set default swfURL if not explicitly set
|
||||
if (!this.swfURL) {
|
||||
// find our script tag, and use that base URL
|
||||
var base_url = '';
|
||||
var scpts = document.getElementsByTagName('script');
|
||||
for (var idx = 0, len = scpts.length; idx < len; idx++) {
|
||||
var src = scpts[idx].getAttribute('src');
|
||||
if (src && src.match(/\/webcam(\.min)?\.js/)) {
|
||||
base_url = src.replace(/\/webcam(\.min)?\.js.*$/, '');
|
||||
idx = len;
|
||||
}
|
||||
}
|
||||
if (base_url) this.swfURL = base_url + '/webcam.swf';
|
||||
else this.swfURL = 'webcam.swf';
|
||||
}
|
||||
|
||||
// if this is the user's first visit, set flashvar so flash privacy settings panel is shown first
|
||||
if (window.localStorage && !localStorage.getItem('visited')) {
|
||||
this.params.new_user = 1;
|
||||
localStorage.setItem('visited', 1);
|
||||
}
|
||||
|
||||
// construct flashvars string
|
||||
var flashvars = '';
|
||||
for (var key in this.params) {
|
||||
if (flashvars) flashvars += '&';
|
||||
flashvars += key + '=' + escape(this.params[key]);
|
||||
}
|
||||
|
||||
html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+this.protocol+'://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+this.params.width+'" height="'+this.params.height+'" id="webcam_movie_obj" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+this.swfURL+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><embed id="webcam_movie_embed" src="'+this.swfURL+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+this.params.width+'" height="'+this.params.height+'" name="webcam_movie_embed" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'"></embed></object>';
|
||||
|
||||
return html;
|
||||
},
|
||||
|
||||
getMovie: function() {
|
||||
// get reference to movie object/embed in DOM
|
||||
if (!this.loaded) return this.dispatch('error', "Flash Movie is not loaded yet");
|
||||
var movie = document.getElementById('webcam_movie_obj');
|
||||
if (!movie || !movie._snap) movie = document.getElementById('webcam_movie_embed');
|
||||
if (!movie) this.dispatch('error', "Cannot locate Flash movie in DOM");
|
||||
return movie;
|
||||
},
|
||||
|
||||
snap: function() {
|
||||
// take snapshot and return image data uri
|
||||
if (!this.loaded) return this.dispatch('error', "Webcam is not loaded yet");
|
||||
if (!this.live) return this.dispatch('error', "Webcam is not live yet");
|
||||
|
||||
if (this.userMedia) {
|
||||
// native implementation
|
||||
this.context.drawImage(this.video, 0, 0, this.params.dest_width, this.params.dest_height);
|
||||
return this.canvas.toDataURL('image/' + this.params.image_format, this.params.jpeg_quality / 100 );
|
||||
}
|
||||
else {
|
||||
// flash fallback
|
||||
var raw_data = this.getMovie()._snap();
|
||||
return 'data:image/'+this.params.image_format+';base64,' + raw_data;
|
||||
}
|
||||
},
|
||||
|
||||
configure: function(panel) {
|
||||
// open flash configuration panel -- specify tab name:
|
||||
// "camera", "privacy", "default", "localStorage", "microphone", "settingsManager"
|
||||
if (!panel) panel = "camera";
|
||||
this.getMovie()._configure(panel);
|
||||
},
|
||||
|
||||
flashNotify: function(type, msg) {
|
||||
// receive notification from flash about event
|
||||
switch (type) {
|
||||
case 'flashLoadComplete':
|
||||
// movie loaded successfully
|
||||
this.loaded = true;
|
||||
this.dispatch('load');
|
||||
break;
|
||||
|
||||
case 'cameraLive':
|
||||
// camera is live and ready to snap
|
||||
this.live = true;
|
||||
this.dispatch('live');
|
||||
break;
|
||||
|
||||
case 'error':
|
||||
// Flash error
|
||||
this.dispatch('error', msg);
|
||||
break;
|
||||
|
||||
default:
|
||||
// catch-all event, just in case
|
||||
// console.log("webcam flash_notify: " + type + ": " + msg);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
b64ToUint6: function(nChr) {
|
||||
// convert base64 encoded character to 6-bit integer
|
||||
// from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
|
||||
return nChr > 64 && nChr < 91 ? nChr - 65
|
||||
: nChr > 96 && nChr < 123 ? nChr - 71
|
||||
: nChr > 47 && nChr < 58 ? nChr + 4
|
||||
: nChr === 43 ? 62 : nChr === 47 ? 63 : 0;
|
||||
},
|
||||
|
||||
base64DecToArr: function(sBase64, nBlocksSize) {
|
||||
// convert base64 encoded string to Uintarray
|
||||
// from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
|
||||
var sB64Enc = sBase64.replace(/[^A-Za-z0-9\+\/]/g, ""), nInLen = sB64Enc.length,
|
||||
nOutLen = nBlocksSize ? Math.ceil((nInLen * 3 + 1 >> 2) / nBlocksSize) * nBlocksSize : nInLen * 3 + 1 >> 2,
|
||||
taBytes = new Uint8Array(nOutLen);
|
||||
|
||||
for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {
|
||||
nMod4 = nInIdx & 3;
|
||||
nUint24 |= this.b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 18 - 6 * nMod4;
|
||||
if (nMod4 === 3 || nInLen - nInIdx === 1) {
|
||||
for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {
|
||||
taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;
|
||||
}
|
||||
nUint24 = 0;
|
||||
}
|
||||
}
|
||||
return taBytes;
|
||||
},
|
||||
|
||||
upload: function(image_data_uri, target_url, callback) {
|
||||
// submit image data to server using binary AJAX
|
||||
if (callback) Webcam.on('uploadComplete', callback);
|
||||
var form_elem_name = 'webcam';
|
||||
|
||||
// detect image format from within image_data_uri
|
||||
var image_fmt = '';
|
||||
if (image_data_uri.match(/^data\:image\/(\w+)/))
|
||||
image_fmt = RegExp.$1;
|
||||
else
|
||||
throw "Cannot locate image format in Data URI";
|
||||
|
||||
// extract raw base64 data from Data URI
|
||||
var raw_image_data = image_data_uri.replace(/^data\:image\/\w+\;base64\,/, '');
|
||||
|
||||
// contruct use AJAX object
|
||||
var http = new XMLHttpRequest();
|
||||
http.open("POST", target_url, true);
|
||||
|
||||
// setup progress events
|
||||
if (http.upload && http.upload.addEventListener) {
|
||||
http.upload.addEventListener( 'progress', function(e) {
|
||||
if (e.lengthComputable) {
|
||||
var progress = e.loaded / e.total;
|
||||
Webcam.dispatch('uploadProgress', progress, e);
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
|
||||
// completion handler
|
||||
http.onload = function() {
|
||||
Webcam.dispatch('uploadComplete', http.status, http.responseText, http.statusText);
|
||||
};
|
||||
|
||||
// create a blob and decode our base64 to binary
|
||||
var blob = new Blob( [ this.base64DecToArr(raw_image_data) ], {type: 'image/'+image_fmt} );
|
||||
|
||||
// stuff into a form, so servers can easily receive it as a standard file upload
|
||||
var form = new FormData();
|
||||
form.append( form_elem_name, blob, form_elem_name+"."+image_fmt.replace(/e/, '') );
|
||||
|
||||
// send data to server
|
||||
http.send(form);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Webcam.init();
|
||||
|
||||
///#source 1 1 /ClientSource/Scripts/Modules/Disco-AttachmentUploader/disco-attachmentuploader.js
|
||||
/// <reference path="webcam.js" />
|
||||
|
||||
; (function (window, document, $, Webcam) {
|
||||
"use strict";
|
||||
|
||||
var attachmentUploader = function (uploadUrl, dropTarget, uploadProgressContainer) {
|
||||
var self = this;
|
||||
|
||||
self.uploadUrl = uploadUrl;
|
||||
self.dropTarget = dropTarget;
|
||||
self.uploadProgressContainer = uploadProgressContainer;
|
||||
|
||||
// #region File Selection Support
|
||||
self._uploadFilesInput = null;
|
||||
self.uploadFiles = function () {
|
||||
if (!!self._uploadFilesInput) {
|
||||
self._uploadFilesInput.remove();
|
||||
}
|
||||
self._uploadFilesInput = $('<input>');
|
||||
self._uploadFilesInput.attr({
|
||||
type: 'file',
|
||||
multiple: 'multiple',
|
||||
title: 'Disco File Uploading'
|
||||
})
|
||||
.hide()
|
||||
.change(function (e) {
|
||||
var files = e.target.files;
|
||||
if (!!files && files.length > 0) {
|
||||
self._uploadFiles(files);
|
||||
}
|
||||
self._uploadFilesInput.remove();
|
||||
}).appendTo(self.uploadProgressContainer)
|
||||
.click();
|
||||
};
|
||||
// #endregion
|
||||
|
||||
// #region File Drop Support
|
||||
if (!!self.dropTarget) {
|
||||
var $document = $(document);
|
||||
var dragFinished = false;
|
||||
var dragFinishedToken = null;
|
||||
$document.on('dragover', function () {
|
||||
self.dropTarget.addClass('dragHighlight');
|
||||
self.dropTarget.removeClass('dragHover');
|
||||
dragFinished = false;
|
||||
});
|
||||
$document.on('dragleave', function () {
|
||||
if (!!dragFinishedToken)
|
||||
window.clearInterval(dragFinishedToken);
|
||||
|
||||
dragFinished = true;
|
||||
window.setTimeout(function () {
|
||||
if (dragFinished)
|
||||
self.dropTarget.removeClass('dragHighlight');
|
||||
dragFinishedToken = null;
|
||||
}, 200);
|
||||
});
|
||||
|
||||
self.dropTarget.on('dragover', function (e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
self.dropTarget.addClass('dragHover');
|
||||
|
||||
dragFinished = false;
|
||||
|
||||
e.originalEvent.dataTransfer.dropEffect = 'copy';
|
||||
});
|
||||
|
||||
self.dropTarget.on('drop', function (e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
dragFinished = true;
|
||||
self.dropTarget.removeClass('dragHighlight');
|
||||
|
||||
var files = e.originalEvent.dataTransfer.files;
|
||||
self._uploadFiles(files);
|
||||
});
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Webcam Support
|
||||
self.uploadImage = function () {
|
||||
var mediaWidth = 720;
|
||||
var mediaHeight = 540;
|
||||
var mediaStream;
|
||||
|
||||
// Setup Dialog
|
||||
var dialog = $('<div>')
|
||||
.attr({
|
||||
id: 'disco_attachmentUpload_imageDialog',
|
||||
title: 'Upload Image',
|
||||
'class': 'dialog disco-attachmentUpload-imageDialog'
|
||||
});
|
||||
dialog.dialog({
|
||||
autoOpen: true,
|
||||
draggable: false,
|
||||
modal: true,
|
||||
resizable: false,
|
||||
width: mediaWidth,
|
||||
height: mediaHeight,
|
||||
close: function () {
|
||||
Webcam.reset();
|
||||
window.setTimeout(function () {
|
||||
dialog.dialog('destroy');
|
||||
}, 1);
|
||||
}
|
||||
}).closest('.ui-dialog').children('.ui-dialog-titlebar').css('border-bottom', 'none');
|
||||
|
||||
var dialogButtons = [{
|
||||
text: 'Capture',
|
||||
click: captureImage
|
||||
}];
|
||||
|
||||
// Capturing
|
||||
function captureImage() {
|
||||
var dataUri = Webcam.snap();
|
||||
self._uploadImage(dataUri);
|
||||
}
|
||||
Webcam.set({
|
||||
width: mediaWidth,
|
||||
height: mediaHeight,
|
||||
dest_width: mediaWidth * 1.5,
|
||||
dest_height: mediaHeight * 1.5,
|
||||
jpeg_quality: 95
|
||||
});
|
||||
Webcam.setSWFLocation('/ClientSource/Scripts/Modules/Disco-AttachmentUploader/webcam.swf');
|
||||
Webcam.on('error', function (error) {
|
||||
alert(error);
|
||||
dialog.dialog('close');
|
||||
});
|
||||
Webcam.on('live', function () {
|
||||
dialog.dialog('option', 'buttons', dialogButtons);
|
||||
dialog.closest('.ui-dialog')
|
||||
.children('.ui-dialog-buttonpane')
|
||||
.css('margin-top', 0)
|
||||
.find('.ui-button:first').focus();
|
||||
});
|
||||
Webcam.attach(dialog.attr('id'));
|
||||
};
|
||||
// #endregion
|
||||
|
||||
// #region Helpers
|
||||
self.getFileComments = function (fileName, thumbnailHandler, complete) {
|
||||
var result = false;
|
||||
var dialog = $('<div>')
|
||||
.attr({
|
||||
title: 'Upload File',
|
||||
'class': 'dialog disco-attachmentUpload-commentDialog'
|
||||
});
|
||||
dialog.html('<table><tr><th>File Name:</th><td class="filename"></td></tr><tr><th>Comments:</th><td><input class="comments" type="text"></input></td></tr><tr><td class="thumbnail" colspan="2"><img /></td></tr></table>');
|
||||
|
||||
if (!!thumbnailHandler) {
|
||||
var td = dialog.find('td.thumbnail');
|
||||
var img = td.find('img');
|
||||
if (thumbnailHandler(img))
|
||||
td.show();
|
||||
}
|
||||
|
||||
dialog.find('td.filename').text(fileName).attr('title', fileName);
|
||||
var comments = dialog.find('input.comments')
|
||||
.keypress(function (e) {
|
||||
if (e.which === 13) {
|
||||
result = true;
|
||||
dialog.dialog("close");
|
||||
}
|
||||
});
|
||||
|
||||
dialog.dialog({
|
||||
resizable: false,
|
||||
width: 400,
|
||||
modal: true,
|
||||
autoOpen: true,
|
||||
buttons: {
|
||||
"Upload": function () {
|
||||
result = true;
|
||||
dialog.dialog("close");
|
||||
},
|
||||
Cancel: function () {
|
||||
dialog.dialog("close");
|
||||
}
|
||||
},
|
||||
close: function () {
|
||||
var commentsVal = comments.val();
|
||||
dialog.dialog('destroy').remove();
|
||||
complete(result, commentsVal);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self._uploadImage = function (dataUri) {
|
||||
var imageData = dataUri.replace(/^data\:image\/\w+\;base64\,/, '');
|
||||
|
||||
var imageBlob = new Blob([Webcam.base64DecToArr(imageData)], { type: 'image/jpeg' });
|
||||
|
||||
var fileName = 'CapturedImage-' + moment().format('YYYYMMDD-HHmmss') + '.jpg';
|
||||
|
||||
self.getFileComments(fileName, function (img) {
|
||||
img.attr('src', dataUri);
|
||||
return true;
|
||||
}, function (result, comments) {
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
self._uploadFile(imageBlob, fileName, comments);
|
||||
});
|
||||
};
|
||||
|
||||
self._uploadFiles = function (fileList) {
|
||||
var files = $.makeArray(fileList);
|
||||
|
||||
var processNextFile = function () {
|
||||
if (!files || files.length === 0)
|
||||
return;
|
||||
|
||||
var file = files.shift();
|
||||
self.getFileComments(file.name, function (img) {
|
||||
if (!!file.type && file.type.indexOf('image/') === 0) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function (e) {
|
||||
img.attr('src', e.target.result);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}, function (result, comments) {
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
self._uploadFile(file, file.name, comments);
|
||||
|
||||
processNextFile();
|
||||
});
|
||||
};
|
||||
processNextFile();
|
||||
};
|
||||
|
||||
self._uploadFile = function (fileData, fileName, comments) {
|
||||
var formData = new FormData();
|
||||
var xhr = new XMLHttpRequest();
|
||||
var progress = $('<div>')
|
||||
.append($('<i>').addClass('fa fa-cog fa-spin'))
|
||||
.append($('<span>').text('Uploading: ' + fileName))
|
||||
.appendTo(self.uploadProgressContainer);
|
||||
|
||||
formData.append('Comments', comments);
|
||||
formData.append('File', fileData, fileName);
|
||||
|
||||
xhr.open("POST", self.uploadUrl, true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
if (xhr.status !== 200) {
|
||||
alert('Error Uploading [' + fileName + ']: ' + xhr.responseText);
|
||||
}
|
||||
progress.slideUp(400, function () {
|
||||
progress.remove();
|
||||
});
|
||||
}
|
||||
};
|
||||
xhr.send(formData);
|
||||
};
|
||||
// #endregion
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
if (!document.Disco) {
|
||||
document.Disco = {};
|
||||
}
|
||||
document.Disco.AttachmentUploader = attachmentUploader;
|
||||
|
||||
}(this, document, $, Webcam));
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<bundle minify="true" runOnBuild="true" output="Disco-AttachmentUploader.js">
|
||||
<file>/ClientSource/Scripts/Modules/Disco-AttachmentUploader/webcam.js</file>
|
||||
<file>/ClientSource/Scripts/Modules/Disco-AttachmentUploader/disco-attachmentuploader.js</file>
|
||||
</bundle>
|
||||
@@ -0,0 +1,4 @@
|
||||
var Webcam={version:"1.0.0",protocol:location.protocol.match(/https/i)?"https":"http",swfURL:"",loaded:!1,live:!1,userMedia:!0,params:{width:0,height:0,dest_width:0,dest_height:0,image_format:"jpeg",jpeg_quality:90,force_flash:!1},hooks:{load:null,live:null,uploadcomplete:null,uploadprogress:null,error:function(n){alert("Webcam.js Error: "+n)}},init:function(){navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;window.URL=window.URL||window.webkitURL||window.mozURL||window.msURL;this.userMedia=this.userMedia&&!!navigator.getUserMedia&&!!window.URL;navigator.userAgent.match(/Firefox\D+(\d+)/)&&parseInt(RegExp.$1,10)<21&&(this.userMedia=null)},attach:function(n){var t,i,r,u,f,e;if(typeof n=="string"&&(n=document.getElementById(n)||document.querySelector(n)),!n)return this.dispatch("error","Could not locate DOM element to attach to.");this.container=n;this.params.width||(this.params.width=n.offsetWidth);this.params.height||(this.params.height=n.offsetHeight);this.params.dest_width||(this.params.dest_width=this.params.width);this.params.dest_height||(this.params.dest_height=this.params.height);this.params.force_flash&&(this.userMedia=null);this.userMedia?(t=document.createElement("video"),t.setAttribute("autoplay","autoplay"),t.style.width=""+this.params.dest_width+"px",t.style.height=""+this.params.dest_height+"px",i=this.params.width/this.params.dest_width,r=this.params.height/this.params.dest_height,(i!=1||r!=1)&&(n.style.overflow="visible",t.style.webkitTransformOrigin="0px 0px",t.style.mozTransformOrigin="0px 0px",t.style.msTransformOrigin="0px 0px",t.style.oTransformOrigin="0px 0px",t.style.transformOrigin="0px 0px",t.style.webkitTransform="scaleX("+i+") scaleY("+r+")",t.style.mozTransform="scaleX("+i+") scaleY("+r+")",t.style.msTransform="scaleX("+i+") scaleY("+r+")",t.style.oTransform="scaleX("+i+") scaleY("+r+")",t.style.transform="scaleX("+i+") scaleY("+r+")"),n.appendChild(t),this.video=t,u=document.createElement("canvas"),u.width=this.params.dest_width,u.height=this.params.dest_height,f=u.getContext("2d"),this.context=f,this.canvas=u,e=this,navigator.getUserMedia({audio:!1,video:!0},function(n){t.src=window.URL.createObjectURL(n)||n;Webcam.stream=n;Webcam.loaded=!0;Webcam.live=!0;Webcam.dispatch("load");Webcam.dispatch("live")},function(){return e.dispatch("error","Could not access webcam.")})):n.innerHTML=this.getSWFHTML()},reset:function(){if(this.userMedia){try{this.stream.stop()}catch(n){}delete this.stream;delete this.canvas;delete this.context;delete this.video}this.container.innerHTML="";delete this.container;this.loaded=!1;this.live=!1},set:function(){if(arguments.length==1)for(var n in arguments[0])this.params[n]=arguments[0][n];else this.params[arguments[0]]=arguments[1]},on:function(n,t){if(n=n.replace(/^on/i,"").toLowerCase(),typeof this.hooks[n]=="undefined")throw"Event type not supported: "+n;this.hooks[n]=t},dispatch:function(){var n=arguments[0].replace(/^on/i,"").toLowerCase(),t=Array.prototype.slice.call(arguments,1);return this.hooks[n]?(typeof this.hooks[n]=="function"?this.hooks[n].apply(this,t):typeof this.hooks[n]=="array"?this.hooks[n][0][this.hooks[n][1]].apply(this.hooks[n][0],t):window[this.hooks[n]]&&window[this.hooks[n]].apply(window,t),!0):!1},setSWFLocation:function(n){this.swfURL=n},getSWFHTML:function(){var i,u,t,f,r,n,e;if(location.protocol.match(/file/))return'<h1 style="color:red">Sorry, the Webcam.js Flash fallback does not work from local disk. Please upload it to a web server first.<\/h1>';if(!this.swfURL){for(i="",u=document.getElementsByTagName("script"),t=0,f=u.length;t<f;t++)r=u[t].getAttribute("src"),r&&r.match(/\/webcam(\.min)?\.js/)&&(i=r.replace(/\/webcam(\.min)?\.js.*$/,""),t=f);this.swfURL=i?i+"/webcam.swf":"webcam.swf"}window.localStorage&&!localStorage.getItem("visited")&&(this.params.new_user=1,localStorage.setItem("visited",1));n="";for(e in this.params)n&&(n+="&"),n+=e+"="+escape(this.params[e]);return""+('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+this.protocol+'://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+this.params.width+'" height="'+this.params.height+'" id="webcam_movie_obj" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+this.swfURL+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+n+'"/><embed id="webcam_movie_embed" src="'+this.swfURL+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+this.params.width+'" height="'+this.params.height+'" name="webcam_movie_embed" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+n+'"><\/embeLine truncated
|
||||
/*
|
||||
//# sourceMappingURL=Disco-AttachmentUploader.min.js.map
|
||||
*/
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"version":3,
|
||||
"file":"Disco-AttachmentUploader.min.js",
|
||||
"lineCount":1,
|
||||
"mappings":"AAyBA,IAAIA,OAAS,CACZ,OAAO,CAAE,OAAO,CAGhB,QAAQ,CAAEC,QAAQC,SAASC,MAAM,CAAS,QAAT,CAAW,CAAE,OAAQ,CAAE,MAAM,CAC9D,MAAM,CAAE,EAAE,CACV,MAAM,CAAE,CAAA,CAAK,CACb,IAAI,CAAE,CAAA,CAAK,CACX,SAAS,CAAE,CAAA,CAAI,CAEf,MAAM,CAAE,CACP,KAAK,CAAE,CAAC,CACR,MAAM,CAAE,CAAC,CACT,UAAU,CAAE,CAAC,CACb,WAAW,CAAE,CAAC,CACd,YAAY,CAAE,MAAM,CACpB,YAAY,CAAE,EAAE,CAChB,WAAW,CAAE,CAAA,CAPN,CAQP,CAED,KAAK,CAAE,CACN,IAAI,CAAE,IAAI,CACV,IAAI,CAAE,IAAI,CACV,cAAc,CAAE,IAAI,CACpB,cAAc,CAAE,IAAI,CACpB,KAAK,CAAEC,QAAQ,CAACC,CAAD,CAAM,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B,CAAoBU,MAAM,CAAC,IAAIN,MAAO,CAAAJ,CAAA,CAAM,CAAA,CAAA,CAAE,CAAEK,CAAtB,CAF1C,CAIInE,MAAO,CAAA,IAAIkE,MAAO,CAAAJ,CAAA,CAAX,C,EAEf9D,MAAQ,CAAA,IAAIkE,MAAO,CAAAJ,CAAA,CAAX,CAAkBU,MAAM,CAACxE,MAAM,CAAEmE,CAAT,C,CAE1B,CAAA,EAbJ,CAeG,CAAA,CApBa,CAqBpB,CAED,cAAc,CAAEM,QAAQ,CAACC,CAAD,CAAM,CAE7B,IAAIC,OAAQ,CAAED,CAFe,CAG7B,CAED,UAAU,CLine truncated
|
||||
"sources":["/ClientSource/Scripts/Modules/Disco-AttachmentUploader/webcam.js","/ClientSource/Scripts/Modules/Disco-AttachmentUploader/disco-attachmentuploader.js"],
|
||||
"names":["Webcam","location","protocol","match","error","msg","alert","init","navigator","getUserMedia","webkitGetUserMedia","mozGetUserMedia","msGetUserMedia","window","URL","webkitURL","mozURL","msURL","userMedia","userAgent","parseInt","RegExp","$1","attach","elem","video","scaleX","scaleY","canvas","context","self","document","getElementById","querySelector","dispatch","container","params","width","offsetWidth","height","offsetHeight","dest_width","dest_height","force_flash","createElement","setAttribute","style","overflow","webkitTransformOrigin","mozTransformOrigin","msTransformOrigin","oTransformOrigin","transformOrigin","webkitTransform","mozTransform","msTransform","oTransform","transform","appendChild","getContext","stream","src","createObjectURL","loaded","live","innerHTML","getSWFHTML","reset","stop","e","set","arguments","length","key","on","name","callback","replace","toLowerCase","hooks","args","Array","prototype","slice","call","apply","setSWFLocation","url","swfURL","base_url","scpts","idx","len","flashvars","getElementsByTagName","getAttribute","localStorage","getItem","new_user","setItem","escape","getMovie","movie","_snap","snap","drawImage","toDataURL","image_format","jpeg_quality","raw_data","configure","panel","_configure","flashNotify","type","b64ToUint6","nChr","base64DecToArr","sBase64","nBlocksSize","sB64Enc","nInLen","nOutLen","Math","ceil","taBytes","Uint8Array","nMod3","nMod4","nUint24","nOutIdx","nInIdx","charCodeAt","upload","image_data_uri","target_url","form_elem_name","image_fmt","raw_image_data","http","blob","form","XMLHttpRequest","open","addEventListener","lengthComputable","progress","total","onload","http.onload","status","responseText","statusText","Blob","FormData","append","send","$","attachmentUploader","uploadUrl","dropTarget","uploadProgressContainer","_uploadFilesInput","uploadFiles","self.uploadFiles","remove","attr","hide","change","files","target","_uploadFiles","appendTo","click","$document","dragFinished","dragFinishedToken","addClass","removeClass","clearInterval","setTimeout","stopPropagation","preventDefault","originalEvent","dataTransfer","dropEffect","uploadImage","self.uploadImage","captureImage","dataUri","_uploadImage","mediaWidth","mediaHeight","dialog","dialogButtons","close","closest","children","css","find","focus","getFileComments","self.getFileComments","fileName","thumbnailHandler","complete","result","td","img","comments","html","show","text","keypress","which","Upload","Cancel","commentsVal","val","self._uploadImage","imageData","imageBlob","moment","format","_uploadFile","self._uploadFiles","fileList","makeArray","processNextFile","file","shift","indexOf","reader","FileReader","reader.onload","readAsDataURL","self._uploadFile","fileData","formData","xhr","onreadystatechange","xhr.onreadystatechange","readyState","slideUp","Disco","AttachmentUploader"]
|
||||
}
|
||||
+274
@@ -0,0 +1,274 @@
|
||||
/// <reference path="webcam.js" />
|
||||
|
||||
; (function (window, document, $, Webcam) {
|
||||
"use strict";
|
||||
|
||||
var attachmentUploader = function (uploadUrl, dropTarget, uploadProgressContainer) {
|
||||
var self = this;
|
||||
|
||||
self.uploadUrl = uploadUrl;
|
||||
self.dropTarget = dropTarget;
|
||||
self.uploadProgressContainer = uploadProgressContainer;
|
||||
|
||||
// #region File Selection Support
|
||||
self._uploadFilesInput = null;
|
||||
self.uploadFiles = function () {
|
||||
if (!!self._uploadFilesInput) {
|
||||
self._uploadFilesInput.remove();
|
||||
}
|
||||
self._uploadFilesInput = $('<input>');
|
||||
self._uploadFilesInput.attr({
|
||||
type: 'file',
|
||||
multiple: 'multiple',
|
||||
title: 'Disco File Uploading'
|
||||
})
|
||||
.hide()
|
||||
.change(function (e) {
|
||||
var files = e.target.files;
|
||||
if (!!files && files.length > 0) {
|
||||
self._uploadFiles(files);
|
||||
}
|
||||
self._uploadFilesInput.remove();
|
||||
}).appendTo(self.uploadProgressContainer)
|
||||
.click();
|
||||
};
|
||||
// #endregion
|
||||
|
||||
// #region File Drop Support
|
||||
if (!!self.dropTarget) {
|
||||
var $document = $(document);
|
||||
var dragFinished = false;
|
||||
var dragFinishedToken = null;
|
||||
$document.on('dragover', function () {
|
||||
self.dropTarget.addClass('dragHighlight');
|
||||
self.dropTarget.removeClass('dragHover');
|
||||
dragFinished = false;
|
||||
});
|
||||
$document.on('dragleave', function () {
|
||||
if (!!dragFinishedToken)
|
||||
window.clearInterval(dragFinishedToken);
|
||||
|
||||
dragFinished = true;
|
||||
window.setTimeout(function () {
|
||||
if (dragFinished)
|
||||
self.dropTarget.removeClass('dragHighlight');
|
||||
dragFinishedToken = null;
|
||||
}, 200);
|
||||
});
|
||||
|
||||
self.dropTarget.on('dragover', function (e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
self.dropTarget.addClass('dragHover');
|
||||
|
||||
dragFinished = false;
|
||||
|
||||
e.originalEvent.dataTransfer.dropEffect = 'copy';
|
||||
});
|
||||
|
||||
self.dropTarget.on('drop', function (e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
dragFinished = true;
|
||||
self.dropTarget.removeClass('dragHighlight');
|
||||
|
||||
var files = e.originalEvent.dataTransfer.files;
|
||||
self._uploadFiles(files);
|
||||
});
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Webcam Support
|
||||
self.uploadImage = function () {
|
||||
var mediaWidth = 720;
|
||||
var mediaHeight = 540;
|
||||
var mediaStream;
|
||||
|
||||
// Setup Dialog
|
||||
var dialog = $('<div>')
|
||||
.attr({
|
||||
id: 'disco_attachmentUpload_imageDialog',
|
||||
title: 'Upload Image',
|
||||
'class': 'dialog disco-attachmentUpload-imageDialog'
|
||||
});
|
||||
dialog.dialog({
|
||||
autoOpen: true,
|
||||
draggable: false,
|
||||
modal: true,
|
||||
resizable: false,
|
||||
width: mediaWidth,
|
||||
height: mediaHeight,
|
||||
close: function () {
|
||||
Webcam.reset();
|
||||
window.setTimeout(function () {
|
||||
dialog.dialog('destroy');
|
||||
}, 1);
|
||||
}
|
||||
}).closest('.ui-dialog').children('.ui-dialog-titlebar').css('border-bottom', 'none');
|
||||
|
||||
var dialogButtons = [{
|
||||
text: 'Capture',
|
||||
click: captureImage
|
||||
}];
|
||||
|
||||
// Capturing
|
||||
function captureImage() {
|
||||
var dataUri = Webcam.snap();
|
||||
self._uploadImage(dataUri);
|
||||
}
|
||||
Webcam.set({
|
||||
width: mediaWidth,
|
||||
height: mediaHeight,
|
||||
dest_width: mediaWidth * 1.5,
|
||||
dest_height: mediaHeight * 1.5,
|
||||
jpeg_quality: 95
|
||||
});
|
||||
Webcam.setSWFLocation('/ClientSource/Scripts/Modules/Disco-AttachmentUploader/webcam.swf');
|
||||
Webcam.on('error', function (error) {
|
||||
alert(error);
|
||||
dialog.dialog('close');
|
||||
});
|
||||
Webcam.on('live', function () {
|
||||
dialog.dialog('option', 'buttons', dialogButtons);
|
||||
dialog.closest('.ui-dialog')
|
||||
.children('.ui-dialog-buttonpane')
|
||||
.css('margin-top', 0)
|
||||
.find('.ui-button:first').focus();
|
||||
});
|
||||
Webcam.attach(dialog.attr('id'));
|
||||
};
|
||||
// #endregion
|
||||
|
||||
// #region Helpers
|
||||
self.getFileComments = function (fileName, thumbnailHandler, complete) {
|
||||
var result = false;
|
||||
var dialog = $('<div>')
|
||||
.attr({
|
||||
title: 'Upload File',
|
||||
'class': 'dialog disco-attachmentUpload-commentDialog'
|
||||
});
|
||||
dialog.html('<table><tr><th>File Name:</th><td class="filename"></td></tr><tr><th>Comments:</th><td><input class="comments" type="text"></input></td></tr><tr><td class="thumbnail" colspan="2"><img /></td></tr></table>');
|
||||
|
||||
if (!!thumbnailHandler) {
|
||||
var td = dialog.find('td.thumbnail');
|
||||
var img = td.find('img');
|
||||
if (thumbnailHandler(img))
|
||||
td.show();
|
||||
}
|
||||
|
||||
dialog.find('td.filename').text(fileName).attr('title', fileName);
|
||||
var comments = dialog.find('input.comments')
|
||||
.keypress(function (e) {
|
||||
if (e.which === 13) {
|
||||
result = true;
|
||||
dialog.dialog("close");
|
||||
}
|
||||
});
|
||||
|
||||
dialog.dialog({
|
||||
resizable: false,
|
||||
width: 400,
|
||||
modal: true,
|
||||
autoOpen: true,
|
||||
buttons: {
|
||||
"Upload": function () {
|
||||
result = true;
|
||||
dialog.dialog("close");
|
||||
},
|
||||
Cancel: function () {
|
||||
dialog.dialog("close");
|
||||
}
|
||||
},
|
||||
close: function () {
|
||||
var commentsVal = comments.val();
|
||||
dialog.dialog('destroy').remove();
|
||||
complete(result, commentsVal);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self._uploadImage = function (dataUri) {
|
||||
var imageData = dataUri.replace(/^data\:image\/\w+\;base64\,/, '');
|
||||
|
||||
var imageBlob = new Blob([Webcam.base64DecToArr(imageData)], { type: 'image/jpeg' });
|
||||
|
||||
var fileName = 'CapturedImage-' + moment().format('YYYYMMDD-HHmmss') + '.jpg';
|
||||
|
||||
self.getFileComments(fileName, function (img) {
|
||||
img.attr('src', dataUri);
|
||||
return true;
|
||||
}, function (result, comments) {
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
self._uploadFile(imageBlob, fileName, comments);
|
||||
});
|
||||
};
|
||||
|
||||
self._uploadFiles = function (fileList) {
|
||||
var files = $.makeArray(fileList);
|
||||
|
||||
var processNextFile = function () {
|
||||
if (!files || files.length === 0)
|
||||
return;
|
||||
|
||||
var file = files.shift();
|
||||
self.getFileComments(file.name, function (img) {
|
||||
if (!!file.type && file.type.indexOf('image/') === 0) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function (e) {
|
||||
img.attr('src', e.target.result);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}, function (result, comments) {
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
self._uploadFile(file, file.name, comments);
|
||||
|
||||
processNextFile();
|
||||
});
|
||||
};
|
||||
processNextFile();
|
||||
};
|
||||
|
||||
self._uploadFile = function (fileData, fileName, comments) {
|
||||
var formData = new FormData();
|
||||
var xhr = new XMLHttpRequest();
|
||||
var progress = $('<div>')
|
||||
.append($('<i>').addClass('fa fa-cog fa-spin'))
|
||||
.append($('<span>').text('Uploading: ' + fileName))
|
||||
.appendTo(self.uploadProgressContainer);
|
||||
|
||||
formData.append('Comments', comments);
|
||||
formData.append('File', fileData, fileName);
|
||||
|
||||
xhr.open("POST", self.uploadUrl, true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
if (xhr.status !== 200) {
|
||||
alert('Error Uploading [' + fileName + ']: ' + xhr.responseText);
|
||||
}
|
||||
progress.slideUp(400, function () {
|
||||
progress.remove();
|
||||
});
|
||||
}
|
||||
};
|
||||
xhr.send(formData);
|
||||
};
|
||||
// #endregion
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
if (!document.Disco) {
|
||||
document.Disco = {};
|
||||
}
|
||||
document.Disco.AttachmentUploader = attachmentUploader;
|
||||
|
||||
}(this, document, $, Webcam));
|
||||
@@ -0,0 +1,398 @@
|
||||
// WebcamJS v1.0
|
||||
// Webcam library for capturing JPEG/PNG images in JavaScript
|
||||
// Attempts getUserMedia, falls back to Flash
|
||||
// Author: Joseph Huckaby: http://github.com/jhuckaby
|
||||
// Based on JPEGCam: http://code.google.com/p/jpegcam/
|
||||
// Copyright (c) 2012 Joseph Huckaby
|
||||
// Licensed under the MIT License
|
||||
|
||||
/* Usage:
|
||||
<div id="my_camera" style="width:320px; height:240px;"></div>
|
||||
<div id="my_result"></div>
|
||||
|
||||
<script language="JavaScript">
|
||||
Webcam.attach( '#my_camera' );
|
||||
|
||||
function take_snapshot() {
|
||||
var data_uri = Webcam.snap();
|
||||
document.getElementById('my_result').innerHTML =
|
||||
'<img src="'+data_uri+'"/>';
|
||||
}
|
||||
</script>
|
||||
|
||||
<a href="javascript:void(take_snapshot())">Take Snapshot</a>
|
||||
*/
|
||||
|
||||
var Webcam = {
|
||||
version: '1.0.0',
|
||||
|
||||
// globals
|
||||
protocol: location.protocol.match(/https/i) ? 'https' : 'http',
|
||||
swfURL: '', // URI to webcam.swf movie (defaults to cwd)
|
||||
loaded: false, // true when webcam movie finishes loading
|
||||
live: false, // true when webcam is initialized and ready to snap
|
||||
userMedia: true, // true when getUserMedia is supported natively
|
||||
|
||||
params: {
|
||||
width: 0,
|
||||
height: 0,
|
||||
dest_width: 0, // size of captured image
|
||||
dest_height: 0, // these default to width/height
|
||||
image_format: 'jpeg', // image format (may be jpeg or png)
|
||||
jpeg_quality: 90, // jpeg image quality from 0 (worst) to 100 (best)
|
||||
force_flash: false // force flash mode
|
||||
},
|
||||
|
||||
hooks: {
|
||||
load: null,
|
||||
live: null,
|
||||
uploadcomplete: null,
|
||||
uploadprogress: null,
|
||||
error: function(msg) { alert("Webcam.js Error: " + msg); }
|
||||
}, // callback hook functions
|
||||
|
||||
init: function() {
|
||||
// initialize, check for getUserMedia support
|
||||
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
|
||||
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
|
||||
|
||||
this.userMedia = this.userMedia && !!navigator.getUserMedia && !!window.URL;
|
||||
|
||||
// Older versions of firefox (< 21) apparently claim support but user media does not actually work
|
||||
if (navigator.userAgent.match(/Firefox\D+(\d+)/)) {
|
||||
if (parseInt(RegExp.$1, 10) < 21) this.userMedia = null;
|
||||
}
|
||||
},
|
||||
|
||||
attach: function(elem) {
|
||||
// create webcam preview and attach to DOM element
|
||||
// pass in actual DOM reference, ID, or CSS selector
|
||||
if (typeof(elem) == 'string') {
|
||||
elem = document.getElementById(elem) || document.querySelector(elem);
|
||||
}
|
||||
if (!elem) {
|
||||
return this.dispatch('error', "Could not locate DOM element to attach to.");
|
||||
}
|
||||
|
||||
this.container = elem;
|
||||
if (!this.params.width) this.params.width = elem.offsetWidth;
|
||||
if (!this.params.height) this.params.height = elem.offsetHeight;
|
||||
|
||||
// set defaults for dest_width / dest_height if not set
|
||||
if (!this.params.dest_width) this.params.dest_width = this.params.width;
|
||||
if (!this.params.dest_height) this.params.dest_height = this.params.height;
|
||||
|
||||
// if force_flash is set, disable userMedia
|
||||
if (this.params.force_flash) this.userMedia = null;
|
||||
|
||||
if (this.userMedia) {
|
||||
// setup webcam video container
|
||||
var video = document.createElement('video');
|
||||
video.setAttribute('autoplay', 'autoplay');
|
||||
video.style.width = '' + this.params.dest_width + 'px';
|
||||
video.style.height = '' + this.params.dest_height + 'px';
|
||||
|
||||
// adjust scale if dest_width or dest_height is different
|
||||
var scaleX = this.params.width / this.params.dest_width;
|
||||
var scaleY = this.params.height / this.params.dest_height;
|
||||
|
||||
if ((scaleX != 1.0) || (scaleY != 1.0)) {
|
||||
elem.style.overflow = 'visible';
|
||||
video.style.webkitTransformOrigin = '0px 0px';
|
||||
video.style.mozTransformOrigin = '0px 0px';
|
||||
video.style.msTransformOrigin = '0px 0px';
|
||||
video.style.oTransformOrigin = '0px 0px';
|
||||
video.style.transformOrigin = '0px 0px';
|
||||
video.style.webkitTransform = 'scaleX('+scaleX+') scaleY('+scaleY+')';
|
||||
video.style.mozTransform = 'scaleX('+scaleX+') scaleY('+scaleY+')';
|
||||
video.style.msTransform = 'scaleX('+scaleX+') scaleY('+scaleY+')';
|
||||
video.style.oTransform = 'scaleX('+scaleX+') scaleY('+scaleY+')';
|
||||
video.style.transform = 'scaleX('+scaleX+') scaleY('+scaleY+')';
|
||||
}
|
||||
|
||||
// add video element to dom
|
||||
elem.appendChild( video );
|
||||
this.video = video;
|
||||
|
||||
// create offscreen canvas element to hold pixels later on
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = this.params.dest_width;
|
||||
canvas.height = this.params.dest_height;
|
||||
var context = canvas.getContext('2d');
|
||||
this.context = context;
|
||||
this.canvas = canvas;
|
||||
|
||||
// ask user for access to their camera
|
||||
var self = this;
|
||||
navigator.getUserMedia({
|
||||
"audio": false,
|
||||
"video": true
|
||||
},
|
||||
function(stream) {
|
||||
// got access, attach stream to video
|
||||
video.src = window.URL.createObjectURL( stream ) || stream;
|
||||
Webcam.stream = stream;
|
||||
Webcam.loaded = true;
|
||||
Webcam.live = true;
|
||||
Webcam.dispatch('load');
|
||||
Webcam.dispatch('live');
|
||||
},
|
||||
function(err) {
|
||||
return self.dispatch('error', "Could not access webcam.");
|
||||
});
|
||||
}
|
||||
else {
|
||||
// flash fallback
|
||||
elem.innerHTML = this.getSWFHTML();
|
||||
}
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
// shutdown camera, reset to potentially attach again
|
||||
if (this.userMedia) {
|
||||
try { this.stream.stop(); } catch (e) {;}
|
||||
delete this.stream;
|
||||
delete this.canvas;
|
||||
delete this.context;
|
||||
delete this.video;
|
||||
}
|
||||
|
||||
this.container.innerHTML = '';
|
||||
delete this.container;
|
||||
|
||||
this.loaded = false;
|
||||
this.live = false;
|
||||
},
|
||||
|
||||
set: function() {
|
||||
// set one or more params
|
||||
// variable argument list: 1 param = hash, 2 params = key, value
|
||||
if (arguments.length == 1) {
|
||||
for (var key in arguments[0]) {
|
||||
this.params[key] = arguments[0][key];
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.params[ arguments[0] ] = arguments[1];
|
||||
}
|
||||
},
|
||||
|
||||
on: function(name, callback) {
|
||||
// set callback hook
|
||||
// supported hooks: onLoad, onError, onLive
|
||||
name = name.replace(/^on/i, '').toLowerCase();
|
||||
|
||||
if (typeof(this.hooks[name]) == 'undefined')
|
||||
throw "Event type not supported: " + name;
|
||||
|
||||
this.hooks[name] = callback;
|
||||
},
|
||||
|
||||
dispatch: function() {
|
||||
// fire hook callback, passing optional value to it
|
||||
var name = arguments[0].replace(/^on/i, '').toLowerCase();
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
if (this.hooks[name]) {
|
||||
if (typeof(this.hooks[name]) == 'function') {
|
||||
// callback is function reference, call directly
|
||||
this.hooks[name].apply(this, args);
|
||||
}
|
||||
else if (typeof(this.hooks[name]) == 'array') {
|
||||
// callback is PHP-style object instance method
|
||||
this.hooks[name][0][this.hooks[name][1]].apply(this.hooks[name][0], args);
|
||||
}
|
||||
else if (window[this.hooks[name]]) {
|
||||
// callback is global function name
|
||||
window[ this.hooks[name] ].apply(window, args);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false; // no hook defined
|
||||
},
|
||||
|
||||
setSWFLocation: function(url) {
|
||||
// set location of SWF movie (defaults to webcam.swf in cwd)
|
||||
this.swfURL = url;
|
||||
},
|
||||
|
||||
getSWFHTML: function() {
|
||||
// Return HTML for embedding flash based webcam capture movie
|
||||
var html = '';
|
||||
|
||||
// make sure we aren't running locally (flash doesn't work)
|
||||
if (location.protocol.match(/file/)) {
|
||||
return '<h1 style="color:red">Sorry, the Webcam.js Flash fallback does not work from local disk. Please upload it to a web server first.</h1>';
|
||||
}
|
||||
|
||||
// set default swfURL if not explicitly set
|
||||
if (!this.swfURL) {
|
||||
// find our script tag, and use that base URL
|
||||
var base_url = '';
|
||||
var scpts = document.getElementsByTagName('script');
|
||||
for (var idx = 0, len = scpts.length; idx < len; idx++) {
|
||||
var src = scpts[idx].getAttribute('src');
|
||||
if (src && src.match(/\/webcam(\.min)?\.js/)) {
|
||||
base_url = src.replace(/\/webcam(\.min)?\.js.*$/, '');
|
||||
idx = len;
|
||||
}
|
||||
}
|
||||
if (base_url) this.swfURL = base_url + '/webcam.swf';
|
||||
else this.swfURL = 'webcam.swf';
|
||||
}
|
||||
|
||||
// if this is the user's first visit, set flashvar so flash privacy settings panel is shown first
|
||||
if (window.localStorage && !localStorage.getItem('visited')) {
|
||||
this.params.new_user = 1;
|
||||
localStorage.setItem('visited', 1);
|
||||
}
|
||||
|
||||
// construct flashvars string
|
||||
var flashvars = '';
|
||||
for (var key in this.params) {
|
||||
if (flashvars) flashvars += '&';
|
||||
flashvars += key + '=' + escape(this.params[key]);
|
||||
}
|
||||
|
||||
html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+this.protocol+'://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+this.params.width+'" height="'+this.params.height+'" id="webcam_movie_obj" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+this.swfURL+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><embed id="webcam_movie_embed" src="'+this.swfURL+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+this.params.width+'" height="'+this.params.height+'" name="webcam_movie_embed" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'"></embed></object>';
|
||||
|
||||
return html;
|
||||
},
|
||||
|
||||
getMovie: function() {
|
||||
// get reference to movie object/embed in DOM
|
||||
if (!this.loaded) return this.dispatch('error', "Flash Movie is not loaded yet");
|
||||
var movie = document.getElementById('webcam_movie_obj');
|
||||
if (!movie || !movie._snap) movie = document.getElementById('webcam_movie_embed');
|
||||
if (!movie) this.dispatch('error', "Cannot locate Flash movie in DOM");
|
||||
return movie;
|
||||
},
|
||||
|
||||
snap: function() {
|
||||
// take snapshot and return image data uri
|
||||
if (!this.loaded) return this.dispatch('error', "Webcam is not loaded yet");
|
||||
if (!this.live) return this.dispatch('error', "Webcam is not live yet");
|
||||
|
||||
if (this.userMedia) {
|
||||
// native implementation
|
||||
this.context.drawImage(this.video, 0, 0, this.params.dest_width, this.params.dest_height);
|
||||
return this.canvas.toDataURL('image/' + this.params.image_format, this.params.jpeg_quality / 100 );
|
||||
}
|
||||
else {
|
||||
// flash fallback
|
||||
var raw_data = this.getMovie()._snap();
|
||||
return 'data:image/'+this.params.image_format+';base64,' + raw_data;
|
||||
}
|
||||
},
|
||||
|
||||
configure: function(panel) {
|
||||
// open flash configuration panel -- specify tab name:
|
||||
// "camera", "privacy", "default", "localStorage", "microphone", "settingsManager"
|
||||
if (!panel) panel = "camera";
|
||||
this.getMovie()._configure(panel);
|
||||
},
|
||||
|
||||
flashNotify: function(type, msg) {
|
||||
// receive notification from flash about event
|
||||
switch (type) {
|
||||
case 'flashLoadComplete':
|
||||
// movie loaded successfully
|
||||
this.loaded = true;
|
||||
this.dispatch('load');
|
||||
break;
|
||||
|
||||
case 'cameraLive':
|
||||
// camera is live and ready to snap
|
||||
this.live = true;
|
||||
this.dispatch('live');
|
||||
break;
|
||||
|
||||
case 'error':
|
||||
// Flash error
|
||||
this.dispatch('error', msg);
|
||||
break;
|
||||
|
||||
default:
|
||||
// catch-all event, just in case
|
||||
// console.log("webcam flash_notify: " + type + ": " + msg);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
b64ToUint6: function(nChr) {
|
||||
// convert base64 encoded character to 6-bit integer
|
||||
// from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
|
||||
return nChr > 64 && nChr < 91 ? nChr - 65
|
||||
: nChr > 96 && nChr < 123 ? nChr - 71
|
||||
: nChr > 47 && nChr < 58 ? nChr + 4
|
||||
: nChr === 43 ? 62 : nChr === 47 ? 63 : 0;
|
||||
},
|
||||
|
||||
base64DecToArr: function(sBase64, nBlocksSize) {
|
||||
// convert base64 encoded string to Uintarray
|
||||
// from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
|
||||
var sB64Enc = sBase64.replace(/[^A-Za-z0-9\+\/]/g, ""), nInLen = sB64Enc.length,
|
||||
nOutLen = nBlocksSize ? Math.ceil((nInLen * 3 + 1 >> 2) / nBlocksSize) * nBlocksSize : nInLen * 3 + 1 >> 2,
|
||||
taBytes = new Uint8Array(nOutLen);
|
||||
|
||||
for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {
|
||||
nMod4 = nInIdx & 3;
|
||||
nUint24 |= this.b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 18 - 6 * nMod4;
|
||||
if (nMod4 === 3 || nInLen - nInIdx === 1) {
|
||||
for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {
|
||||
taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;
|
||||
}
|
||||
nUint24 = 0;
|
||||
}
|
||||
}
|
||||
return taBytes;
|
||||
},
|
||||
|
||||
upload: function(image_data_uri, target_url, callback) {
|
||||
// submit image data to server using binary AJAX
|
||||
if (callback) Webcam.on('uploadComplete', callback);
|
||||
var form_elem_name = 'webcam';
|
||||
|
||||
// detect image format from within image_data_uri
|
||||
var image_fmt = '';
|
||||
if (image_data_uri.match(/^data\:image\/(\w+)/))
|
||||
image_fmt = RegExp.$1;
|
||||
else
|
||||
throw "Cannot locate image format in Data URI";
|
||||
|
||||
// extract raw base64 data from Data URI
|
||||
var raw_image_data = image_data_uri.replace(/^data\:image\/\w+\;base64\,/, '');
|
||||
|
||||
// contruct use AJAX object
|
||||
var http = new XMLHttpRequest();
|
||||
http.open("POST", target_url, true);
|
||||
|
||||
// setup progress events
|
||||
if (http.upload && http.upload.addEventListener) {
|
||||
http.upload.addEventListener( 'progress', function(e) {
|
||||
if (e.lengthComputable) {
|
||||
var progress = e.loaded / e.total;
|
||||
Webcam.dispatch('uploadProgress', progress, e);
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
|
||||
// completion handler
|
||||
http.onload = function() {
|
||||
Webcam.dispatch('uploadComplete', http.status, http.responseText, http.statusText);
|
||||
};
|
||||
|
||||
// create a blob and decode our base64 to binary
|
||||
var blob = new Blob( [ this.base64DecToArr(raw_image_data) ], {type: 'image/'+image_fmt} );
|
||||
|
||||
// stuff into a form, so servers can easily receive it as a standard file upload
|
||||
var form = new FormData();
|
||||
form.append( form_elem_name, blob, form_elem_name+"."+image_fmt.replace(/e/, '') );
|
||||
|
||||
// send data to server
|
||||
http.send(form);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Webcam.init();
|
||||
Binary file not shown.
@@ -1,414 +0,0 @@
|
||||
///#source 1 1 /ClientSource/Scripts/Modules/Silverlight/Silverlight.js
|
||||
if (!window.Silverlight) {
|
||||
window.Silverlight = {};
|
||||
}
|
||||
|
||||
// Silverlight control instance counter for memory mgt
|
||||
Silverlight._silverlightCount = 0;
|
||||
Silverlight.fwlinkRoot = 'http://go2.microsoft.com/fwlink/?LinkID=';
|
||||
Silverlight.onGetSilverlight = null;
|
||||
Silverlight.onSilverlightInstalled = function () { window.location.reload(false); };
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// isInstalled, checks to see if the correct version is installed
|
||||
//////////////////////////////////////////////////////////////////
|
||||
Silverlight.isInstalled = function (version) {
|
||||
var isVersionSupported = false;
|
||||
var container = null;
|
||||
|
||||
try {
|
||||
var control = null;
|
||||
|
||||
try {
|
||||
control = new ActiveXObject('AgControl.AgControl');
|
||||
if (version == null) {
|
||||
isVersionSupported = true;
|
||||
}
|
||||
else if (control.IsVersionSupported(version)) {
|
||||
isVersionSupported = true;
|
||||
}
|
||||
control = null;
|
||||
}
|
||||
catch (e) {
|
||||
var plugin = navigator.plugins["Silverlight Plug-In"];
|
||||
if (plugin) {
|
||||
if (version === null) {
|
||||
isVersionSupported = true;
|
||||
}
|
||||
else {
|
||||
var actualVer = plugin.description;
|
||||
if (actualVer === "1.0.30226.2")
|
||||
actualVer = "2.0.30226.2";
|
||||
var actualVerArray = actualVer.split(".");
|
||||
while (actualVerArray.length > 3) {
|
||||
actualVerArray.pop();
|
||||
}
|
||||
while (actualVerArray.length < 4) {
|
||||
actualVerArray.push(0);
|
||||
}
|
||||
var reqVerArray = version.split(".");
|
||||
while (reqVerArray.length > 4) {
|
||||
reqVerArray.pop();
|
||||
}
|
||||
|
||||
var requiredVersionPart;
|
||||
var actualVersionPart
|
||||
var index = 0;
|
||||
|
||||
|
||||
do {
|
||||
requiredVersionPart = parseInt(reqVerArray[index]);
|
||||
actualVersionPart = parseInt(actualVerArray[index]);
|
||||
index++;
|
||||
}
|
||||
while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);
|
||||
|
||||
if (requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart)) {
|
||||
isVersionSupported = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
isVersionSupported = false;
|
||||
}
|
||||
if (container) {
|
||||
document.body.removeChild(container);
|
||||
}
|
||||
|
||||
return isVersionSupported;
|
||||
}
|
||||
Silverlight.WaitForInstallCompletion = function () {
|
||||
if (!Silverlight.isBrowserRestartRequired && Silverlight.onSilverlightInstalled) {
|
||||
try {
|
||||
navigator.plugins.refresh();
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
if (Silverlight.isInstalled(null)) {
|
||||
Silverlight.onSilverlightInstalled();
|
||||
}
|
||||
else {
|
||||
setTimeout(Silverlight.WaitForInstallCompletion, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
Silverlight.__startup = function () {
|
||||
Silverlight.isBrowserRestartRequired = Silverlight.isInstalled(null);//(!window.ActiveXObject || Silverlight.isInstalled(null));
|
||||
if (!Silverlight.isBrowserRestartRequired) {
|
||||
Silverlight.WaitForInstallCompletion();
|
||||
}
|
||||
if (window.removeEventListener) {
|
||||
window.removeEventListener('load', Silverlight.__startup, false);
|
||||
}
|
||||
else {
|
||||
window.detachEvent('onload', Silverlight.__startup);
|
||||
}
|
||||
}
|
||||
|
||||
if (window.addEventListener) {
|
||||
window.addEventListener('load', Silverlight.__startup, false);
|
||||
}
|
||||
else {
|
||||
window.attachEvent('onload', Silverlight.__startup);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
|
||||
slPluginHelper.version = slProperties.version;
|
||||
slProperties.source = source;
|
||||
slPluginHelper.alt = slProperties.alt;
|
||||
|
||||
//rename properties to their tag property names
|
||||
if (initParams)
|
||||
slProperties.initParams = initParams;
|
||||
if (slProperties.isWindowless && !slProperties.windowless)
|
||||
slProperties.windowless = slProperties.isWindowless;
|
||||
if (slProperties.framerate && !slProperties.maxFramerate)
|
||||
slProperties.maxFramerate = slProperties.framerate;
|
||||
if (id && !slProperties.id)
|
||||
slProperties.id = id;
|
||||
|
||||
// remove elements which are not to be added to the instantiation tag
|
||||
delete slProperties.ignoreBrowserVer;
|
||||
delete slProperties.inplaceInstallPrompt;
|
||||
delete slProperties.version;
|
||||
delete slProperties.isWindowless;
|
||||
delete slProperties.framerate;
|
||||
delete slProperties.data;
|
||||
delete slProperties.src;
|
||||
delete slProperties.alt;
|
||||
|
||||
|
||||
// detect that the correct version of Silverlight is installed, else display install
|
||||
|
||||
if (Silverlight.isInstalled(slPluginHelper.version)) {
|
||||
//move unknown events to the slProperties array
|
||||
for (var name in slEvents) {
|
||||
if (slEvents[name]) {
|
||||
if (name == "onLoad" && typeof slEvents[name] == "function" && slEvents[name].length != 1) {
|
||||
var onLoadHandler = slEvents[name];
|
||||
slEvents[name] = function (sender) { return onLoadHandler(document.getElementById(id), userContext, sender) };
|
||||
}
|
||||
var handlerName = Silverlight.__getHandlerName(slEvents[name]);
|
||||
if (handlerName != null) {
|
||||
slProperties[name] = handlerName;
|
||||
slEvents[name] = null;
|
||||
}
|
||||
else {
|
||||
throw "typeof events." + name + " must be 'function' or 'string'";
|
||||
}
|
||||
}
|
||||
}
|
||||
slPluginHTML = Silverlight.buildHTML(slProperties);
|
||||
}
|
||||
//The control could not be instantiated. Show the installation prompt
|
||||
else {
|
||||
slPluginHTML = Silverlight.buildPromptHTML(slPluginHelper);
|
||||
}
|
||||
|
||||
// insert or return the HTML
|
||||
if (parentElement) {
|
||||
parentElement.innerHTML = slPluginHTML;
|
||||
}
|
||||
else {
|
||||
return slPluginHTML;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// create HTML that instantiates the control
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
Silverlight.buildHTML = function (slProperties) {
|
||||
var htmlBuilder = [];
|
||||
|
||||
htmlBuilder.push('<object type=\"application/x-silverlight\" data="data:application/x-silverlight,"');
|
||||
if (slProperties.id != null) {
|
||||
htmlBuilder.push(' id="' + slProperties.id + '"');
|
||||
}
|
||||
if (slProperties.width != null) {
|
||||
htmlBuilder.push(' width="' + slProperties.width + '"');
|
||||
}
|
||||
if (slProperties.height != null) {
|
||||
htmlBuilder.push(' height="' + slProperties.height + '"');
|
||||
}
|
||||
htmlBuilder.push(' >');
|
||||
|
||||
delete slProperties.id;
|
||||
delete slProperties.width;
|
||||
delete slProperties.height;
|
||||
|
||||
for (var name in slProperties) {
|
||||
if (slProperties[name]) {
|
||||
htmlBuilder.push('<param name="' + Silverlight.HtmlAttributeEncode(name) + '" value="' + Silverlight.HtmlAttributeEncode(slProperties[name]) + '" />');
|
||||
}
|
||||
}
|
||||
htmlBuilder.push('<\/object>');
|
||||
return htmlBuilder.join('');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 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 = "";
|
||||
var urlRoot = Silverlight.fwlinkRoot;
|
||||
var shortVer = slPluginHelper.version;
|
||||
if (slPluginHelper.alt) {
|
||||
slPluginHTML = slPluginHelper.alt;
|
||||
}
|
||||
else {
|
||||
if (!shortVer) {
|
||||
shortVer = "";
|
||||
}
|
||||
slPluginHTML = "<a href='javascript:Silverlight.getSilverlight(\"{1}\");' style='text-decoration: none;'><img src='{2}' alt='Get Microsoft Silverlight' style='border-style: none'/></a>";
|
||||
slPluginHTML = slPluginHTML.replace('{1}', shortVer);
|
||||
slPluginHTML = slPluginHTML.replace('{2}', urlRoot + '108181');
|
||||
}
|
||||
|
||||
return slPluginHTML;
|
||||
}
|
||||
|
||||
|
||||
Silverlight.getSilverlight = function (version) {
|
||||
if (Silverlight.onGetSilverlight) {
|
||||
Silverlight.onGetSilverlight();
|
||||
}
|
||||
|
||||
var shortVer = "";
|
||||
var reqVerArray = String(version).split(".");
|
||||
if (reqVerArray.length > 1) {
|
||||
var majorNum = parseInt(reqVerArray[0]);
|
||||
if (isNaN(majorNum) || majorNum < 2) {
|
||||
shortVer = "1.0";
|
||||
}
|
||||
else {
|
||||
shortVer = reqVerArray[0] + '.' + reqVerArray[1];
|
||||
}
|
||||
}
|
||||
|
||||
var verArg = "";
|
||||
|
||||
if (shortVer.match(/^\d+\056\d+$/)) {
|
||||
verArg = "&v=" + shortVer;
|
||||
}
|
||||
|
||||
Silverlight.followFWLink("114576" + verArg);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Navigates to a url based on fwlinkid
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Silverlight.followFWLink = function (linkid) {
|
||||
top.location = Silverlight.fwlinkRoot + String(linkid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// 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;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Releases event handler resources when the page is unloaded
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Silverlight.__cleanup = function () {
|
||||
for (var i = Silverlight._silverlightCount - 1; i >= 0; i--) {
|
||||
window['__slEvent' + i] = null;
|
||||
}
|
||||
Silverlight._silverlightCount = 0;
|
||||
if (window.removeEventListener) {
|
||||
window.removeEventListener('unload', Silverlight.__cleanup, false);
|
||||
}
|
||||
else {
|
||||
window.detachEvent('onunload', Silverlight.__cleanup);
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Releases event handler resources when the page is unloaded
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Silverlight.__getHandlerName = function (handler) {
|
||||
var handlerName = "";
|
||||
if (typeof handler == "string") {
|
||||
handlerName = handler;
|
||||
}
|
||||
else if (typeof handler == "function") {
|
||||
if (Silverlight._silverlightCount == 0) {
|
||||
if (window.addEventListener) {
|
||||
window.addEventListener('onunload', Silverlight.__cleanup, false);
|
||||
}
|
||||
else {
|
||||
window.attachEvent('onunload', Silverlight.__cleanup);
|
||||
}
|
||||
}
|
||||
var count = Silverlight._silverlightCount++;
|
||||
handlerName = "__slEvent" + count;
|
||||
|
||||
window[handlerName] = handler;
|
||||
}
|
||||
else {
|
||||
handlerName = null;
|
||||
}
|
||||
return handlerName;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<bundle minify="true" runOnBuild="true">
|
||||
<file>/ClientSource/Scripts/Modules/Silverlight/Silverlight.js</file>
|
||||
</bundle>
|
||||
@@ -1,2 +0,0 @@
|
||||
window.Silverlight||(window.Silverlight={}),Silverlight._silverlightCount=0,Silverlight.fwlinkRoot="http://go2.microsoft.com/fwlink/?LinkID=",Silverlight.onGetSilverlight=null,Silverlight.onSilverlightInstalled=function(){window.location.reload(!1)},Silverlight.isInstalled=function(n){var t=!1,c=null,f,s,e,i,r,o,h,u;try{f=null;try{f=new ActiveXObject("AgControl.AgControl"),n==null?t=!0:f.IsVersionSupported(n)&&(t=!0),f=null}catch(l){if(s=navigator.plugins["Silverlight Plug-In"],s)if(n===null)t=!0;else{for(e=s.description,e==="1.0.30226.2"&&(e="2.0.30226.2"),i=e.split(".");i.length>3;)i.pop();while(i.length<4)i.push(0);for(r=n.split(".");r.length>4;)r.pop();u=0;do o=parseInt(r[u]),h=parseInt(i[u]),u++;while(u<r.length&&o===h);o<=h&&!isNaN(o)&&(t=!0)}}}catch(l){t=!1}return c&&document.body.removeChild(c),t},Silverlight.WaitForInstallCompletion=function(){if(!Silverlight.isBrowserRestartRequired&&Silverlight.onSilverlightInstalled){try{navigator.plugins.refresh()}catch(n){}Silverlight.isInstalled(null)?Silverlight.onSilverlightInstalled():setTimeout(Silverlight.WaitForInstallCompletion,3e3)}},Silverlight.__startup=function(){Silverlight.isBrowserRestartRequired=Silverlight.isInstalled(null),Silverlight.isBrowserRestartRequired||Silverlight.WaitForInstallCompletion(),window.removeEventListener?window.removeEventListener("load",Silverlight.__startup,!1):window.detachEvent("onload",Silverlight.__startup)},window.addEventListener?window.addEventListener("load",Silverlight.__startup,!1):window.attachEvent("onload",Silverlight.__startup),Silverlight.createObject=function(n,t,i,r,u,f,e){var c={},o=r,h=u,s,a,l;if(c.version=o.version,o.source=n,c.alt=o.alt,f&&(o.initParams=f),o.isWindowless&&!o.windowless&&(o.windowless=o.isWindowless),o.framerate&&!o.maxFramerate&&(o.maxFramerate=o.framerate),i&&!o.id&&(o.id=i),delete o.ignoreBrowserVer,delete o.inplaceInstallPrompt,delete o.version,delete o.isWindowless,delete o.framerate,delete o.data,delete o.src,delete o.alt,Silverlight.isInstalled(c.version)){for(s in h)if(h[s])if(s=="onLoad"&&typeof h[s]=="function"&&h[s].length!=1&&(a=h[s],h[s]=function(n){return a(document.getElementById(i),e,n)}),l=Silverlight.__getHandlerName(h[s]),l!=null)o[s]=l,h[s]=null;else throw"typeof events."+s+" must be 'function' or 'string'";slPluginHTML=Silverlight.buildHTML(o)}else slPluginHTML=Silverlight.buildPromptHTML(c);if(t)t.innerHTML=slPluginHTML;else return slPluginHTML},Silverlight.buildHTML=function(n){var t=[],i;t.push('<object type="application/x-silverlight" data="data:application/x-silverlight,"'),n.id!=null&&t.push(' id="'+n.id+'"'),n.width!=null&&t.push(' width="'+n.width+'"'),n.height!=null&&t.push(' height="'+n.height+'"'),t.push(" >"),delete n.id,delete n.width,delete n.height;for(i in n)n[i]&&t.push('<param name="'+Silverlight.HtmlAttributeEncode(i)+'" value="'+Silverlight.HtmlAttributeEncode(n[i])+'" />');return t.push("<\/object>"),t.join("")},Silverlight.createObjectEx=function(n){var t=n,i=Silverlight.createObject(t.source,t.parentElement,t.id,t.properties,t.events,t.initParams,t.context);if(t.parentElement==null)return i},Silverlight.buildPromptHTML=function(n){var t="",r=Silverlight.fwlinkRoot,i=n.version;return n.alt?t=n.alt:(i||(i=""),t="<a href='javascript:Silverlight.getSilverlight(\"{1}\");' style='text-decoration: none;'><img src='{2}' alt='Get Microsoft Silverlight' style='border-style: none'/><\/a>",t=t.replace("{1}",i),t=t.replace("{2}",r+"108181")),t},Silverlight.getSilverlight=function(n){var i,t,r,u;Silverlight.onGetSilverlight&&Silverlight.onGetSilverlight(),i="",t=String(n).split("."),t.length>1&&(r=parseInt(t[0]),i=isNaN(r)||r<2?"1.0":t[0]+"."+t[1]),u="",i.match(/^\d+\056\d+$/)&&(u="&v="+i),Silverlight.followFWLink("114576"+u)},Silverlight.followFWLink=function(n){top.location=Silverlight.fwlinkRoot+String(n)},Silverlight.HtmlAttributeEncode=function(n){var t,i="",r;if(n==null)return null;for(r=0;r<n.length;r++)t=n.charCodeAt(r),i=t>96&&t<123||t>64&&t<91||t>43&&t<58&&t!=47||t==95?i+String.fromCharCode(t):i+"&#"+t+";";return i},Silverlight.default_error_handler=function(n,t){var u,r=t.ErrorType,i;u=t.ErrorCode,i="\nSilverlight error message \n",i+="ErrorCode: "+u+"\n",i+="ErrorType: "+r+" \n",i+="Message: "+t.ErrorMessage+" \n",r=="ParserError"?(i+="XamlFile: "+t.xamlFile+" \n",i+="Line: "+t.lineNumber+" \n",i+="Position: "+t.charPosition+" \n"):r=="RuntimeError"&&(t.lineNumber!=0&&(i+="Line: "+t.lineNumber+" \n",i+="Position: "+t.charPosition+" \n"),i+="MethodName: "+t.methodName+" \n"),alert(i)},Silverlight.__cleanup=function(){for(var n=Silverlight._silverlightCount-1;n>=0;n--)window["__slEvent"+n]=null;Silverlight._silverlightCount=0,window.removeEventListener?window.removeEventListener("unload",Silverlight.__cleanup,!1):window.detachEvent("onunload",Silverlight.__cleanup)},Silverlight.__getHandlerName=function(n){var t="",i;return typeof n=="string"?t=n:typeof n=="function"?(Silverlight._silverlightCount==0&&(Line truncated
|
||||
//# sourceMappingURL=Silverlight.min.js.map
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"version":3,
|
||||
"file":"Silverlight.min.js",
|
||||
"lineCount":1,
|
||||
"mappings":"AAAKA,MAAMC,Y,GACPD,MAAMC,YAAa,CAAE,CAAA,EAAE,CAI3BA,WAAWC,kBAAmB,CAAE,CAAC,CACjCD,WAAWE,WAAY,CAAE,0CAA0C,CACnEF,WAAWG,iBAAkB,CAAE,IAAI,CACnCH,WAAWI,uBAAwB,CAAEC,QAAS,CAAA,CAAG,CAAEN,MAAMO,SAASC,OAAO,CAAC,CAAA,CAAD,C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D,CAAc,CACvBiD,CAAWI,KAAK,CAAC,EAAD,CAzBqB,C,CAgChDnF,WAAWoF,eAAgB,CAAEC,QAAS,CAACC,CAAD,CAAS,CAC3C,IAAIC,EAAaD,EACbE,EAAOxF,WAAW+C,aAAa,CAACwC,CAAUtC,OAAO,CAAEsC,CAAUrC,cAAc,CAAEqC,CAAUpC,GAAG,CAAEoC,CAAUnC,WAAW,CAAEmC,CAAUlC,OAAO,CAAEkC,CAAUjC,WAAW,CAAEiC,CAAUE,QAAxI,CADZ,CAEvB,GAAIF,CAAUrC,cAAe,EAAG,K,OACrBsC,CAJgC,C,CAW/CxF,WAAW4E,gBAAiB,CAAEc,QAAS,CAAClC,CAAD,CAAiB,CACpD,IAAIkB,EAAe,GACfiB,EAAU3F,WAAWE,YACrB0F,EAAWpC,CAAc9C,QAFR,CAerB,OAZI8C,CAAcM,IAAlB,CACIY,CAAa,CAAElB,CAAcM,IADjC,EAIS8B,C,GACDA,CAAS,CAAE,GAAE,CAEjBlB,CAAa,CAAE,2KAA0K,CACzLA,CAAa,CAAEA,CAAYmB,QAAQ,CAAC,KAAK,CAAED,CAAR,CAALine truncated
|
||||
"sources":["/ClientSource/Scripts/Modules/Silverlight/Silverlight.js"],
|
||||
"names":["window","Silverlight","_silverlightCount","fwlinkRoot","onGetSilverlight","onSilverlightInstalled","Silverlight.onSilverlightInstalled","location","reload","isInstalled","Silverlight.isInstalled","version","isVersionSupported","container","control","plugin","actualVer","actualVerArray","reqVerArray","requiredVersionPart","actualVersionPart","index","ActiveXObject","IsVersionSupported","e","navigator","plugins","description","split","length","pop","push","parseInt","isNaN","document","body","removeChild","WaitForInstallCompletion","Silverlight.WaitForInstallCompletion","isBrowserRestartRequired","refresh","setTimeout","__startup","Silverlight.__startup","removeEventListener","detachEvent","addEventListener","attachEvent","createObject","Silverlight.createObject","source","parentElement","id","properties","events","initParams","userContext","slPluginHelper","slProperties","slEvents","name","onLoadHandler","handlerName","alt","isWindowless","windowless","framerate","maxFramerate","ignoreBrowserVer","inplaceInstallPrompt","data","src","sender","getElementById","__getHandlerName","slPluginHTML","buildHTML","buildPromptHTML","innerHTML","Silverlight.buildHTML","htmlBuilder","width","height","HtmlAttributeEncode","join","createObjectEx","Silverlight.createObjectEx","params","parameters","html","context","Silverlight.buildPromptHTML","urlRoot","shortVer","replace","getSilverlight","Silverlight.getSilverlight","majorNum","verArg","String","match","followFWLink","Silverlight.followFWLink","linkid","top","Silverlight.HtmlAttributeEncode","strInput","c","retVal","cnt","charCodeAt","fromCharCode","default_error_handler","Silverlight.default_error_handler","args","iErrorCode","errorType","ErrorType","errMsg","ErrorCode","ErrorMessage","xamlFile","lineNumber","charPosition","methodName","alert","__cleanup","Silverlight.__cleanup","i","Silverlight.__getHandlerName","handler","count"]
|
||||
}
|
||||
@@ -1,413 +0,0 @@
|
||||
if (!window.Silverlight) {
|
||||
window.Silverlight = {};
|
||||
}
|
||||
|
||||
// Silverlight control instance counter for memory mgt
|
||||
Silverlight._silverlightCount = 0;
|
||||
Silverlight.fwlinkRoot = 'http://go2.microsoft.com/fwlink/?LinkID=';
|
||||
Silverlight.onGetSilverlight = null;
|
||||
Silverlight.onSilverlightInstalled = function () { window.location.reload(false); };
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// isInstalled, checks to see if the correct version is installed
|
||||
//////////////////////////////////////////////////////////////////
|
||||
Silverlight.isInstalled = function (version) {
|
||||
var isVersionSupported = false;
|
||||
var container = null;
|
||||
|
||||
try {
|
||||
var control = null;
|
||||
|
||||
try {
|
||||
control = new ActiveXObject('AgControl.AgControl');
|
||||
if (version == null) {
|
||||
isVersionSupported = true;
|
||||
}
|
||||
else if (control.IsVersionSupported(version)) {
|
||||
isVersionSupported = true;
|
||||
}
|
||||
control = null;
|
||||
}
|
||||
catch (e) {
|
||||
var plugin = navigator.plugins["Silverlight Plug-In"];
|
||||
if (plugin) {
|
||||
if (version === null) {
|
||||
isVersionSupported = true;
|
||||
}
|
||||
else {
|
||||
var actualVer = plugin.description;
|
||||
if (actualVer === "1.0.30226.2")
|
||||
actualVer = "2.0.30226.2";
|
||||
var actualVerArray = actualVer.split(".");
|
||||
while (actualVerArray.length > 3) {
|
||||
actualVerArray.pop();
|
||||
}
|
||||
while (actualVerArray.length < 4) {
|
||||
actualVerArray.push(0);
|
||||
}
|
||||
var reqVerArray = version.split(".");
|
||||
while (reqVerArray.length > 4) {
|
||||
reqVerArray.pop();
|
||||
}
|
||||
|
||||
var requiredVersionPart;
|
||||
var actualVersionPart
|
||||
var index = 0;
|
||||
|
||||
|
||||
do {
|
||||
requiredVersionPart = parseInt(reqVerArray[index]);
|
||||
actualVersionPart = parseInt(actualVerArray[index]);
|
||||
index++;
|
||||
}
|
||||
while (index < reqVerArray.length && requiredVersionPart === actualVersionPart);
|
||||
|
||||
if (requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart)) {
|
||||
isVersionSupported = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
isVersionSupported = false;
|
||||
}
|
||||
if (container) {
|
||||
document.body.removeChild(container);
|
||||
}
|
||||
|
||||
return isVersionSupported;
|
||||
}
|
||||
Silverlight.WaitForInstallCompletion = function () {
|
||||
if (!Silverlight.isBrowserRestartRequired && Silverlight.onSilverlightInstalled) {
|
||||
try {
|
||||
navigator.plugins.refresh();
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
if (Silverlight.isInstalled(null)) {
|
||||
Silverlight.onSilverlightInstalled();
|
||||
}
|
||||
else {
|
||||
setTimeout(Silverlight.WaitForInstallCompletion, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
Silverlight.__startup = function () {
|
||||
Silverlight.isBrowserRestartRequired = Silverlight.isInstalled(null);//(!window.ActiveXObject || Silverlight.isInstalled(null));
|
||||
if (!Silverlight.isBrowserRestartRequired) {
|
||||
Silverlight.WaitForInstallCompletion();
|
||||
}
|
||||
if (window.removeEventListener) {
|
||||
window.removeEventListener('load', Silverlight.__startup, false);
|
||||
}
|
||||
else {
|
||||
window.detachEvent('onload', Silverlight.__startup);
|
||||
}
|
||||
}
|
||||
|
||||
if (window.addEventListener) {
|
||||
window.addEventListener('load', Silverlight.__startup, false);
|
||||
}
|
||||
else {
|
||||
window.attachEvent('onload', Silverlight.__startup);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
|
||||
slPluginHelper.version = slProperties.version;
|
||||
slProperties.source = source;
|
||||
slPluginHelper.alt = slProperties.alt;
|
||||
|
||||
//rename properties to their tag property names
|
||||
if (initParams)
|
||||
slProperties.initParams = initParams;
|
||||
if (slProperties.isWindowless && !slProperties.windowless)
|
||||
slProperties.windowless = slProperties.isWindowless;
|
||||
if (slProperties.framerate && !slProperties.maxFramerate)
|
||||
slProperties.maxFramerate = slProperties.framerate;
|
||||
if (id && !slProperties.id)
|
||||
slProperties.id = id;
|
||||
|
||||
// remove elements which are not to be added to the instantiation tag
|
||||
delete slProperties.ignoreBrowserVer;
|
||||
delete slProperties.inplaceInstallPrompt;
|
||||
delete slProperties.version;
|
||||
delete slProperties.isWindowless;
|
||||
delete slProperties.framerate;
|
||||
delete slProperties.data;
|
||||
delete slProperties.src;
|
||||
delete slProperties.alt;
|
||||
|
||||
|
||||
// detect that the correct version of Silverlight is installed, else display install
|
||||
|
||||
if (Silverlight.isInstalled(slPluginHelper.version)) {
|
||||
//move unknown events to the slProperties array
|
||||
for (var name in slEvents) {
|
||||
if (slEvents[name]) {
|
||||
if (name == "onLoad" && typeof slEvents[name] == "function" && slEvents[name].length != 1) {
|
||||
var onLoadHandler = slEvents[name];
|
||||
slEvents[name] = function (sender) { return onLoadHandler(document.getElementById(id), userContext, sender) };
|
||||
}
|
||||
var handlerName = Silverlight.__getHandlerName(slEvents[name]);
|
||||
if (handlerName != null) {
|
||||
slProperties[name] = handlerName;
|
||||
slEvents[name] = null;
|
||||
}
|
||||
else {
|
||||
throw "typeof events." + name + " must be 'function' or 'string'";
|
||||
}
|
||||
}
|
||||
}
|
||||
slPluginHTML = Silverlight.buildHTML(slProperties);
|
||||
}
|
||||
//The control could not be instantiated. Show the installation prompt
|
||||
else {
|
||||
slPluginHTML = Silverlight.buildPromptHTML(slPluginHelper);
|
||||
}
|
||||
|
||||
// insert or return the HTML
|
||||
if (parentElement) {
|
||||
parentElement.innerHTML = slPluginHTML;
|
||||
}
|
||||
else {
|
||||
return slPluginHTML;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// create HTML that instantiates the control
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
Silverlight.buildHTML = function (slProperties) {
|
||||
var htmlBuilder = [];
|
||||
|
||||
htmlBuilder.push('<object type=\"application/x-silverlight\" data="data:application/x-silverlight,"');
|
||||
if (slProperties.id != null) {
|
||||
htmlBuilder.push(' id="' + slProperties.id + '"');
|
||||
}
|
||||
if (slProperties.width != null) {
|
||||
htmlBuilder.push(' width="' + slProperties.width + '"');
|
||||
}
|
||||
if (slProperties.height != null) {
|
||||
htmlBuilder.push(' height="' + slProperties.height + '"');
|
||||
}
|
||||
htmlBuilder.push(' >');
|
||||
|
||||
delete slProperties.id;
|
||||
delete slProperties.width;
|
||||
delete slProperties.height;
|
||||
|
||||
for (var name in slProperties) {
|
||||
if (slProperties[name]) {
|
||||
htmlBuilder.push('<param name="' + Silverlight.HtmlAttributeEncode(name) + '" value="' + Silverlight.HtmlAttributeEncode(slProperties[name]) + '" />');
|
||||
}
|
||||
}
|
||||
htmlBuilder.push('<\/object>');
|
||||
return htmlBuilder.join('');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 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 = "";
|
||||
var urlRoot = Silverlight.fwlinkRoot;
|
||||
var shortVer = slPluginHelper.version;
|
||||
if (slPluginHelper.alt) {
|
||||
slPluginHTML = slPluginHelper.alt;
|
||||
}
|
||||
else {
|
||||
if (!shortVer) {
|
||||
shortVer = "";
|
||||
}
|
||||
slPluginHTML = "<a href='javascript:Silverlight.getSilverlight(\"{1}\");' style='text-decoration: none;'><img src='{2}' alt='Get Microsoft Silverlight' style='border-style: none'/></a>";
|
||||
slPluginHTML = slPluginHTML.replace('{1}', shortVer);
|
||||
slPluginHTML = slPluginHTML.replace('{2}', urlRoot + '108181');
|
||||
}
|
||||
|
||||
return slPluginHTML;
|
||||
}
|
||||
|
||||
|
||||
Silverlight.getSilverlight = function (version) {
|
||||
if (Silverlight.onGetSilverlight) {
|
||||
Silverlight.onGetSilverlight();
|
||||
}
|
||||
|
||||
var shortVer = "";
|
||||
var reqVerArray = String(version).split(".");
|
||||
if (reqVerArray.length > 1) {
|
||||
var majorNum = parseInt(reqVerArray[0]);
|
||||
if (isNaN(majorNum) || majorNum < 2) {
|
||||
shortVer = "1.0";
|
||||
}
|
||||
else {
|
||||
shortVer = reqVerArray[0] + '.' + reqVerArray[1];
|
||||
}
|
||||
}
|
||||
|
||||
var verArg = "";
|
||||
|
||||
if (shortVer.match(/^\d+\056\d+$/)) {
|
||||
verArg = "&v=" + shortVer;
|
||||
}
|
||||
|
||||
Silverlight.followFWLink("114576" + verArg);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Navigates to a url based on fwlinkid
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Silverlight.followFWLink = function (linkid) {
|
||||
top.location = Silverlight.fwlinkRoot + String(linkid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// 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;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Releases event handler resources when the page is unloaded
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Silverlight.__cleanup = function () {
|
||||
for (var i = Silverlight._silverlightCount - 1; i >= 0; i--) {
|
||||
window['__slEvent' + i] = null;
|
||||
}
|
||||
Silverlight._silverlightCount = 0;
|
||||
if (window.removeEventListener) {
|
||||
window.removeEventListener('unload', Silverlight.__cleanup, false);
|
||||
}
|
||||
else {
|
||||
window.detachEvent('onunload', Silverlight.__cleanup);
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Releases event handler resources when the page is unloaded
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Silverlight.__getHandlerName = function (handler) {
|
||||
var handlerName = "";
|
||||
if (typeof handler == "string") {
|
||||
handlerName = handler;
|
||||
}
|
||||
else if (typeof handler == "function") {
|
||||
if (Silverlight._silverlightCount == 0) {
|
||||
if (window.addEventListener) {
|
||||
window.addEventListener('onunload', Silverlight.__cleanup, false);
|
||||
}
|
||||
else {
|
||||
window.attachEvent('onunload', Silverlight.__cleanup);
|
||||
}
|
||||
}
|
||||
var count = Silverlight._silverlightCount++;
|
||||
handlerName = "__slEvent" + count;
|
||||
|
||||
window[handlerName] = handler;
|
||||
}
|
||||
else {
|
||||
handlerName = null;
|
||||
}
|
||||
return handlerName;
|
||||
}
|
||||
Reference in new issue
Block a user