/* tendina jquery plugin v0.8.1 copyright (c) 2014 ivan prignano released under the mit license */ (function() { var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __slice = [].slice; (function($, window) { var tendina; tendina = (function() { tendina.prototype.defaults = { animate: true, speed: 500 }; function tendina(el, options) { this._clickhandler = __bind(this._clickhandler, this); this.options = $.extend({}, this.defaults, options); this.$el = $(el); this._checkoptions(); this.$el.addclass('tendina'); this.firstlvlsubmenu = ".tendina > li"; this.secondlvlsubmenu = ".tendina > li > ul > li"; this.firstlvlsubmenulink = "" + this.firstlvlsubmenu + " > a"; this.secondlvlsubmenulink = "" + this.secondlvlsubmenu + " > a"; this._hidesubmenus(); this._bindevents(); } tendina.prototype._bindevents = function() { return $(document).on('click.tendina', "" + this.firstlvlsubmenulink + ", " + this.secondlvlsubmenulink, this._clickhandler); }; tendina.prototype._unbindevents = function() { return $(document).off('click.tendina'); }; tendina.prototype._isfirstlevel = function(clickedel) { if ($(clickedel).parent().parent().hasclass('tendina')) { return true; } }; tendina.prototype._clickhandler = function(event) { var clickedel, submenulevel; clickedel = event.currenttarget; submenulevel = this._isfirstlevel(clickedel) ? this.firstlvlsubmenu : this.secondlvlsubmenu; if (this._haschildenandishidden(clickedel)) { event.preventdefault(); return this._opensubmenu(submenulevel, clickedel); } else if (this._iscurrentlyopen(clickedel)) { event.preventdefault(); return this._closesubmenu(clickedel); } }; tendina.prototype._opensubmenu = function(el, clickedel) { var $clickednestedmenu, $firstnestedmenu, $lastnestedmenu; $firstnestedmenu = $(el).find('> ul'); $lastnestedmenu = $(el).find('> ul > li > ul'); $clickednestedmenu = $(clickedel).next('ul'); $(el).removeclass('selected'); $(clickedel).parent().addclass('selected'); this._close($firstnestedmenu); this._open($clickednestedmenu); if (el === this.firstlvlsubmenu) { $(el).find('> ul > li').removeclass('selected'); this._close($lastnestedmenu); } if (this.options.opencallback) { return this.options.opencallback($(clickedel).parent()); } }; tendina.prototype._closesubmenu = function(el) { var $clickednestedmenu; $clickednestedmenu = $(el).next('ul'); $(el).parent().removeclass('selected'); this._close($clickednestedmenu); if (this.options.closecallback) { return this.options.closecallback($(el).parent()); } }; tendina.prototype._open = function($el) { if (this.options.animate) { return $el.slidedown(this.options.speed); } else { return $el.show(); } }; tendina.prototype._close = function($el) { if (this.options.animate) { return $el.slideup(this.options.speed); } else { return $el.hide(); } }; tendina.prototype._haschildenandishidden = function(el) { return $(el).next('ul').length > 0 && $(el).next('ul').is(':hidden'); }; tendina.prototype._iscurrentlyopen = function(el) { return $(el).parent().hasclass('selected'); }; tendina.prototype._hidesubmenus = function() { $("" + this.firstlvlsubmenu + " > ul, " + this.secondlvlsubmenu + " > ul").hide(); return $("" + this.firstlvlsubmenu + " > ul").removeclass('selected'); }; tendina.prototype._showsubmenus = function() { $("" + this.firstlvlsubmenu + " > ul, " + this.secondlvlsubmenu + " > ul").show(); return $("" + this.firstlvlsubmenu).removeclass('selected'); }; tendina.prototype._checkoptions = function() { if (this.options.animate !== true || false) { console.warn("jquery.fn.tendina - '" + this.options.animate + "' is not a valid parameter for the 'animate' option. falling back to default value."); } if (this.options.speed !== parseint(this.options.speed)) { return console.warn("jquery.fn.tendina - '" + this.options.speed + "' is not a valid parameter for the 'speed' option. falling back to default value."); } }; tendina.prototype.destroy = function() { this.$el.removedata('tendina'); this._unbindevents(); this._showsubmenus(); this.$el.removeclass('tendina'); return this.$el.find('.selected').removeclass('selected'); }; tendina.prototype.hideall = function() { return this._hidesubmenus(); }; tendina.prototype.showall = function() { return this._showsubmenus(); }; return tendina; })(); return $.fn.extend({ tendina: function() { var args, option; option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; return this.each(function() { var $this, data; $this = $(this); data = $this.data('tendina'); if (!data) { $this.data('tendina', (data = new tendina(this, option))); } if (typeof option === 'string') { return data[option].apply(data, args); } }); } }); })(window.jquery, window); }).call(this);