﻿// Post script for RE1001
re1001.Attachment=function(a,b,c,d,e){this.target=$(a);this.field=(!!b)?$(b):null;this.filename=$.trim($('span',a).text());this.fullname=d;this.used=c;this.toggling=false;this.summary=e;this.toggleText();$('a',this.target).unbind();this.bind('a.delete','click',this.del_click);this.bind('a.insert','click',this.toggle_click);if($.browser.msie&&re1001.post.isPicture(d)){this.bind('span','mouseover',this.over);this.bind('span','mouseout',this.out)}};$.extend(re1001.Attachment.prototype,{bind:function(a,b,c){$(a,this.target).bind(b,{attachment:this},c)},over:function(e){try{var a=$('#img_hidden').get(0);a.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod='image';a.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src=e.data.attachment.fullname;var b=resize(a.offsetWidth,a.offsetHeight,re1001.post.options.maxWidth,re1001.post.options.maxHeight);$(this).prepend('<div style="position:absolute; margin-top:-'+(parseInt(b[1])+8)+'px; margin-left:-21px;"><img width="'+b[0]+'px" height="'+b[1]+'px" style="width:'+b[0]+'px; height:'+b[1]+'px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\'scale\', src=\''+e.data.attachment.fullname+'\');" src="http://res.re1001.com/image/spacer.gif" /></div>')}catch(e){}},out:function(e){$('div',this).remove()},del_click:function(e){e.preventDefault();if(!confirm('是否要删除此文件？'))return;var a=$(this).parent().find('a.insert')[0].rel;e.data.attachment.del(a);if(re1001.post.files.length-1<re1001.post.options.maxFiles){var b=$(':file:last',re1001.post.options.inputContainer);b.show()}a--;re1001.post.files[a]=null;re1001.post.options.filesId[a]=''},del:function(a){this.remove(a);if(!!this.field)this.field.remove();this.target.remove()},toggle_click:function(e){e.preventDefault();var a=e.data.attachment;var b=this.rel;if(a.toggling)return;if(re1001.post.options.editor.EditingArea.Mode==1){alert('请在可视编辑状态插入文件！');return}a.toggling=true;if(a.used)a.remove(b);else a.insert(b);a.toggleText();a.toggling=false},remove:function(a){try{var b=$('body',re1001.post.options.editor.EditorDocument.documentElement);var c='[file]'+a+'_'+this.filename+'[/file]';var d=b.html();while(d.indexOf(c)!=-1){d=d.replace(c,'')}d=d.replace(/<([p|P])[^>]*?>[\s]*?<\/([p|P])>/ig,'');d=d.replace(/<([p|P])[^>]*?>(&nbsp\;)*?<\/([p|P])>/ig,'');d=d.replace(/<([p|P])[^>]*?>[\s]*?(<br[\/]*?>)*?[\s]*?<\/([p|P])>/ig,'');b.html(d)}catch(e){}this.used=false},insert:function(a){try{re1001.post.options.editor.InsertHtml('[file]'+a+'_'+this.filename+'[/file]')}catch(e){}this.used=true},toggleText:function(){if(this.used){this.target.addClass('select');$('a.insert',this.target).text('[移除]')}else{this.target.removeClass('select');$('a.insert',this.target).text('[插入]')}}});(function(g){g=g.post={init:function(){if(!!g.options.filesId.length){$('li',g.options.listContainer).each(function(){var a=$('li',g.options.listContainer).index(this);if(a==0)return true;$(this).children('a.insert').attr('rel',g.options.filesId[a-1])})}g.files=$.map($('li:gt(0)',g.options.listContainer),function(a){return new re1001.Attachment(a,null,true,g.options.urlPrefix+$('span',a).text(),$('input',a).val())});if($("li[class='select']",g.options.listContainer).length==g.options.maxFiles)$(':file:last',g.options.inputContainer).hide();var f=$(':file:last',g.options.inputContainer);if(f.val())f.remove();$(':file',g.options.inputContainer).change(g.append);g.options.form.submit(function(){var c=false;var d=[];var e=$.map(g.files,function(a,b){if(a==null)return null;if(b>=g.options.maxFiles||!a.used){c=true;d.push(a.filename)}else return a.filename});g.options.hiddenValues.val(e.join(','));g.fillSerial();if(!c)return true;if(!confirm('下列文件没有插入到编辑器，放弃保存这些文件吗？\n\n* '+d.join('\n* ')))return false;for(var i=0;i<g.files.length;i++)if(!g.files[i].used){g.files[i].del();re1001.post.options.filesId[i]=''}g.fillSerial()});$(':text',g.options.form).keypress(function(e){if(e.which==13)e.preventDefault()})},updateLoginInfo:function(){top.re1001.user=re1001.user;if($.isFunction(re1001.nav.init))re1001.nav.init()},append:function(e){var a=$.trim(this.value);if(!a.length)return false;a=a.replace('/','\\').substr(a.lastIndexOf('\\')+1);if($.inArray(g.getExtension(a),g.options.blackList)!=-1){$(this).clone(true).show().val('').appendTo(g.options.inputContainer);$(this).remove();window.alert('您所选择附件 '+a+' 的文件类型被阻止，请选择其他文件');return false}$(':file:last',g.options.form).hide().clone(true).show().val('').appendTo(g.options.inputContainer);var b=g.options.template.clone(true).show();b.appendTo(g.options.listContainer);var c=g.renameFile();$('a.insert',b).attr('rel',c);re1001.post.options.filesId.push(c);if((g.files.length+1)>=g.options.maxFiles)$(':file:last',g.options.inputContainer).hide();$('span',b).text(a);g.files.push(new re1001.Attachment(b,this,false,this.value,$('input',b).val()));return true},getExtension:function(a){var b=null;var c=a.lastIndexOf('.');if(c>=0&&c<a.length-1)b=a.substr(c+1).toLowerCase();return b},isPicture:function(a){var b=['jpg','gif','png','jpeg'];var c=g.getExtension(a);return $.inArray(c,b)!=-1},renameFile:function(){var a=0;if(!!g.options.filesId.length)a=g.options.filesId.sort()[g.options.filesId.length-1];return++a},fillSerial:function(){g.options.fileSerial.val($.map(g.options.filesId,function(v,i){if(!!v)return v}).join(','))}};window.re1001.post.merge={init:function(){var b=re1001.post.merge.options.subjecContainer;var c=re1001.post.merge.options.target;var d=re1001.post.merge.options.hiddenContainer;var e=b.val().split('#')[0].split('/').pop().split('-')[0];c.html('正在查找目标主题信息……').css({color:'red'});if(/\d+/.test(e)){d.val(e);$.get('/service/GetTopicSubject.ashx',{id:e},function(a){c.html("目标贴标题为: "+a).css({color:'#666'})})}else{c.html("url错误, 请重新输入URL").css({color:'#666'});d.val('')}}}})(window.re1001);window.re1001.post.initPoll=function(d){var e=$('#poll_period :radio');var f=$('#poll_period :text');e.click(function(){var c=e.index(this)==e.length-1;f[0].disabled=!c;$.each(d.periodValidators,function(a,b){window.ValidatorEnable($('#'+b)[0],c)});if(c)f.focus()});$(function(){$('#poll_period :radio:checked').click()})};window.re1001.post.showPoll=function(h){var i=document.getElementById(h.container);if(!h.id){$(i).remove();return}$('.polltitle .desc',i).append(', 有效期: '+new Date(h.start).toLocaleString()+' - '+new Date(h.end).toLocaleString());var j=new Date();var k='';if(!re1001.user)k='您没有登录，不能参加投票';else if(new Date(h.start)>j)k='投票尚未开始';else if(new Date(h.end)<j)k='投票已经过期';var l=$('.cmd :button',i);if(!!k){l.replaceWith('<span class="desc">'+k+'</span>');return}else{var m=h.multiple?'checkbox':'radio';$('.label label',i).each(function(a){$(this).attr('for','option'+a).before($('<input name="poll" type="'+m+'"/>').attr({value:a,id:'option'+a}))});$('.cmd span.desc',i).remove();if(!l[0]){$('.cmd').append('<input type="button" value="投票" />');l=$('.cmd :button',i)}}l.click(function(e){e.preventDefault();this.value='投票中';this.disabled=true;var g=[];$('.label input',i).each(function(a){if(this.checked)g.push(a)});$.getJSON('/service/VoteService',{id:h.id,value:g.join(','),r:Math.random()},function(d){var e;if(d.status.code!=200){window.alert(d.status.message);e=d.status.code==403?d.status.message:'您已经投过票'}else{var f=d.data.total;$('.totalvotes',i).text(f);$.each(d.data.votes,function(a,b){var c=$('table',i).find('tr').eq(a);if(b>0){$('.poll_line > div',c).show();c.find('td:last span:last').attr('class','percent');$('.percent',c).text(''+b+' ('+Math.round(b/f*10000)/100+'%)');$('.chart_body',c).animate({width:b/f*460},1000)}});e='您刚刚投票'}if(d.status.code==200||d.status.code==403){$('.label input',i).remove();l.unbind().replaceWith('<span class="desc">'+e+'</span>')}else l.val('投票').removeAttr('disabled')})})};function FCKeditor_OnComplete(b){if(!re1001.editors)re1001.editors=[];re1001.editors.push(b);$('#editor').next().hide().end().slideDown('fast');$('#editor_command, #attachment_row').show('fast');var c=$('#editor iframe');$('#editor_command area:first').click(function(e){e.preventDefault();var a=c.height()+100;c.height(a);this.disabled=a>600;$(this).next().removeAttr('disabled')});$('#editor_command area:last').click(function(e){e.preventDefault();var a=c.height()-100;c.height(a);this.disabled=a<=100;$(this).prev().removeAttr('disabled')});editor_loaded();if($('#textLength').length>0)b.Events.AttachEvent('OnSelectionChange',FCKeditor_OnSelectionChange)};function FCKeditor_OnSelectionChange(a){var b=$('#textLength');var c=a.GetHTML().length;if(a.Config.MaxLength)b.html(c+"/"+a.Config.MaxLength+"字符");else b.html(c+"字符")};function resize(w,h,a,c){if(w<a&&h<c)return[w,h];var b=1;if(w>a&&w>h)b=w/a;if(h>c&&h>w)b=h/c;return[Math.ceil(w/b),Math.ceil(h/b)]};