cell merge plugin

using jQuery v.1.4.2

by Seungrae Lee

HTML

<table id="dataList" border="1" cellspacing="0" cellpadding="5">
    <tr>
        <td>row</td>
        <td>col</td>
        <td>cell</td>
    </tr>
    <tr>
        <td>1</td>
        <td>1</td>
        <td>cell11</td>
    </tr>
    <tr>
        <td>1</td>
        <td>2</td>
        <td>cell12</td>
    </tr>
    <tr>
        <td>1</td>
        <td>3</td>
        <td>cell13</td>
    </tr>
    <tr>
        <td>1</td>
        <td>3</td>
        <td>cell14</td>
    </tr>
    <tr>
        <td>2</td>
        <td>1</td>
        <td>cell21</td>
    </tr>
    <tr>
        <td>2</td>
        <td>2</td>
        <td>cell22</td>
    </tr>
    <tr>
        <td>2</td>
        <td>3</td>
        <td>cell23</td>
    </tr>
    <tr>
        <td>3</td>
        <td>1</td>
        <td>cell31</td>
    </tr>
    <tr>
        <td>3</td>
        <td>2</td>
        <td>cell32</td>
    </tr>
    <tr>
        <td>3</td>
        <td>3</td>
        <td>cell33</td>
    </tr>
    <tr>
        <td>4</td>
        <td>1</td>
        <td>cell41</td>
    </tr>
</table>

JavaScript

/*
 * usage:
 *         $(selector).rowMerge({
 *            rowIndex: 2,
 *            cellIndex: [1, 2]
 *         });
 * options:
 *        @rowIndex: start row index(1-index)
 *        @cellIndex: td indexes to be merged(1-index)
 */ (function ($) {
    $.extend($.fn, {
        version: '0.9.0',
        rowMerge: function (options) {
            return new $.impl(options, this);
        }
    });

    // constructor
    $.impl = function (options, target) {
        // merge options
        this.o = $.extend(true, {}, $.impl.defaults, options);
        this.target = target;
        this.init();
    };

    // implementation
    $.extend($.impl, {
        defaults: {
            rowIndex: 1,
            cellIndex: [1]
        },
        prototype: {
            init: function () {
                this.tdLen = this.target.find('tr:nth-child(' + this.o.rowIndex + ') td').length;
                this.delArrays = [];
                this._scan();
            },
            _scan: function () {
                var self = this,
                    indexArray = self.o.cellIndex;
                $.each(indexArray, function (i, o) {
                    self._cellMergeChk(o);
                });
            },
            _cellMergeChk: function (cellIndex) {
                var self = this,
                    $target = $(self.target),
                    options = self.o,
                    cnt = 1,
                    compareObj = $target.find('tr:nth-child(' + options.rowIndex + ') td:nth-child(' + cellIndex + ')');

                // :gt(0-index)
                $target.find('tr:gt(' + (options.rowIndex - 1) + ')').each(function (i, o) {
                    // compare cell's length
                    compareIndex = cellIndex;
                    cellsLen = $(this).find('td').length;

                    if (self.tdLen != cellsLen) {
                        compareIndex = compareIndex - (self.tdLen - cellsLen);
                    }
                    cellObj =...