/** * jquery.dlmenu.js v1.0.1 * http://www.codrops.com * * licensed under the mit license. * http://www.opensource.org/licenses/mit-license.php * * copyright 2013, codrops * http://www.codrops.com */ (function(e, t, n) { "use strict"; var r = t.modernizr, i = e("body"); e.dlmenu = function(t, n) { this.$el = e(n); this._init(t) }; e.dlmenu.defaults = { animationclasses: { classin: "dl-animate-in-1", classout: "dl-animate-out-1" }, onlevelclick: function(e, t) { return false }, onlinkclick: function(e, t) { return false } }; e.dlmenu.prototype = { _init: function(t) { this.options = e.extend(true, {}, e.dlmenu.defaults, t); this._config(); var n = { webkitanimation: "webkitanimationend", oanimation: "oanimationend", msanimation: "msanimationend", animation: "animationend" }, i = { webkittransition: "webkittransitionend", moztransition: "transitionend", otransition: "otransitionend", mstransition: "mstransitionend", transition: "transitionend" }; this.animendeventname = n[r.prefixed("animation")] + ".dlmenu"; this.transendeventname = i[r.prefixed("transition")] + ".dlmenu", this.supportanimations = r.cssanimations, this.supporttransitions = r.csstransitions; this._initevents() }, _config: function() { this.open = false; this.$trigger = this.$el.children(".dl-trigger"); this.$menu = this.$el.children("ul.dl-menu"); this.$menuitems = this.$menu.find("li:not(.dl-back)"); this.$el.find("ul.dl-submenu").prepend('
  • 返回上一级
  • '); this.$back = this.$menu.find("li.dl-back") }, _initevents: function() { var t = this; this.$trigger.on("click.dlmenu", function() { if (t.open) { t._closemenu() } else { t._openmenu() } return false }); this.$menuitems.on("click.dlmenu", function(n) { n.stoppropagation(); var r = e(this), i = r.children("ul.dl-submenu"); if (i.length > 0) { var s = i.clone().css("opacity", 0).insertafter(t.$menu), o = function() { t.$menu.off(t.animendeventname).removeclass(t.options.animationclasses.classout).addclass("dl-subview"); r.addclass("dl-subviewopen").parents(".dl-subviewopen:first").removeclass("dl-subviewopen").addclass("dl-subview"); s.remove() }; settimeout(function() { s.addclass(t.options.animationclasses.classin); t.$menu.addclass(t.options.animationclasses.classout); if (t.supportanimations) { t.$menu.on(t.animendeventname, o) } else { o.call() } t.options.onlevelclick(r, r.children("a:first").text()) }); return false } else { t.options.onlinkclick(r, n) } }); this.$back.on("click.dlmenu", function(n) { var r = e(this), i = r.parents("ul.dl-submenu:first"), s = i.parent(), o = i.clone().insertafter(t.$menu); var u = function() { t.$menu.off(t.animendeventname).removeclass(t.options.animationclasses.classin); o.remove() }; settimeout(function() { o.addclass(t.options.animationclasses.classout); t.$menu.addclass(t.options.animationclasses.classin); if (t.supportanimations) { t.$menu.on(t.animendeventname, u) } else { u.call() } s.removeclass("dl-subviewopen"); var e = r.parents(".dl-subview:first"); if (e.is("li")) { e.addclass("dl-subviewopen") } e.removeclass("dl-subview") }); return false }) }, closemenu: function() { if (this.open) { this._closemenu() } }, _closemenu: function() { var e = this, t = function() { e.$menu.off(e.transendeventname); e._resetmenu() }; this.$menu.removeclass("dl-menuopen"); this.$menu.addclass("dl-menu-toggle"); this.$trigger.removeclass("dl-active"); if (this.supporttransitions) { this.$menu.on(this.transendeventname, t) } else { t.call() } this.open = false }, openmenu: function() { if (!this.open) { this._openmenu() } }, _openmenu: function() { var t = this; i.off("click").on("click.dlmenu", function() { t._closemenu() }); this.$menu.addclass("dl-menuopen dl-menu-toggle").on(this.transendeventname, function() { e(this).removeclass("dl-menu-toggle") }); this.$trigger.addclass("dl-active"); this.open = true }, _resetmenu: function() { this.$menu.removeclass("dl-subview"); this.$menuitems.removeclass("dl-subview dl-subviewopen") } }; var s = function(e) { if (t.console) { t.console.error(e) } }; e.fn.dlmenu = function(t) { if (typeof t === "string") { var n = array.prototype.slice.call(arguments, 1); this.each(function() { var r = e.data(this, "dlmenu"); if (!r) { s("cannot call methods on dlmenu prior to initialization; " + "attempted to call method '" + t + "'"); return } if (!e.isfunction(r[t]) || t.charat(0) === "_") { s("no such method '" + t + "' for dlmenu instance"); return } r[t].apply(r, n) }) } else { this.each(function() { var n = e.data(this, "dlmenu"); if (n) { n._init() } else { n = e.data(this, "dlmenu", new e.dlmenu(t, this)) } }) } return this } })(jquery, window)