js类 from qq

2016-02-19 11:41 5 1 收藏

今天天气好晴朗处处好风光,好天气好开始,图老师又来和大家分享啦。下面给大家推荐js类 from qq,希望大家看完后也有个好心情,快快行动吧!

【 tulaoshi.com - Web开发 】

代码如下:

var Comment = new Object();

var $C = function(tagName)
{
    return document.createElement(tagName);
};
String.prototype.trim = function()
{
    return this.replace(/^s*|s*$/g,"");
};
String.prototype.realLength = function()
{
    return this.replace(/[^x00-xff]/g,"**").length;
};
String.prototype.left = function(n)
{
    if (this.length  n)
    {
        return this.substr(0, n) + '...';
    }
    else
    {
        return this;
    }
};
Array.prototype.remove = function(n)
{
    if (n  0)
    {
        return this;
    }
    else
    {
        return this.slice(0, n).concat(this.slice(n + 1, this.length));
    }
};
function findPosX(obj) 
{
    var curleft = 0;
    if (obj && obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    }
    else if (obj && obj.x) curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if (obj && obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    } 
    else if (obj && obj.y) curtop += obj.y;
    return curtop;
}
var input_domain = 'http://input.comment.qq.com';
var index_domain = 'http://comment1.qq.com';
var pinglun_domain = 'http://pinglun.qq.com';
var js_domain = 'http://pinglun.qq.com';
var img_domain = 'http://mat1.qq.com/pinglun';
Comment.Configure = {
    version:                '1.0',
    newline:                'n',
    site_length:            20,
    key_length:                20,
    id_length:                10,
    index_line_sum:            10000,
    index_width:            5,
    default_mode:            'origin_count',
    default_order:            1,
    default_reply_per_page:    10,
    quote_str_len:            60,
    intro_len:                150,
    debate_intro_len:        200,
    content_len:            200,
    reply_default_title:    '请填写标题',
    intro_min_length:        20,
    request_delay:            100,
    login_frame_delay:        2000,
    reply_type_def:            {
        '1':    'span class="reply_top"[精]/span ',
        '2':    'span class="reply_commend"[荐]/span ',
        '3':    'span class="reply_expert"[专]/span '
    },
    postUrl:                input_domain + '/post.cmt',
    logoutUrl:                input_domain + '/cgi-bin/qqlogout',
    commentIndex:            'http://pinglun.qq.com/',
    loginIframeUrl:            index_domain + '/i_login.htm',
    defaultLogoUrl:            img_domain + '/images/defpic.jpg'
}

Comment.Define = {
    getReplyType: function(type)
    {
        if (Comment.Configure.reply_type_def[type])
        {
            return Comment.Configure.reply_type_def[type];
        }
        else
        {
            return '';
        }
    }
}

Comment.PGV_Count = function(option)
{
    if (typeof(pgvMain) == 'function')
    {
        pvRepeatCount = 1;
        pvCurDomain = sDomain;
        if (option)
        {
            if (option.domain)
            {
                pvCurDomain = option.domain;
            }
            if (option.path)
            {
                pvCurUrl = option.path;
            }
        }
        pgvMain();
        //Debug.log('call pgv function');
    }
}

Comment.UrlFactory = {
    get3LevelDir: function(id)
    {
        var path = parseInt(id / 1000000) + '/';
        path += parseInt(id / 1000) + '/';
        path += id / 1;
        return path;
    },
    getCommentUrl: function(id)
    {
        return (this.get3LevelDir(id) + '/');
    },
    getDebateUrl: function(id)
    {
        return this.get3LevelDir(id);
    },
    getUserUrl: function(id)
    {
        return this.get3LevelDir(id);
    },
    getReplyUrl: function(key)
    {
        var path = key.substr(0, 8);
        path += '/' + (key.substr(8, 4));
        path += '/' + (key.substr(12, 2));
        path += '/' + key;
        return path;
    },
    getIndexUrl: function(id)
    {
        var length = id.toString().length;
        if (length  Comment.Configure.index_width)
        {
            for (var i = 0; i  Comment.Configure.index_width - length; ++i)
            {
                id = '0' + id;
            }
        }
        return id;
    },
    getIndexDir: function(mode)
    {
        var modes = {
            'origin_count':    'originindex',
            'total_count':    'allindex',
            'top_count':    'topindex'
        };
        return modes[mode];
    },
    getRangeHeader: function(start, length, line_len)
    {
        var range_start = start * line_len;
        var range_length = length * line_len;
        return ['Range','bytes=' + range_start + '-' + (parseInt(range_start) + parseInt(range_length) - 1 - Comment.Configure.newline.length)];
    },
    getCommentNormalUrl: function(site, id)
    {
        return 'comment.htm?site=' + site + '&id=' + id;
    },
    getCommentGroupUrl: function(site, id)
    {
        return 'comment_group.htm?site=' + site + '&id=' + id;
    },
    getCommentDebateUrl: function(site, id)
    {
        return 'comment_debate.htm?site=' + site + '&id=' + id;
    },
    getCommentUserUrl: function(uin)
    {
        return 'comment_user.htm?uin=' + uin;
    },
    getCommentUserLink: function(uin, nick)
    {
        return 'a href="' + this.getCommentUserUrl(uin) + '" target="_blank"' + (nick ? nick : uin) + '/a';
    },
    getCommentListLink: function(site_en, site_cn, sort_en, sort_cn, className)
    {
        if (className)
        {
            className = 'class="' + className + '"';
        }
        else
        {
            className = '';
        }
        return 'a href="' + Comment.Configure.commentIndex + '" ' + className + ' target="_blank"评论首页/a  '
            + 'a href="list.htm?' + site_en + '." ' + className + ' target="_blank"' + site_cn + '/a  '
            + 'a href="list.htm?' + site_en + '.' + sort_en + '" ' + className + ' target="_blank"' + sort_cn + '/a';
    }
}

Comment.ContentFormat = {
    decode: function(content)
    {
        return content.split(Comment.Configure.newline);
    }
}

Comment.DataObjectFactory = function(content, model)
{
    content = Comment.ContentFormat.decode(content);
    var dataModel = Comment.DataObject[model];
    if (content.length - 1 != dataModel.length)
    {
        if (model != 'commentinfo' && model != 'listsum')
        {
            //alert('[DEBUG 信息] O/R 映射失败,远程数据和本地模型数量不匹配!请检查!');
        }
    }
    var dataObject = new Object();
    for (var i = 0; i  dataModel.length; ++i)
    {
        dataObject[dataModel[i]] = content[i];
    }
    return dataObject;
}

Comment.DataObject = {
    'commentinfo':
    [
        'site_cn',
        'sort_en',
        'sort_cn',
        'source',
        'source_url',
        'title',
        'url',
        'intro',
        'intro_img',
        'group_id',
        'intro_show',
        'create_time',
        'debate_id'
    ],
    'groupinfo':
    [
         'site_cn',
        'title',
        'url',
        'intro',
        'intro_img',
        'comment_id',
        'intro_show',
        'create_time'
    ],
    'debateinfo':
    [
         'site_cn',
        'title',
        'url',
        'intro',
        'intro_img',
        'agree_id',
        'disagree_id',
        'middle_id',
        'intro_show',
        'create_time'
    ],
    'sum':
    [
         'origin_count',
        'total_count',
        'top_count'
    ],
    'reply':
    [
        'comment_id',
        'uin',
        'nickname',
        'pub_time',
        'pass_time',
        'ip',
        'title',
        'content',
        'reply_key',
        'is_del',
        'reply_type',
        'reply_kind',
        'tips'
    ],
    'pksum':
    [
         'agree',
        'disagree',
        'middle'
    ],
    'listsum':
    [
        'all'
    ],
    'usersum':
    [
         'total_count',
        'top_count',
        'is_expert'

    ],
    'userinfo':
    [
         'user_img',
        'user_intro'
    ]
}

/* 控制器类 */
Comment.Control = new Object();

/* 分页控制器 */
Comment.Control.Pagination = Class.create();
Comment.Control.Pagination.prototype = {
    initialize: function(option)
    {
        this.totalPage = option.totalPage;
        this.currPage = 1;
        this.zoom_start = 3;
        this.zoom_end = 613;
        this.bindControl();
    },
    reset: function(option)
    {
        this.totalPage = option.totalPage;
        this.currPage = 1;
        this.movePageControl(this.currPage);
    },
    updateOrder: function()
    {

    },
    countCurrPage: function(offset)
    {
        var page = parseInt(offset * this.totalPage / this.zoom_end) + 1;
        if (page  this.totalPage)
        {
            page = this.totalPage;
        }
        return page;
    },
    movePageControl: function(toPage)
    {
        if (toPage  1 || toPage  this.totalPage)
        {
            return;
        }
        var offset = 0;
        if (toPage == 1)
        {
            offset = this.zoom_start;
        }
        else if (toPage == this.totalPage)
        {
            offset = this.zoom_end;
        }
        else
        {
            offset = this.zoom_start + (toPage - 1) * (this.zoom_end / (this.totalPage - 1));
        }
        $('scrfloat').style.left = offset + 'px';
        //$('scrfloat_2').style.left = offset + 'px';
    },
    bindControl: function()
    {
        var self = this;
        var tooltip = $('Page_tip');
        var offsetX = 10;
        var offsetY = -10;
        function getSite(o)
        {
            var obj = o;
            var objS = obj.offsetLeft;
            while (obj != obj.offsetParent && obj.offsetParent)
            {
                obj = obj.offsetParent;
                if (obj.tagName == 'span')
                {
                    objS += obj.offsetLeft;
                }
            }
            return objS;
        }
        Event.observe($('scr'), 'mousedown', mDown, false);
        //Event.observe($('scr_2'), 'mousedown', mDown, false);
        var flag = false;
        function mDown()
        {
            flag = true;
            if(window.event.srcElement.id != 'scr'
               && window.event.srcElement.id != 'scr_2')
            {
                $('scrfloat').style.left = $('scrfloat').offsetLeft;
                //$('scrfloat_2').style.left = $('scrfloat').style.left;
            }
            else
            {
                $('scrfloat').style.left = (window.event.x - 5);
                //$('scrfloat_2').style.left = $('scrfloat').style.left;
            }
            tooltip.style.display = 'block';
            t = $('scrfloat').offsetLeft;
            tooltip.innerHTML = self.countCurrPage(t);
            tooltip.style.left = window.event.clientX + offsetX + 'px';
            tooltip.style.top = window.event.clientY + offsetY + document.documentElement.scrollTop + 'px';
        }
        function mMove()
        {
            if(flag)
            {
                $('scrfloat').style.left = window.event.clientX - getSite($('scr')) - 5 + 'px';
                //$('scrfloat_2').style.left = window.event.clientX - getSite($('scr')) - 5 + 'px';
            }
            if (parseInt($('scrfloat').style.left.replace('px', ''))  self.zoom_end)
            {
                $('scrfloat').style.left = self.zoom_end + 'px';
                //$('scrfloat_2').style.left = $('scrfloat').style.left;
            }
            if (parseInt($("scrfloat").style.left.replace('px', ''))  self.zoom_start)
            {
                $('scrfloat').style.left = self.zoom_start + 'px';
                //$('scrfloat_2').style.left = $('scrfloat').style.left;
            }
            if (flag)
            {
                t = $('scrfloat').offsetLeft;
                tooltip.innerHTML = self.countCurrPage(t);
                tooltip.style.left = window.event.clientX + offsetX + 'px';
                tooltip.style.top = window.event.clientY + offsetY + document.documentElement.scrollTop + 'px';
            }
        }  
        function mUp()
        {
            if (flag)
            {
                t = $('scrfloat').offsetLeft;
                self.setCurrPage(self.countCurrPage(t));
            }
            flag = false;
            tooltip.style.display = 'none';
        }

        function mEnd()
        {
            window.event.returnValue = false;
        }

        window.document.onmousemove = mMove;
        window.document.ondragstart = mEnd;
        window.document.onmouseup = mUp;

        Event.observe($('up'), 'click', mUpBtn, false);
        Event.observe($('down'), 'click', mDownBtn, false);
        function mUpBtn()
        {
            self.setCurrPage(self.currPage - 1, 1);
        }
        function mDownBtn()
        {
            self.setCurrPage(self.currPage + 1, 1);
        }
    },
    nextPage: function()
    {
        if (this.currPage  this.totalPage)
        {
            ++this.currPage;
            this.onPageChange();
        }
    },
    previousPage: function()
    {
        if (this.currPage  0)
        {
            --this.currPage;
            this.onPageChange();
        }
    },
    setCurrPage: function(page, move)
    {
        if (page  0 && page = this.totalPage && page != this.currPage)
        {
            this.currPage = page;
            this.onPageChange();
            if (move != null)
            {
                this.movePageControl(page);
            }
        }
    },
    onPageChange: function()
    {
    },
    getCurrPage: function()
    {
        return this.currPage;
    }
}

Comment.Iterator = {
    getIndex: function(objComment)
    {
        var rangeList = new Array();
        function getIndexId(reply_id)
        {
            return parseInt(reply_id / Comment.Configure.index_line_sum);
        }
        function getReplyPos(reply_id)
        {
            return (reply_id % Comment.Configure.index_line_sum);
        }

        if (objComment.order == 0)
        {
            var reply_start = (objComment.currPage - 1) * objComment.replyPerPage;
            var start_index_id = getIndexId(reply_start);
            var start_reply_id = getReplyPos(reply_start);
            var currReply = 1;
            var replySum = 0;
            while (currReply++)
            {
                if (reply_start + currReply  objComment.totalReply)
                {
                    rangeList.push({
                        url:    Comment.UrlFactory.getIndexUrl(start_index_id),
                        range:    Comment.UrlFactory.getRangeHeader(start_reply_id, currReply - replySum - 1, objComment.index_line_len)
                    });
                    break;
                }
                if (currReply == objComment.replyPerPage)
                {
                    rangeList.push({
                        url:    Comment.UrlFactory.getIndexUrl(start_index_id),
                        range:    Comment.UrlFactory.getRangeHeader(start_reply_id, currReply - replySum, objComment.index_line_len)
                    });
                    break;
                }
                if (start_reply_id + currReply  Comment.Configure.index_line_sum)
                {
                    rangeList.push({
                        url:    Comment.UrlFactory.getIndexUrl(start_index_id),
                        range:    Comment.UrlFactory.getRangeHeader(start_reply_id, currReply, objComment.index_line_len)
                    });
                    start_index_id++;
                    start_reply_id = 0;
                    replySum = currReply - 1;
                }
            }
        }
        else
        {
            var reply_start = objComment.totalReply - 1 - (objComment.currPage - 1) * objComment.replyPerPage;
            var start_index_id = getIndexId(reply_start);
            var start_reply_id = getReplyPos(reply_start);
            var currReply = 1;
            var replySum = 0;
            while (currReply++)
            {
                if (reply_start - currReply  0)
                {
                    rangeList.push({
                        url:    Comment.UrlFactory.getIndexUrl(start_index_id),
                        range:    Comment.UrlFactory.getRangeHeader(0, start_reply_id + 1, objComment.index_line_len)
                    });
                    break;
                }
                if (currReply == objComment.replyPerPage)
                {
                    rangeList.push({
                        url:    Comment.UrlFactory.getIndexUrl(start_index_id),
                        range:    Comment.UrlFactory.getRangeHeader(start_reply_id - currReply + replySum + 1, currReply - replySum, objComment.index_line_len)
                    });
                    break;
                }
                if (start_reply_id - currReply  0)
                {
                    rangeList.push({
                        url:    Comment.UrlFactory.getIndexUrl(start_index_id),
                        range:    Comment.UrlFactory.getRangeHeader(0, start_reply_id + 1, objComment.index_line_len)
                    });
                    start_index_id--;
                    start_reply_id = Comment.Configure.index_line_sum - 1;
                    replySum = currReply;
                }
            }
        }
        return rangeList;
    }
}

/* 显示样式控制器 */
Comment.Control.Display = Class.create();
Comment.Control.Display.prototype = {
    initialize: function()
    {
    }
}

/* 页面显示类 */
Comment.Page = new Object();
/* 评论页控制接口 */
Comment.Page.Base = {
    changeMode: function(mode)
    {
        this.mode = mode;
        this.totalReply = this.data_sum[mode];
        this.totalPage = parseInt(this.totalReply / this.replyPerPage)
            + (this.totalReply % this.replyPerPage != 0 ? 1 : 0);
    },
    changeOrder: function(order)
    {
        if (this.order == order)
            return;
        this.order = order;
        this.currPage = 1;
        this.resetPageControl();
        this.bindPageNav();
        this.bindReplyList();
        this.bindOrderControl();
    },
    bindOrderControl: function()
    {
        var self = this;
        if (self.order == 0)
        {
            $('order_front').style.cursor = 'none';
            $('order_front').style.color = '#000';
            $('order_front').onclick = function(e)
            {
                return false;
            }
            $('order_desc').style.cursor = 'pointer';
            $('order_desc').style.color = '#3B78AF';
            $('order_desc').onclick = function()
            {
                self.changeOrder(1);
                return false;
            }
        }
        else if (self.order == 1)
        {
            $('order_front').style.cursor = 'pointer';
            $('order_front').style.color = '#3B78AF';
            $('order_front').onclick = function(e)
            {
                self.changeOrder(0);
                return false;
            }
            $('order_desc').style.cursor = 'none';
            $('order_desc').style.color = '#000';
            $('order_desc').onclick = function()
            {
                return false;
            }
        }
    },
    bindRowsPerPage: function()
    {
        var self = this;
        $A($('rows_page').getElementsByTagName('a')).each(function(button)
        {
            button.onclick = function()
            {
                self.replyPerPage = button.value;
                self.currPage = 1;
                self.resetPageControl();
                self.bindPageNav();
                self.bindReplyList();
                return false;
            }
        });
    },
    selectTab: function(mode)
    {
        var self = this;
        $A($('mode_tab').getElementsByTagName('p')).each(function(tab)
        {
            if (tab.value == mode)
            {
                $A($('mode_tab').getElementsByTagName('p')).each(function(t)
                {
                    if (t.value != '')
                    {
                        t.className = 'none';
                    }
                });
                tab.className = 'c';
            }
        });
    },
    appendTab: function(option)
    {
        var pTab = $C('p');
        pTab.innerHTML = option.title;
        pTab.value = '';
        $('mode_tab').appendChild(pTab);
        pTab.onclick = function()
        {
            window.open(option.url);
        }
        return false;
    },
    bindTabControl: function()
    {
        var self = this;
        $A($('mode_tab').getElementsByTagName('p')).each(function(tab)
        {
            var mode = tab.value;
            if (mode != '')
            {
                tab.onclick = function()
                {
                    $A($('mode_tab').getElementsByTagName('p')).each(function(t)
                    {
                        t.className = 'none';
                    });
                    this.className = 'c';
                    self.currPage = 1;
                    self.changeMode(mode)
                    self.resetPageControl();
                    self.bindPageNav();
                    self.bindReplyList();
                    return false;
                }
            }
        });
    },
    bindPageRandom: function()
    {
        var self = this;
        $A($('page_random', 'page_random_2')).each(function(button)
        {
            button.onclick = function()
            {
                if (self.totalPage == 1)
                {
                    self.currPage = 1;
                }
                else
                {
                    self.currPage = Math.floor(Math.random() * (self.totalPage&

来源:https://www.tulaoshi.com/n/20160219/1598247.html

延伸阅读
标签: Web开发
titleJS复制本页地址/title input type="button"   name="Submit" onClick='copyToClipBoard()' value="点击复制本页地址,分享给QQ/MSN上的好友" width="100" height="16" script language="javascript" function copyToClipBoard(){ var clipBoardContent=&quo...
标签: ASP
  <% Conn_String = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("link.mdb") Set Conn=Server.CreateObject("ADODB.Connection") Conn.Open Conn_String sql = "select * from cat order by ID" set rs = Conn.Execute (sql) 'Connect to databa...
integer to String : int i = 42;String str = Integer.toString(i); or String str = "" + i double to String : String str = Double.toString(i); long to String : String str = Long.toString(l); float to String : String str = Float.toString(f); String to integ...
标签: Web开发
比如我们要在一个类中设定一个方法可以根据调入一个方法保存在类变量中,等需要的时候可以通过访问类变量来得到。 通常如果我们生成一个实例 如:var temp=new TopnetTree(); 如果我们通过设定属性的方式来传入一个方法,会发现传入的是一个函数的内容,而非函数名。 如temp.fileAction=fnTest; //fnTest是一个函数 于是偶...
标签: Web开发
不知大家有没有玩过QQ秀?玩过的话一定会想自己也做一个类似的功能。不过没有玩过也没关系,你可以看看下面的演示。用户可以在列出的图片中自由定制自己的形象,用在论坛社区、留言本等地方的形象显示可是个不错的主意哦!怎么样?心动了吧?那让我们看看这东西到底是怎么回事吧! 查看演示效果 实际上,左边形象预览的形象是由...

经验教程

15

收藏

11
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部