使用 MooTools 调用 javascript 新函数

发布于 2024-12-17 05:43:56 字数 1591 浏览 2 评论 0原文

我找到了 Nivoo Slider 的 MooTools 版本(理论上)可以与我们的 MooTools 下拉菜单配合使用。但是,菜单使用的是 MooTools 1.2.x,Nivoo 使用的是 1.3.2 或 1.4.0。每次我尝试同时使用菜单和滑块时,菜单都会停止工作。

MooTools框架的版本不向后兼容吗?

另外,这些插件是否兼容,或者其中一个插件是否覆盖另一个插件?

我对 JS 的了解不够,无法纠正我的错误或重写函数调用。有这方面好的初学者教程吗?

window.addEvent('domready', function () {
    var menu = new UvumiDropdown('dropdown-demo');

    // initialize Nivoo-Slider
    new NivooSlider($('slider'), {
        directionNavHide: true,
        effect: 'wipeDown',
        interval: 1000
    });
}); 

在尝试在不兼容的情况下进行转换时,以下是我不确定如何实施的说明。

Instruction

:: 1.2 代码行

$clear => use the native clearTimeout when using fn.delay, use clearInterval when using fn.periodical.

:: $clear(a.retrieve('closeDelay'))

myFn.create => Use the according functions like .pass, .bind, .delay, .periodical

:: this.createSubmenu(this.menu)

myFn.bind(this, [arg1, arg2, arg3]) => myFn.bind(this, arg1, arg2, arg3) OR myFn.pass([arg1, arg2, arg3], this)

:: this.domReady.bind(this)

$$ now only accepts a single selector, an array or arguments of elements

:: $$(b,b.getChildren ('li')

这些指令都具有兼容性。

myElement.get('tween', options); // WRONG
myElement.set('tween', options).get('tween'); // YES, INDEED.

:: this.menu.get('tag')!='ul'

:: this.menu.getElement('ul')

I have found a MooTools version of Nivoo Slider that (in theory) will work with our MooTools dropdown menu. However, the menu is using MooTools 1.2.x, and Nivoo is using 1.3.2 or 1.4.0. Every time I try and use both the menu and the slider, the menu stops working.

Are the versions of the MooTools framework not backward compatible?

Also, are these plugins compatible or is one overriding the other?

I don't know enough about JS to correct my errors or rewrite the function call. Is there a good beginner's tutorial for this?

window.addEvent('domready', function () {
    var menu = new UvumiDropdown('dropdown-demo');

    // initialize Nivoo-Slider
    new NivooSlider($('slider'), {
        directionNavHide: true,
        effect: 'wipeDown',
        interval: 1000
    });
}); 

In trying to convert without compatibility, here are instructions that I was not sure how to implement.

Instruction

:: Line of 1.2 code

$clear => use the native clearTimeout when using fn.delay, use clearInterval when using fn.periodical.

:: $clear(a.retrieve('closeDelay'))

myFn.create => Use the according functions like .pass, .bind, .delay, .periodical

:: this.createSubmenu(this.menu)

myFn.bind(this, [arg1, arg2, arg3]) => myFn.bind(this, arg1, arg2, arg3) OR myFn.pass([arg1, arg2, arg3], this)

:: this.domReady.bind(this)

$ now only accepts a single selector, an array or arguments of elements

:: $$(b,b.getChildren('li')

These instructions are with compatibility. I'm trying both.

myElement.get('tween', options); // WRONG
myElement.set('tween', options).get('tween'); // YES, INDEED.

:: this.menu.get('tag')!='ul'

:: this.menu.getElement('ul')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

调妓 2024-12-24 05:43:56

好的,我使用 mootools 1.4.x 测试了 UvumiDropdown 最新版本,只要我包含包含 Fx.Elements 的 Mootools 更多版本,它就可以正常工作

希望这会有所帮助

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.1/mootools-yui-compressed.js"> </script>

    // MooTools: the javascript framework.
    // Load this file's selection again by visiting: http://mootools.net/more/c8813373963b6a3e9a4d4bcfe9290081 
    // Or build this file again with packager using: packager build More/Fx.Elements
    /*
    ---

    script: More.js

    name: More

    description: MooTools More

    license: MIT-style license

    authors:
      - Guillermo Rauch
      - Thomas Aylott
      - Scott Kyle
      - Arian Stolwijk
      - Tim Wienk
      - Christoph Pojer
      - Aaron Newton
      - Jacob Thornton

    requires:
      - Core/MooTools

    provides: [MooTools.More]

    ...
    */

    MooTools.More = {
        'version': '1.4.0.1',
        'build': 'a4244edf2aa97ac8a196fc96082dd35af1abab87'
    };


    /*
    ---

    script: Fx.Elements.js

    name: Fx.Elements

    description: Effect to change any number of CSS properties of any number of Elements.

    license: MIT-style license

    authors:
      - Valerio Proietti

    requires:
      - Core/Fx.CSS
      - /MooTools.More

    provides: [Fx.Elements]

    ...
    */

    Fx.Elements = new Class({

        Extends: Fx.CSS,

        initialize: function(elements, options){
            this.elements = this.subject = $(elements);
            this.parent(options);
        },

        compute: function(from, to, delta){
            var now = {};

            for (var i in from){
                var iFrom = from[i], iTo = to[i], iNow = now[i] = {};
                for (var p in iFrom) iNow[p] = this.parent(iFrom[p], iTo[p], delta);
            }

            return now;
        },

        set: function(now){
            for (var i in now){
                if (!this.elements[i]) continue;

                var iNow = now[i];
                for (var p in iNow) this.render(this.elements[i], p, iNow[p], this.options.unit);
            }

            return this;
        },

        start: function(obj){
            if (!this.check(obj)) return this;
            var from = {}, to = {};

            for (var i in obj){
                if (!this.elements[i]) continue;

                var iProps = obj[i], iFrom = from[i] = {}, iTo = to[i] = {};

                for (var p in iProps){
                    var parsed = this.prepare(this.elements[i], p, iProps[p]);
                    iFrom[p] = parsed.from;
                    iTo[p] = parsed.to;
                }
            }

            return this.parent(from, to);
        }

    });

/*
UvumiTools Dropdown Menu v1.1.2 http://uvumi.com/tools/dropdown.html

Copyright (c) 2009 Uvumi LLC

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

var UvumiDropdown = new Class({
    Implements:Options,

    options:{
        clickToOpen:false,  //if set to true,  must click to open submenues
        openDelay:150,  //if hover mode, duration the mouse must stay on target before submenu is opened. if exits before delay expires, timer is cleared 
        closeDelay:500, //delay before the submenu close when mouse exits. If mouse enter the submenu again before timer expires, it's cleared
        duration:250,   //duration in millisecond of opening/closing effect
        link:'cancel',
        transition:Fx.Transitions.linear,   //effect's transitions. See http://docs.mootools.net/Fx/Fx.Transitions for more details
        mode:'horizontal' //if set to horizontal, the top level menu will be displayed horizontally. If set to vertical, it will be displayed vertically. If it does not match any of those two words, 'horizontal' will be used.
    },

    initialize: function(menu,options){
        this.menu = menu;
        this.setOptions(options);
        if(this.options.mode != 'horizontal' && this.options.mode != 'vertical'){
            this.options.mode = 'horizontal';
        }
        //some versions of Safari and Chrome run domready before DOM is actually ready, causing wrong positioning. If you still have some display issues in those browser try to increase the delay value a bit. I tried to keep it as low as possible, but sometimes it can take a bit longer than expected
        if(Browser.Engine.webkit){
            window.addEvent('domready',this.domReady.delay(200,this));
        }else{
            window.addEvent('domready',this.domReady.bind(this));
        }
    },

    domReady:function(){
        this.menu = $(this.menu);
        if(!$defined(this.menu)){
            return false;
        }
        //if passed element is not a UL, tries to find one in the children elements
        if(this.menu.get('tag')!='ul'){
            this.menu = this.menu.getElement('ul');
            if(!$defined(this.menu)){
                return false;
            }
        }
        //handles pages written form right to left.
        if(this.menu.getStyle('direction') == 'rtl' || $(document.body).getStyle('direction') == 'rtl'){
            this.rtl = true;
            if(Browser.Engine.trident && $(document.body).getStyle('direction') == 'rtl'){
                this.menu.getParent().setStyle('direction','ltr');
                this.menu.setStyle('direction','rtl');
            }
        }
        //start setup
        this.menu.setStyles({
            visibility:'hidden',
            display:'block',
            overflow:'hidden',
            height:0,
            marginLeft:(Browser.Engine.trident?1:-1)
        });
        //we call the createSubmenu function on the main UL, which is a recursive function
        this.createSubmenu(this.menu);
        //the LIs must be floated to be displayed horisotally
        if(this.options.mode=='horizontal'){
            this.menu.getChildren('li').setStyles({
                'float':(this.rtl?'right':'left'),
                display:'block',
                top:0
            });

            //We create an extar LI which role will be to clear the floats of the others
            var clear = new Element('li',{
                html:" ",
                styles:{
                    clear:(this.rtl?'right':'left'),
                    display:(Browser.Engine.trident?'inline':'block'), //took me forever to find that fix
                    position:'relative',
                    top:0,
                    height:0,
                    width:0,
                    fontSize:0,
                    lineHeight:0,
                    margin:0,
                    padding:0
                }
            }).inject(this.menu);
        }else{
            this.menu.getChildren('li').setStyles({
                display:'block',
                top:0
            });
        }
        this.menu.setStyles({
            height:'auto',
            overflow:'visible',
            visibility:'visible'
        });
        //hack for IE, again
        this.menu.getElements('a').setStyle('display',(Browser.Engine.trident?'inline-block':'block'));
    },

    createSubmenu:function(ul){
        //we collect all the LI of the ul
        var LIs = ul.getChildren('li');
        var offset = 0;
        //loop through the LIs
        LIs.each(function(li){
            li.setStyles({
                position:'relative',
                display:'block',
                top:-offset,
                zIndex:1
            });
            offset += li.getSize().y;
            var innerUl = li.getFirst('ul');
            //if the current LI contains a UL
            if($defined(innerUl)){
                ul.getElements('ul').setStyle('display','none');
                //if the current UL is the main one, that means we are still in the top row, and the submenu must drop down
                if(ul == this.menu && this.options.mode == 'horizontal'){
                    li.addClass('submenu-down');
                    var x = 0;
                    var y = li.getSize().y;
                    this.options.link='cancel';
                    li.store('animation',new Fx.Elements($(innerUl,innerUl.getChildren('li')).setStyle('opacity',0),this.options));
                //if the current UL is not the main one, the sub menu must pop from the side
                }else{
                    li.addClass('submenu-left');
                    var x = li.getSize().x-(this.rtl&&!Browser.Engine.trident?2:1)*li.getStyle('border-left-width').toInt();
                    var y = -li.getStyle('border-bottom-width').toInt();
                    this.options.link='chain';
                    li.store('animation',new Fx.Elements($(innerUl,innerUl.getChildren('li')).setStyle('opacity',0),this.options));
                    offset=li.getSize().y+li.getPosition(this.menu).y;
                }
                innerUl.setStyles({
                    position:'absolute',
                    top:y,
                    opacity:0
                });
                ul.getElements('ul').setStyle('display','block');
                if(this.rtl){
                    innerUl.setStyles({
                        right:x,
                        marginRight:-x
                    });
                }else{
                    innerUl.setStyles({
                        left:x,
                        marginLeft:-x
                    });
                }
                //we call the createsubmenu function again, on the new UL
                this.createSubmenu(innerUl);
                //apply events to make the submenu appears when hovering the LI
                if(this.options.clickToOpen){
                    li.addEvent('mouseenter',function(){
                            $clear(li.retrieve('closeDelay'));
                        }.bind(this)
                    );
                    li.getFirst('a').addEvent('click',function(e){
                        e.stop();
                        $clear(li.retrieve('closeDelay'));
                        this.showChildList(li);
                    }.bind(this));
                }else{
                    li.addEvent('mouseenter',function(){
                        $clear(li.retrieve('closeDelay'));
                        li.store('openDelay',this.showChildList.delay(this.options.openDelay,this,li));
                    }.bind(this));
                }
                li.addEvent('mouseleave', function(){
                    $clear(li.retrieve('openDelay'));
                    li.store('closeDelay',this.hideChildList.delay(this.options.closeDelay,this,li));
                }.bind(this));
            }
        },this);
    },

    //display submenu
    showChildList:function(li){
        var ul = li.getFirst('ul');
        var LIs =  $(ul.getChildren('li'));
        var animation = li.retrieve('animation');
        //if the parent menu is not the main menu, the submenu must pop from the side
        if(li.getParent('ul')!=this.menu || this.options.mode == 'vertical'){
            animation.cancel();
            var anim ={
                0:{
                    opacity:1
                },
                1:{
                    opacity:1
                }
            };
            if(this.rtl){
                anim[0]['marginRight'] = 0;
            }else{
                anim[0]['marginLeft'] = 0;
            }
            animation.start(anim);
            var animobject={};
        //if the parent menu us the main menu, the submenu must drop down
        }else{
            var animobject = {0:{opacity:1}};
        }
        LIs.each(function(innerli,i){
            animobject[i+1]={
                top:0,
                opacity:1
            };
        });
        li.setStyle('z-index',99);
        animation.start(animobject);
    },

    //hide the menu
    hideChildList:function(li){
        var animation = li.retrieve('animation');
        var ul = li.getFirst('ul');
        var LIs =  $(ul.getChildren('li'));
        var offset = 0;
        var animobject={};
        LIs.each(function(innerli,i){
            animobject[i+1]={
                top:-offset,
                opacity:0
            };
            offset += innerli.getSize().y;
        });
        li.setStyle('z-index',1);
        //if the parent menu is not the main menu, the submenu must fold up, and go to the left
        if(li.getParent('ul')!=this.menu || this.options.mode == 'vertical'){
            animobject[1]=null;
            animation.cancel();
            animation.start(animobject);
            var anim = {
                0:{
                    opacity:0
                },
                1:{
                    opacity:0
                }
            };

            if(this.rtl){
                anim[0]['marginRight'] = -ul.getSize().x;
            }else{
                anim[0]['marginLeft'] = -ul.getSize().x;
            }
            animation.start(anim);
        //if the parent menu is the main menu, the submenu must just fold up
        }else{
            animobject[0]={opacity:0};
            animation.start(animobject);
        }
    }
});

OK I tested the UvumiDropdown latest build with mootools 1.4.x and it worked fine as long as I included a Mootools more build that includes Fx.Elements

Hope this helps

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.1/mootools-yui-compressed.js"> </script>

    // MooTools: the javascript framework.
    // Load this file's selection again by visiting: http://mootools.net/more/c8813373963b6a3e9a4d4bcfe9290081 
    // Or build this file again with packager using: packager build More/Fx.Elements
    /*
    ---

    script: More.js

    name: More

    description: MooTools More

    license: MIT-style license

    authors:
      - Guillermo Rauch
      - Thomas Aylott
      - Scott Kyle
      - Arian Stolwijk
      - Tim Wienk
      - Christoph Pojer
      - Aaron Newton
      - Jacob Thornton

    requires:
      - Core/MooTools

    provides: [MooTools.More]

    ...
    */

    MooTools.More = {
        'version': '1.4.0.1',
        'build': 'a4244edf2aa97ac8a196fc96082dd35af1abab87'
    };


    /*
    ---

    script: Fx.Elements.js

    name: Fx.Elements

    description: Effect to change any number of CSS properties of any number of Elements.

    license: MIT-style license

    authors:
      - Valerio Proietti

    requires:
      - Core/Fx.CSS
      - /MooTools.More

    provides: [Fx.Elements]

    ...
    */

    Fx.Elements = new Class({

        Extends: Fx.CSS,

        initialize: function(elements, options){
            this.elements = this.subject = $(elements);
            this.parent(options);
        },

        compute: function(from, to, delta){
            var now = {};

            for (var i in from){
                var iFrom = from[i], iTo = to[i], iNow = now[i] = {};
                for (var p in iFrom) iNow[p] = this.parent(iFrom[p], iTo[p], delta);
            }

            return now;
        },

        set: function(now){
            for (var i in now){
                if (!this.elements[i]) continue;

                var iNow = now[i];
                for (var p in iNow) this.render(this.elements[i], p, iNow[p], this.options.unit);
            }

            return this;
        },

        start: function(obj){
            if (!this.check(obj)) return this;
            var from = {}, to = {};

            for (var i in obj){
                if (!this.elements[i]) continue;

                var iProps = obj[i], iFrom = from[i] = {}, iTo = to[i] = {};

                for (var p in iProps){
                    var parsed = this.prepare(this.elements[i], p, iProps[p]);
                    iFrom[p] = parsed.from;
                    iTo[p] = parsed.to;
                }
            }

            return this.parent(from, to);
        }

    });

/*
UvumiTools Dropdown Menu v1.1.2 http://uvumi.com/tools/dropdown.html

Copyright (c) 2009 Uvumi LLC

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

var UvumiDropdown = new Class({
    Implements:Options,

    options:{
        clickToOpen:false,  //if set to true,  must click to open submenues
        openDelay:150,  //if hover mode, duration the mouse must stay on target before submenu is opened. if exits before delay expires, timer is cleared 
        closeDelay:500, //delay before the submenu close when mouse exits. If mouse enter the submenu again before timer expires, it's cleared
        duration:250,   //duration in millisecond of opening/closing effect
        link:'cancel',
        transition:Fx.Transitions.linear,   //effect's transitions. See http://docs.mootools.net/Fx/Fx.Transitions for more details
        mode:'horizontal' //if set to horizontal, the top level menu will be displayed horizontally. If set to vertical, it will be displayed vertically. If it does not match any of those two words, 'horizontal' will be used.
    },

    initialize: function(menu,options){
        this.menu = menu;
        this.setOptions(options);
        if(this.options.mode != 'horizontal' && this.options.mode != 'vertical'){
            this.options.mode = 'horizontal';
        }
        //some versions of Safari and Chrome run domready before DOM is actually ready, causing wrong positioning. If you still have some display issues in those browser try to increase the delay value a bit. I tried to keep it as low as possible, but sometimes it can take a bit longer than expected
        if(Browser.Engine.webkit){
            window.addEvent('domready',this.domReady.delay(200,this));
        }else{
            window.addEvent('domready',this.domReady.bind(this));
        }
    },

    domReady:function(){
        this.menu = $(this.menu);
        if(!$defined(this.menu)){
            return false;
        }
        //if passed element is not a UL, tries to find one in the children elements
        if(this.menu.get('tag')!='ul'){
            this.menu = this.menu.getElement('ul');
            if(!$defined(this.menu)){
                return false;
            }
        }
        //handles pages written form right to left.
        if(this.menu.getStyle('direction') == 'rtl' || $(document.body).getStyle('direction') == 'rtl'){
            this.rtl = true;
            if(Browser.Engine.trident && $(document.body).getStyle('direction') == 'rtl'){
                this.menu.getParent().setStyle('direction','ltr');
                this.menu.setStyle('direction','rtl');
            }
        }
        //start setup
        this.menu.setStyles({
            visibility:'hidden',
            display:'block',
            overflow:'hidden',
            height:0,
            marginLeft:(Browser.Engine.trident?1:-1)
        });
        //we call the createSubmenu function on the main UL, which is a recursive function
        this.createSubmenu(this.menu);
        //the LIs must be floated to be displayed horisotally
        if(this.options.mode=='horizontal'){
            this.menu.getChildren('li').setStyles({
                'float':(this.rtl?'right':'left'),
                display:'block',
                top:0
            });

            //We create an extar LI which role will be to clear the floats of the others
            var clear = new Element('li',{
                html:" ",
                styles:{
                    clear:(this.rtl?'right':'left'),
                    display:(Browser.Engine.trident?'inline':'block'), //took me forever to find that fix
                    position:'relative',
                    top:0,
                    height:0,
                    width:0,
                    fontSize:0,
                    lineHeight:0,
                    margin:0,
                    padding:0
                }
            }).inject(this.menu);
        }else{
            this.menu.getChildren('li').setStyles({
                display:'block',
                top:0
            });
        }
        this.menu.setStyles({
            height:'auto',
            overflow:'visible',
            visibility:'visible'
        });
        //hack for IE, again
        this.menu.getElements('a').setStyle('display',(Browser.Engine.trident?'inline-block':'block'));
    },

    createSubmenu:function(ul){
        //we collect all the LI of the ul
        var LIs = ul.getChildren('li');
        var offset = 0;
        //loop through the LIs
        LIs.each(function(li){
            li.setStyles({
                position:'relative',
                display:'block',
                top:-offset,
                zIndex:1
            });
            offset += li.getSize().y;
            var innerUl = li.getFirst('ul');
            //if the current LI contains a UL
            if($defined(innerUl)){
                ul.getElements('ul').setStyle('display','none');
                //if the current UL is the main one, that means we are still in the top row, and the submenu must drop down
                if(ul == this.menu && this.options.mode == 'horizontal'){
                    li.addClass('submenu-down');
                    var x = 0;
                    var y = li.getSize().y;
                    this.options.link='cancel';
                    li.store('animation',new Fx.Elements($(innerUl,innerUl.getChildren('li')).setStyle('opacity',0),this.options));
                //if the current UL is not the main one, the sub menu must pop from the side
                }else{
                    li.addClass('submenu-left');
                    var x = li.getSize().x-(this.rtl&&!Browser.Engine.trident?2:1)*li.getStyle('border-left-width').toInt();
                    var y = -li.getStyle('border-bottom-width').toInt();
                    this.options.link='chain';
                    li.store('animation',new Fx.Elements($(innerUl,innerUl.getChildren('li')).setStyle('opacity',0),this.options));
                    offset=li.getSize().y+li.getPosition(this.menu).y;
                }
                innerUl.setStyles({
                    position:'absolute',
                    top:y,
                    opacity:0
                });
                ul.getElements('ul').setStyle('display','block');
                if(this.rtl){
                    innerUl.setStyles({
                        right:x,
                        marginRight:-x
                    });
                }else{
                    innerUl.setStyles({
                        left:x,
                        marginLeft:-x
                    });
                }
                //we call the createsubmenu function again, on the new UL
                this.createSubmenu(innerUl);
                //apply events to make the submenu appears when hovering the LI
                if(this.options.clickToOpen){
                    li.addEvent('mouseenter',function(){
                            $clear(li.retrieve('closeDelay'));
                        }.bind(this)
                    );
                    li.getFirst('a').addEvent('click',function(e){
                        e.stop();
                        $clear(li.retrieve('closeDelay'));
                        this.showChildList(li);
                    }.bind(this));
                }else{
                    li.addEvent('mouseenter',function(){
                        $clear(li.retrieve('closeDelay'));
                        li.store('openDelay',this.showChildList.delay(this.options.openDelay,this,li));
                    }.bind(this));
                }
                li.addEvent('mouseleave', function(){
                    $clear(li.retrieve('openDelay'));
                    li.store('closeDelay',this.hideChildList.delay(this.options.closeDelay,this,li));
                }.bind(this));
            }
        },this);
    },

    //display submenu
    showChildList:function(li){
        var ul = li.getFirst('ul');
        var LIs =  $(ul.getChildren('li'));
        var animation = li.retrieve('animation');
        //if the parent menu is not the main menu, the submenu must pop from the side
        if(li.getParent('ul')!=this.menu || this.options.mode == 'vertical'){
            animation.cancel();
            var anim ={
                0:{
                    opacity:1
                },
                1:{
                    opacity:1
                }
            };
            if(this.rtl){
                anim[0]['marginRight'] = 0;
            }else{
                anim[0]['marginLeft'] = 0;
            }
            animation.start(anim);
            var animobject={};
        //if the parent menu us the main menu, the submenu must drop down
        }else{
            var animobject = {0:{opacity:1}};
        }
        LIs.each(function(innerli,i){
            animobject[i+1]={
                top:0,
                opacity:1
            };
        });
        li.setStyle('z-index',99);
        animation.start(animobject);
    },

    //hide the menu
    hideChildList:function(li){
        var animation = li.retrieve('animation');
        var ul = li.getFirst('ul');
        var LIs =  $(ul.getChildren('li'));
        var offset = 0;
        var animobject={};
        LIs.each(function(innerli,i){
            animobject[i+1]={
                top:-offset,
                opacity:0
            };
            offset += innerli.getSize().y;
        });
        li.setStyle('z-index',1);
        //if the parent menu is not the main menu, the submenu must fold up, and go to the left
        if(li.getParent('ul')!=this.menu || this.options.mode == 'vertical'){
            animobject[1]=null;
            animation.cancel();
            animation.start(animobject);
            var anim = {
                0:{
                    opacity:0
                },
                1:{
                    opacity:0
                }
            };

            if(this.rtl){
                anim[0]['marginRight'] = -ul.getSize().x;
            }else{
                anim[0]['marginLeft'] = -ul.getSize().x;
            }
            animation.start(anim);
        //if the parent menu is the main menu, the submenu must just fold up
        }else{
            animobject[0]={opacity:0};
            animation.start(animobject);
        }
    }
});
給妳壹絲溫柔 2024-12-24 05:43:56

MooTools 遵循 SemVer(语义版本控制),这意味着次版本号 (x.Y. z) 凹凸保证向后兼容(并且通常不保证向后兼容)。

但是,新版本带有兼容层。如果您确实无法升级代码,只需勾选 MooTools Core builder 上的框即可。但您应该避免这样做,这对性能和潜在的前向兼容性不利。

至于教程,了解如何将代码从一个版本升级到另一个版本的最佳方法是阅读 1.3 的变更日志,了解与 1.2 的差异,以及 从 1.3 到 1.4 如果您想升级到最新版本。根据这些知识,重写所有使用过时 API 的调用。

乍一看,这似乎是一项艰巨的任务,但通常进展得很快(实际上,在这种情况下,最常见的是重写 Hash 引用和 .each 调用) 。如果您正在学习 JS,这可能会很困难,但这绝对会是一次非常有益的 JS 体验,尤其是在 MooTools 中,因为您将了解是什么让代码变得“Mooish”:)

MooTools follows SemVer (Semantic Versioning), meaning that a minor version number (x.Y.z) bump is not guaranteed to be backward-compatible (and is usually not).

However, new versions come with a compatibility layer. Just tick the box on the MooTools Core builder if you really can't upgrade your code. You should though avoid to do such a thing, it is bad for performance and potentially forward-compatibility.

As for a tutorial, the best way to learn how to upgrade code from one version to the other is to read the changelog of the 1.3 to learn about the differences with 1.2, and from the 1.3 to the 1.4 if you want to upgrade to the latest version. From this knowledge, rewrite all calls that make use of outdated APIs.

It looks like a daunting task at first, but it usually goes very quickly (actually, in this precise case, it is most often about rewriting Hash references and .each calls). It might be hard if you're learning JS, but it will definitely be a very rewarding experience in JS, and especially in MooTools, as you'll learn about what makes a code ”Mooish” :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文