📄 post.js
字号:
var CODE_INDEX = 0;
function render_code(){
var elements = document.getElementsByName("ubb_code");
if (elements && elements[CODE_INDEX]){
dp.SyntaxHighlighter.HighlightAll("ubb_code",true,false,false,true,false,CODE_INDEX);
CODE_INDEX = CODE_INDEX+1;
}
}
function imgzoom(o) {
if(event.ctrlKey) {
var zoom = parseInt(o.style.zoom, 10) || 100;
zoom -= event.wheelDelta / 12;
if(zoom > 0) {
o.style.zoom = zoom + '%';
}
return false;
} else {
return true;
}
}
function imgresize(obj){
if (obj){
if(obj.width > 300){
obj.width = 300;
}
}
}
function imgappresize (obj){
if (obj){
if(obj.width > 200){
obj.width = 200;
}
if(obj.height > 50){
obj.height = 50;
}
}
}
//发帖时,选择主题操作
function addTopicType(topicType) {
var title;
var curTitle = $("ef_form").post_title.value;
var topic_type = $("ef_form").topic_type;
for (var i =0; i < topic_type.length; i++ ){
var index = curTitle.indexOf(topic_type[i].value);
if (index == 0){
curTitle = curTitle.substr(topic_type[i].value.length);
}
}
title = topicType+curTitle;
$("ef_form").post_title.value=title;
$("ef_form").post_title.focus();
return;
}
//清空帖子内容
function resetPostContent(){
var content = $("ef_form").post_content;
if (content) {
content.value = "";
content.focus();
}
}
function checkContentLength(){
var titleLength = $("ef_form").post_title.value.length;
var contentLength = wysiwyg ? html2bbcode(getEditorContents()).length:$("ef_form").post_content.value.length;
alert("标题长度:"+titleLength+"个字符(系统限制 0 到 100 个字符,汉字占两位)\n内容长度:"+contentLength+"个字符(系统限制 "+postminchars+" 到 "+postmaxchars+" 个字符,汉字占两位)");
}
var sEdit = "post_content";
var originImage=new Image();
//获得原图的象素宽度
function getImageWidth(oImage){
if(originImage.src!=oImage.src)originImage.src=oImage.src;
return originImage.width;
}
//获得原图的象素高度
function getImageHeight(oImage){
if(originImage.src!=oImage.src)originImage.src=oImage.src;
return originImage.height;
}
//帆布宽度和高度
var canvas_width = 140;
var canvas_height = 110;
//不失帧加载图片
function imgOnload(obj){
var wh = getImageWh(obj.src,canvas_width,canvas_height);
if(wh){
obj.width=wh['w'];
obj.height=wh['h'];
}
}
function getImageWh(src,width,height){
if($('img_hidden') && $('img_hidden').filters){
$('img_hidden').filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = 'image';
try {
$('img_hidden').filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = src;
} catch (e) {
return null;
}
var wh = {'w' : $('img_hidden').offsetWidth, 'h' : $('img_hidden').offsetHeight};
$('img_hidden').style.width = '10px';
$('img_hidden').style.height = '10px';
$('img_hidden').filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = 'scale';
if(wh['w'] <= 1 || wh['h'] <= 1){
return {'w' : width, 'h' : height};
}
if(wh['w'] >= width || wh['h'] >= height) {
wh = getAttachImageWh(wh['w'], wh['h'],width,height);
}
return wh;
}
return null;
}
function getAttachImageWh(w, h, twidth, theight){
twidth = !twidth ? thumbwidth : twidth;
theight = !theight ? thumbheight : theight;
var x_ratio = twidth / w;
var y_ratio = theight / h;
var wh = new Array();
if((x_ratio * h) < theight) {
wh['h'] = Math.ceil(x_ratio * h);
wh['w'] = twidth;
} else {
wh['w'] = Math.ceil(y_ratio * w);
wh['h'] = theight;
}
return wh;
}
//获得新的附件序号
function getAttachNo(){
return attachStart ++;
}
//新增一个附件
function newUpload(checkNum){
//检查上传组件的数量。
if(checkNum && maxUpload){
var obj = document.getElementsByName("attachId");
//去除掉隐藏的对象
var count = -1;
for(var i = 0 ; i < obj.length; i ++){
if(obj[i].value == "#id#"){
count++;
}
}
if( maxUpload <= count){
alert("暂时不允许上传更多的附件!");
return;
}
}
//TODO 如果第一个用户还没有选择,则不增加
insertUpload(getAttachNo());
}
function insertUpload(no,id){
if($('attach').hasChildNodes()){
$('attach').insertBefore(getUploadElement(no,id),$('attach').childNodes.item(0));
} else {
$('attach').appendChild(getUploadElement(no,id));
}
}
/**
* 获得上传组件
*/
function getUploadElement(no,id){
var div = document.createElement("div");
div.id="upload" + no;
div.className="upload";
var copyDiv = $('tplupload').innerHTML;
var Reg = /#no#/g;
var html = copyDiv.replace(Reg,no);
if(id){
div.id="upload" + id;
Reg = /#id#/g;
html = html.replace(Reg,id);
}
div.innerHTML = html;
//alert(html);
return div;
}
//新增附件
var attachNew = new Array();
//删除附件
var attachDelete = new Array();
//浏览一个文件
function initUpload(obj,attachNo){
if ( allAttachType && allAttachType.length >0){
var fileType = getFileType(obj);
var index = -1;
for(i=0; i<allAttachType.length ; i++){
//alert(allAttachType[i][0]+"-----"+fileType);
if (allAttachType[i][0] == fileType){
//alert(i);
index = i;
break;
}
}
if (index == -1){
alert("不允许上传此种类型的附件!");
try{
var copy = obj.cloneNode(false);
obj.replaceNode(copy);
} catch(e){
}
return;
}
//如果是图片
if (allAttachType[index][1] == "1"){
if(browser.isIE){
var wh = getImageWh($("attach"+attachNo).value,canvas_width,canvas_height);
$("demopic"+attachNo).src = "ef/images/ubb/clear.gif";
$("demopic"+attachNo).style.filter ='progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale",src="file:///' + obj.value +'"';
$("demopic"+attachNo).style.width=wh['w']+"px"
$("demopic"+attachNo).style.height=wh['h']+"px";
}else{
$("demopic"+attachNo).src = allAttachType[index][2];
}
}else {
$("demopic"+attachNo).style.filter="";
$("demopic"+attachNo).style.width="";
$("demopic"+attachNo).style.height="";
$("demopic"+attachNo).src = allAttachType[index][2];
}
var fileTitle = obj.value.substr(obj.value.lastIndexOf('\\')+1);
$("demopic"+attachNo).title = fileTitle;
$("filePath" + attachNo).value = "###资源" + attachNo + "###";
$("fileFullPath"+attachNo).value=obj.value;
$("fileTitle"+attachNo).value=fileTitle;
if (attachNew.indexOf(attachNo) < 0){
attachNew.push(attachNo);
}
$('attach_new').value = attachNew;
} else {
alert("不允许上传此种类型的附件!");
try{
var copy = obj.cloneNode(false);
obj.replaceNode(copy);
} catch(e){
}
}
}
//获得文件类型
function getFileType(obj){
return obj.value.substr(obj.value.lastIndexOf('.')+1).toLowerCase();
}
//增加到文章中
function addArticle(attachNo){
insertAttach(attachNo);
}
//判断是否插入
function checkInsertID(val,no){
var value = val;
var txt = getEditorContents();
var r =new RegExp("\\[upload\\]"+value+"\\[/upload\\]","ig");
if(r.test(txt)){
return false;
}
r = new RegExp("aid=([\"\']?)attach_"+no,"ig");
if(r.test(txt)){
return false;
}
return true;
}
function insertHTML(_sStr) {
var oRng;
var oEdit;
oEdit = $(sEdit);
oEdit.focus();
if (browser.isIE) {
oRng = oEdit.document.selection.createRange();
oRng.text += _sStr;
} else {
oEdit.value = oEdit.value.substring(0, oEdit.selectionStart) + _sStr + oEdit.value.substring(oEdit.selectionEnd, oEdit.value.length);
}
}
//删除
function clearSelect(no,id){
//如果还没有添加返回
if (!$('filePath'+no).value){
alert("尚未添加附件");
return;
}
//TODO 如果是新增则回复为默认属性
if (confirm("确认删除附件?")){
deleteUpload(no,id);
}
}
function deleteUpload(attachNo,id){
var uploadid = attachNo;
//已上传资源
if ("#id#" != id){
attachDelete.push(id);
$('attach_delete').value = attachDelete;
//删除ID组件
uploadid = id;
//初始化数组数据
if(!isUndefined(attachArray)){
for(var i = 0; i < attachArray.length; i++) {
if(attachArray[i]['no'] == attachNo ){
attachArray[i]['ext'] = "no";
break;
}
}
}
} else {
//如果已经加入到新增数组中,则删除。
setAttachNew(attachNo);
}
$('attach').removeChild($("upload"+uploadid));
}
function setAttachNew(attachNo){
//如果已经选择了文件,则
if (attachNew.indexOf(attachNo) >= 0){
var copy = new Array();
for(var i = 0; i < attachNew.length ; i++){
if (attachNo != attachNew[i]){
copy.push(attachNew[i]);
}
}
attachNew = copy;
$('attach_new').value = attachNew;
}
}
function in_array(needle, haystack) {
if(typeof needle == 'string' || typeof needle == 'number') {
for(var i in haystack) {
if(haystack[i] == needle) {
return true;
}
}
}
return false;
}
var efallowpic =new Array('gif', 'jpg','jpeg', 'png', 'bmp');
//已有附件
function hadUpload(attachNo,attachId, title, filePath,fileTitle){
insertUpload(attachNo,attachId);
$("attach"+attachNo+"_title").value=title;
$("demopic"+attachNo).src=filePath;
$("demopic"+attachNo).title=fileTitle;
var ext = fileTitle.substr(fileTitle.lastIndexOf('.')+1).toLowerCase();
if(in_array(ext, efallowpic)){
$("fileFullPath"+attachNo).value=filePath;
} else {
$("fileFullPath"+attachNo).value=fileTitle;
}
$("fileTitle"+attachNo).value=fileTitle;
// alert(("fileFullPath"+attachNo).value);
$("file"+attachNo).disabled="true";
$("filePath" + attachNo).value = "###资源" + attachNo + "###";
$("demopic"+attachNo).onload=function (e){var wh = getImageWh(this.src,canvas_width,canvas_height);if(wh){this.width=wh['w'];this.height=wh['h'];}};
}
//submit topic
function submitTopicCheck(vLevel){
if (!checkTitleInfo()){
return false;
}
if (!checkPostConent()){
return false;
}
if(vLevel){
if(!checkVisitLevel(vLevel)){
return false;
}
}
return true;
}
//submit topic
function submitPostCheck(){
if (!checkTitleMax()){
return false;
}
if (!checkPostConent()){
return false;
}
return true;
}
//post submit;
function postSubmit(button){
if (button){
button.disabled="true";
}
$("ef_form").target ="";
$("ef_form").enctype="multipart/form-data";
$("ef_form")._fn.value=$("ef_form")._fn_old.value;
$("ef_form").submit();
}
function forumPreview(){
$("ef_form").target ="_postpreview";
$("ef_form").enctype="";
$("ef_form")._fn.value="Preview";
$("ef_form").submit();
}
//check post title
function checkTitleInfo(){
if ($('post_title') ){
//trim title
$('post_title').value = Trim($('post_title').value);
if ($('post_title').value == "" ){
alert("标题必须填写!");
return false;
}
if(!checkTitleMax()){
return false;
}
}
return true;
}
//check titleMax
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -