Comments (16)
@lenamtl
I'm not planning to this in near future.
from metismenu.
+1
from metismenu.
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.
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.
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.
Great feature added ;) thanks
from metismenu.
@valgen thanks for the great feature.
@onokumus please add this to your release.
from metismenu.
@valgen Thanks! Works great.
from metismenu.
Thanks
from metismenu.
Works great. Why it's not in master?
from metismenu.
I would like to see this in master perhaps 2.0.1 ASAP
from metismenu.
+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.
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.
Any change someone can add the feature to "find" the current selected item by location/url rather than with cookies?
Thanks!
from metismenu.
how to use this plugin?
from metismenu.
Any update?
from metismenu.
Related Issues (20)
- Version v3 not work in IE11 HOT 3
- htmlelement type for menu element HOT 1
- 3.0.0-beta vs 3.0.3 HOT 2
- vue 中如何使用
- Problem with last version 3.0.4 HOT 13
- Clicking a link prevent navigate to the page HOT 5
- The opened < ul> element not collapse on click the <li> which do not have child <ul>.and also want to add active class to the <li> to those which do not have child<ul>
- Add SCSS styles
- Not Workin HOT 1
- Second click on item removes mm-active class HOT 3
- Scroll to link if the link is active and out of screen HOT 2
- Laravel 7.x SCSS compile error
- demo website 404 HOT 1
- .has-arrow::after arrow icon is not aligned correctly
- error - TypeError: this is undefined 'r'
- Yet another TypeError: $(...).metisMenu is not a function
- MetisMenu highlighting all the links if anchor tag links doesnt end with .html
- Is about multiple init air datepicker
- Flash menu on page reload fix HOT 1
- How to render a divider/separator ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metismenu.