Sha256: 0c779e09254608f640d7d69c995589572ab6107cfe3b97a25f8d8c75ca4468d5

Contents?: true

Size: 1.9 KB

Versions: 6

Compression:

Stored size: 1.9 KB

Contents

var BowlineMenu = function(element, options){
  var defaults = {childSelector: "li", trace: false};
  this.options = jQuery.extend({}, defaults, options);
  
  this.element = jQuery(element);
  
  if(this.options.current) this.change(this.options.current);
    
  var self = this;
  this.elements().click(function(){
    var view = self.viewName(this);
    self.change(view);
  });
};

BowlineMenu.fn = BowlineMenu.prototype;

BowlineMenu.fn.log = function(){
  if( !this.options.trace ) return;
  var args = jQuery.makeArray(arguments);
  args.unshift("(BowlineMenu)");
  console.log.apply(console, args);
};

BowlineMenu.fn.onChange = function(func){
  this.element.bind("change.bowline", func);
};

BowlineMenu.fn.triggerChange = function(data){
  this.element.trigger("change.bowline", data);
};

BowlineMenu.fn.viewName = function(element){
  return jQuery(element).dataset("view");
};

BowlineMenu.fn.currentName = function(){
  return this.viewName(this.current);
};

BowlineMenu.fn.elements = function(){
  return this.element.find(this.options.childSelector);
};

BowlineMenu.fn.elementFor = function(name){
  return this.element.find(
    "[data-view='" + name + "']:first"
  );
};

BowlineMenu.fn.items = function(){
  var self = this;
  return jQuery.map(this.elements(), function(n){
    return self.viewName(n);
  });
};

BowlineMenu.fn.change = function(name){  
  if(name != false && jQuery.inArray(name, this.items()) == -1) return false;

  var fromView      = this.current;
  var fromViewName  = this.viewName(fromView);
  
  var toView        = this.elementFor(name);
  var toViewName    = name;
  
  this.log("changing:", fromViewName, toViewName);
  
  this.elements().removeClass("current");
  if(toView) {
    this.current = toView;
    toView.addClass("current");
  }
  
  this.triggerChange({
    toView:       toView, 
    toViewName:   toViewName,
    fromView:     fromView,
    fromViewName: fromViewName
  });
};

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bowline-0.6.3 assets/bowline.menu.js
bowline-0.6.2 assets/bowline.menu.js
bowline-0.6.1 assets/bowline.menu.js
bowline-0.6.0 assets/bowline.menu.js
bowline-0.5.8 assets/bowline.menu.js
bowline-0.5.7 assets/bowline.menu.js