• layui 源码解读(部分)


    <!DOCTYPE html>
    <head>
    </head>
    <body>
        <input  type="button" id="btn1" value="get请求" > 
        <script>
        ;!function(win) {
        var o = {
                modules: {},
                status: {},
                timeout: 10,
                event: {}
        } ,
        t = document,
        n = function() {
            this.v = "2.4.5"
        },
        u = {
                layer: "modules/layer",
                laydate: "modules/laydate",
                laypage: "modules/laypage",
                laytpl: "modules/laytpl",
                layim: "modules/layim",
                layedit: "modules/layedit",
                form: "modules/form",
                upload: "modules/upload",
                tree: "modules/tree",
                table: "modules/table",
                element: "modules/element",
                rate: "modules/rate",
                colorpicker: "modules/colorpicker",
                slider: "modules/slider",
                carousel: "modules/carousel",
                flow: "modules/flow",
                util: "modules/util",
                code: "modules/code",
                jquery: "modules/jquery",
                mobile: "modules/mobile",
                "layui.all": "../layui.all"
        },
        r = function() {
            var e = t.currentScript ? t.currentScript.src : function() {
                for (var e, o = t.scripts, n = o.length - 1, r = n; r > 0; r--)
                    if ("interactive" === o[r].readyState) {
                        e = o[r].src;
                        break
                    }
                return e || o[n].src
            }();
            return e.substring(0, e.lastIndexOf("/") + 1)
        }(),
         i = function(t) {
            e.console && console.error && console.error("Layui hint: " + t)
        };
         //扩展属性 (自执行函数的返回值)
         n.prototype.modules = function() {
            var e = {};
            for (var t in u)
                e[t] = u[t];
            return e
        }();
        //扩展方法 config(e)
        n.prototype.config = function(e) {
            e = e || {};
            for (var t in e) 
                o[t] = e[t];
            return this
        };
        //扩展方法 extend(e)
        n.prototype.extend = function(e) {
        var t = this;
        e = e || {};
        for (var o in e)
            t[o] || t.modules[o] ? i("模块名 " + o + " 已被占用") : t.modules[o] = e[o];
        return t
        };
        //扩展方法 use(e)
        n.prototype.use = function(e, n, l) {
            function s(e, t) {
                var n = "PLaySTATION 3" === navigator.platform ? /^complete$/ : /^(complete|loaded)$/;
                ("load" === e.type || n.test((e.currentTarget || e.srcElement).readyState)) && (o.modules[f] = t,
                d.removeChild(v),
                function r() {
                    return ++m > 1e3 * o.timeout / 4 ? i(f + " is not a valid module") : void (o.status[f] ? c() : setTimeout(r, 4))
                }())
            }
            function c() {
                l.push(layui[f]),
                e.length > 1 ? y.use(e.slice(1), n, l) : "function" == typeof n && n.apply(layui, l)
            }
    
            var y = this
              , p = o.dir = o.dir ? o.dir : r
              , d = t.getElementsByTagName("head")[0];
            e = "string" == typeof e ? [e] : e,
            window.jQuery && jQuery.fn.on && (y.each(e, function(t, o) {
                "jquery" === o && e.splice(t, 1)
            }),
            layui.jquery = layui.$ = jQuery);
            var f = e[0]
              , m = 0;
            if (l = l || [],
            o.host = o.host || (p.match(///([sS]+?)//) || ["//" + location.host + "/"])[0],
            0 === e.length || layui["layui.all"] && u[f] || !layui["layui.all"] && layui["layui.mobile"] && u[f])
                return c(),
                y;
            if (o.modules[f])
                !function g() {
                    return ++m > 1e3 * o.timeout / 4 ? i(f + " is not a valid module") : void ("string" == typeof o.modules[f] && o.status[f] ? c() : setTimeout(g, 4))
                }();
            else {
                var v = t.createElement("script")
                  , h = (u[f] ? p + "lay/" : /^{/}/.test(y.modules[f]) ? "" : o.base || "") + (y.modules[f] || f) + ".js";
                h = h.replace(/^{/}/, ""),
                v.async = !0,
                v.charset = "utf-8",
                v.src = h + function() {
                    var e = o.version === !0 ? o.v || (new Date).getTime() : o.version || "";
                    return e ? "?v=" + e : ""
                }(),
                d.appendChild(v),   //追加节点 // GET file:///C:/lib/larryms/js/base.js?v=2.0.8 net::ERR_FILE_NOT_FOUND
                !v.attachEvent || v.attachEvent.toString && v.attachEvent.toString().indexOf("[native code") < 0 || a ? v.addEventListener("load", function(e) {
                    s(e, h)
                }, !1) : v.attachEvent("onreadystatechange", function(e) {
                    s(e, h)
                }),
                o.modules[f] = h
            }
            return y
        }
    
    
        win.layui = new n; //继承
        }(window);
    
        </script>
        <script>
         /*      layui.config({version: "2.0.8",base: '/lib/larryms/',mods: 'list/',page: 'Department',isFunction: true})
                .extend({larry: 'js/base'})
                .use('larry'); 
                var  abc = null ||{version: "2.0.8"}; //==对象
                var  abc1 = 0 ||{version: "2.0.8"}; //==对象
                var  abc2 = 1 ||{version: "2.0.8"}; //==1
                var obj = {version: "2.0.8"};
                for(var t in obj)
                {
                    //t="version" 
                    // obj[t] = obj["version"]
                    // o[t] = o["version"]  
                }
            */
                var t =  layui.config({version: "2.0.8",base: '/lib/larryms/',mods: 'list/',page: 'Department',isFunction: true});
                var t1 = t.extend({larry: 'js/base'});
                t1.use('larry');
                
                var y = 0;
    
    
                
    
    
    
        </script>
    </body>
    </html>
  • 相关阅读:
    G1垃圾收集器入门-原创译文
    Dubbo微容器(Cooma)详解
    Dubbo工程结构和Maven打包
    Greys学习笔记(未完待续)
    ES学习笔记
    CSS标准盒子模型和IE怪异盒子模型
    npm install 报错
    安卓手机scrollTop失效问题记录
    npm run dev报错
    severless扫盲
  • 原文地址:https://www.cnblogs.com/enych/p/11480416.html
Copyright © 2020-2023  润新知