Skip to content

Commit 9d26d2f

Browse files
committed
Code Cleanup
1 parent cde5d43 commit 9d26d2f

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

src/jquery.navgoco.js

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery Navgoco Menus Plugin v0.1.0 (2013-07-07)
2+
* jQuery Navgoco Menus Plugin v0.1.1 (2013-07-08)
33
* https://github.com/tefra/navgoco
44
*
55
* Copyright (c) 2013 Chris T
@@ -82,27 +82,6 @@
8282
this.open[idx] = 0;
8383
}
8484
},
85-
toggle: function(flag) {
86-
var self = this;
87-
var list = Array.prototype.slice.call(arguments, 1);
88-
var only = {};
89-
90-
for (var i = 0; i < list.length; i++) {
91-
only[list[i]] = true;
92-
}
93-
94-
self.$el.find('ul').each(function() {
95-
var sub = $(this);
96-
var idx = sub.attr('data-index');
97-
if (!only.length || only.hasOwnProperty(idx)) {
98-
self._toggle(sub, flag);
99-
if (only.length === 1) {
100-
return false;
101-
}
102-
}
103-
});
104-
self._save();
105-
},
10685
_save: function() {
10786
if (this.options.save) {
10887
var save = {};
@@ -124,6 +103,32 @@
124103
this.open = cookie.hasOwnProperty(this.uuid) ? cookie[this.uuid] : {};
125104
}
126105
},
106+
toggle: function(open) {
107+
var self = this;
108+
var list = {};
109+
var args = Array.prototype.slice.call(arguments, 1);
110+
var length = args.length;
111+
112+
for (var i = 0; i < length; i++) {
113+
list[args[i]] = true;
114+
}
115+
116+
self.$el.find('ul').each(function() {
117+
var sub = $(this);
118+
var idx = sub.attr('data-index');
119+
if (length === 0 || list.hasOwnProperty(idx)) {
120+
self._toggle(sub, open);
121+
if (length === 1) {
122+
return false;
123+
}
124+
}
125+
});
126+
self._save();
127+
},
128+
destroy: function() {
129+
$.removeData(this.$el);
130+
this.$el.find("li:has(ul) > a").unbind('click');
131+
}
127132
};
128133

129134
var cookie = null;
@@ -134,7 +139,7 @@
134139
save: true,
135140
cookie: {
136141
name: 'navgoco',
137-
expires: false,
142+
expires: 0,
138143
path: '/'
139144
},
140145
slide: {
@@ -144,8 +149,8 @@
144149
};
145150

146151
$.fn.navgoco = function(options) {
147-
var method = (typeof options === 'string' && options.charAt(0) !== '_');
148-
if (method) {
152+
if (typeof options === 'string' && options.charAt(0) !== '_' && options !== 'init') {
153+
var callback = true;
149154
var args = Array.prototype.slice.call(arguments, 1);
150155
} else {
151156
options = $.extend({}, defaults, options || {});
@@ -156,10 +161,12 @@
156161
return this.each(function(idx) {
157162
var $this = $(this);
158163
var obj = $this.data('navgoco');
159-
if (method && obj) {
164+
if (!obj) {
165+
obj = new Plugin(this, callback ? defaults : options, idx);
166+
$this.data('navgoco', obj);
167+
}
168+
if (callback) {
160169
obj[options].apply(obj, args);
161-
} else if (!obj && !method) {
162-
$this.data('navgoco', new Plugin(this, options, idx));
163170
}
164171
});
165172
};

src/jquery.navgoco.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)