[JavaScript 프레임워크 봉인] JQuery의 기본 기능을 포함하는 프레임워크와 핵심 원본 공유(단일 파일 버전)를 직접 봉인합니다.

전체 포장 과정과 JQuery 원본을 읽는 과정은 기본적으로 한 달 동안 지속되었지요. 최종적으로 30% 정도의 JQuery 기능의 프레임워크 버전을 실현했지만 그 안에 관련된 지식도 매우 많았습니다. 총 코드에 관련 주석을 달면 3000줄 정도일 것입니다. 하지만 JQuery의 안에 있는 지식에 대해 대충 알고 있을 뿐입니다.후속으로 JQuery에서 다루는 지식을 더욱 깊이 있게 이해하고 고품질의 코드를 작성할 수 있기를 바랍니다. 이로써 그동안 배운 점을 기록해 드리겠습니다.
/*
* @Author:       
* @Time: 20180722
* @Desc:        JQuery     
* V 1.0:        、    、CSS  、    、    、       
* V 2.0:           ,        ,         
* V 3.0:    :    、    、   、     、domReady,     
* V 4.0:        、          ,       (     )
* V 5.0:         ,          
* V 6.0:    CSS         
* V 7.0:              
* V 8.0:              
* V 8.0:    DOM        
* V 9.0:            (    、cookie、Localstorage  )
* V 10.0                
* V 11.0         +       ;        
* */
 

/**
 *    js            
 */
;(function () {
    //                ,         
    stringExtend()
    arrayExtend()
    functionExtend()


    // String       
    function stringExtend() {
        // str = 'name: @(name), age:@(age)'
        // data = {name : 'xiugang', age : 18}
        /**
         *            
         * @param str
         * @param data
         * @return {*}
         */
        String.prototype.formateString = function (data) {
            return this.replace(/@\((\w+)\)/g, function (match, key) {
                //               (   undefined,      )
                //   :           undefined,    typeof  
                console.log(typeof data[key] === 'undefined');
                return data[key] === 'undefined' ? '' : data[key];
            });

        }
        /**
         *        
         * @param str
         * @return {*}
         */
        String.prototype.ltrim = function () {
            return this.replace(/^\s*/g, '');

        }
        /**
         *        
         * @param str
         * @return {*}
         */
        String.prototype.rtrim = function () {
            return this.replace(/\s*$/g, '');
        }
        /**
         *        
         * @param str
         * @return {*}
         */
        String.prototype.trim = function () {
            return this.replace(/(^\s*)|(\s*$)/g, '');
        }

        // red===>Red
        /**
         *         ,      
         * @param str
         * @return {*}
         */
        String.prototype.camelCase = function () {
            // .*?       ,         ,         0-n    ,     0-1;
            // (^\w{1}):           
            // (.*):             

            // - param 1:        
            // - param 2:         
            // - param 3:        
            // - param 4:                
            // - param 5:      

            return this.replace(/(^\w{1})(.*)/g, function (match, g1, g2) {
                return g1.toUpperCase() + g2.toLowerCase();
            });
        }
        /**
         *                 
         * @param str
         * @return {*}
         */
        String.prototype.dashString = function () {
            //     this                      
            return this.replace(/\_/g, '-');
        }

        /**
         *             
         * @return {boolean}
         */
        String.prototype.isEmpty = function () {
            return this.length === 0;

        }
        /**
         *                
         * @param target
         * @return {boolean}
         */
        String.prototype.contains = function (target) {
            //     indexOf     -1  ,            ,         
            // indexOf()                           ,       ,   -1
            return this.indexOf(target) !== -1;
        }
        /**
         *                 
         * @return {string}
         */
        String.prototype.escapeHTML = function () {
            /*    	  	    	    
                          	 	 
                        <	   	<	<
                        >	   	>	>
                        &	  	&	&
                        "	  	"	"
                        '	   	' (IE   )	'
                        ¢	 	¢	¢
                        �0�5	 	£	£
                        �0�6	  	¥	¥
                        €	  	&euro
            * **/


            //         ,       
            var strArr = this.split('');
            for (var pos = 0, l = strArr.length, tmp; pos < l; pos++) {
                //            
                tmp = strArr[pos];
                //                ,               
                switch (tmp) {
                    // pos   1,         1 
                    case '':
                        replaceArr(strArr, pos, '>');
                        break;
                    case '\'':
                        replaceArr(strArr, pos, ''');
                        break;
                    case '\"':
                        replaceArr(strArr, pos, '"');
                        break;
                    case '&':
                        replaceArr(strArr, pos, '&');
                        break;
                    default:
                        ;
                }
            }
            // join()                     。
            return strArr.join('');

            //              
            /**
             *          
             * @param arr
             * @param pos
             * @param item
             * @return {*}
             */
            function replaceArr(arr, pos, item) {
                // Splice: splice     JS        ,    ,  ,   ,         
                //     :array.splice(index,num),        ,array    。index    ,num         。
                //     :array.splice(index,0,insertValue),index      ,insertValue     
                //     :array.splice(index,num,insertValue),index    ,num       ,insertValue     
                return arr.splice(pos, 1, item);
            }

        }
        /**
         *   HTML           
         * @return {string}
         */
        String.prototype.escapeHTML = function () {
            return Array.prototype.slice.call(this).join('').replace(/$/g, '&amp')
                .replace(/\/g, '&gt')
                .replace(/\'/g, ''')
                .replace(/\"/g, '&quot');
        }
        /**
         *          
         * @return {string}
         */
        String.prototype.unescapeHTML = function () {
            //      this              ,                       
            console.log(typeof this);
            // 1.              
            var arr = Array.prototype.slice.call(this);
            // 2.             
            var res = arr.join('');
            //      < > & " '   ,    
            return res.replace(/&lt/g, '')
                .replace(/'/g, '\'')
                .replace(/&quot/g, '\"')
                .replace(/&amp/g, '')

                // String.fromCharCode()           Unicode                。String.fromCharCode(65,66,67) “ABC”
                .replace(/(\d+)/g, function ($0, $1) {
                    //parseInt()               (radix/base)      。      string  radix      10  
                    return String.fromCharCode(parseInt($1, 10));
                });
        }
        /**
         *             
         * @return {string}
         */
        String.prototype.reverse = function () {
            // 1.           ,        
            var arr = this.toString().split('');
            // 2.                   
            arr = arr.reverse();
            // 3.              
            return arr.join();
            //return (this.toString()).split('').reverse().join();
        }


    }

    // Array       
    function arrayExtend() {
        /**
         *          
         * @return {Array}
         */
        Array.prototype.clear = function () {
            this.length = 0;
            return this;
        }
        /**
         *          
         * @return {*}
         */
        Array.prototype.size = function () {
            return this.length;
        }
        /**
         *             
         * @return {*}
         */
        Array.prototype.first = function () {
            return this[0];
        }
        /**
         *            
         * @return {*}
         */
        Array.prototype.last = function () {
            return this[this.length - 1]
        }


        function cacl(arr, callback) {
            //       (             )
            var ret;
            for (var i = 0, len = arr.length; i < len; i++) {
                ret = callback(arr[i], ret);
            }
            return ret;
        }

        /**
         *             
         * @return {*}
         */
        Array.prototype.sum = function () {
            // 1.      
            /*var ret = 0;
            for (var i = 0, len = this.length; i < len; i++){
                ret = ret + this[i];
            }
            return ret;*/

            // 2.        
            /**
             * @param:item       
             * @param:sum        
             */
            return cacl(this, function (item, sum) {
                //             ,          sum(ret)    
                if (typeof sum === 'undefined') {
                    return item;
                } else {
                    return sum += item;
                }
            })

        }
        /**
         *          
         * @return {*}
         */
        Array.prototype.max = function () {
            // 1.           
            /*var ret = 0;
            for (var i = 0, len = this.length; i < len; i++){
                if (ret < this[i]){
                    ret = this[i];
                }
            }
            return ret;*/

            // 2.      
            return cacl(this, function (item, max) {
                if (typeof max === 'undefined') {
                    return item;
                } else {
                    if (max < item) {
                        return item;
                    } else {
                        return max;
                    }
                }
            })
        }
        /**
         *            
         * @return {*}
         */
        Array.prototype.min = function () {
            return cacl(this, function (item, min) {
                if (typeof min === 'undefined') {
                    return item;
                } else {
                    //                 
                    if (!(min < item)) {
                        return item;
                    } else {
                        return min;
                    }
                }
            })
        }

        /**
         *                
         * @return {*}
         */
        Array.prototype.avg = function () {
            // 1.                  ,           
            if (this.length === 0) {
                return;
            }
            var sum = this.sum();
            return sum / this.length;
            /*return cacl(this, function (item, avg) {
                // 1.    (         , this    window  ,  window     sum   ,     )
                //var sum = this.sum();
                // 2.     
                if (typeof avg === 'undefined'){
                    return item;
                } else{
                    avg = sum / (this.length);
                }
                return avg;
            })*/
        }


        //          
        /*
        *     :              ,                        
        * 【                 】
        * */
        Array.prototype.unique = function () {
            var a = [],
                len = this.length;
            for (var i = 0; i < len; i++) {
                for (var j = i + 1; j < len; j++) {
                    if (this[i] === this[j]) {
                        //                 ,i        
                        //   j   i           
                        j = ++i;
                    }
                }
                a.push(this[i]);
            }
            ;
            return a;
        }
        /**
         *          
         * 【    】:        ,             
         * @return {Array}
         */
        Array.prototype.unique = function () {
            var tmp = [],
                len = this.length;
            // 1.           
            this.sort();
            // 2.       
            for (var i = 0; i < len; i++) {
                //          ,     
                if (this[i] === this[i + 1]) {
                    continue;
                }

                //   tmp.length        0,           1,           1,             
                tmp[tmp.length] = this[i];
            }
            return tmp;
        }

        /**
         *          ,        
         * @param target
         * @return {*}
         */
        Array.prototype.union = function (target) {
            // concat()              。
            //                  
            return this.concat(target).union();
        }

        /**
         *          
         * @param target
         * @return {Array|*[]}
         */
        Array.prototype.intersect = function (target) {
            // 1.                  
            var originArr = this.unique(),
                targetArr = target.unique();
            // filter()                  ,             
            // 2.        
            /**
             * @param element(  ):      
             @param index(  ):        
             @param array(  ):         
             */
            return originArr.filter(function (element, index, array) {
                // filter           false     
                for (var i = 0, len = targetArr.length; i < len; i++) {
                    if (element === targetArr[i]) {
                        //        true     ,         
                        return true;
                    }
                    //return false;
                }
                //                 true,          false
                return false;
            });

        }

        /**
         *             
         * @param target
         * @return {Array|*[]}
         */
        Array.prototype.diff = function (target) {
            // 1.            ,     
            var orignArr = this.unique(),
                targetArr = target.unique();
            // 2.     filter      
            return orignArr.filter(function (element, index, array) {
                for (var i = 0, len = targetArr.length; i < len; i++) {
                    //         ,      
                    if (element === targetArr[i]) {
                        return false;
                    }
                }
                return true;
            });
        }

        /**
         *                     (      )
         * @param fn
         * @param ctx
         */
        Array.prototype.forEach = function (fn, ctx) {
            var i = 0,
                len = this.length;
            for (; i < len; i++) {
                // element, index, array
                // call          this   ,                    
                fn.call(ctx || null, this[i], i, this);
            }
        }

        /**
         *
         *            ,               
         * @param fn
         * @param ctx
         * @return {Array}
         */
        Array.prototype.map = function (fn, ctx) {
            //      
            var ret = [],
                i = 0,
                len = this.length;
            //           ,                
            for (; i < len; i++) {
                //       ,       
                res = fn.call(ctx || null, this[i], i, this);
                //                     
                ret.push(res);
            }
            return ret;
        }
        /**
         *              ,            true     
         * @param fn
         * @param ctx
         */
        Array.prototype.filter = function (fn, ctx) {
            var ret = [],
                i = 0,
                len = this.length;
            //      ,      true          
            for (; i < len; i++) {
                //                         true      
                fn.call(ctx || null, this[i], i, this) && ret.push(this[i]);
            }
            return ret;
        }


        /**
         *            
         * @param fn
         */
        Array.prototype.each = function (fn) {
            var i = 0,
                len = this.length;
            for (; i < len; i++) {
                fn.call(this[i]);
            }
        }


        /**
         *     【   】      ,           true,    true
         * @param fn
         * @param ctx
         */
        Array.prototype.every = function (fn, ctx) {
            var i = 0,
                len = this.length;
            //           ,             false   false,       true    true
            for (; i < len; i++) {
                //  :a   undefined,!a true,!!a  false,  b   false,    undefined。             。
                //   ,!!(a)     a        (boolean)。
                //   a = null, !!(a)       ,                      
                //                  bool   
                if (!!fn.call(ctx || null, this[i], i, this) === false)
                    return false;

                //         
                /*if (fn.call(ctx || null, this[i], i, this)) {
                    return true;
                }*/
            }
            return true;
        }
        /**
         *               ,      true  ,  true,    false
         * @param fn
         * @param ctx
         */
        Array.prototype.some = function (fn, ctx) {
            var i = 0,
                len = this.length;
            //        ,      true,  true
            for (; i < len; i++) {
                /*
                * //      Boolean   !!
                var bool = !!"c";
                console.log(typeof bool); // boolean

                //      Number   +
                var num = +"1234";
                console.log(typeof num); // number

                //      String   ""+
                var str = ""+ 1234;
                console.log(typeof str); // string
                * */
                if (!!fn.call(ctx || null, this[i], i, this) === true)
                    return true;
            }
            return false;
        }

        /**
         *           (       )
         *               
         * @param callback
         */
        Array.prototype.reduce = function (callback) {
            var i = 0,
                len = this.length,
                callbackRet = this[0];          //                     ,            
            for (; i < len; i++) {
                // this   ,element, index,       
                // callbackRet                  
                callbackRet = callback.call(null, callbackRet, this[i], i, this);
            }
            return callbackRet;
        }

        /**
         *            ,         
         * @param callback
         */
        Array.prototype.reduceRight = function (callback) {
            var len = this.length,
                i = this[len - 2],
                callbackRet = this[len - 1];        //        

            //                   
            for (; i >= 0; i--) {
                //this  , prev, element, index, arr
                callbackRet = callback.call(null, callbackRet, this[i], i, this);
            }
            return callbackRet;
        }


        /**
         *      target            ,            
         * @param target
         * @param start
         */
        Array.prototype.indexOf = function (target, start) {

            /*
            *                 ,       
            ~~true == 1
            ~~false == 0
            ~~"" == 0
            ~~[] == 0
            ~~undefined ==0
            ~~!undefined == 1
            ~~null == 0
            ~~!null == 1
            * */
            var len = this.length,
                start = ~~start;        //   start    ,    undefined,         ,     ~~              
            if (start < 0) {
                //              0  ,     0         
                start = 0;
            }
            //                 
            for (; start < len; start++) {
                if (this[start] === target) {
                    return start;
                }
            }
            //        ,   -1
            return -1;
        }


        /**
         *                      
         * @param target
         * @param start
         */
        Array.prototype.lastIndexOf = function (target, start) {
            //       typeof start ==== 'undefined'
            if (start === void 0) {
                start = this.length;
            } else if (start < 0) {
                start = 0;
            }

            //              
            for (; start >= 0; start--) {
                //       target             (     )
                if (this[start] === target) {
                    return start;
                }
            }
            return -1;
        }

        /**
         *           
         *    :                  ,             ,      
         * ['ff', 1, '1']
         */
        Array.prototype.enhanceUnique = function () {
            var ret = [],
                tempMap = {},
                i = 0,
                len = this.length,
                temp;

            //         
            for (; i < len; i++) {
                temp = this[i];
                //     tempMap        ,          
                if (tempMap[temp] === void 0) {
                    ret.push(temp);
                    // {}        {1 : true, 2 : false, 3 : false}
                    tempMap[temp] = true;
                }
            }
            return ret;
        }


        /**
         *           ,   arguments                
         *     ,               
         * @return {Array}
         */
        Array.prototype.without = function () {
            // slice(start, end)                  。
            //   slice()               ,          start       
            // 1.           ,           
            //var args = [].slice.call(arguments).unique();
            /*
            * Array.prototype.slice.call({
             0:"likeke",
             1:12,
             2:true,
             length:3
            });
            * */
            //1.   arguments         ,             
            //      arguments     
            var arr = Array.prototype.slice.call(arguments) || [].slice.call(arguments);
            // 2.            
            var args = arr.unique(),
                len = this.length,
                aLength = args.length,
                i = 0,
                j = 0;


            //        (               ,   this.length           ,                    length)
            for (; i < len; i++) {
                for (; j < aLength; j++) {
                    if (this[i] === args[j]) {
                        //               ,     
                        // i      ,1      ,      i     
                        // splice           , this            
                        this.splice(i, 1);

                        //                      ,                 
                        // len = this.length;
                    }

                }
                //  j    ,       (       j          j         )
                j = 0;
            }
            return this;
        }


        /**
         *           
         */
        Array.prototype.enhanceWithout = function () {
            //                 
            var ret = [],
                len = this.length,
                args = ([]).slice.call(arguments),
                argsLength = args.length,
                i = 0,
                j = 0;

            for (; i < len; i++) {
                for (; j < argsLength; j++) {
                    if (args[j] !== this[i]) {
                        ret.push(this[i]);
                    }
                }
                //      j        ,          
                j = 0;
            }
            return ret;
        }


        /**
         *           (               )【      】
         * [[], [], [], [[], [], []]]
         * @return {Array}
         */
        Array.prototype.flatten = function () {
            //     flatten  ,           array(  ) (         )          
            //                 ,
            var ret = [],
                len = this.length,      //               ,   this    tmp
                i = 0,
                tmp;

            for (; i < len; i++) {
                //                  
                tmp = this[i];
                //                    (        )
                if (({}).toString.call(tmp) === '[object Array]' || Object.prototype.toString.call(tmp) === '[object Array]') {
                    //       (                )
                    // 1.                  , tmp.flatten()              
                    // 2.   ret       ,  concat                  
                    //              this        tmp  
                    ret = ret.concat(tmp.flatten())
                    //tmp.flatten();
                } else {
                    //           ,             
                    ret.push(tmp);
                }
            }
            return ret;
        }


        /**
         *             
         * @param pos
         * @return {Array}
         */
        Array.prototype.removeAt = function (pos) {
            //            
            // slice()                   ,   this        
            this.splice(pos, 1);
            return this;
        }

        /*
        【    1】
                (==)    ,       (    var      ),    。
                   ,   typeof   ,  typeof         ,    "undefined"   。
            ,       typeof ,            js            ,
                ,        js           , ==       :is not defined
        【    2】

          slice() splice()       
        * */


        /**
         *              
         * @param target
         * @return {boolean}
         */
        Array.prototype.contains = function (target) {
            //             some  ,        ,    true
            return this.some(function (element, index, self) {
                //   this.some()                  
                return element === target;
            })
        }

        /**
         *            (           )
         * @param n
         * @return {*}
         */
        Array.prototype.random = function (n) {
            //Math.floor():    。Math.floor(1.8) -> 1
            //Math.ceil():    。Math.ceil(1.1) -> 2
            //v = Math.random() * n:      0 < v < nv  
            //v2 = Math.floor(Math.random() * n):v2       0,  n   
            var index = (Math.floor(Math.random() * n));
            return this[index] || this[this.length - 1];
        }
    }


    // Function       
    function functionExtend(func) {
        Function.prototype.before = function (func) {
            //                 ,                。
            var __self = this;      //          
            return function () {
                //                ,           false,   false
                if (func.apply(this, arguments) === false) {
                    return false;
                }
                //                
                return __self.apply(this, arguments);
            }
        }


        /**
         * AOP          
         * @param func
         * @return {Function}
         */
        Function.prototype.after = function (func) {
            var __self = this;
            return function () {
                var ret = __self.apply(this, arguments);        // //      ,         ,    ,            ,      myFunc,      fn
                if (ret === false) {
                    return false;
                }
                func.apply(this, arguments);
                return ret;
            }
        }

    }
})();


//    :      ,             
;(function (w) {
    //     Xframe  ,          
    var xframe = function (selector, context) {
        //          this      xframe  ,          this   
        return this.init.apply(this, [selector, context]);
    };

    //          ,              
    //           JQuery         ,           
    //        :                    JQuery         
    xframe.prototype.init = function (selector, context) {
        //          :{1 : list[0], 2 : list[1], , , , length : list.length}
        this.length = 0;

        //            
        if (typeof selector === 'undefined') {
            return this;
        }

        if (typeof  selector === 'string') {
            var nodeList = (context || document).querySelectorAll(selector);
            this.length = nodeList.length;
            for (var i = 0, len = this.length; i < len; i++) {
                this[i] = nodeList[i];
            }
        } else if (selector.nodeType) {
            //             ,    ,        
            this[0] = selector;
            this.length++;
        }

        //                this      
        return this;
    };


    //                  ,         
    // 【        】
    var $$ = function (selector, context) {
        //                ,     DOM                 
        if (typeof selector === 'function') {
            // selector  DOM                    
            //w.onload = selector;

            //               domReady(ele, fn)   ,       document              
            //   call            ,             
            //$$.onDOMReady.call(this, selector);

            //   apply                 
            //$$.onDOMReady.apply(this, [selector]);

            //     bind  (              ,       )
            // bind        ,      ;apply 、call        。【         ,          】
            var func = $$.onDOMReady.bind(this, selector);
            //     bind()       
            func();

        } else {
            //           
            return new xframe(selector, context);
        }
    }

    //     extend  ,            ,            
    $$.extend = function () {
        //           :
        // 1.              ,      xframe      
        // 2.          ,             (                 )
        var len = arguments.length,
            target = null,              // target                   
            i = 1,                      //      i,                
            key;                        //              ,                        
        if (len === 0) {
            return;
        } else if (len === 1) {
            //  xrame      
            target = xframe.prototype;
            i--;
        } else {
            //       ,                         
            //          :        i   ,           ,        ,                    
            //   :                   ,                              
            target = arguments[0];
        }


        //     target         ,          source, source             target    
        for (; i < len; i++) {
            //           json  ,json                   
            //      arguments,           ,                
            for (key in arguments[i]) {
                target[key] = arguments[i][key];
            }
        }
        return target;
    }


    //                         
    w.xframe = w.$ = $$;

})(window);


//     
//     :    、    、   、     、domReady  ,     
;(function (xframe) {
    //          (    prototype           )
    xframe.extend({
        //   1:      
        each: function (fn) {
            var i = 0,
                len = this.length;
            for (; i < len; i++) {
                // call             this   ,           fn       (   )
                // this[i]           json  ,                 nodeList          
                fn.call(this[i]);
            }
            return this;
        },
        //   2:       (    DOM            )
        each: function (fn) {
            var i = this.length - 1;
            for (; i >= 0; i--) {
                fn.call(this[i], i);
            }
        },
        /**
         *            ,          
         * @param pArr
         * @param fn
         */
        toArray: function (pArr, fn) {
            var arr = Array.prototype.slice.call(pArr),
                i = arr.length - 1;
            for (; i >= 0; i--) {
                // element index
                fn.call(arr[i], i);
            }

        },

    });

    //           
    /*    */
    xframe.extend(xframe, {});

    /*       */
    xframe.extend(xframe, {
        /*
        *                ,      
        * camelCase          background-color        :backgroundColor
        * */
        camelCase: function (str) {
            //  all: -c, letter: c
            return str.replace(/\-(\w)/g, function (all, letter) {
                //                
                return letter.toUpperCase();
            });
        },
        /**
         *         str = ' ()'
         * @param str
         * @returns {*}
         */
        ltrim: function (str) {
            /*
            ^ :   XX  
            \s:     
            *:            
            g:       ,              
            (^\s*):                 
            str.replace(, ''):   ……


            ----------------------------------------------------[      ]-------------------------------------
            ^, $:        ,           eg:
            g, i:    ,          ; eg: /a/g, /a/i
            *, +, ?:       ,              , 0   1 

            [] :         ; eg: [a-z]         , [0-9]       
                                  eg: [a-zA-Z]          
               ^:              ,          
            {}:                 eg:{N}   n 
                                            eg:{n, m}  n-m 
                                            eg: {n, }    n 
                                            eg:{,m}    m 



            // 【  :     】
            \s:     :    、  、  、tab,   [
\r\t\f] \S: , [^
\r\t\f] \d: , [0-9] \D: , [^0-9] \w( ): , [a-zA-Z0-9] \W: , \w , :[^a-zA-Z0-9]* * */ return str.replace(/(^\s*)/g, ''); }, /* , str = '() ' * @param str */ rtrim: function (str) { return str.replace(/(\s*$)/g, ''); }, /** * ( ) str =' () ' * @param str * @returns {*} */ trimOld: function (str) { return str.replace(/(\s*$)/g, ''); }, /** * 【 】 * : @(name), @(sex) * data: var user = {name : 'xiugang', role, ' '} * str: = ' @(name), :@(role) !'; * @param str * @param data , json , json = {name : 'xiuxiu', age : 18} * @returns {*} */ formateString: function (str, data) { // // :((\w+)) JavaScript $1, match // (\w+) $2, key // match: @(name), @(age), @(sex) // key: name, age, sex return str.replace(/@\((\w+)\)/g, function (match, key) { // // @() , // json data data[key] , return typeof data[key] === 'undefined' ? '' : data[key]; }); }, /** * @param str * @returns {*} */ trimLeft: function (str) { return str.replace(/^\s*/g, ''); }, /** * @param str * @returns {*} */ trimRight: function (str) { return str.replace(/\s*$/g, ''); }, /** * ( ), * , * @param str * @returns {*} */ trim: function (str) { // var regx = '/^\s*\s*$/g'; // return str.replace(regx, ''); // | , | , | // (^\s*) 0 // (\s*$) , 0 // /…/g , , return str.replace(/(^\s*)|(\s*$)/g, ""); //return this.trimRight(this.trimLeft(str)); }, /** * ajax * @param url URL * @param fn, */ ajax: function (url, fn) { // XMLHTTPRequest var xhr = createXHR(); // readyState , onreadystatechange 。 xhr.onreadystatechange = function () { if (xhr.readyState === 4) { // , status , 200 , responseText ; // 304 , 。 if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) { fn(xhr.responseText); } else { alert(' !'); } } }; // , url get xhr.open('get', url, true); // // : 。 // false, , send() , 。 // true , , onreadystatechange 。 xhr.send(); /** * XHR */ function createXHR() { // 《JavaScript 3 》 21 if (typeof XMLHttpRequest != "undefined") { return new XMLHttpRequest(); } else if (typeof ActiveXObject != "undefined") { // arguments.callee if (typeof arguments.callee.activeXString != "string") { var versions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp" ], i, len; for (i = 0, len = versions.length; i < len; i++) { try { new ActiveXObject(versions[i]); arguments.callee.activeXString = versions[i]; break; } catch (ex) { //skip } } } return new ActiveXObject(arguments.callee.activeXString); } else { throw new Error("No XHR object available."); } } }, /** * json * @param json * @returns {string} */ json2String: function (json) { return JSON.stringify(json); }, /** * json * @param str * @returns {any} */ string2Json: function (str) { return eval(str); } }); /* */ xframe.extend(xframe, { /** * , * 0 * @return {xframe} */ clear: function () { this.length = 0; return this; }, /** * 0 * @return {*} */ first: function () { return this[0]; }, /** * * @return {*} */ last: function () { return this[this.length - 1]; }, /** * * @return {number|*} */ size: function () { return this.length; }, cacl: function (arr, callback) { var ret; for (var i = 0; i < arr.length; i++) { // ret = callback(arr[i], ret); } return ret; }, /** * * @return {*} */ sum: function () { // 1. var ret; for (var i = 0; i < this.length; i++) { ret = ret + this[i]; } return ret; }, max: function () { }, min: function () { }, avg: function () { }, intersect: function () { }, union: function () { }, diff: function () { }, unique: function () { }, forEach: function () { }, map: function () { }, filter: function () { }, every: function () { }, some: function () { }, reduce: function () { }, reduceRight: function () { }, indexOf: function () { }, lastIndexOf: function () { }, enhanceUnique: function () { }, without: function () { }, flatten: function () { }, random: function () { }, removeAt: function () { }, contains: function () { } }); /*Math*/ xframe.extend(xframe, { random: function () { } }); /* */ xframe.extend(xframe, { // (duck typing) , , 。 // , , , 。 // 【 】: , , !!! isNumber: function (val) { // , return (typeof val === 'number' && isFinite(val)) && (Object.prototype.toString.call(val) === '[object Number]'); }, /*** * Boolean * @param val * @returns {boolean} */ isBoolean: function (val) { return (typeof val === 'boolean') && (Object.prototype.toString.call(val) === '[object Boolean]'); }, /** * * @param val * @returns {boolean} */ isString: function (val) { return (typeof val === 'string') && (Object.prototype.toString.call(val) === '[object String]'); }, /** * undefined * @param val * @returns {boolean} */ isUndefined: function (val) { // oid 0 is a correct and standard way to produce undefined. return (val === void 0) || (typeof val === 'undefined') && (Object.prototype.toString.call(val) === '[object Undefined]'); }, /** * * @param val * @returns {boolean} */ isNull: function (val) { return (val === null) && (Object.prototype.toString.call(val) === '[object Null]'); }, /** * * @param obj * @returns {*} */ isNaN: function (val) { // typef return val !== val; }, /** * * @param val * @returns {boolean} */ isObject: function (val) { if (val !== null && val !== undefined) { if ((typeof val === 'object') && (Object.prototype.toString.call(val))) { return true; } } return false; }, /** * * @param val * @returns {boolean|void|string} */ isArray: function (val) { // , val , val.constructor ,error if (val !== null || typeof val !== "undefined") { // constructor constructor , return (val.constructor === Array) && (Object.prototype.toString.call(val) === '[object Array]'); } return false; } }); /* :arguments, document.forms, document.getElementsByName, document.getElementsByTagName()*/ xframe.extend(xframe, { /** * * : , !!! * @param start * @param end * @returns {Array} */ toArray: function (start, end) { var result = []; var start = start || 0, // this , call , this , ( this ) // this , this xframe end = end || this.length; for (var i = start; i < end; i++) { result.push(this[i]); } return result; }, /** * : JavaScript * @param obj * @returns {T[]} */ slice: function (obj) { return Array.prototype.slice.apply(obj); } }); /*domReady */ xframe.extend(xframe, { //arguments , callee , , arguments /** * domReady : * @param domElement * @param fn */ onDOMReady: function (fn) { if (document.addEventListener) { // W3C : DOM , DOM , , document document.addEventListener('DOMContentLoaded', fn, false); } else { // IE IEContentLoaded(fn); } /** * IE * @param fn * @constructor */ function IEContentLoaded(fn) { // var done = false, document = window.document; // DOM var init = (function () { if (!done) { console.log('done……'); // DOM done = true; fn(); } })(); /* IE domReady */ (function () { try { // DOM doScroll , document.documentElement.doScroll('left'); } catch (err) { // 1 , 【 】 // clllee , arguments , setTimeout(arguments.callee, 1); return; } // , DOM , init(); })(); // document (DOM ) document.onreadystatechange = function () { console.log('onreadystatechange……'); if (document.readyState === 'complete') { console.log('complete……'); // document.onreadystatechange = null; init(); } } } } }); })(xframe); // ;(function (xframe) { // ( prototype ) xframe.extend({ /** * * @param type * @param fn * @return {on} */ on: function (type, fn) { // var i = this.length - 1; // IE W3c if (document.addEventListener) { // w3c( , DOM ) for (; i >= 0; i--) { this[i].addEventListener(type, fn, false); } } else if (document.attachEvent) { // IE for (; i >= 0; i--) { this[i].attachEvent('on' + type, fn); } } else { // for (; i >= 0; i--) { // json , this[i]['on' + type] = fn; } } return this; }, /** * * @param type * @param fn * @return {un} */ un: function (type, fn) { // var i = this.length - 1; if (document.removeEventListener) { // W3c for (; i >= 0; i--) { this[i].removeEventListener(type, fn, false); } } else if (document.detachEvent) { // IE for (; i >= 0; i--) { this[i].detachEvent(type, fn); } } else { // , null for (; i >= 0; i--) { // this[i]['on' + type] = null; } } return this; }, /** * * @param fn * @return {click} */ click: function (fn) { this.on('click', fn); return this; }, /** * ( ) * @param fnOver * @param fnOut * @return {hover} */ hover: function (fnOver, fnOut) { var i = this.length; // for (; i >= 0; i--) { if (fnOver && typeof fnOver === 'function') { this.on('mouseover', fnOver); } if (fnOut && typeof fnOut === 'function') { this.on('mouseout', fnOut); } } return this; }, /** * , , , 。 * toggle , , , . : * @return {toggle} */ toggle: function () { // f1, f2 var self = this, _arguments = arguments, i = 0, len = this.length; // for (; i < len; i++) { addToToggle(this[i]); } /** * * @param obj */ function addToToggle(obj) { // var count = 0; // self.on('click', function () { // call this ( , ) _arguments[count++ % _arguments.length].call(obj); }); } return this; } }); // xframe.extend(xframe, { /** * * @param event * @return {Event} */ getEvent: function (event) { return event ? event : window.event; }, /** * * @param event * @return {*|Element|Object} */ getTarget: function (event) { var event = this.getEvent(event); return event.target || event.srcElement; }, /** * * @param event */ stopPropagation: function (event) { var event = this.getEvent(event); if (event.stopPropagation) { // W3c event.stopPropagation(); } else { // IE event.cancelBubble = true; } }, /** * * @param event */ preventDefault: function (event) { var event = this.getEvent(event); if (event.preventDefault) { // w3c event.preventDefault(); } else { // IE event.returnValue = false; } }, /** * * @param event * @return {*} */ getDelta: function (event) { var event = this.getEvent(event); if (event.wheelDelta) { // w3c return event.wheelDelta; } else { // ie // Firefox , , 40, return -event.detail * 40; } } }); })(xframe); // CSS ;(function (xframe) { // ( prototype )【 this , 】 xframe.extend({ /** * DOM / CSS * @return {*} */ css: function () { // , , var arg = arguments, len = arg.length, j = this.length - 1; if (len === 0) { // , DOM return this; } else if (len === 1) { // if (typeof arg[0] === 'string') { if (this[0].currentStyle) { // w3c return this[0].currentStyle[arg[0]]; } else { // IE return getComputedStyle(this[0], false)[arg[0]]; } } else if (typeof arg[0] === 'object') { // , json , // {name : xiugang, age : 18} for (var item in arg[0]) { // , for (; j >= 0; j--) { // CSS , // item :backgroundcolor --> backgroundColor item = $.camelCase(item) this[j].style[item] = arg[0][item]; } } } } else if (len === 2) { // for (; j >= 0; j--) { // this[j].style[$.camelCase(arg[0])] = arg[1]; } } return this; }, /** * * @return {hide} */ hide: function () { var j = this.length - 1; for (; j >= 0; j--) { this[j].style.display = 'none'; } return this; // : this.each(function () { this.style.display = 'none'; }) }, /** * * @return {show} */ show: function () { this.each(function () { this.style.display = 'block'; }) return this; }, /** * * @return {*} */ width: function () { return this[0].clientWidth; }, /** * * @return {*} */ height: function () { return this[0].clientHeight; }, /** * // , : ( + ) * * @return {*} */ scrollWidth: function () { return this[0].scrollWidth; }, /** * * @return {*} */ scrollHeight: function () { return this[0].scrollHeight; }, /** * * @return {*} */ scrollTop: function () { return this[0].scrollTop; }, /** * * @return {*} */ scrollLeft: function () { return this[0].scrollLeft; }, }); // xframe.extend(xframe, { getThis: function () { console.log(xframe, typeof this); // function, this function (selector, context) }, /** * * @return {number} */ screenHeight: function () { return window.screen.height; }, /** * U * @return {number} */ screenWidth: function () { return window.screen.width; }, /** * , * @return {number} */ wWidth: function () { return document.documentElement.clientWidth; }, /** * , * @return {number} */ wHeight: function () { return document.documentElement.clientHeight; }, /** * * @return {number} */ wScrollHeight: function () { return document.body.scrollHeight; }, /** * * @return {number} */ wScrollWidth: function () { return document.body.scrollWidth; }, /** * * @return {number} */ wScrollTop: function () { var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; return scrollTop; }, /** * ( ) * @return {number} */ wScrollLeft: function () { var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft; return scrollLeft; } }); })(xframe); // ;(function (xframe) { // ( prototype ) xframe.extend({}); // xframe.extend(xframe, { /** * ID * @param context * @return {HTMLElement | *} */ $id: function (context) { // context DOM context = this.isString(context) ? document.getElementById(context) : context; return context; }, /** * tag , context; ( ) * @param tag * @param context * @return {NodeListOf} */ $tag: function (tag, context) { // if (typeof context === 'string') { context = this.$id(context); } // , if (context) { if (context.length) { // 0 return [].slice.call(context)[0].getElementsByTagName(tag); } else { return context.getElementsByTagName(tag); } } return document.getElementsByTagName(tag); }, /** * * @param className * @param context * @return {*} */ $class: function (className, context) { // context DOM // DOM context(DOM ) context = this.$id(context) || document; // 1. getElementByClassName() , // 2. getElementByTagName() , className class if (context.getElementsByClassName) { // return context.getElementsByClassName(className); } else { // var doms = context.getElementsByTagName('*'), res = []; // doms.each(function () { if (this.className === className) { // class , res.push(this); } }); return res; } }, /** * * @return {Array} */ $cengci: function () { var self = this; // : // : str = '#className div a p' className P // 1. ( ) var args = Array.prototype.slice.call(arguments)[0].toString().split(' '), index, first, item, selector, res = [], // context = []; // 【 !】, context = 'tag .class #id' // : , ??? // 2. args.each(function () { // , (res ) res = []; // item = this.trim(); first = item.charAt(0); index = item.indexOf(first); selector = item.slice(index + 1); // !!! switch (first) { case '.': // class if (context.length) { // class context.each(function () { pushArray(self.$class(selector, this)); }); } else { // pushArray(self.$class(selector)); } // context = res; break; case '#': // ID // ID , res.push(self.$id(selector)); // context = res; break; default: // tag if (context.length) { // context.each(function () { // tag , ID , // 1. , pushArray(self.$tag(item, this)); }); } else { // pushArray(self.$tag(item)); } // context = res; break; } }); /** * * @param doms */ function pushArray(doms) { if (doms) { [].slice.call(doms).each(function () { res.push(this); }); } } return context; }, /** * group * @return {Array} */ $group: function () { var self = this; // '.moshou,#moshou,span,.dream' // 1. var args = [].slice.call(arguments), arr = args[0].split(',').unique(), // , item, index, first, selector; res = []; // 2. , arr.each(function () { // 3. , item = this.trim(); // 4. , // 4. first = item.charAt(0); index = item.indexOf(first); selector = item.slice(index + 1); // , switch (first) { case '.': // class res.push(self.$class(selector)); break; case '#': // ID res.push(self.$id(selector)); break; default: // TAG ( first , selector ) res.push(self.$tag(item)); break; } }); return res; }, /** * + * @return {Array} */ $select: function () { // str = '#tag , .calss' var args = [].slice.call(arguments)[0].toString().split(','), ret = [], self = this; // args , args.each(function () { // 1. , , var res = self.$cengci(this); // 2. , , pushArray(res); }); // function pushArray(doms) { if (doms.length) { doms.each(function () { ret.push(this); }); } } return ret; } }); })(xframe); // ;(function (xframe) { // ( prototype ) xframe.extend({ /** * / * @return {*} */ attr: function () { // : ,1. 2. var args = arguments; if (args.length === 0) { // , return this; } else if (args.length === 1) { // if (typeof args[0] === 'string') { // return this[0].getAttribute(args[0]); } else if (typeof args[0] === 'object') { // json for (var item in args[0]) { Array.prototype.slice.call(this).each(function () { this.setAttribute(item, args[0][item]); }); } } } else if (args.length === 2) { Array.prototype.slice.call(this).each(function () { this.setAttribute(args[0], args[1]); }); } // this xframe , xframe.eatend(xframe, {}) this xframe(selector, context) , return this; }, /** * DOM * @param val * @return {boolean} */ hasClass: function (val) { if (!this[0]) { return false; } // return this[0].className === val.trim() ? true : false; }, /** * class class='xiugang 18 nan' * @param val */ addClass: function (val) { // val = val.trim(); [].slice.call(this).each(function () { // DOM , if (val !== this.className) { this.className += ' ' + val; } }) return this; }, /** * replace() * @param val */ removeClass: function (val) { val = val.trim(); [].slice.call(this).each(function () { if (val === this.className) { // this.className = this.className.replace(val, ''); } }) return this; }, /** * , * @param val * @return {toggleClass} */ toggleClass: function (val) { val = val.trim(); [].slice.call(this).each(function () { if (val === this.className) { // this.className.replace(val, ''); } else { // this.className += ' ' + val; } }); return this; } }); // xframe.extend(xframe, {}); })(xframe); // ;(function (xframe) { // ( prototype ) xframe.extend({ /** * .html() HTML js innerHTML * @return {html} */ html: function () { var arg = arguments, len = arg.length, arr = Array.prototype.slice.call(this); if (this.length < 1) { return this; } // if (len === 0) { // return this[0].innerHTML; } else if (len === 1) { // arr.each(function () { this.innerHTML = arg[0]; }); } return this; }, /** * * @return {*} */ text: function () { var args = arguments, len = args.length; if (this.length === 0) { return this; } if (len === 0) { // return this[0].innerText; } else if (len === 1) { // this.each(function () { this.innerText = args[0]; }); } return this; }, /** * (input, form) * @return {*} */ val: function () { // val(); ( value ); var args = arguments, len = args.length; if (this.length === 0) { return this; } if (len === 0) { return this[0].value; } else if (len === 1) { this.each(function () { this.value = args[0]; }); } return this; } }); // xframe.extend(xframe, {}); })(xframe); // DOM ( ) ;(function (xframe) { // ( prototype ) xframe.extend({ /** * ( this ) * @param dom * @return {add} */ add: function (dom) { // 1. this[this.length] = dom; // 2. this.length++; return this; }, /** * dom ( child) * @param child, JQuery */ append: function (child) { // var doms = typeof child === 'string' ? $(child) : $(child[0]), arr = Array.prototype.slice.call(doms); //console.log(typeof doms[0], typeof arr[0]); // 2. , /*for (var i = 0; i < this.length; i++){ for (var j = 0; j < doms.length; j++){ // , , this , this.length this[i].appendChild(doms[j]); } }*/ /*this.each(function (element) { arr.forEach(function (childNode) { element.appendChild(childNode); }); });*/ // , DOM this DOM if (arr.length !== this.length) { arr = []; // Array.prototype.slice.call(this).each(function () { arr.push(doms[0]); }); } // Array.prototype.slice.call(this).forEach(function (element, index) { element.appendChild(arr[index]); }); // this /*for (var i = 0; i < this.length; i++){ for (var j = 0; j < arr.length; j++){ if (this[i].childNodes){ continue; } // , , this , this.length this[i].appendChild(arr[j]); } }*/ }, /** * * @param parent */ appendTo: function (parent) { // 1. var doms = $(parent), self = this; // 2. Array.prototype.slice.call(this).forEach(function (element, index) { doms[index].appendChild(self[index]); }); return this; }, /** * DOM * @param num * @return {null} */ get: function (num) { return this[num] ? this[num] : null; }, /** * JQuery * @param num * @return {jQuery|HTMLElement} */ eq: function (num) { // 1. JQuery , DOM var dom = this.get(num); // 2. DOM JQuery return $(dom); }, /** * JQuery * @return {*|jQuery|HTMLElement} */ first: function () { return this.eq(0); }, /** * JQuery * @return {*|jQuery|HTMLElement} */ last: function () { return this.eq(this.length - 1); }, /** * DOM * @return {array} */ children: function () { // // 1. , , var children = this[0].children, len = children.length, that = {}, i = 0; // that.length = len; for (; i < len; i++) { that[i] = children[i]; } return that; }, /** * DOM * @param str * @return {} */ find: function (str) { var res = [], self = this, doms; this.each(function () { switch (str.charAt(0)) { case '.': // doms = $.$class(str.substring(1), self[i]); pushArray(doms); break; default: // doms = $.$tag(str, self[i]); pushArray(doms); break; } }); function pushArray(doms) { if (doms.length) { self.toArray(doms, function () { res.push(this); }); } } // 【 :】 JQuery , var that = this; that.length = this.length; this.each(function (index) { // , that[index] = res[index]; }); // that this return that; }, /** * * @return {parent} */ parent: function () { // , JQuery var parent = this[0].parentNode; this[0] = parent; this.length = 1; // , 1 return this; }, /** * * @return {number} */ index: function () { // var srcNode = this[0], children = srcNode.parentNode.children, self = this, defaultRes = -1; self.toArray(children, function (index) { // this , index if (children[index] === srcNode) { defaultRes = index; } }); // return defaultRes; } }); // xframe.extend(xframe, { /** * DOM * @param type * @param value * @param html * @return {*} */ create: function (type, value, html) { var dom = document.createElement(type); return xframe().add(dom).attr(value).html(html); }, /** * * @param dom * @param tag * @return {jQuery|HTMLElement} */ directChildren: function (dom, tag) { var res = [], tag = tag; if (typeof dom === 'string') { dom = $(dom); } // if (dom.length) { Array.prototype.slice.call(dom).each(function () { getDOM(this.children); }); } else { // getDOM(dom.children); } /** * DOM res * @param doms */ function getDOM(doms) { Array.prototype.slice.call(doms).each(function () { if (this.tagName.toLowerCase() === tag.toLowerCase()) { res.push(this); } }); } // , return $(res); }, }); })(xframe); // ;(function (xframe) { // ( prototype ) xframe.extend({}); // xframe.extend(xframe, {}); // xframe.Animate = (function (xframe) { // 1. API (API ) var api = { timer: null,// queen: [] // }; // ------------------------------------------------- /** * ( ), */ api.run = function () { // , api.timer = setInterval(function () { // , api.loop(); }, 16); // 16mm } /** * */ api.loop = function () { // obj obj = {id, now, pass, tween, duration, style} api.queen.forEach(function (obj) { // , api.move(obj); }); } /** * */ api.move = function (obj) { // 1. obj.pass = +new Date(); // 2. ( ) var tween = api.getTween(obj.now, obj.pass, obj.duration, 'easeOutBounce'); // , obj.tween = tween; //console.log(tween); // 3. if (tween >= 1) { // ( ) api.stop(); } else { // 4. api.setManyProperty(obj); } } // ------------------------------------------------- /** * @param , , , */ api.add = function () { var args = arguments, id = args[0], json = args[1], duration = args[2]; // , try { // 1. api.adapterMany(id, json, duration); // 2. api.run(); } catch (e) { console.error(e.message); } } /** * , ( ) * @param id * @param json * @param duration */ api.adapterOne = function (id, json, duration) { var obj = {} // OBj , obj.id = id // ID obj.now = +new Date() // obj.pass = 0 // obj.tween = 0 // obj.duration = duration // obj.styles = [] // // if ($.isString(duration)) { switch (duration) { case 'slow': case ' ': duration = 8000; break; case 'normal': case ' ': duration = 4000; break; case 'fast': case ' ': duration = 1000; break; } } // obj.styles = api.getStyles(id, json); return obj; } /** * * @param id * @param json * @param data */ api.adapterMany = function (id, json, data) { // ( , , ) var obj = this.adapterOne(id, json, data); // ( queen ) api.queen.push(obj); } /** * * @param id * @param json */ api.getStyles = function (id, json) { // animate('#sun', {left: 200, top : 500}, 7000); // var styles = []; // json for (var item in json) { var style = {}; // item :left, top style.name = item; // style.start = parseFloat($(id).css(item).toString()); // ( ) style.length = parseFloat(json[item]) - style.start; styles.push(style); } return styles; } /** * * @param now * @param pass * @param all * @param ease */ api.getTween = function (now, pass, all, ease) { // 1. var eases = { // linear: function (t, b, c, d) { return (c - b) * (t / d); }, // easeOutBounce: function (t, b, c, d) { if ((t /= d) < (1 / 2.75)) { return c * (7.5625 * t * t) + b; } else if (t < (2 / 2.75)) { return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b; } else if (t < (2.5 / 2.75)) { return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b; } else { return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b; } }, // swing: function (t, b, c, d) { return this.easeOutQuad(t, b, c, d); }, easeInQuad: function (t, b, c, d) { return c * (t /= d) * t + b; }, easeOutQuad: function (t, b, c, d) { return -c * (t /= d) * (t - 2) + b; }, easeInOutQuad: function (t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t + b; return -c / 2 * ((--t) * (t - 2) - 1) + b; }, easeInCubic: function (t, b, c, d) { return c * (t /= d) * t * t + b; }, easeOutCubic: function (t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b; }, easeInOutCubic: function (t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t + b; return c / 2 * ((t -= 2) * t * t + 2) + b; }, easeInQuart: function (t, b, c, d) { return c * (t /= d) * t * t * t + b; }, easeOutQuart: function (t, b, c, d) { return -c * ((t = t / d - 1) * t * t * t - 1) + b; }, easeInOutQuart: function (t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b; return -c / 2 * ((t -= 2) * t * t * t - 2) + b; }, easeInQuint: function (t, b, c, d) { return c * (t /= d) * t * t * t * t + b; }, easeOutQuint: function (t, b, c, d) { return c * ((t = t / d - 1) * t * t * t * t + 1) + b; }, easeInOutQuint: function (t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b; return c / 2 * ((t -= 2) * t * t * t * t + 2) + b; }, easeInSine: function (t, b, c, d) { return -c * Math.cos(t / d * (Math.PI / 2)) + c + b; }, easeOutSine: function (t, b, c, d) { return c * Math.sin(t / d * (Math.PI / 2)) + b; }, easeInOutSine: function (t, b, c, d) { return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b; }, easeInExpo: function (t, b, c, d) { return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b; }, easeOutExpo: function (t, b, c, d) { return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; }, easeInOutExpo: function (t, b, c, d) { if (t == 0) return b; if (t == d) return b + c; if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b; return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b; }, easeInCirc: function (t, b, c, d) { return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b; }, easeOutCirc: function (t, b, c, d) { return c * Math.sqrt(1 - (t = t / d - 1) * t) + b; }, easeInOutCirc: function (t, b, c, d) { if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b; return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b; }, easeInElastic: function (t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a < Math.abs(c)) { a = c; var s = p / 4; } else var s = p / (2 * Math.PI) * Math.asin(c / a); return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; }, easeOutElastic: function (t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a < Math.abs(c)) { a = c; var s = p / 4; } else var s = p / (2 * Math.PI) * Math.asin(c / a); return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b; }, easeInOutElastic: function (t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5); if (a < Math.abs(c)) { a = c; var s = p / 4; } else var s = p / (2 * Math.PI) * Math.asin(c / a); if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b; }, easeInBack: function (t, b, c, d, s) { if (s == undefined) s = 1.70158; return c * (t /= d) * t * ((s + 1) * t - s) + b; }, easeOutBack: function (t, b, c, d, s) { if (s == undefined) s = 1.70158; return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; }, easeInOutBack: function (t, b, c, d, s) { if (s == undefined) s = 1.70158; if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b; return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b; }, easeInBounce: function (t, b, c, d) { return c - this.easeOutBounce(d - t, 0, c, d) + b; }, easeInOutBounce: function (t, b, c, d) { if (t < d / 2) return this.easeInBounce(t * 2, 0, c, d) * .5 + b; return this.easeOutBounce(t * 2 - d, 0, c, d) * .5 + c * .5 + b; } }; // 2. var yongshi = pass - now; // 3. return eases[ease](yongshi, 0, 1, all); } /** * ( ) * @param obj */ api.setOneProperty = function (obj) { // (obj.id, obj.json) // 【 】: , if (obj.name === 'opacity') { $(obj.id).css(obj.name, (obj.start + obj.length * obj.tween)); } else { // px, $(obj.id).css(obj.name, (obj.start + obj.length * obj.tween) + 'px'); } } /** * obj.json = {width : '200px', height : '500px', 'opacity' : '0.1'} */ api.setManyProperty = function (obj) { // obj.styles obj.styles.forEach(function (style) { // obj.name = style.name; obj.start = style.start; obj.length = style.length; api.setOneProperty(obj); console.log(obj.tween); }); // styles style.name, style.start, style.length , } /** * */ api.stop = function () { clearInterval(api.timer); } // ---------------------------------------------------- api.destory = function () { } // // ,id, json, duration xframe.animate = api.add; })(xframe); })(xframe); // ;(function (xframe) { /** * ( ) * @type {{data: Array, get: (function(*): *), add: xframe.cache.add, delete: (function(*): boolean), update: (function(*, *): boolean), isExist: (function(*): boolean)}} */ xframe.cache = { data: [], // /** * json * @param key * @return {*} */ get: function (key) { var value = null; this.data.each(function () { if (key.trim() === this.key.trim()) { value = this.value; } }); return value; }, /** * * @param key * @param value */ add: function (key, value) { this.data.push({ key: key.trim(), value: value.trim() }); }, /** * key * @param key * @return {boolean} */ delete: function (key) { // key var status = false, // , self = this; this.data.forEach(function (element, index) { // , if (key.trim() === element.key.trim()) { // , self.data.splice(index, 1); status = true; } }); return status; }, /** * * @param key * @param value */ update: function (key, value) { var status = false; this.data.forEach(function (element) { if (key.trim() === element.key) { // key , , element json , element.key element.value element.value = value.trim(); status = true; } }); return status; }, /** * * @param key * @return {boolean} */ isExist: function (key) { // this.data.forEach(function () { if (key.trim() === this.key) { return true; } }); return false; } } /** * Cookie ( HTML ) * @type {{getCookie: xframe.cookie.getCookie, setCookie: xframe.cookie.setCookie, deleteCookie: xframe.cookie.deleteCookie, clearAllCookies: xframe.cookie.clearAllCookies}} */ xframe.cookie = { /** * cookie Cookie * @param name * @return {*} */ getCookie: function (name) { // var name = name.escapeHTML(), // cookie allCookies = document.cookie; // Cookie ( ) // H_PS_645EC=af88R0s3e76Ig1PlwkvrhnGGtg4qt5pcZNPKBUntPI2vGearAlyZyjXjmKYn%2BkggUXbNjhg; // 1. name cookie script3&amp5; //name = name.substring(0, name.length-1); // ( ); name += '='; // , cookie // 2. 'name=' Cookie var pos = allCookies.indexOf(name); // 3. cookie if (pos !== -1) { // , // 3. 'cookie=' var start = pos + name.length; // 3. 'cookie=' , ; , start var end = allCookies.indexOf(';', start); if (end === -1) { // -1 , cookie Cookie end = allCookies.length; } // 4. Cookie var value = allCookies.substring(start, end); // 5. ( , )【 OK, , , ok 】 return value.unescapeHTML(); } else { // , cookie return ''; } // return ''; }, /** * cookie * @param name * @param value * @param days * @param path */ setCookie: function (name, value, days, path) { var name = name.escapeHTML(), value = value.escapeHTML(), expires = new Date(), _expires, res; //name = name.substring(0, name.length-1); // ( ); // cookie ( ) expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000); if (path === '') { path = ''; } else { path = (';path=' + path); } if (typeof expires === 'string') { _expires = ''; } else { // UTC _expires = (';expires=' + expires.toUTCString()); } // cookie ,【 :】( COokie , , ) res = name + '=' + value + _expires + path; // document.cookie="userId=828; userName=hulk"; document.cookie = res; }, /** * cookie * @param name * @param path */ deleteCookie: function (name, path) { var name = name.escapeHTML(), expires = new Date(); if (path === '') { path = ''; } else { path = (';path=' + path); } // cookie document.cookie = name + '=' + ';expires=' + expires.toUTCString() + path; }, /** * cookie */ clearAllCookies: function () { // 1. cookie // "name&amp=xiuxiu& name=xiuxiu; script=alert(2); script2=<script>alert(2); script3=<script>alert(2); script3&amp=&ltscript&gtalert(2); script4&amp=&ltscript&gtalert(2); a&amp=&lta&gtalert(2)&lt/a&gt&amp" var cookies = document.cookie.split(';'); if (cookies.length) { cookies.forEach(function (element) { // :name&amp=xiuxiu&amp var index = element.indexOf('='), name = element.substring(0, index); // : COOkie , cookie name document.cookie = name + '=' + ';expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; }); } } } // localstorage xframe.store = (function (xframe) { // API, API var api = {}, localStorageName = 'localStorage', globalStorageName = 'globalStorage', win = window, doc = window.document, storage; // api.set = function (key, value) { } api.get = function (key) { } api.remove = function (key) { } api.clear = function () { } /* * a) sessionStorage localStorage window , Storage , :window.sessionStorage instanceof Storage True,window.localStorage instanceof Storage True, Storage 。 b) sessoinStorage , , 。 , sessionStorage , 。localStorage c) window.globalStorage Gecko 13 (Firefox 13) 。 * * */ if (localStorageName in win && win[localStorageName]) { // storage = win[localStorageName]; // /** * * @param key * @param value */ api.set = function (key, value) { storage.setItem(key, value); } /** * * @param key * @return {*} */ api.get = function (key) { return storage.getItem(key); } /** * * @param key */ api.remove = function (key) { storage.removeItem(key); } /** * */ api.clear = function () { storage.clear(); } } else if (globalStorageName in win && win[globalStorageName]) { // HTML5 localStorage globalStorgae // 1. ( Json )[Firefox ] storage = win[globalStorageName][win.location.hostname]; api.set = function (key, value) { storage[key] = value; } api.get = function (key) { return storage[key] && storage[key].value; } api.remove = function (key) { // delete 。 delete storage[key]; } api.clear = function () { for (var key in storage) { delete storage[key]; } } } else if (doc.documentElement.addBehavior) { // // storage function getStorage() { // Storage if (storage) { return storage; } storage = doc.body.appendChild(doc.createElement('div')); storage.style.display = 'none'; // userData 64KB IE storage.addBehavior('#default#userData'); // , storage.load(localStorageName); return storage; } api.set = function (key, value) { var storage = getStorage(); // storage.setAttribute(key, value); // storage.save(localStorageName); } api.get = function (key) { var storage = getStorage(); return storage.getAttribute(key); } api.remove = function (key) { var storage = getStorage(); storage.removeAttribute(key); // storage.save(localStorageName); } api.clear = function () { // 1. Storage var storage = getStorage(); // 2. storage var attributes = storage.XmlDocument.documentElement.attributes; storage.load(localStorageName); // 3. , [].slice.call(attributes).forEach(function (element) { storage.removeAttribute(element.name); }) // 4. , storage.save(localStorageName); } return api; } // ( , ) xframe.storage = api; })(xframe); })(xframe);</code></pre> <p> </p> </div> </div> </div> </div> </div> <!--PC WAP --> <div id="SOHUCS" sid="1292039545512075264"></div> <script type="text/javascript" src="/views/front/js/chanyan.js">
이 가능하다, ~할 수 있다,...
  • 자바에서 자주 사용하는 정렬 알고리즘 / 프로그래머가 반드시 파악해야 할 8대 정렬 알고리즘
    cugfy
    java
  • [Spark102] Spark 엔클로저 BlockManager 분석
    bit1129
    manager
  • linux 보기 포트가 점용된 상황 설명
    daizj
    linux 포트 사용 netstat lsof
  • Hosts 파일 사용
    주범양
    hosts locahost
  • javaexcel 도구
    g21121
    Java excel
  • 웹 보고서 도구finereport 상용 함수의 용법 요약 (수조 함수)
    A형은 괴롭히지 않는다
    finereport 웹 보고서 함수 총결산
  • 게임 서버 네트워크 대역폭 부하 계산
    담 위의 풀 한 포기.
    서버
  • 내 스프링 학습 노트 2 - IoC (역방향 제어 의존 주입)
    aijuans
    Spring 3 시리즈
  • 문자별:
    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 기타
    첫 페이지 -
    우리 -
    역내 수색 -
    Sitemap -
    권리 침해 신고
    저작권 소유 IT 기술 자료 CopyRight© 2000-2050 IT Knowledgebase IT610.com , All Rights Reserved.
    경ICP비09083238호









    좋은 웹페이지 즐겨찾기