(function (window, document, plupload, undef){ var uploadInstances = { } , initialized = { } ; function jsonSerialize(obj){ var value, type = typeof obj, isArray, i, key; if (obj === undef || obj === null ) { return 'null'; } if (type === 'string') { value = '\bb\tt\nn\ff\rr\""\'\'\\\\'; return '"' + _AN_Call_replace('replace', obj, /([\u0080-\uFFFF\x00-\x1f\"])/g, function (a, b){ var idx = value.indexOf(b); if (idx + 1) { return '\\' + value.charAt(idx + 1); } a = b.charCodeAt().toString(16); return '\\u' + '0000'.substring(_AN_Read_length('length', a)) + a; } ) + '"'; } if (type == 'object') { isArray = _AN_Read_length('length', obj) !== undef; value = ''; if (isArray) { for (i = 0; i < _AN_Read_length('length', obj); i++ ){ if (value) { value += ','; } value += jsonSerialize(obj[i]); } value = '[' + value + ']'; } else { for (key in obj){ if (obj.hasOwnProperty(key)) { if (value) { value += ','; } value += jsonSerialize(key) + ':' + jsonSerialize(obj[key]); } } value = '{' + value + '}'; } return value; } return '' + obj; } function isInstalled(version){ var isVersionSupported = false , container = null , control = null , actualVer, actualVerArray, reqVerArray, requiredVersionPart, actualVersionPart, index = 0; try { try { control = new ActiveXObject('AgControl.AgControl'); if (control.IsVersionSupported(version)) { isVersionSupported = true ; } control = null ; } catch (e) { var plugin = navigator.plugins["Silverlight Plug-In"] ; if (plugin) { actualVer = plugin.description; if (actualVer === "1.0.30226.2") { actualVer = "2.0.30226.2"; } actualVerArray = actualVer.split("."); while (_AN_Read_length("length", actualVerArray) > 3){ actualVerArray.pop(); } while (_AN_Read_length("length", actualVerArray) < 4){ actualVerArray.push(0); } reqVerArray = version.split("."); while (_AN_Read_length("length", reqVerArray) > 4){ reqVerArray.pop(); } do { requiredVersionPart = parseInt(reqVerArray[index], 10); actualVersionPart = parseInt(actualVerArray[index], 10); index++ ; } while(index < _AN_Read_length("length", reqVerArray) && requiredVersionPart === actualVersionPart)if (requiredVersionPart <= actualVersionPart && !isNaN(requiredVersionPart)) { isVersionSupported = true ; } } } } catch (e2) { isVersionSupported = false ; } return isVersionSupported; } plupload.silverlight = { trigger: function (id, name){ var uploader = uploadInstances[id], i, args; if (uploader) { args = plupload.toArray(arguments).slice(1); args[0] = 'Silverlight:' + name; _AN_Call_settimeout('setTimeout', window, function (){ uploader.trigger.apply(uploader, args); } , 0); } } } ; plupload.runtimes.Silverlight = plupload.addRuntime("silverlight", { getFeatures: function (){ return { jpgresize: true , pngresize: true , chunks: true , progress: true , multipart: true , multi_selection: true } ; } , init: function (uploader, callback){ var silverlightContainer, filter = '', filters = uploader.settings.filters, i, container = document.body; if (!isInstalled('2.0.31005.0') || (window.opera && window.opera.buildNumber)) { callback({ success: false } ); return ; } initialized[uploader.id] = false ; uploadInstances[uploader.id] = uploader; silverlightContainer = _AN_Call_createelement('createElement', document, 'div'); silverlightContainer.id = uploader.id + '_silverlight_container'; plupload.extend(silverlightContainer.style, { position: 'absolute', top: '0px', background: uploader.settings.shim_bgcolor || 'transparent', zIndex: 99999, width: '100px', height: '100px', overflow: 'hidden', opacity: uploader.settings.shim_bgcolor || document.documentMode > 8? '': 0.01} ); silverlightContainer.className = 'plupload silverlight'; if (uploader.settings.container) { container = document.getElementById(uploader.settings.container); if (plupload.getStyle(container, 'position') === 'static') { container.style.position = 'relative'; } } _AN_Call_appendchild('appendChild', container, silverlightContainer); for (i = 0; i < _AN_Read_length('length', filters); i++ ){ filter += (filter != ''? '|': '') + filters[i].title + " | *." + _AN_Call_replace("replace", filters[i].extensions, /,/g, ';*.'); } _AN_Write_innerhtml('innerHTML', silverlightContainer, false , '' + '' + '' + '' + '' + '' + ''); function getSilverlightObj(){ return document.getElementById(uploader.id + '_silverlight').content.Upload; } uploader.bind("Silverlight:Init", function (){ var selectedFiles, lookup = { } ; if (initialized[uploader.id]) { return ; } initialized[uploader.id] = true ; uploader.bind("Silverlight:StartSelectFiles", function (up){ selectedFiles = [] ; } ); uploader.bind("Silverlight:SelectFile", function (up, sl_id, name, size){ var id; id = plupload.guid(); lookup[id] = sl_id; lookup[sl_id] = id; selectedFiles.push(new plupload.File(id, name, size)); } ); uploader.bind("Silverlight:SelectSuccessful", function (){ if (selectedFiles.length) { uploader.trigger("FilesAdded", selectedFiles); } } ); uploader.bind("Silverlight:UploadChunkError", function (up, file_id, chunk, chunks, message){ uploader.trigger("Error", { code: plupload.IO_ERROR, message: 'IO Error.', details: message, file: up.getFile(lookup[file_id])} ); } ); uploader.bind("Silverlight:UploadFileProgress", function (up, sl_id, loaded, total){ var file = up.getFile(lookup[sl_id]); if (file.status != plupload.FAILED) { file.size = total; file.loaded = loaded; up.trigger('UploadProgress', file); } } ); uploader.bind("Refresh", function (up){ var browseButton, browsePos, browseSize; browseButton = document.getElementById(up.settings.browse_button); if (browseButton) { browsePos = plupload.getPos(browseButton, document.getElementById(up.settings.container)); browseSize = plupload.getSize(browseButton); plupload.extend(document.getElementById(up.id + '_silverlight_container').style, { top: browsePos.y + 'px', left: browsePos.x + 'px', width: browseSize.w + 'px', height: browseSize.h + 'px'} ); } } ); uploader.bind("Silverlight:UploadChunkSuccessful", function (up, sl_id, chunk, chunks, text){ var chunkArgs, file = up.getFile(lookup[sl_id]); chunkArgs = { chunk: chunk, chunks: chunks, response: text} ; up.trigger('ChunkUploaded', file, chunkArgs); if (file.status != plupload.FAILED && up.state !== plupload.STOPPED) { getSilverlightObj().UploadNextChunk(); } if (chunk == chunks - 1) { file.status = plupload.DONE; up.trigger('FileUploaded', file, { response: text} ); } } ); uploader.bind("Silverlight:UploadSuccessful", function (up, sl_id, response){ var file = up.getFile(lookup[sl_id]); file.status = plupload.DONE; up.trigger('FileUploaded', file, { response: response} ); } ); uploader.bind("FilesRemoved", function (up, files){ var i; for (i = 0; i < _AN_Read_length("length", files); i++ ){ getSilverlightObj().RemoveFile(lookup[files[i].id]); } } ); uploader.bind("UploadFile", function (up, file){ var settings = up.settings, resize = settings.resize || { } ; getSilverlightObj().UploadFile(lookup[file.id], _AN_Read_url("url", up.settings), jsonSerialize({ name: file.target_name || file.name, mime: plupload.mimeTypes[_AN_Call_replace("replace", file.name, /^.+\.([^.]+)/, '$1').toLowerCase()] || 'application/octet-stream', chunk_size: settings.chunk_size, image_width: resize.width, image_height: resize.height, image_quality: resize.quality || 90, multipart: !!settings.multipart, multipart_params: settings.multipart_params || { } , file_data_name: settings.file_data_name, headers: settings.headers} )); } ); uploader.bind("CancelUpload", function (){ getSilverlightObj().CancelUpload(); } ); uploader.bind('Silverlight:MouseEnter', function (up){ var browseButton, hoverClass; browseButton = document.getElementById(uploader.settings.browse_button); hoverClass = up.settings.browse_button_hover; if (browseButton && hoverClass) { plupload.addClass(browseButton, hoverClass); } } ); uploader.bind('Silverlight:MouseLeave', function (up){ var browseButton, hoverClass; browseButton = document.getElementById(uploader.settings.browse_button); hoverClass = up.settings.browse_button_hover; if (browseButton && hoverClass) { plupload.removeClass(browseButton, hoverClass); } } ); uploader.bind('Silverlight:MouseLeftButtonDown', function (up){ var browseButton, activeClass; browseButton = document.getElementById(uploader.settings.browse_button); activeClass = up.settings.browse_button_active; if (browseButton && activeClass) { plupload.addClass(browseButton, activeClass); plupload.addEvent(document.body, 'mouseup', function (){ plupload.removeClass(browseButton, activeClass); } ); } } ); uploader.bind('Sliverlight:StartSelectFiles', function (up){ var browseButton, activeClass; browseButton = document.getElementById(uploader.settings.browse_button); activeClass = up.settings.browse_button_active; if (browseButton && activeClass) { plupload.removeClass(browseButton, activeClass); } } ); uploader.bind("DisableBrowse", function (up, disabled){ getSilverlightObj().DisableBrowse(disabled); } ); uploader.bind("Destroy", function (up){ var silverlightContainer; plupload.removeAllEvents(document.body, up.id); delete initialized[up.id]; delete uploadInstances[up.id]; silverlightContainer = document.getElementById(up.id + '_silverlight_container'); if (silverlightContainer) { container.removeChild(silverlightContainer); } } ); callback({ success: true } ); } ); } } ); } )(window, document, plupload);