Hi all,
the following is my first plug-in.

I've got the code from a web site I liked and then I modified it. As a result it is not my real code, however I applied a lot of changes including the get and set methods...

There are several things I don't like within it.

1) First of all, is there any other way in order to call my methods rather than

$.Slider.NameOfMyMethod?


2) Why inside the function init() I am able to set
    var obj = $.Slider.getObjIsMenuAnimated();
but I can't define sl =
$.Slider.getSlideMenu(); // it doesn't work
    the only way is to define 
var sl =  $( "#slideMenu" );

3) is there another way to get the variable value without creating get and set methods?

Many thanks
JH





<here the script>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var menuContainer = $( "#menuContainer" );
var slideMenu = $( "#slideMenu" );
var menuPosition = {Min: "0px",Max: "-49px"};
var timerMouseOut = null;
var objIsMenuAnimated = {Show: false,Hide: false};


jQuery.Slider = {
    getMenuContainer: function(){
        var c = menuContainer;
        return c;
    },
    getSlideMenu: function(){
        var s = slideMenu;
        return s;
    },
    getMenuPosition: function(){
        var obj = menuPosition;
        return obj;
    },
    getTimerMouseOut:function(){
        //tM = null;
        var t = timerMouseOut;
        return t;
    },
    setTimerMouseOut:function(time){
        //tM = null;
        timerMouseOut = time;
    },
    getObjIsMenuAnimated: function(){
        var o = objIsMenuAnimated;
        return o;
    },
    setObjIsMenuAnimated: function(p1,p2){
        objIsMenuAnimated = {Show: p1,Hide: p2};
    },
   
    init: function() {
        var mc = $.Slider.getMenuContainer();
        var slm = $( "#slideMenu" );
       

        $( [] ).add( mc ).add( slm ).mouseover(
            function(){$.Slider.ManageShowMenu();
                return( false );
            }
        );
       
        $( [] ).add( mc ).add( slm ).mouseout(
            function(){$.Slider.ManageHideMenu();
                return( false );
            }
        );
    },
    ManageShowMenu: function() {
        clearTimeout($.Slider.getTimerMouseOut());
        $.Slider.ShowMenu();
    },
    ManageHideMenu: function() {
        $.Slider.setTimerMouseOut(
            setTimeout(
                function(){
                    $.Slider.HideMenu();
                },
                100
            )
        );
    },
    ShowMenu: function() {
        var obj = $.Slider.getObjIsMenuAnimated();
        var sl =  $( "#slideMenu" );
        if (!obj.Show || obj.Hide){
                if (obj.Hide){
                    sl.stop();
                }
                $.Slider.setObjIsMenuAnimated(true,false);
                sl.animate(
                    {
                        bottom: menuPosition.Max
                    },
                    {
                        duration: 100,
                        complete: function(){
                            $.Slider.setObjIsMenuAnimated(false,false);
                        }
                    }
                );
            }
        },
    HideMenu: function() {
        var sl =  $( "#slideMenu" );
       
        $.Slider.setObjIsMenuAnimated(false,true);
        sl.animate(
                {
                    bottom: menuPosition.Min
                },
                {
                    duration: 500,
                    complete: function(){
                        $.Slider.setObjIsMenuAnimated(false,false);
                    }
                }
        ).fadeTo( 9, 9 );
    }
   
};



jakiri hutimora ha scritto:

Hi everybody,

I have solved the problem here illustrated  "call a method outside a jquery object"

with a different approach.

I just defined a plug-in function and I have called the "public method" from autside using the following syntax

$.myPluginName.myMethod();


I am not sure it is an elegant solution,
any advice is welcomed.

regards




--------------------------------------------------------------------------------------

jakiri hutimora ha scritto:
Hi Matt, otherwise the script doesn't work. :/








I didn't write the function, however the script is something similar to this
$(
        function(){
                function openMenu(){
                        doSomething(x);
                }
                function closeMenu(){
                        doSomething(x);
                }

        }
);



Matt Kruse ha scritto:
On Jun 26, 12:44 pm, jakiri hutimora <jakirihutim...@gmail.com> wrote:
  
Actually I really need to access to a method inside another function.
$(
        function(){
                function openMenu(){
                        doSomething(x);
                }
                function closeMenu(){
                        doSomething(x);
                }

        }
);
    

Why are you defining these functions inside $()? Just define them
outside of $() and they will be global.

function openMenu(){
   doSomething(x);
}
function closeMenu(){
   doSomething(x);
}
$(openMenu);

If you want a function to be available outside of the function scope
that is currently executing, then define it outside.

Matt Kruse

  

Reply via email to