Giter VIP home page Giter VIP logo

Comments (16)

onokumus avatar onokumus commented on May 25, 2024 7

@lenamtl
I'm not planning to this in near future.

from metismenu.

amastaneh avatar amastaneh commented on May 25, 2024 2

+1

from metismenu.

valgen avatar valgen commented on May 25, 2024

I have added a basic cookie support as I needed it for my open source CMS (http://www.mvcwcms.com).

If you have more than one menu in a single page you need to specify the cookieName attribute as in the following example:

        $('#menu').metisMenu({
            cookieName: "MetisMenuState1"
        });
        $('#menu2').metisMenu({
            toggle: false,
            cookieName: "MetisMenuState2"
        });

This is the modified plugin:

;(function ($, window, document, undefined) {

    var pluginName = "metisMenu",
        defaults = {
            toggle: true,
            cookieName: "MetisMenuState"
        };

    function Plugin(element, options) {
        this.element = element;
        this.settings = $.extend({}, defaults, options);
        this._defaults = defaults;
        this._name = pluginName;
        this.init();
    }

    Plugin.prototype = {
        init: function () {

            var $this = $(this.element),
                $toggle = this.settings.toggle,
                $cookieName = this.settings.cookieName;

            //Restores the menu state from cookies
            var documentCookie = document.cookie;
            $this.find('li').has('ul').each(function (i) {
                var pos = documentCookie.indexOf($cookieName + "_" + i + "=");
                if (pos > -1) {
                    documentCookie.substr(pos).split('=')[1].indexOf('false') ? $(this).addClass('active') : $(this).removeClass('active');
                }
            });

            if (this.isIE() <= 9) {
                $this.find('li.active').has('ul').children('ul').collapse('show');
                $this.find('li').not('.active').has('ul').children('ul').collapse('hide');
            } else {
                $this.find('li.active').has('ul').children('ul').addClass('collapse in');
                $this.find('li').not('.active').has('ul').children('ul').addClass('collapse');
            }

            $this.find('li').has('ul').children('a').on('click', function (e) {
                e.preventDefault();

                $(this).parent('li').toggleClass('active').children('ul').collapse('toggle');

                if ($toggle) {
                    $(this).parent('li').siblings().removeClass('active').children('ul.in').collapse('hide');
                }

                //Stores the menu state in cookies
                $this.find('li').has('ul').each(function (i) {
                    document.cookie = $cookieName + "_" + i + "=" + $(this).hasClass('active');
                });
            });
        },

        isIE: function() {//https://gist.github.com/padolsey/527683
            var undef,
                v = 3,
                div = document.createElement('div'),
                all = div.getElementsByTagName('i');

            while (
                div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
                all[0]
            );
            return v > 4 ? v : undef;
        }
    };

    $.fn[ pluginName ] = function (options) {
        return this.each(function () {
            if (!$.data(this, "plugin_" + pluginName)) {
                $.data(this, "plugin_" + pluginName, new Plugin(this, options));
            }
        });
    };

})(jQuery, window, document);

from metismenu.

zaki1 avatar zaki1 commented on May 25, 2024

I have two or more menus as below :

And as you suggested I am giving each menu an id and passing a cookie name :

 
        (function ($) {
         $('#artistMenu').metisMenu({
                cookieName: "MetisMenuState1"
            });
            $('#lyricsMenu').metisMenu({
                toggle: false,
                cookieName: "MetisMenuState2"
            });
        })(jQuery);

But when I click on "Add Artist" sub menu the first time it is fine, then open "Manage lyrics" and click on "All lyrics" the view changes but menu would be still "Add Lyrics"...if I click once more it seems to be fine..any solutions?

from metismenu.

valgen avatar valgen commented on May 25, 2024

I have fixed the above issue by adding a cookie expiration.

Change has been submitted here: https://github.com/onokumus/metisMenu/pull/10/files

Now you can also specify the cookieExpiration (number of days) that by default is 1.

from metismenu.

mwinandy avatar mwinandy commented on May 25, 2024

Great feature added ;) thanks

from metismenu.

rygel avatar rygel commented on May 25, 2024

@valgen thanks for the great feature.
@onokumus please add this to your release.

from metismenu.

FreeAsInBeer avatar FreeAsInBeer commented on May 25, 2024

@valgen Thanks! Works great.

from metismenu.

lenamtl avatar lenamtl commented on May 25, 2024

Thanks

from metismenu.

imshenitsky avatar imshenitsky commented on May 25, 2024

Works great. Why it's not in master?

from metismenu.

mteichtahl avatar mteichtahl commented on May 25, 2024

I would like to see this in master perhaps 2.0.1 ASAP

from metismenu.

lenamtl avatar lenamtl commented on May 25, 2024

+1 Yes please add it to the latest version.

I'm trying to use this code with the actual JS code but the JS code is different, anyone have done the modification yet?

from metismenu.

mteichtahl avatar mteichtahl commented on May 25, 2024

You will need to patch this manually.

Sent from my iPhone

On 6 May 2015, at 05:04, lenamtl [email protected] wrote:

+1 Yes please add it to the latest version.

I'm trying to use this code with the actual JS code but the JS code is different, anyone have done the modification yet?


Reply to this email directly or view it on GitHub.

from metismenu.

Webkungen avatar Webkungen commented on May 25, 2024

Any change someone can add the feature to "find" the current selected item by location/url rather than with cookies?

Thanks!

from metismenu.

3xxx avatar 3xxx commented on May 25, 2024

how to use this plugin?

from metismenu.

esfomeado avatar esfomeado commented on May 25, 2024

Any update?

from metismenu.

Related Issues (20)

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.