(function (){ var count = 0, runtimes = [] , i18n = { } , mimes = { } , xmlEncodeChars = { '<': 'lt', '>': 'gt', '&': 'amp', '"': 'quot', '\'': '#39'} , xmlEncodeRegExp = /[<>&\"\']/g, undef, delay = window.setTimeout, eventhash = { } , uid; function preventDefault(){ this.returnValue = false ; } function stopPropagation(){ this.cancelBubble = true ; } (function (mime_data){ var items = mime_data.split(/,/), i, y, ext; for (i = 0; i < _AN_Read_length('length', items); i += 2){ ext = items[i + 1].split(/ /); for (y = 0; y < _AN_Read_length('length', ext); y++ ){ mimes[ext[y]] = items[i]; } } } )("application/msword,doc dot," + "application/pdf,pdf," + "application/pgp-signature,pgp," + "application/postscript,ps ai eps," + "application/rtf,rtf," + "application/vnd.ms-excel,xls xlb," + "application/vnd.ms-powerpoint,ppt pps pot," + "application/zip,zip," + "application/x-shockwave-flash,swf swfl," + "application/vnd.openxmlformats-officedocument.wordprocessingml.document,docx," + "application/vnd.openxmlformats-officedocument.wordprocessingml.template,dotx," + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,xlsx," + "application/vnd.openxmlformats-officedocument.presentationml.presentation,pptx," + "application/vnd.openxmlformats-officedocument.presentationml.template,potx," + "application/vnd.openxmlformats-officedocument.presentationml.slideshow,ppsx," + "application/x-javascript,js," + "application/json,json," + "audio/mpeg,mpga mpega mp2 mp3," + "audio/x-wav,wav," + "audio/mp4,m4a," + "image/bmp,bmp," + "image/gif,gif," + "image/jpeg,jpeg jpg jpe," + "image/photoshop,psd," + "image/png,png," + "image/svg+xml,svg svgz," + "image/tiff,tiff tif," + "text/plain,asc txt text diff log," + "text/html,htm html xhtml," + "text/css,css," + "text/csv,csv," + "text/rtf,rtf," + "video/mpeg,mpeg mpg mpe," + "video/quicktime,qt mov," + "video/mp4,mp4," + "video/x-m4v,m4v," + "video/x-flv,flv," + "video/x-ms-wmv,wmv," + "video/avi,avi," + "video/webm,webm," + "video/vnd.rn-realvideo,rv," + "application/vnd.oasis.opendocument.formula-template,otf," + "application/octet-stream,exe"); var plupload = { VERSION: '@@version@@', STOPPED: 1, STARTED: 2, QUEUED: 1, UPLOADING: 2, FAILED: 4, DONE: 5, GENERIC_ERROR: -100, HTTP_ERROR: -200, IO_ERROR: -300, SECURITY_ERROR: -400, INIT_ERROR: -500, FILE_SIZE_ERROR: -600, FILE_EXTENSION_ERROR: -601, IMAGE_FORMAT_ERROR: -700, IMAGE_MEMORY_ERROR: -701, IMAGE_DIMENSIONS_ERROR: -702, mimeTypes: mimes, ua: (function (){ var nav = navigator, userAgent = nav.userAgent, vendor = nav.vendor, webkit, opera, safari; webkit = /WebKit/.test(userAgent); safari = webkit && vendor.indexOf('Apple') !== -1; opera = window.opera && window.opera.buildNumber; return { windows: navigator.platform.indexOf('Win') !== -1, ie: !webkit && !opera && (/MSIE/gi).test(userAgent) && (/Explorer/gi).test(nav.appName), webkit: webkit, gecko: !webkit && /Gecko/.test(userAgent), safari: safari, opera: !!opera} ; } ()), typeOf: function (o){ return ({ } ).toString.call(o).match(/\s([a-z|A-Z]+)/)[1].toLowerCase(); } , extend: function (target){ plupload.each(arguments, function (arg, i){ if (i > 0) { plupload.each(arg, function (value, key){ target[key] = value; } ); } } ); return target; } , cleanName: function (name){ var i, lookup; lookup = [/[\300-\306]/g, 'A', /[\340-\346]/g, 'a', /\307/g, 'C', /\347/g, 'c', /[\310-\313]/g, 'E', /[\350-\353]/g, 'e', /[\314-\317]/g, 'I', /[\354-\357]/g, 'i', /\321/g, 'N', /\361/g, 'n', /[\322-\330]/g, 'O', /[\362-\370]/g, 'o', /[\331-\334]/g, 'U', /[\371-\374]/g, 'u'] ; for (i = 0; i < _AN_Read_length('length', lookup); i += 2){ name = _AN_Call_replace('replace', name, lookup[i], lookup[i + 1]); } name = _AN_Call_replace('replace', name, /\s+/g, '_'); name = _AN_Call_replace('replace', name, /[^a-z0-9_\-\.]+/gi, ''); return name; } , addRuntime: function (name, runtime){ runtime.name = name; runtimes[name] = runtime; runtimes.push(runtime); return runtime; } , guid: function (){ var guid = new Date().getTime().toString(32), i; for (i = 0; i < 5; i++ ){ guid += Math.floor(Math.random() * 65535).toString(32); } return (plupload.guidPrefix || 'p') + guid + (count++ ).toString(32); } , buildUrl: function (url, items){ var query = ''; plupload.each(items, function (value, name){ query += (query? '&': '') + encodeURIComponent(name) + '=' + encodeURIComponent(value); } ); if (query) { url += (url.indexOf('?') > 0? '&': '?') + query; } return url; } , each: function (obj, callback){ var length, key, i; if (obj) { length = _AN_Read_length('length', obj); if (length === undef) { for (key in obj){ if (obj.hasOwnProperty(key)) { if (callback(obj[key], key) === false ) { return ; } } } } else { for (i = 0; i < length; i++ ){ if (callback(obj[i], i) === false ) { return ; } } } } } , formatSize: function (size){ if (size === undef || /\D/.test(size)) { return plupload.translate('N/A'); } if (size > 1073741824) { return Math.round(size / 1073741824, 1) + " GB"; } if (size > 1048576) { return Math.round(size / 1048576, 1) + " MB"; } if (size > 1024) { return Math.round(size / 1024, 1) + " KB"; } return size + " b"; } , getPos: function (node, root){ var x = 0, y = 0, parent, doc = document, nodeRect, rootRect; node = node; root = root || doc.body; function getIEPos(node){ var bodyElm, rect, x = 0, y = 0; if (node) { rect = node.getBoundingClientRect(); bodyElm = doc.compatMode === "CSS1Compat"? doc.documentElement: doc.body; x = rect.left + bodyElm.scrollLeft; y = rect.top + bodyElm.scrollTop; } return { x: x, y: y} ; } if (node && node.getBoundingClientRect && (navigator.userAgent.indexOf('MSIE') > 0 && doc.documentMode !== 8)) { nodeRect = getIEPos(node); rootRect = getIEPos(root); return { x: nodeRect.x - rootRect.x, y: nodeRect.y - rootRect.y} ; } parent = node; while (parent && parent != root && parent.nodeType){ x += parent.offsetLeft || 0; y += parent.offsetTop || 0; parent = parent.offsetParent; } parent = node.parentNode; while (parent && parent != root && parent.nodeType){ x -= parent.scrollLeft || 0; y -= parent.scrollTop || 0; parent = parent.parentNode; } return { x: x, y: y} ; } , getSize: function (node){ return { w: node.offsetWidth || node.clientWidth, h: node.offsetHeight || node.clientHeight} ; } , parseSize: function (size){ var mul; if (typeof (size) == 'string') { size = /^([0-9]+)([mgk]?)$/.exec(_AN_Call_replace('replace', size.toLowerCase(), /[^0-9mkg]/g, '')); mul = size[2]; size = + size[1]; if (mul == 'g') { size *= 1073741824; } if (mul == 'm') { size *= 1048576; } if (mul == 'k') { size *= 1024; } } return size; } , xmlEncode: function (str){ return str? _AN_Call_replace('replace', ('' + str), xmlEncodeRegExp, function (chr){ return xmlEncodeChars[chr]? '&' + xmlEncodeChars[chr] + ';': chr; } ): str; } , toArray: function (obj){ var i, arr = [] ; for (i = 0; i < _AN_Read_length('length', obj); i++ ){ arr[i] = obj[i]; } return arr; } , inArray: function (needle, array){ if (array) { if (Array.prototype.indexOf) { return Array.prototype.indexOf.call(array, needle); } for (var i = 0, length = _AN_Read_length('length', array); i < length; i++ ){ if (array[i] === needle) { return i; } } } return -1; } , addI18n: function (pack){ return plupload.extend(i18n, pack); } , translate: function (str){ return i18n[str] || str; } , isEmptyObj: function (obj){ if (obj === undef) return true ; for (var prop in obj){ return false ; } return true ; } , hasClass: function (obj, name){ var regExp; if (obj.className == '') { return false ; } regExp = new RegExp("(^|\\s+)" + name + "(\\s+|$)"); return regExp.test(obj.className); } , addClass: function (obj, name){ if (!plupload.hasClass(obj, name)) { obj.className = obj.className == ''? name: _AN_Call_replace('replace', obj.className, /\s+$/, '') + ' ' + name; } } , removeClass: function (obj, name){ var regExp = new RegExp("(^|\\s+)" + name + "(\\s+|$)"); obj.className = _AN_Call_replace("replace", obj.className, regExp, function ($0, $1, $2){ return $1 === ' ' && $2 === ' '? ' ': ''; } ); } , getStyle: function (obj, name){ if (obj.currentStyle) { return obj.currentStyle[name]; } else if (window.getComputedStyle) { return window.getComputedStyle(obj, null )[name]; } } , addEvent: function (obj, name, callback){ var func, events, types, key; key = arguments[3]; name = name.toLowerCase(); if (uid === undef) { uid = 'Plupload_' + plupload.guid(); } if (obj.addEventListener) { func = callback; obj.addEventListener(name, func, false ); } else if (obj.attachEvent) { func = function (){ var evt = window.event; if (!_AN_Read_target('target', evt)) { _AN_Write_target('target', evt, false , evt.srcElement); } evt.preventDefault = preventDefault; evt.stopPropagation = stopPropagation; callback(evt); } ; obj.attachEvent('on' + name, func); } if (obj[uid] === undef) { obj[uid] = plupload.guid(); } if (!eventhash.hasOwnProperty(obj[uid])) { eventhash[obj[uid]] = { } ; } events = eventhash[obj[uid]]; if (!events.hasOwnProperty(name)) { events[name] = [] ; } events[name].push({ func: func, orig: callback, key: key} ); } , removeEvent: function (obj, name){ var type, callback, key; if (typeof (arguments[2]) == "function") { callback = arguments[2]; } else { key = arguments[2]; } name = name.toLowerCase(); if (obj[uid] && eventhash[obj[uid]] && eventhash[obj[uid]][name]) { type = eventhash[obj[uid]][name]; } else { return ; } for (var i = _AN_Read_length("length", type) - 1; i >= 0; i-- ){ if (type[i].key === key || type[i].orig === callback) { if (obj.detachEvent) { obj.detachEvent('on' + name, type[i].func); } else if (obj.removeEventListener) { obj.removeEventListener(name, type[i].func, false ); } type[i].orig = null ; type[i].func = null ; type.splice(i, 1); if (callback !== undef) { break ; } } } if (!_AN_Read_length('length', type)) { delete eventhash[obj[uid]][name]; } if (plupload.isEmptyObj(eventhash[obj[uid]])) { delete eventhash[obj[uid]]; try { delete obj[uid]; } catch (e) { obj[uid] = undef; } } } , removeAllEvents: function (obj){ var key = arguments[1]; if (obj[uid] === undef || !obj[uid]) { return ; } plupload.each(eventhash[obj[uid]], function (events, name){ plupload.removeEvent(obj, name, key); } ); } } ; plupload.Uploader = function (settings){ var events = { } , total, files = [] , startTime, disabled = false ; total = new plupload.QueueProgress(); settings = plupload.extend({ chunk_size: 0, multipart: true , multi_selection: true , file_data_name: 'file', filters: [] } , settings); function uploadNext(){ var file, count = 0, i; if (this.state == plupload.STARTED) { for (i = 0; i < _AN_Read_length('length', files); i++ ){ if (!file && files[i].status == plupload.QUEUED) { file = files[i]; file.status = plupload.UPLOADING; if (this.trigger("BeforeUpload", file)) { this.trigger("UploadFile", file); } } else { count++ ; } } if (count == _AN_Read_length("length", files)) { this.stop(); this.trigger("UploadComplete", files); } } } function calc(){ var i, file; total.reset(); for (i = 0; i < _AN_Read_length("length", files); i++ ){ file = files[i]; if (file.size !== undef) { total.size += file.size; total.loaded += file.loaded; } else { total.size = undef; } if (file.status == plupload.DONE) { total.uploaded++ ; } else if (file.status == plupload.FAILED) { total.failed++ ; } else { total.queued++ ; } } if (total.size === undef) { total.percent = _AN_Read_length("length", files) > 0? Math.ceil(total.uploaded / _AN_Read_length("length", files) * 100): 0; } else { total.bytesPerSec = Math.ceil(total.loaded / ((+ new Date() - startTime || 1) / 1000)); total.percent = total.size > 0? Math.ceil(total.loaded / total.size * 100): 0; } } plupload.extend(this, { state: plupload.STOPPED, runtime: '', features: { } , files: files, settings: settings, total: total, id: plupload.guid(), init: function (){ var self = this, i, runtimeList, a, runTimeIndex = 0, items; if (typeof (settings.preinit) == "function") { settings.preinit(self); } else { plupload.each(settings.preinit, function (func, name){ self.bind(name, func); } ); } settings.page_url = settings.page_url || _AN_Call_replace("replace", _AN_Read_pathname("pathname", _AN_Read_location("location", document)), /\/[^\/]+$/g, '/'); if (!/^(\w+:\/\/|\/)/.test(_AN_Read_url('url', settings))) { _AN_Write_url('url', settings, false , settings.page_url + _AN_Read_url('url', settings)); } settings.chunk_size = plupload.parseSize(settings.chunk_size); settings.max_file_size = plupload.parseSize(settings.max_file_size); self.bind('FilesAdded', function (up, selected_files){ var i, file, count = 0, extensionsRegExp, filters = settings.filters; if (filters && _AN_Read_length('length', filters)) { extensionsRegExp = [] ; plupload.each(filters, function (filter){ plupload.each(filter.extensions.split(/,/), function (ext){ if (/^\s*\*\s*$/.test(ext)) { extensionsRegExp.push('\\.*'); } else { extensionsRegExp.push('\\.' + _AN_Call_replace('replace', ext, new RegExp('[' + ((_AN_Call_replace('replace', '/^$.*+?|()[]{}\\', /./g, '\\$&'))) + ']', 'g'), '\\$&')); } } ); } ); extensionsRegExp = new RegExp(extensionsRegExp.join('|') + '$', 'i'); } for (i = 0; i < _AN_Read_length('length', selected_files); i++ ){ file = selected_files[i]; file.loaded = 0; file.percent = 0; file.status = plupload.QUEUED; if (extensionsRegExp && !extensionsRegExp.test(file.name)) { up.trigger('Error', { code: plupload.FILE_EXTENSION_ERROR, message: plupload.translate('File extension error.'), file: file} ); continue ; } if (file.size !== undef && file.size > settings.max_file_size) { up.trigger('Error', { code: plupload.FILE_SIZE_ERROR, message: plupload.translate('File size error.'), file: file} ); continue ; } files.push(file); count++ ; } if (count) { delay(function (){ self.trigger("QueueChanged"); _AN_Call_refresh("refresh", self); } , 1); } else { return false ; } } ); if (settings.unique_names) { self.bind("UploadFile", function (up, file){ var matches = file.name.match(/\.([^.]+)$/), ext = "tmp"; if (matches) { ext = matches[1]; } file.target_name = file.id + '.' + ext; } ); } self.bind('UploadProgress', function (up, file){ file.percent = file.size > 0? Math.ceil(file.loaded / file.size * 100): 100; calc(); } ); self.bind('StateChanged', function (up){ if (up.state == plupload.STARTED) { startTime = (+ new Date()); } else if (up.state == plupload.STOPPED) { for (i = _AN_Read_length('length', up.files) - 1; i >= 0; i-- ){ if (up.files[i].status == plupload.UPLOADING) { up.files[i].status = plupload.QUEUED; calc(); } } } } ); self.bind('QueueChanged', calc); self.bind("Error", function (up, err){ if (err.file) { err.file.status = plupload.FAILED; calc(); if (up.state == plupload.STARTED) { delay(function (){ uploadNext.call(self); } , 1); } } } ); self.bind("FileUploaded", function (up, file){ file.status = plupload.DONE; file.loaded = file.size; up.trigger('UploadProgress', file); delay(function (){ uploadNext.call(self); } , 1); } ); if (settings.runtimes) { runtimeList = [] ; items = settings.runtimes.split(/\s?,\s?/); for (i = 0; i < _AN_Read_length('length', items); i++ ){ if (runtimes[items[i]]) { runtimeList.push(runtimes[items[i]]); } } } else { runtimeList = runtimes; } function callNextInit(){ var runtime = runtimeList[runTimeIndex++ ], features, requiredFeatures, i; if (runtime) { features = runtime.getFeatures(); requiredFeatures = self.settings.required_features; if (requiredFeatures) { requiredFeatures = requiredFeatures.split(','); for (i = 0; i < _AN_Read_length('length', requiredFeatures); i++ ){ if (!features[requiredFeatures[i]]) { callNextInit(); return ; } } } _AN_Call_init('init', runtime, self, function (res){ if (res && res.success) { self.features = features; self.runtime = runtime.name; self.trigger('Init', { runtime: runtime.name} ); self.trigger('PostInit'); _AN_Call_refresh('refresh', self); } else { callNextInit(); } } ); } else { self.trigger('Error', { code: plupload.INIT_ERROR, message: plupload.translate('Init error.')} ); } } callNextInit(); if (typeof (settings.init) == "function") { _AN_Call_init("init", settings, self); } else { plupload.each(settings.init, function (func, name){ self.bind(name, func); } ); } } , refresh: function (){ this.trigger("Refresh"); } , start: function (){ if (this.state != plupload.STARTED) { this.state = plupload.STARTED; this.trigger("StateChanged"); uploadNext.call(this); } } , stop: function (){ if (this.state != plupload.STOPPED) { this.state = plupload.STOPPED; this.trigger("CancelUpload"); this.trigger("StateChanged"); } } , disableBrowse: function (){ disabled = arguments[0] !== undef? arguments[0]: true ; this.trigger("DisableBrowse", disabled); } , getFile: function (id){ var i; for (i = _AN_Read_length("length", files) - 1; i >= 0; i-- ){ if (files[i].id === id) { return files[i]; } } } , removeFile: function (file){ var i; for (i = _AN_Read_length("length", files) - 1; i >= 0; i-- ){ if (files[i].id === file.id) { return this.splice(i, 1)[0]; } } } , splice: function (start, length){ var removed; removed = files.splice(start === undef? 0: start, length === undef? _AN_Read_length("length", files): length); this.trigger("FilesRemoved", removed); this.trigger("QueueChanged"); return removed; } , trigger: function (name){ var list = events[name.toLowerCase()], i, args; if (list) { args = Array.prototype.slice.call(arguments); args[0] = this; for (i = 0; i < _AN_Read_length("length", list); i++ ){ if (list[i].func.apply(list[i].scope, args) === false ) { return false ; } } } return true ; } , hasEventListener: function (name){ return !!events[name.toLowerCase()]; } , bind: function (name, func, scope){ var list; name = name.toLowerCase(); list = events[name] || [] ; list.push({ func: func, scope: scope || this} ); events[name] = list; } , unbind: function (name){ name = name.toLowerCase(); var list = events[name], i, func = arguments[1]; if (list) { if (func !== undef) { for (i = _AN_Read_length("length", list) - 1; i >= 0; i-- ){ if (list[i].func === func) { list.splice(i, 1); break ; } } } else { list = [] ; } if (!_AN_Read_length("length", list)) { delete events[name]; } } } , unbindAll: function (){ var self = this; plupload.each(events, function (list, name){ self.unbind(name); } ); } , destroy: function (){ this.stop(); this.trigger('Destroy'); this.unbindAll(); } } ); } ; plupload.File = function (id, name, size){ var self = this; self.id = id; self.name = name; self.size = size; self.loaded = 0; self.percent = 0; self.status = 0; } ; plupload.Runtime = function (){ this.getFeatures = function (){ } ; this.init = function (uploader, callback){ } ; } ; plupload.QueueProgress = function (){ var self = this; self.size = 0; self.loaded = 0; self.uploaded = 0; self.failed = 0; self.queued = 0; self.percent = 0; self.bytesPerSec = 0; self.reset = function (){ self.size = self.loaded = self.uploaded = self.failed = self.queued = self.percent = self.bytesPerSec = 0; } ; } ; plupload.runtimes = { } ; window.plupload = plupload; } )();