CJL.0.1.js

/*!
 * Cloudgamer JavaScript Library v0.1
 * Copyright (c) 2009 cloudgamer
 * Blog: http://cloudgamer.cnblogs.com/
 * Date: 2009-10-15
 */

var $$, $$B, $$A, $$F, $$D, $$E, $$CE, $$S;

(function(undefined){

var O, B, A, F, D, E, CE, S;

/*Object*/

O = function (id) {
    return "string" == typeof id ? document.getElementById(id) : id;
};

O.emptyFunction = function(){};

O.extend = function (destination, source, override) {
    if (override === undefined) override = true;
    for (var property in source) {
        if (override || !(property in destination)) {
            destination[property] = source[property];
        }
    }
    return destination;
};

O.deepextend = function (destination, source) {
    for (var property in source) {
        var copy = source[property];
        if ( destination === copy ) continue;
        if ( typeof copy === "object" ){
            destination[property] = arguments.callee( destination[property] || {}, copy );
        }else{
            destination[property] = copy;
        }
    }
    return destination;
};

/*from youa*/
O.wrapper = function(me, parent) {
    var ins = function() { me.apply(this, arguments); };
    var subclass = function() {};
    subclass.prototype = parent.prototype;
    ins.prototype = new subclass;
    return ins;
};

/*Browser*/

/*from youa*/
B = (function(ua){
    var b = {
        msie: /msie/.test(ua) && !/opera/.test(ua),
        opera: /opera/.test(ua),
        safari: /webkit/.test(ua) && !/chrome/.test(ua),
        firefox: /firefox/.test(ua),
        chrome: /chrome/.test(ua)
    };
    var vMark = "";
    for (var i in b) {
        if (b[i]) { vMark = "safari" == i ? "version" : i; break; }
    }
    b.version = vMark && RegExp("(?:" + vMark + ")[\\/: ]([\\d.]+)").test(ua) ? RegExp.$1 : "0";

    b.ie = b.msie;
    b.ie6 = b.msie && parseInt(b.version, 10) == 6;
    b.ie7 = b.msie && parseInt(b.version, 10) == 7;
    b.ie8 = b.msie && parseInt(b.version, 10) == 8;

    return b;
})(window.navigator.userAgent.toLowerCase());

/*Array*/

A = function(){

    var ret = {
        isArray: function( obj ) {
            return Object.prototype.toString.call(obj) === "[object Array]";
        },
        indexOf: function( array, elt, from ){
            if (array.indexOf) {
                return isNaN(from) ? array.indexOf(elt) : array.indexOf(elt, from);
            } else {
                var len = array.length;
                from = isNaN(from) ? 0
                    : from < 0 ? Math.ceil(from) + len : Math.floor(from);

                for ( ; from < len; from++ ) { if ( array[from] === elt ) return from; }
                return -1;
            }
        },
        lastIndexOf: function( array, elt, from ){
            if (array.lastIndexOf) {
                return isNaN(from) ? array.lastIndexOf(elt) : array.lastIndexOf(elt, from);
            } else {
                var len = array.length;
                from = isNaN(from) || from >= len - 1 ? len - 1
                    : from < 0 ? Math.ceil(from) + len : Math.floor(from);

                for ( ; from > -1; from-- ) { if ( array[from] === elt ) return from; }
                return -1;
            }
        }
    };

    function each( object, callback ) {
        if ( undefined === object.length ){
            for ( var name in object ) {
                if (false === callback( object[name], name, object )) break;
            }
        } else {
            for ( var i = 0, len = object.length; i < len; i++ ) {
                if (i in object) { if (false === callback( object[i], i, object )) break; }
            }
        }
    };

    each({
            forEach: function( object, callback, thisp ){
                each( object, function(){ callback.apply(thisp, arguments); } );
            },
            map: function( object, callback, thisp ){
                var ret = [];
                each( object, function(){ ret.push(callback.apply(thisp, arguments)); });
                return ret;
            },
            filter: function( object, callback, thisp ){
                var ret = [];
                each( object, function(item){
                        callback.apply(thisp, arguments) && ret.push(item);
                    });
                return ret;
            },
            every: function( object, callback, thisp ){
                var ret = true;
                each( object, function(){
                        if ( !callback.apply(thisp, arguments) ){ ret = false; return false; };
                    });
                return ret;
            },
            some: function( object, callback, thisp ){
                var ret = false;
                each( object, function(){
                        if ( callback.apply(thisp, arguments) ){ ret = true; return false; };
                    });
                return ret;
            }
        }, function(method, name){
            ret[name] = function( object, callback, thisp ){
                if (object[name]) {
                    return object[name]( callback, thisp );
                } else {
                    return method( object, callback, thisp );
                }
            }
        });

    return ret;
}();

/*Function*/

F = (function(){
    var slice = Array.prototype.slice;
    return {
        bind: function( fun, thisp ) {
            var args = slice.call(arguments, 2);
            return function() {
                return fun.apply(thisp, args.concat(slice.call(arguments)));
            }
        },
        bindAsEventListener: function( fun, thisp ) {
            var args = slice.call(arguments, 2);
            return function(event) {
                return fun.apply(thisp, [E.fixEvent(event)].concat(args));
            }
        }
    };
})();

/*Dom*/

D = {
    getScrollTop: function(node) {
        var doc = node ? node.ownerDocument : document;
        return doc.documentElement.scrollTop || doc.body.scrollTop;
    },
    getScrollLeft: function(node) {
        var doc = node ? node.ownerDocument : document;
        return doc.documentElement.scrollLeft || doc.body.scrollLeft;
    },
    contains: document.defaultView
        ? function (a, b) { return !!( a.compareDocumentPosition(b) & 16 ); }
        : function (a, b) { return a != b && a.contains(b); },
    rect: function(node){
        var left = 0, top = 0, right = 0, bottom = 0;
        //ie8的getBoundingClientRect获取不准确
        if ( !node.getBoundingClientRect || B.ie8 ) {
            var n = node;
            while (n) { left += n.offsetLeft, top += n.offsetTop; n = n.offsetParent; };
            right = left + node.offsetWidth; bottom = top + node.offsetHeight;
        } else {
            var rect = node.getBoundingClientRect();
            left = right = D.getScrollLeft(node); top = bottom = D.getScrollTop(node);
            left += rect.left; right += rect.right;
            top += rect.top; bottom += rect.bottom;
        };
        return { "left": left, "top": top, "right": right, "bottom": bottom };
    },
    clientRect: function(node) {
        var rect = D.rect(node), sLeft = D.getScrollLeft(node), sTop = D.getScrollTop(node);
        rect.left -= sLeft; rect.right -= sLeft;
        rect.top -= sTop; rect.bottom -= sTop;
        return rect;
    },
    curStyle: document.defaultView
        ? function (elem) { return document.defaultView.getComputedStyle(elem, null); }
        : function (elem) { return elem.currentStyle; },
    getStyle: document.defaultView
        ? function (elem, name) {
            var style = document.defaultView.getComputedStyle(elem, null);
            return name in style ? style[ name ] : style.getPropertyValue( name );
        }
        : function (elem, name) {
            var style = elem.style, curStyle = elem.currentStyle;
            //透明度 from youa
            if ( name == "opacity" ) {
                if ( /alpha\(opacity=(.*)\)/i.test(curStyle.filter) ) {
                    var opacity = parseFloat(RegExp.$1);
                    return opacity ? opacity / 100 : 0;
                }
                return 1;
            }
            if ( name == "float" ) { name = "styleFloat"; }
            var ret = curStyle[ name ] || curStyle[ S.camelize( name ) ];
            //单位转换 from jqury
            if ( !/^-?\d+(?:px)?$/i.test( ret ) && /^\-?\d/.test( ret ) ) {
                var left = style.left, rtStyle = elem.runtimeStyle, rsLeft = rtStyle.left;

                rtStyle.left = curStyle.left;
                style.left = ret || 0;
                ret = style.pixelLeft + "px";

                style.left = left;
                rtStyle.left = rsLeft;
            }
            return ret;
        },
    setStyle: function(elems, style, value) {
        if ( !elems.length ) { elems = [ elems ]; }
        if ( typeof style == "string" ) { var s = style; style = {}; style[s] = value; }
        A.forEach( elems, function(elem ) {
            for (var name in style) {
                var value = style[name];
                if (name == "opacity" && B.ie) {
                    //ie透明度设置 from jquery
                    elem.style.filter = (elem.currentStyle && elem.currentStyle.filter || "").replace( /alpha\([^)]*\)/, "" ) + " alpha(opacity=" + (value * 100 | 0) + ")";
                } else if (name == "float") {
                    elem.style[ B.ie ? "styleFloat" : "cssFloat" ] = value;
                } else {
                    elem.style[ S.camelize( name ) ] = value;
                }
            };
        });
    },
    getSize: function(elem) {
        var width = elem.offsetWidth, height = elem.offsetHeight;
        if ( !width && !height ) {
            var repair = !D.contains( document.body, elem ), parent;
            if ( repair ) {//如果元素不在body上
                parent = elem.parentNode;
                document.body.insertBefore(elem, document.body.childNodes[0]);
            }
            var style = elem.style,
                cssShow = { position: "absolute", visibility: "hidden", display: "block", left: "-9999px", top: "-9999px" },
                cssBack = { position: style.position, visibility: style.visibility, display: style.display, left: style.left, top: style.top };
            D.setStyle( elem, cssShow );
            width = elem.offsetWidth; height = elem.offsetHeight;
            D.setStyle( elem, cssBack );
            if ( repair ) {
                parent ? parent.appendChild(elem) : document.body.removeChild(elem);
            }
        }
        return { "width": width, "height": height };
    }
};

/*Event*/
E = (function(){
    /*from dean edwards*/
    var addEvent, removeEvent, guid = 1,
        storage = function( element, type, handler ){
            if (!handler.$$guid) handler.$$guid = guid++;
            if (!element.events) element.events = {};
            var handlers = element.events[type];
            if (!handlers) {
                handlers = element.events[type] = {};
                if (element["on" + type]) {
                    handlers[0] = element["on" + type];
                }
            }
        };
    if ( window.addEventListener ) {
        var fix = { "mouseenter": "mouseover", "mouseleave": "mouseout" };
        addEvent = function( element, type, handler ){
            if ( type in fix ) {
                storage( element, type, handler );
                var fixhandler = element.events[type][handler.$$guid] = function(event){
                    var related = event.relatedTarget;
                    if ( !related || (element != related && !(element.compareDocumentPosition(related) & 16)) ){
                        handler.call(this, event);
                    }
                };
                element.addEventListener(fix[type], fixhandler, false);
            } else {
                element.addEventListener(type, handler, false);
            };
        };
        removeEvent = function( element, type, handler ){
            if ( type in fix ) {
                if (element.events && element.events[type]) {
                    element.removeEventListener(fix[type], element.events[type][handler.$$guid], false);
                    delete element.events[type][handler.$$guid];
                }
            } else {
                element.removeEventListener(type, handler, false);
            };
        };
    } else {
        addEvent = function( element, type, handler ){
            storage( element, type, handler );
            element.events[type][handler.$$guid] = handler;
            element["on" + type] = handleEvent;
        };
        removeEvent = function( element, type, handler ){
            if (element.events && element.events[type]) {
                delete element.events[type][handler.$$guid];
            }
        };
        function handleEvent() {
            var returnValue = true, event = fixEvent();
            var handlers = this.events[event.type];
            for (var i in handlers) {
                this.$$handleEvent = handlers[i];
                if (this.$$handleEvent(event) === false) {
                    returnValue = false;
                }
            }
            return returnValue;
        };
    }

    function fixEvent(event) {
        if (event) return event;
        event = window.event;
        event.pageX = event.clientX + D.getScrollLeft(event.srcElement);
        event.pageY = event.clientY + D.getScrollTop(event.srcElement);
        event.target = event.srcElement;
        event.stopPropagation = stopPropagation;
        event.preventDefault = preventDefault;
        var relatedTarget = {
                "mouseout": event.toElement, "mouseover": event.fromElement
            }[ event.type ];
        if ( relatedTarget ){ event.relatedTarget = relatedTarget;}

        return event;
    };
    function stopPropagation() { this.cancelBubble = true; };
    function preventDefault() { this.returnValue = false; };

    return {
        "addEvent": addEvent,
        "removeEvent": removeEvent,
        "fixEvent": fixEvent
    };
})();

/*CustomEvent*/

CE = (function(){
    var guid = 1;
    return {
        addEvent: function( object, type, handler ){
            if (!handler.$$$guid) handler.$$$guid = guid++;
            if (!object.cusevents) object.cusevents = {};
            if (!object.cusevents[type]) object.cusevents[type] = {};
            object.cusevents[type][handler.$$$guid] = handler;
        },
        removeEvent: function( object, type, handler ){
            if (object.cusevents && object.cusevents[type]) {
                delete object.cusevents[type][handler.$$$guid];
            }
        },
        fireEvent: function( object, type ){
            if (!object.cusevents) return;
            var args = Array.prototype.slice.call(arguments, 2),
                handlers = object.cusevents[type];
            for (var i in handlers) {
                handlers[i].apply(object, args);
            }
        },
        clearEvent: function( object ){
            if (!object.cusevents) return;
            for (var type in object.cusevents) {
                var handlers = object.cusevents[type];
                for (var i in handlers) {
                    handlers[i] = null;
                }
                object.cusevents[type] = null;
            }
            object.cusevents = null;
        }
    };
})();

/*String*/

S = {
    camelize: function(s){
        return s.replace(/-([a-z])/ig, function(all, letter) { return letter.toUpperCase(); });
    }
};

/*System*/

// remove css image flicker
if (B.ie6) {
    try {
        document.execCommand("BackgroundImageCache", false, true);
    } catch(e) {}
};

/*define*/

$$ = O; $$B = B; $$A = A; $$F = F; $$D = D; $$E = E; $$CE = CE; $$S = S;

})();
时间: 2024-10-12 15:43:43

CJL.0.1.js的相关文章

MyEclipse导入jquery-1.8.0.min.js等文件报错的解决方案

MyEclipse导入jquery-1.8.0.min.js等文件报错的解决方案 版权声明:本文为博主原创文章,未经博主允许不得转载. MyEclipse导入jQuery-1.8.0.min.js等文件的时候有时候会报了一堆missing semicolon的错误.怎么解决这个报错呢?方法如下: 1.选中报错的jquery文件例如“jquery-1.8.0.min.js”. 2.右键选择 MyEclipse-->Exclude From Validation . 3.再右键选择 MyEclips

[0] D3.js的简介和安装

想要详细了解D3.js的朋友,欢迎来http://www.ourd3js.com/ 讨论 D3的全称是(Data-Driven Documents),顾名思义可以知道是一个关于数据驱动的文档的javascript类库.如果你不知道什么是javascript,请先学习javascript的相关知识. 说得简单一点,D3.js主要是用于操作数据的,它通过使用HTML.SVG.CSS来给你的数据注入生命,即转换为各种简单易懂的绚丽的图形. 先看一个简单的例子. 现在有一组数据, [  4 , 32 ,

Vue2.0+Node.js+MongoDB 全栈打造商城系统

第1章 课程介绍简单回顾前端近几年的框架模式,了解不同时期下的框架特点.其次介绍Vue框架的背景和核心思想,以及同其它MV*框架的对比.1-1 课程-导学1-2 前端框架回顾1-3 vue概况以及核心思想1-4 vue框架优缺点对比 第2章 Vue基础从0到1,如何搭建一个简单的Vue项目:本章节主要讲解Node和Npm环境的搭建,其次介绍vue-cli脚手架的使用,以及通过详细拆解介绍脚手架生成的配置文件信息,最后给大家介绍了Vue涵盖的基础语法.2-1 nodejs和npm的安装和环境搭建2

微信6.0.2 js 分享

12月25日 微信更新到6.0.2版本,此次对开发者影响比较大的就是原来微信分享的JS 将不再对开发者开发,对此官方的解释是: 旧版的获取分享状态及设置分享内容的JS接口一直用于内部业务,并未对外开放,在微信公开的开放文档里面并没有此接口. 某些第三方借助微信客户端漏洞在未获得权限的情况下使用接口,微信6.0.2版本对此漏洞做了修复以确保用户分享内容的准确性,避免诱导分享. 另外,不久将向广大公众号开放正式分享接口供开发者使用. 根据今天我们公司跟腾讯交涉的反馈是腾讯将对此接口进行白名单验证,相

[ActionScript 3.0] 与js通信

AS3代码,可做文档类; 1 package { 2 import flash.display.Sprite; 3 import flash.events.*; 4 import flash.external.ExternalInterface; 5 import flash.text.TextField; 6 import flash.utils.Timer; 7 import flash.text.TextFieldType; 8 import flash.text.TextFieldAut

as3.0和js相互调用,js控制flash的颜色

程序应用场景:flash是一副地图,地图上一单击,就调用js,弹出一个对话框,显示一些自己想要的信息:js定时调用as提供的方法,然后去改变flash的颜色. 以下是as代码: import flash.events.MouseEvent; import flash.text.TextField; //给每一栋楼增加监听事件 mc0001.addEventListener(MouseEvent.CLICK,onClick); mc0004.addEventListener(MouseEvent.

Get全栈技能点 Vue2.0/Node.js/MongoDB 打造商城

第1章 课程介绍简单回顾前端近几年的框架模式,了解不同时期下的框架特点.其次介绍Vue框架的背景和核心思想,以及同其它MV*框架的对比. 第2章 Vue基础从0到1,如何搭建一个简单的Vue项目:本章节主要讲解Node和Npm环境的搭建,其次介绍vue-cli脚手架的使用,以及通过详细拆解介绍脚手架生成的配置文件信息,最后给大家介绍了Vue涵盖的基础语法. 第3章 Vue-router主要介绍4种路由的使用方式,主要包括动态路由.嵌套路由.编程式路由以及命名路由. 第4章 Vue-resourc

前端0:js基础

1.js是按顺序执行的,故把 <script> 内容放到 <head> 里,或放到 <body> 内容之前,与<script> 内容放到 <body> 内容之后 执行的效果会有所不同.经常会遇到: ①<head><script> 里修改图片路径 obj.src 失败,由于未加载 window.onload. 2.节点处理 由于浏览器兼容性差异,各标签之间的空白也算为节点,index 随之变化. 3.查询字符串:JS与服务器

CK2359-vue2.0+node.js+MongoDB全栈打造商城(完整版)

随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到程序开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了.对于学习有困难不知道如何提升自己可以加扣:1225462853进行交流得到帮助,获取学习资料. 下载地址:http://pan.baidu.com/s/1jI05TPW 从前端入门全栈,让未来更宽广 通过实现简易的商城系统来贯穿当下最热最流行的大前端框架 - 商城采用前后端分离的开发方式 - Vue全家桶全部涉