paragraph.js 1.4 KB
Newer Older
M
Minwe 已提交
1
define(function(require, exports, module) {
M
Minwe 已提交
2 3 4
  'use strict';

  require('core');
Hzp_D's avatar
Hzp_D 已提交
5
  require('ui.pureview');
M
Minwe 已提交
6

M
Minwe 已提交
7 8 9
  var $ = window.Zepto;
  var UI = $.AMUI;
  var IScroll = require('ui.iscroll-lite');
M
Minwe 已提交
10 11 12 13 14 15

  /**
   * 表格滚动
   * @param index ID 标识,多个 paragraph 里面多个 table
   */
  $.fn.scrollTable = function(index) {
M
Minwe 已提交
16 17
    var $this = $(this);
    var $parent;
M
Minwe 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

    $this.wrap('<div class="am-paragraph-table-container" ' +
        'id="am-paragraph-table-' + index + '">' +
        '<div class="am-paragraph-table-scroller"></div></div>');

    $parent = $this.parent();
    $parent.width($this.width());
    $parent.height($this.height());

    new IScroll('#am-paragraph-table-' + index, {
      eventPassthrough: true,
      scrollX: true,
      scrollY: false,
      preventDefault: false
    });
  };
L
LUO Minhui 已提交
34

M
Minwe 已提交
35
  function paragraphInit() {
M
Minwe 已提交
36
    var $paragraph = $('[data-am-widget="paragraph"]');
L
LUO Minhui 已提交
37

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

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

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

M
Minwe 已提交
57 58 59
  $(window).on('load', function() {
    paragraphInit();
  });
L
LUO Minhui 已提交
60

M
Minwe 已提交
61 62
  exports.init = paragraphInit;
});