# All files / scripts/CDP/UI/listview LineProfile.ts

22.02% Statements 24/109
4.17% Branches 2/48
13.04% Functions 3/23
20.56% Lines 22/107

    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
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    2351x

    1x
    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

     ﻿namespace CDP.UI {

        import _Config = CDP.UI.ListViewGlobalConfig;
        import _ToolCSS = CDP.UI._ListViewUtils;

        const TAG = "[CDP.UI.LineProfile] ";

        /**
         * @class LineProfile
         * @brief 1 ラインに関するプロファイルクラス
         *        framework が使用する
         */
        export class LineProfile {
            private _index: number = null;              //!< global index
            private _pageIndex: number = null;          //!< 所属する page index
            private _offset: number = null;             //!< global offset
            private _$base: JQuery = null;              //!< 土台となる DOM インスタンスを格納
            private _instance: BaseListItemView = null; //!< ListItemView インスタンスを格納

            /**
             * constructor
             *
             * @param _owner       {IListViewFramework} [in] 管理者である IListViewFramework インスタンス
             * @param _height      {Number}             [in] 初期の高さ
             * @param _initializer {Function}           [in] ListItemView 派生クラスのコンストラクタ
             * @param _info        {Object}             [in] ListItemView コンストラクタに渡されるオプション
             */
            constructor(
                private _owner: IListViewFramework,
                private _height: number,
                private _initializer: new (options?: any) => BaseListItemView,
                private _info: any) {
            }

            ///////////////////////////////////////////////////////////////////////
            // public methods

            //! 有効化
            public activate(): void {
                if (null == this._instance) {
                    let options;
                    this._$base = this.prepareBaseElement();
                    options = $.extend({}, {
                        el: this._$base,
                        owner: this._owner,
                        lineProfile: this,
                    }, this._info);
                    this._instance = new this._initializer(options);
                    if ("none" === this._$base.css("display")) {
                        this._$base.css("display", "block");
                    }
                }
                this.updatePageIndex(this._$base);
                if ("visible" !== this._$base.css("visibility")) {
                    this._$base.css("visibility", "visible");
                }
            }

            //! 不可視化
            public hide(): void {
                if (null == this._instance) {
                    this.activate();
                }
                if ("hidden" !== this._$base.css("visibility")) {
                    this._$base.css("visibility", "hidden");
                }
            }

            //! 無効化
            public inactivate(): void {
                if (null != this._instance) {
                    // xperia AX Jelly Bean (4.1.2)にて、 hidden element の削除でメモリーリークするため可視化する。
                    if ("visible" !== this._$base.css("visibility")) {
                        this._$base.css("visibility", "visible");
                    }
                    this._instance.remove();
                    this._instance = null;
                    this._$base.addClass(_Config.RECYCLE_CLASS);
                    this._$base.css("display", "none");
                    this._$base = null;
                }
            }

            //! 更新
            public refresh(): void {
                if (null != this._instance) {
                    this._instance.render();
                }
            }

            //! 有効無効判定
            public isActive(): boolean {
                return null != this._instance;
            }

            //! 高さ情報の更新. ListItemView からコールされる。
            public updateHeight(newHeight: number, options?: UpdateHeightOptions): void {
                const delta = newHeight - this._height;
                this._height = newHeight;
                this._owner.updateScrollMapHeight(delta);
                if (null != options && options.reflectAll) {
                    this._owner.updateProfiles(this._index);
                }
            }

            //! z-index のリセット. ScrollManager.removeItem() からコールされる。
            public resetDepth(): void {
                if (null != this._instance) {
                    this._$base.css("z-index", this._owner.getListViewOptions().baseDepth);
                }
            }

            ///////////////////////////////////////////////////////////////////////
            // getter/setter methods

            //! getter: ラインの高さ
            public get height(): number {
                return this._height;
            }

            //! getter: global index
            public get index(): number {
                return this._index;
            }

            //! setter: global index
            public set index(index: number) {
                this._index = index;
                if (null != this._$base) {
                    this.updateIndex(this._$base);
                }
            }

            //! getter: 所属ページ index
            public get pageIndex(): number {
                return this._pageIndex;
            }

            //! setter: 所属ページ index
            public set pageIndex(index: number) {
                this._pageIndex = index;
                if (null != this._$base) {
                    this.updatePageIndex(this._$base);
                }
            }

            //! getter: line offset
            public get offset(): number {
                return this._offset;
            }

            //! setter: line offset
            public set offset(offset: number) {
                this._offset = offset;
                if (null != this._$base) {
                    this.updateOffset(this._$base);
                }
            }

            //! getter: info
            public get info(): any {
                return this._info;
            }

            ///////////////////////////////////////////////////////////////////////
            // private methods

            //! Base jQuery オブジェクトの生成
            private prepareBaseElement(): JQuery {
                let $base: JQuery;
                const $map = this._owner.getScrollMapElement();
                const $recycle = this._owner.findRecycleElements().first();
                const itemTagName = this._owner.getListViewOptions().itemTagName;

                if (null != this._$base) {
                    console.warn(TAG + "this._$base is not null.");
                    return this._$base;
                }

                if (0 < $recycle.length) {
                    $base = $recycle;
                    $base.removeAttr("z-index");
                    $base.removeClass(_Config.RECYCLE_CLASS);
                } else {
                    $base = $("<" + itemTagName + " class='" + _Config.LISTITEM_BASE_CLASS + "'></" + itemTagName + ">");
                    $base.css("display", "none");
                    $map.append($base);
                }

                // 高さの更新
                if ($base.height() !== this._height) {
                    $base.height(this._height);
                }

                // index の設定
                this.updateIndex($base);
                // offset の更新
                this.updateOffset($base);

                return $base;
            }

            //! global index の更新
            private updateIndex($base: JQuery): void {
                if ($base.attr(_Config.DATA_CONTAINER_INDEX) !== this._index.toString()) {
                    $base.attr(_Config.DATA_CONTAINER_INDEX, this._index.toString());
                }
            }

            //! page index の更新
            private updatePageIndex($base: JQuery): void {
                if ($base.attr(_Config.DATA_PAGE_INDEX) !== this._pageIndex.toString()) {
                    $base.attr(_Config.DATA_PAGE_INDEX, this._pageIndex.toString());
                }
            }

            //! offset の更新
            private updateOffset($base: JQuery): void {
                const transform = {};
                if (this._owner.getListViewOptions().enableTransformOffset) {
                    if (_ToolCSS.getCssMatrixValue($base, "translateY") !== this._offset) {
                        for (let i = 0; i < _ToolCSS.cssPrefixes.length; i++) {
                            transform[_ToolCSS.cssPrefixes[i] + "transform"] = "translate3d(0px," + this._offset + "px,0px)";
                        }
                        $base.css(transform);
                    }
                } else {
                    if (parseInt($base.css("top"), 10) !== this._offset) {
                        $base.css("top", this._offset + "px");
                    }
                }
            }
        }
    }