media1.query.js 2.29 KB
(function() {
  function setFontsize() {
    var fontSize = 0;
    fontSize = document.documentElement.clientWidth / 375 * 15;
    document.documentElement.style.cssText = 'font-size:' + fontSize + 'px !important';
  }
  setFontsize();
  window.addEventListener("resize", setFontsize, false);
})();

var ModalHelper = (function(bodyCls) {
  var scrollTop;
  return {
    afterOpen: function() {
      scrollTop = document.scrollingElement.scrollTop;
      document.body.classList.add(bodyCls);
      document.body.style.top = -scrollTop + 'px';
    },
    beforeClose: function() {
      document.body.classList.remove(bodyCls);
      // scrollTop lost after set position:fixed, restore it back.
      document.scrollingElement.scrollTop = scrollTop;
    }
  };
})('modal-open');

/* loading */
(function($) {
    var template = 
          '<div class="loading-wrapper">' +
          '  <div class="mask"></div>' +
          '    <div class="m-loading middle middle-content text-center border-radius">' +
          '      <i class="icon-loading"></i>' +
          '      <div class="text m-t-xs text-sm"></div>' +
          '    </div>' +
          '</div>';

    var defaultOpts = {
        selector: 'body',
        mark: true,
        text: '正在提交...',
        loadimg: ''
    };

    function hide () {
        this.dom.hide();
        return this;
    }

    function show () {
        this.dom.show();
        return this;
    }

    function config (options) {
        this.dom.find('.content').text(options.text);

        if (options.mark) {
            this.dom.find('.mark').show();
        } else {
            this.dom.find('.mark').hide();
        }

        if (options.text) {
            this.dom.find('.text').show().text(options.text);
        } else {
            this.dom.find('.text').hide();
        }

        this.dom.find('.icon-loading').addClass(options.loading);

        return this;
    }

    var loading = function(options) {
        var $dom = $(template);
        var opts = $.extend({}, defaultOpts, options || {}, {});

        var obj = {
            dom: $dom,
            hide: hide,
            show: show,
            reset: config
        };

        obj.reset(opts);

        $(opts.selector).append($dom);

        return obj;
    };

    $.extend({
        loading: loading
    });
})(jQuery);