JavaScript实现的浮动层框架用法实例分析

论坛 期权论坛     
niminba   2021-5-15 20:55   67   0
<p>本文实例讲述了JavaScript实现的浮动层框架用法。分享给大家供大家参考。具体如下:</p>
<p>这是一个JavaScript编写的浮动层框架,作为框架来说,骨干已经完成了。可以实现“类”、“构造函数”、“继承”(木有实现多继承)、“静态方法”、“重载”(木有实现多态),对我来说主要的意义就是,我喜欢这种代码风格,可以非常简单的重用和二次开发。</p>
<p>运行效果截图如下:</p>
<p><img alt="" src="https://beijingoptbbs.oss-cn-hangzhou.aliyuncs.com/jb/2426819-afb064e47b9cd09f7f9a8b26111594de"></p>
<p>在线演示地址如下:</p>
<p><a href="http://demo.jb51.net/js/2015/js-float-win-fra-demo/" target="_blank">http://demo.jb51.net/js/2015/js-float-win-fra-demo/</a></p>
<p>具体代码如下:</p>
<div class="blockcode">
<pre class="brush:js;">
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=gb2312" /&gt;
&lt;title&gt;Hutia Javascript Framework&lt;/title&gt;
&lt;script&gt;
function ClassAdapter(a) {
var d, c = a || new Function, b = void 0, f = Math.random();
d = function(b) {
  this.constructor = c;
  this["class"] = d;
  for(var a in e) {
   this[a] = e[a]
  }
  var f;
  b != "&lt;\!-- /* n@o!t#h$i(n&amp;g1 4l5i7k9e24- th69at9 - hutia */ --\&gt;" &amp;&amp; (f = c.apply(this, arguments));
  f = f || this;
  if(f != this) {
   for(a in this) {
    f[a] = this[a]
   }
   f.constructor = c
  }
  return f
};
var e = {su:function() {
  var b = this["class"].get_parent();
  if(!b) {
   return null
  }
  this.su = function(a) {
   return b.prototype[a].apply(this, Array.prototype.slice.apply(arguments).slice(1))
  };
  return b.get_constructor().apply(this, arguments)
}, get_class:function() {
  return this["class"]
}, same_instanceof:function(b, a) {
  if(!b || !b.get_class) {
   return!1
  }
  return this["class"][a &#63; "equals" : "is_descent"](b.get_class())
}, is_instanceof:function(b, a) {
  return this["class"][a &#63; "equals" : "is_descent"](b)
}, trace:function(b) {
  if(typeof window == "undefined") {
   return this.out(b &amp;&amp; b.description || b)
  }
  if(!window.__log__) {
   window.__log__ = []
  }
  window.__log__.push(b &amp;&amp; b.description || b)
}, out:function(b) {
  typeof alert != "undefined" &#63; alert(b) : typeof WScript != "undefined" &amp;&amp; WScript.Echo(b)
}}, a = {is_class:!0, extend:function(b) {
  b = new ClassAdapter(b || c);
  b.set_parent(d);
  b.prototype = new d("&lt;\!-- /* n@o!t#h$i(n&amp;g1 4l5i7k9e24- th69at9 - hutia */ --\&gt;");
  return b
}, equals:function(b) {
  if(!b || !b.is_class) {
   return!1
  }
  return f == b.get_clsid()
}, is_descent:function(a) {
  if(!a || !a.is_class) {
   return!1
  }
  if(f == a.get_clsid()) {
   return!0
  }
  for(var c = b;c;) {
   if(c.equals(a)) {
    return!0
   }
   c = c.get_parent()
  }
  return!1
}, is_instance:function(b, a) {
  return b &amp;&amp; b.is_instanceof &#63; b.is_instanceof(this, a) : !1
}, method:function(b, a) {
  if(arguments.length == 1) {
   for(var c in b) {
    d.prototype[c] = b[c]
   }
  }else {
   d.prototype[b] = a
  }
  return d
}, _default:function(b, a) {
  if(arguments.length == 1) {
   for(var c in b) {
    d.prototype[c] = b[c]
   }
  }else {
   d.prototype[b] = a
  }
  return d
}, _statics:function(b, a) {
  if(arguments.length == 1) {
   for(var c in b) {
    d[c] = b[c]
   }
  }else {
   d[b] = a
  }
  return d
}, get_constructor:function() {
  return c
}, set_constructor:function(b) {
  c = b
}, get_parent:function() {
  return b
}, set_parent:function(a) {
  b = a
}, get_clsid:function() {
  return f
}, toString:function() {
  return String(c)
}, valueOf:function() {
  return String(c)
}};
d.prototype = e;
for(var h in a) {
  d[h] = a[h]
}
return d
}
function Class(a) {
function d() {
  if(++a.err_count &gt; a.max_err) {
   var b;
   a.onerror &amp;&amp; (b = a.onerror());
   return b
  }
  a.recall_timer = setTimeout(function() {
   Class(a)
  }, a.retry_interval || 100)
}
if(!a) {
  return new ClassAdapter
}
var c;
c = void 0;
if(!Class.hash_list) {
  Class.hash_list = {}
}
a.namespace = a.namespace || window;
a.err_count |= 0;
a.max_err = a.max_err || 5;
a.name = a.name || "$" + (new Date).getTime().toString(36) + (Math.random() * 16777215 | 0).toString(36);
a.recall_timer = null;
Class.hash_list[a.name] = a;
if(a.requires) {
  if(typeof a.requires == "string") {
   a.requires = [a.requires]
  }
  for(var b in a.requires) {
   if("undefined" == typeof a.namespace[a.requires[b]]) {
    return d()
   }
  }
}
if(a.parent) {
  if("undefined" == typeof a.namespace[a.parent]) {
   return d()
  }
  a.parent = a.namespace[a.parent]
}
if(typeof a == "function") {
  c = a
}else {
  if(a.init) {
   c = a.init
  }
}
c = a.parent &#63; a.parent.extend(c) : new ClassAdapter(c);
a.method &amp;&amp; c.method(a.method);
a._default &amp;&amp; c._default(a._default);
a._statics &amp;&amp; c._statics(a._statics);
a.namespace[a.name] = c;
a.ready &amp;&amp; a.ready()
}
Class.is_ready = function(a) {
if(Class.hash_list &amp;&amp; Class.hash_list[a] &amp;&amp; !Class.hash_list[a].recall_timer) {
  return!0
}
return!1
};
Class.ready = function(a, d, c) {
function b() {
  var c = !0;
  if(d) {
   for(var f in d) {
    if(!Class.hash_list[d[f]]
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1060120
帖子:212021
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP