⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 post.js

📁 asp的bbs程序
💻 JS
📖 第 1 页 / 共 2 页
字号:
            if (!_attachment[files[i].value]) 
                InsertOne(p, files[i].value, filename, filesize, path, icon);
        }
    }

    EditorEnabled ? window.CustomClose() : Widget.Close();
}
// 添加一个附件
// {p : HTMLElement, fileid : Guid|Number, filename : Array, path : String, icon : String, price : String, attachmentID}
function InsertOne (p, fileid, filename, filesize, path, icon, price, attachid) {
    if (price == null)
        price = 0;
    if (attachid == null)
        attachid = 0;
	var item = fileid + '_' + attachid;
    if (_attachment[item]) return;
    _attachment[item] = {fileid:fileid,filename:filename,filesize:filesize,attachid:attachid};
    p = p || $('attachment');

    // cookie
    AttachmentSetCookie();

    var li = oNode.CreateNode('li');
    oNode.AddNode(li, p);

    var prefix = Global.Random();
    li.id = 'attach_' + prefix;
    li.innerHTML = [
        '<p class="attach-mimeicon">',
        '   <img src="', icon, '" alt="" />',
        '</p>',
        '<p><input type="hidden" name="attachmentID_', fileid, '" value="', attachid, '" />',
        '    文件名:<input type="text" class="text file-name" name="filename_', fileid, '" value="', filename[0], '" />',
        '    <input type="text" class="value" readonly="readonly" size="2" value=".', filename[1], '">',
        '    售价:<input type="text" class="text file-price"  name="price_', fileid, '"  onkeyup="value=value.replace(/[^\\d]/g,\'\');" value="', price, '" />', PointName,
        '    <span class="blue">[', (EditorEnabled ? ' <a href="javascript:void(0);" id="insert_' + prefix + '">插入</a>' : ''), ' <a href="javascript:void(0);" id="del_', prefix, '">删除</a> ]</span>',
        '</p>',
        '<p>',
        (DiskSettingOpenDisk ? '    网络硬盘路径: <span class="gray2">' + path + '</span>' : ''),
        '    文件体积: <span class="gray2">', filesize, '</span>',
        '</p>'].join('');

    // 删除
    Events.AttachEvent($('del_' + prefix), 'click', function (e) {
        Events.CancelAll(e);
		
		// 调用提示服务器删除
		var deleteAttachmentRequest = function () {
			if (!/^[0-9a-z]{8}[0-9a-z]{4}[0-9a-z]{4}[0-9a-z]{4}[0-9a-z]{12}$/.test(attachid || fileid)) {
				return;
			}
			var ajax = new oAjax();
			ajax.url = DeleteAttachmentUrl + (attachid || fileid) + '&rnd=' + Math.random();
			ajax.callback = function (content) {};
			ajax.send();
		};

        var has = IncludeAttachment(fileid, attachid);
        if (has)
            Widget.Confirm('提示', '编辑器包含当前文件,是否真的删除?', function () {
                DeleteAttachment(fileid, attachid);
                DeleteOne(li, fileid, attachid);
				deleteAttachmentRequest();
            });
        else {
            DeleteOne(li, fileid, attachid);
			deleteAttachmentRequest();
		}
    });
	
	if (EditorEnabled)
    Events.AttachEvent($('insert_' + prefix), 'click', function (e) {
        var ext = filename[1].toLowerCase();
        var type = 'html';
        var str;
        switch (ext) {
            case 'jpg':
            case 'gif':
            case 'jpeg':
            case 'png':
            case 'bmp':
                if(attachid > 0 && CurrentPostUserID != UserProfileUserID )//管理员编辑他人帖子时插入发帖者的附件
                    str = '<img src="' + ApplicationUrl + '/Attachment.aspx?ID=' + attachid + '&mode=image" />';
                else
                    str = '<img src="Outputfile.aspx?fileid=' + fileid + '" />';
                break;
            case 'swf':
                type = 'ubb';
                if(attachid > 0 && CurrentPostUserID != UserProfileUserID)
                    str = '[flash]' + ApplicationUrl + '/Attachment.aspx?ID=' + attachid + '[/flash]';
                else
                    str = '[flash]Outputfile.aspx?fileid=' + fileid + '[/flash]';
                break;
            case 'ra':
            case 'wma':
            case 'mp3':
            case 'rm':
            case 'rmvb':
            case 'wmv':
            case 'mov':
                type = 'ubb'
                if (ext == 'rmvb') ext = 'rm';
                if(attachid > 0 && CurrentPostUserID != UserProfileUserID)
                    str = '[' + ext + ']' + ApplicationUrl + '/Attachment.aspx?ID=' + attachid + '[/' + ext + ']';
                else
                    str = '[' + ext + ']Outputfile.aspx?fileid=' + fileid + '[/' + ext + ']';
                break;
            default:
                if(attachid > 0 && CurrentPostUserID != UserProfileUserID)
                    str = '<br /><a class="downloadfiles" href="' + ApplicationUrl + '/Attachment.aspx?ID=' + attachid + '" target="_blank">' + filename.join('.') + '</a>';
                else
                    str = '<br /><a class="downloadfiles" href="Outputfile.aspx?fileid=' + fileid + '" target="_blank">' + filename.join('.') + '</a>';
                break;
        }
        CustomInsert(str, type);
 
        Events.CancelAll(e);
    });
    DisplayAttachment();
}
function DeleteOne (li, fileid, attachid) {
    var p = $('attachment');
    delete _attachment[fileid + '_' + attachid];
    GetFileCountAndSize();
    p.removeChild(li);
    DisplayAttachment();

    AttachmentSetCookie();
}
// 显示附件信息 
function DisplayAttachment () {
    var attachment = $('attachment');
    var lis = attachment.getElementsByTagName('li');
    attachment.parentNode.style.display =  lis.length > 0 ? '' : 'none';
}

/// 编辑器相关,记录与清除Cookie
// 清除
function ClearCookie () {
    if (editorContent) return;
    Cookie.Del(CookieKeyAttachmentIDs);
    Cookie.Del(prefix + 'DMode');
    Cookie.Del(prefix + 'AllowHTML');
    Cookie.Del(prefix + 'AllowUBB');
    Cookie.Del(prefix + 'Text');
}

/// 附件列表关联cookie
function AttachmentSetCookie () {
    if (editorContent) return;
    var ids = '';
    for (var item in _attachment) {
        if (/[0-9a-z]{8}[0-9a-z]{4}[0-9a-z]{4}[0-9a-z]{4}[0-9a-z]{12}|\d+/i.test(item)) {
            if (ids != '') ids += ',';
            ids += _attachment[item].fileid;
        }
    }
    Cookie.Set(CookieKeyAttachmentIDs, ids);
}

/// 附件与编辑器的关联
// included
function IncludeAttachment (fileid, attachid) {
	if (!EditorEnabled) return;
    var text = editor.GetText();

    var test = function (re) {
        return new RegExp(re, 'i').test(text);
    };

    // media
    var has = test('\\[(img|flash|wmv|wav|wma|rm|ra|mp3|mov)[^\\]]*?\\]#file:' + fileid + '#\\[/\\1\\]');
    var has = test('\\[(img|flash|wmv|wav|wma|rm|ra|mp3|mov)[^\\]]*?\\]#attach:' + attachid + '#\\[/\\1\\]');

    // <a>, [url]
    has = has || test('\\[url=#file:' + fileid + '#\\].*?\\[/url\\]');
    has = has || test('\\[url=#attach:' + attachid + '#\\].*?\\[/url\\]');
    has = has || test('<a[^>]+?href="#file:' + fileid + '#"[^>]*?>');
    has = has || test('<a[^>]+?href="#attach:' + attachid + '#"[^>]*?>');
    has = has || test('<a[^>]+?href="(http://' + location.host + '/.*?)?/?Outputfile.aspx\\?fileid=' + fileid + '"[^>]*?>');
    has = has || test('<a[^>]+?href="(http://' + location.host + '/.*?)?/?Attachment.aspx\\?ID=' + attachid + '"[^>]*?>');

    // <img>, [img]
    has = has || test('\\[img[^\\]]*?\\]#file:' + fileid + '#\\[/img\\]');
    has = has || test('\\[img[^\\]]*?\\]#attach:' + attachid + '#\\[/img\\]');
    has = has || test('<img[^>]+?_?src="#file:' + fileid + '#"[^>]*?>');
    has = has || test('<img[^>]+?_?src="#attach:' + attachid + '#"[^>]*?>');
    has = has || test('<img[^>]+?_?src="(http://' + location.host + '/.*?)?/?Outputfile\\.aspx\\?fileid=' + fileid + '"[^>]*?>');
    has = has || test('<img[^>]+?_?src="(http://' + location.host + '/.*?)?/?Attachment\\.aspx\\?ID=' + attachid + '"[^>]*?>');

    return has;
}
// delete
function DeleteAttachment (fileid, attachid) {
	if (!EditorEnabled) return;
    switch (editor.FrameEditor.EditType) {
        case 'wysiwyg':
            var a = editor.FrameEditor.Document.getElementsByTagName('a');
            for (var i = a.length - 1; i > -1; i--) {
                var url = a[i].getAttribute('href', 2);
                removeElement(url, a[i]);
            }
            var img = editor.FrameEditor.Document.getElementsByTagName('img');
            for (var i = img.length - 1; i > -1; i--) {
                var url = img[i].getAttribute('src', 2);
				if (!removeElement(url, img[i])) {
					url = img[i].getAttribute('_src', 2);
					removeElement(url, img[i]);
				}
            }
            break;
        case 'xhtml':
        case 'ubb':
            var v = editor.FrameEditor.TextField.value
                  . replace(new RegExp('\\[(flash|img|wmv|wav|wma|rm|ra|mp3|mov)[^\\]]*?\\]#file:' + fileid + '#\\[/\\1\\]', 'gi'), '')
                  . replace(new RegExp('\\[(flash|img|wmv|wav|wma|rm|ra|mp3|mov)[^\\]]*?\\]#attach:' + attachid + '#\\[/\\1\\]', 'gi'), '')
                  . replace(new RegExp('\\[url=#file:' + fileid + '#\\].*?\\[/url\\]', 'gi'), '')
                  . replace(new RegExp('\\[url=#attach:' + attachid + '#\\].*?\\[/url\\]', 'gi'), '')
                  . replace(new RegExp('<a[^>]+href="#file:' + fileid + '#"[^>]*>.*?</a>', 'gi'), '')
                  . replace(new RegExp('<a[^>]+href="#attach:' + attachid + '#"[^>]*>.*?</a>', 'gi'), '')
                  . replace(new RegExp('<img[^>]+_?src="#file:' + fileid + '#"[^>]*>', 'gi'), '')
                  . replace(new RegExp('<img[^>]+_?src="#attach:' + attachid + '#"[^>]*>', 'gi'), '');
            editor.FrameEditor.TextArea.value = v;
            break;
    }
    function removeElement (url, el) {
        if (new RegExp('^#file:' + fileid + '#$', 'i').test(url)
			|| new RegExp('^#attach:' + attachid + '#$', 'i').test(url)
            || new RegExp('(http://' + location.host + '/.*?)?/?Outputfile\\.aspx\\?fileid=' + fileid, 'i').test(url)
            || new RegExp('(http://' + location.host + '/.*?)?/?Attachment\\.aspx\\?ID=' + attachid, 'i').test(url)) {
            ///
            el.parentNode.removeChild(el);
			return true;
        }
		return false;
    }
}

/// 定时刷新附件列表
function RefreshAttachmentList () {
    var ids = '';
    for (var item in _attachment) {
        if (/[0-9a-z]{8}[0-9a-z]{4}[0-9a-z]{4}[0-9a-z]{4}[0-9a-z]{12}/i.test(item)) {
            if (ids != '') ids += ',';
            ids += item;
        }
    }
    if (ids == '') return;
    var ajax = new oAjax();
    ajax.action = 'post';
    ajax.content = 'GuidString=' + ids;
    ajax.callback = function () {};
    ajax.send('TempFile.aspx?action=updatelastwritetime');
}
//setInterval(RefreshAttachmentList, 10 * 60 * 1000);
//<!-- #/if -->
function setRealReward(rewardTax) {
    var reward=document.getElementsByName("reward")[0];
    if (reward.value=="") {
        $("realReward").innerHTML="0";
        return ;
    }
    if(reward.value.indexOf("0")==0)
        reward.value=reward.value.substring(1,reward.value.length-1);
    var realReward=parseInt(reward.value)+reward.value*rewardTax;
    var dotIndex=realReward.toString().indexOf(".");
    if(dotIndex>-1) {
        realReward=parseInt(realReward.toString().substring(0,dotIndex));
        realReward=realReward+1;
    }
    $("realReward").innerHTML=realReward;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -