Blame view

online-office/src/global/location.js 2.02 KB
wangtao authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
import { luckysheet_searcharray } from '../controllers/sheetSearch';
import Store from '../store';

function rowLocationByIndex(row_index) {
    let row = 0, row_pre = 0;
    row = Store.visibledatarow[row_index];

    if (row_index == 0) {
        row_pre = 0;
    }
    else {
        row_pre = Store.visibledatarow[row_index - 1];
    }

    return [row_pre, row, row_index];
}

function rowLocation(y) {
    let row_index = luckysheet_searcharray(Store.visibledatarow, y);

    if (row_index == -1 && y > 0) {
        row_index = Store.visibledatarow.length - 1;
    }
    else if (row_index == -1 && y <= 0) {
        row_index = 0;
    }

    return rowLocationByIndex(row_index);
}

function colLocationByIndex(col_index){
    let col = 0, col_pre = 0;
    col = Store.visibledatacolumn[col_index];

    if (col_index == 0) {
        col_pre = 0;
    }
    else {
        col_pre = Store.visibledatacolumn[col_index - 1];
    }

    return [col_pre, col, col_index];
}

function colSpanLocationByIndex(col_index, span){
    let col = 0, col_pre = 0;
    col = Store.visibledatacolumn[col_index + span - 1];

    if (col_index == 0) {
        col_pre = 0;
    }
    else {
        col_pre = Store.visibledatacolumn[col_index - 1];
    }

    return [col_pre, col, col_index];
}

function colLocation(x) {
    let col_index = luckysheet_searcharray(Store.visibledatacolumn, x);

    if (col_index == -1 && x > 0) {
        col_index = Store.visibledatacolumn.length - 1;
    }
    else if (col_index == -1 && x <= 0) {
        col_index = 0;
    }

    return colLocationByIndex(col_index);
}

function mouseposition(x, y) {
    let container_offset = $("#" + Store.container).offset();

    let newX = x - container_offset.left - Store.rowHeaderWidth,
        newY = y - container_offset.top - Store.infobarHeight - Store.toolbarHeight - Store.calculatebarHeight - Store.columnHeaderHeight;

    return [newX, newY];
}

export {
    rowLocationByIndex,
    rowLocation,
    colLocationByIndex,
    colSpanLocationByIndex,
    colLocation,
    mouseposition,
}