Giter Site home page Giter Site logo

fookie's People

Watchers

 avatar

fookie's Issues

建议更改部分代码

你好,
刚用了Fookie,运行的非常好,在你的基础上对JS代码做了些改动,
代码如下,简单测试了一下,
几大浏览器跑的比较稳定.

Fookie = (function(){
    var swf, 
        swfUrl = "",
        swfId = "fookie_swf_" + Math.round(Math.random() * 100),
        _self;

    function _waitSwfReady(){
        swf = document[ swfId ] || window[ swfId ];

        if (swf) {
            if (_self.onready) 
                _self.onready.call(_self);
        }else
            setTimeout( arguments.callee, 13 );
    }   

    function _writeSwf(){
        // width = height = 1px
        var a = ['<object id="', swfId, '" classid="clsid:D27CDB6E-AE6D-
11cf-96B8-444553540000" 
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.c
ab#version=7,0,19,0" width="1" height="1">', '<param name="movie" 
value="', swfUrl, '" />', '<param name="quality" value="high" />', '<param 
name="allowscriptaccess" value="samedomain" />', '<embed name="', 
swfId, '" src="', swfUrl, '" allowscriptaccess="samedomain" quality="high" 
pluginspage="http://www.macromedia.com/go/getflashplayer" 
type="application/x-shockwave-flash" width="1" 
height="1"></embed>', "</object>"].join(""),
            ct = document.createElement("div"),
            style = {
                display : "block",
                border  : "none",
                width   : "1px",
                height  : "1px",
                overflow: "hidden"
            };

        for (var m in style) {
            ct.style[m] = style[m];
        }
        //wait for body tag
        (function(){
            if ( document.body ){
                document.body.insertBefore( ct, 
document.body.firstChild );
                ct.innerHTML = a;

                _waitSwfReady();                
            }else
                setTimeout( arguments.callee, 13 )
        })()
    }

    function doAction( method, config, name, value ){
        if ( !swf || !swf[method] )
            return;

        config = config || {};  
        var a = config.application || _self.application,
            p = config.path || _self.path,
            e = config.expires || _self.expires,
            s = config.secure ? true : _self.secure;
        //reset arguments
        var args = [];

        if ( name )
            args.push( name );
        if( value )
            args.push( value ); 

        args.push( a, p );
        //特殊处理
        method == "write" ? args.push( e, s ) : args.push( s );
        if ( method == "clear" ) method = "remove";

        try {
            return swf[ method ].apply( swf, args );
        } catch (e) {
//          alert( "error : " + e.toString() )
        }
    }

    return {
        application : "fookie_data",
        path        : "/",
        expires     : 1000,
        secure      : false,

        init    : function( url, config ){
            _self = this;

            if ( url )
                swfUrl = url;

            for( var c in config || {} )
                this[ c ] = config[ c ];

            //0,1,2表示 该方法拥有几个有效参数         
            var methods = {
                read  : 1,
                write : 2,
                remove: 1,
                clear : 0
            };
            for( var m in methods )
                (function(){
                    var name = m, num = methods[ 
name ];
                    _self[ name ] = function(){
                        //截取有效参数
                        var args = 
Array.prototype.slice.call(arguments, 0, num + 1);
                        //在数组头添加 方法名与配置
项
                        args.unshift(name, 
arguments[ num ] );

                        return doAction.apply( 
null, args )
                    }
                })();

            //加载swf
            _writeSwf();

            return this;    
        }
    }
})();

Original issue reported on code.google.com by [email protected] on 15 Aug 2009 at 3:22

Attachments:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.