/* content-type: multipart/related; boundary="_cloudgamer" --_cloudgamer content-location:blankimage content-transfer-encoding:base64 r0lgodlhaqabajeaaaaaap///////waaach5baeaaaialaaaaaabaaeaaaicvaeaow== */ var imagepreview = function(file, img, options) { this.file = $$(file);//�ļ����� this.img = $$(img);//Ԥ��ͼƭ���� this._preload = null;//Ԥ��ͼƭ���� this._data = "";//ͼ������ this._upload = null;//remoteģʽʹ�õ��θ��ļ����� var opt = this._setoptions(options); this.action = opt.action; this.timeout = opt.timeout; this.ratio = opt.ratio; this.maxwidth = opt.maxwidth; this.maxheight = opt.maxheight; this.oncheck = opt.oncheck; this.onshow = opt.onshow; this.onerr = opt.onerr; //�������ݻ�ȡ���� this._getdata = this._getdatafun(opt.mode); //����Ԥ����ʾ���� this._show = opt.mode !== "filter" ? this._simpleshow : this._filtershow; }; //�����������ȡģʽ imagepreview.mode = $$b.ie7 || $$b.ie8 ? "filter" : $$b.firefox ? "domfile" : $$b.opera || $$b.chrome || $$b.safari ? "remote" : "simple"; //͸��ͼƭ imagepreview.transparent = "images/2-2.png"; imagepreview.prototype = { //����ĭ������ _setoptions: function(options) { this.options = {//ĭ��ֵ mode: imagepreview.mode,//Ԥ��ģʽ ratio: 0,//�զ������ maxwidth: 0,//����ͼ��� maxheight: 0,//����ͼ�߶� oncheck: function(){},//Ԥ�����ʱִ�� onshow: function(){},//Ԥ��ͼƭʱִ�� onerr: function(){},//Ԥ������ʱִ�� //������remoteģʽʱ��ч action: undefined,//����action timeout: 0//���ó�ʱ(0ϊ������) }; return $$.extend(this.options, options || {}); }, //��ʼԤ�� preview: function() { if ( this.file && false !== this.oncheck() ) { this._preview( this._getdata() ); } }, //����mode�������ݻ�ȡ���� _getdatafun: function(mode) { switch (mode) { case "filter" : return this._filterdata; case "domfile" : return this._domfiledata; case "remote" : return this._remotedata; case "simple" : default : return this._simpledata; } }, //�˾����ݻ�ȡ���� _filterdata: function() { this.file.select(); try{ return document.selection.createrange().text; } finally { document.selection.empty(); } }, //domfile���ݻ�ȡ���� _domfiledata: function() { //return this.file.files[0].getasdataurl(); return window.url.createobjecturl(this.file.files[0]); }, //զ�����ݻ�ȡ���� _remotedata: function() { this._setupload(); this._upload && this._upload.upload(); }, //һ�����ݻ�ȡ���� _simpledata: function() { return this.file.value; }, //����remoteģʽ���θ��ļ����� _setupload: function() { if ( !this._upload && this.action !== undefined && typeof quickupload === "function" ) { var othis = this; this._upload = new quickupload(this.file, { onready: function(){ this.action = othis.action; this.timeout = othis.timeout; var parameter = this.parameter; parameter.ratio = othis.ratio; parameter.width = othis.maxwidth; parameter.height = othis.maxheight; }, onfinish: function(iframe){ try{ othis._preview( iframe.contentwindow.document.body.innerhtml ); }catch(e){ othis._error("remote error"); } }, ontimeout: function(){ othis._error("timeout error"); } }); } }, //Ԥ������ _preview: function(data) { //��ֵ����ͬ��ֵ��ִ����ʾ if ( !!data && data !== this._data ) { this._data = data; this._show(); } }, //����һ��Ԥ��ͼƭ���� _simplepreload: function() { if ( !this._preload ) { var preload = this._preload = new image(), othis = this, onload = function(){ othis._imgshow( othis._data, this.width, this.height ); }; this._onload = function(){ this.onload = null; onload.call(this); } preload.onload = $$b.ie ? this._onload : onload; preload.onerror = function(){ othis._error(); }; } else if ( $$b.ie ) { this._preload.onload = this._onload; } }, //һ����ʾ _simpleshow: function() { this._simplepreload(); this._preload.src = this._data; }, //�����˾�Ԥ��ͼƭ���� _filterpreload: function() { if ( !this._preload ) { var preload = this._preload = document.createelement("div"); //���ز������˾� $$d.setstyle( preload, { width: "1px", height: "1px", visibility: "hidden", position: "absolute", left: "-9999px", top: "-9999px", filter: "progid:dximagetransform.microsoft.alphaimageloader(sizingmethod='image')" }); //����body var body = document.body; body.insertbefore( preload, body.childnodes[0] ); } }, //�˾���ʾ _filtershow: function() { this._filterpreload(); var preload = this._preload, data = this._data.replace(/[)'"%]/g, function(s){ return escape(escape(s)); }); try{ preload.filters.item("dximagetransform.microsoft.alphaimageloader").src = data; }catch(e){ this._error("filter error"); return; } //�����˾�����ʾ this.img.style.filter = "progid:dximagetransform.microsoft.alphaimageloader(sizingmethod='scale',src=\"" + data + "\")"; //this._imgshow( imagepreview.transparent, preload.offsetwidth, preload.offsetheight ); if ($$b.ie) { if ($$b.ie8) { this._imgshow(imagepreview.transparent, preload.offsetwidth, preload.offsetheight); } else { this._imgshow(data, preload.offsetwidth, preload.offsetheight); } } else { this._imgshow(imagepreview.transparent, preload.offsetwidth, preload.offsetheight); } }, //��ʾԤ�� _imgshow: function(src, width, height) { var img = this.img, style = img.style, ratio = math.max( 0, this.ratio ) || math.min( 1, math.max( 0, this.maxwidth ) / width || 1, math.max( 0, this.maxheight ) / height || 1 ); //����Ԥ���ߴ� style.width = math.round( width * ratio ) + "px"; style.height = math.round( height * ratio ) + "px"; //����src img.src = src; this.onshow(); }, //���ٳ��� dispose: function() { //�����θ��ļ����� if ( this._upload ) { this._upload.dispose(); this._upload = null; } //����Ԥ��ͼƭ���� if ( this._preload ) { var preload = this._preload, parent = preload.parentnode; this._preload = preload.onload = preload.onerror = null; parent && parent.removechild(preload); } //������ض��� this.file = this.img = null; }, //���� _error: function(err) { this.onerr(err); } }