paragraph.js 1.7 KB
Newer Older
M
Minwe 已提交
1
define(function(require, exports, module) {
L
LUO Minhui 已提交
2 3
    require('core');

M
Minwe 已提交
4 5 6
    var $ = window.Zepto,
        UI = $.AMUI;

7 8
    // Iscroll-lite Plugin
    var IScroll = require('ui.iscroll-lite');
M
Minwe 已提交
9
    
L
LUO Minhui 已提交
10
    var paragraphInit;
M
Minwe 已提交
11 12 13 14 15
    
    /**
     * 表格滚动
     * @param index ID 标识,多个 paragraph 里面多个 table
     */
L
LUO Minhui 已提交
16

17
    $.fn.scrollTable = function(index) {
M
Minwe 已提交
18
        var $this = $(this),
19
            $parent;
L
LUO Minhui 已提交
20

M
Minwe 已提交
21
        $this.wrap('<div class=\'am-paragraph-table-container\' id=\'am-paragraph-table-'+ index + '\'><div class=\'am-paragraph-table-scroller\'></div></div>');
L
LUO Minhui 已提交
22

M
Minwe 已提交
23 24 25
        $parent = $this.parent();
        $parent.width($this.width());
        $parent.height($this.height());
L
LUO Minhui 已提交
26

27 28 29 30 31 32
        var tableScroll = new IScroll('#am-paragraph-table-' + index, {
            eventPassthrough: true,
            scrollX: true,
            scrollY: false,
            preventDefault: false
        });
L
LUO Minhui 已提交
33 34 35 36
    };

    paragraphInit = function() {
        var $body = $('body'),
37
            $paragraph = $('[data-am-widget="paragraph"]');
L
LUO Minhui 已提交
38

39
        $paragraph.each(function(index) {
M
Minwe 已提交
40
            var $this = $(this),
41 42
                options = UI.utils.parseOptions($this.attr('data-am-paragraph')),
                $index = index;
M
Minwe 已提交
43

M
Minwe 已提交
44 45
            if (options.pureview) {
                $this.pureview();
M
Minwe 已提交
46
            }
L
LUO Minhui 已提交
47

M
Minwe 已提交
48
            if (options.tableScrollable) {
49 50 51 52
                $this.find('table').each(function(index) {
                    if ($(this).width() > $(window).width()) {
                        $(this).scrollTable($index + '-' + index);
                    }
M
Minwe 已提交
53 54 55
                });
            }
        });
L
LUO Minhui 已提交
56 57 58 59 60 61 62 63 64

    };

    $(window).on('load', function() {
        paragraphInit();
    });

    exports.init = paragraphInit;
});