百度贴吧上传文件代码

  • 2012-12-15
  • 0
  • 7

今天看了下贴吧的JS  试了下它的文件上传功能,居然又可以了

只不过现在是上传到自己的网盘而不是原来的公共网盘了

JS原地址 http://tb1.bdstatic.com/tb/js/postor_v2_45d99b7a.js

编辑框工具栏初始化代码在5536行

提取代码

if (this._option.open_idisk) {
    this._editor.addPlugin("idisk", new TED.EditorPlugins.IdiskPlugin(this._option.power_idisk, this._data_postor.fid, this._option.upload_max_length, this._option.upload_max_size));
    this._editor.on("idisk_upload_complete", function(e) {
        var k = this.getPostorDataObj("files");
        k = k || [];
        k.push(e);
        this.setPostorDataObj("files", k)
    }, this);
    this._editor.on("idisk_remove_file", function(l) {
        var m = this.getPostorDataObj("files");
        if (!m) {
            return
        }
        if (l.md5) {
            for (var k = 0, e = m.length; k < e; k++) {
                if (m[k].path === l.path) {
                    m.splice(k, 1);
                    if (m.length === 0) {
                        this.setPostorData("files", undefined)
                    } else {
                        this.setPostorDataObj("files", m)
                    }
                    return
                }
            }
        }
    }, this);
    this._editor.on("idisk_uploading_start", function() {
        j._isPosting = true;
        c.attr("disabled", true);
        c.removeClass("subbtn_bg").addClass("subbtn_bg_banned");
        c.next().html("正在上传文件,请稍候...")
    }, this);
    this._editor.on("idisk_uploading_stop", function() {
        j._isPosting = false;
        c.attr("disabled", false);
        c.removeClass("subbtn_bg_banned").addClass("subbtn_bg");
        c.next().html("Ctrl+Enter快捷发表")
    }, this)
}

首先判断是否开启了文件上传,~~~然后初始化工具栏

this是指对象 RichPostor

贴吧加载时初始化了实例 rich_postor

定义一个变量等于rich_postor

然后替换所有的this

得到如下代码

var a=rich_postor;
rich_postor._editor.addPlugin("idisk", new TED.EditorPlugins.IdiskPlugin(a._option.power_idisk, a._data_postor.fid, a._option.upload_max_length, a._option.upload_max_size));
a._editor.on("idisk_upload_complete", function(e) {
        var k = a.getPostorDataObj("files");
        k = k || [];
        k.push(e);
        a.setPostorDataObj("files", k)
    }, a);
a._editor.on("idisk_remove_file", function(l) {
    var m = a.getPostorDataObj("files");
    if (!m) {
        return
    }
    if (l.md5) {
        for (var k = 0, e = m.length; k < e; k++) {
            if (m[k].path === l.path) {
                m.splice(k, 1);
                if (m.length === 0) {
                    a.setPostorData("files", undefined)
                } else {
                    a.setPostorDataObj("files", m)
                }
                return
            }
        }
    }
}, a);
a._editor.on("idisk_uploading_start", function() {
    j._isPosting = true;
    c.attr("disabled", true);
    c.removeClass("subbtn_bg").addClass("subbtn_bg_banned");
    c.next().html("正在上传文件,请稍候...")
}, a);
a._editor.on("idisk_uploading_stop", function() {
    j._isPosting = false;
    c.attr("disabled", false);
    c.removeClass("subbtn_bg_banned").addClass("subbtn_bg");
    c.next().html("Ctrl+Enter快捷发表")
}, a)

贴吧加载完毕后执行下上面的代码就好了

说明:只能发帖的时候使用……
上一篇:    下一篇:

me@ccc5.cc - 衫小寨