| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- /**
- * @fileoverview loading
- * @desc 显示/关闭加载状态
- * @author fool2fish<fool2fish@gmail.com>
- */
- KISSY.add('gallery/loading', function (S, undefined) {
- var D = S.DOM, E = S.Event, doc = document;
- /**
- * 构造器
- * @param {String} [txt = '加载中,请稍候……'] 加载时显示的提示文字
- contanter:0代表是整个页面,其它代表是元素后面
- */
- function Loading(txt, contanter) {
- var self = this;
- self.em = contanter;
- self._txt = txt || '加载中,请稍候……';
- self._init();
- }
- S.augment(Loading, S.EventTarget, {
- _init: function () {
- var self = this;
- self._el = D.create('<div class="loading" style="display:none;"><div class="mask"></div><div class="text" id="loadingtext"><i id="ttt">' + self._txt + '</i><div></div>');
- if (self.em === 0) {
- doc.body.appendChild(self._el);
- } else {
- S.one(self.em).next().html('<span id="divloading" class="loading" style="display:;"><span class="mask"></span><span class="text"><i id="ttt">' + self._txt + '</i><span></span>');
- }
- },
- /**
- * 显示加载状态
- * @param {HTMLElement | String} [refEl = document.body] 显示加载状态时,蒙版要遮罩的参考元素
- */
- show: function (refEl) {
- var self = this, el = self._el;
- if (S.isString(refEl)) refEl = D.get(refEl);
- refEl = refEl || doc.body;
- el.style.left = D.scrollLeft(refEl) + 'px';
- el.style.top = D.scrollTop(refEl) + 'px';
- el.style.width = D.width(refEl) + 'px';
- el.style.height = D.height(refEl) + 'px';
- if (self.em === 0) {
- el.style.display = 'block';
- } else
- S.one("#divloading").attr("style", "display:");
-
- self.fire('show');
- // alert(self._el.innerHTML);
- },
- /**
- * 隐藏加载状态
- */
- hide: function () {
- var self = this, el = self._el;
- if (self.em === 0) {
- el.style.display = 'none';
- } else
- S.one("#divloading").attr("style","display:none");
- self.fire('hide');
- }
- });
- //兼容 1.1.6
- S.namespace('Gallery');
- S.Gallery.Loading = Loading;
- return Loading;
- }, {
- requires: ["core"]
- });
|