Skip to content

Instantly share code, notes, and snippets.

@markmarijnissen
Created July 1, 2014 19:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save markmarijnissen/6bf208f88f34bf47ba94 to your computer and use it in GitHub Desktop.
Save markmarijnissen/6bf208f88f34bf47ba94 to your computer and use it in GitHub Desktop.
Famo.us: Add visibility to modifiers
var Modifier = require('famous/core/Modifier');
var StateModifier = require('famous/modifiers/StateModifier');
__original_modify = Modifier.prototype.modify;
Modifier.prototype.modify = function extended_modify(target) {
__original_modify.call(this,target);
// here is the hack: set target to NULL if it should not be visible!
if(this._visibleGetter) this.visible = this._visibleGetter();
this._output.target = this.visible === undefined || this.visible? target: null;
return this._output;
};
Modifier.prototype.visibleFrom = function(visible){
if (visible instanceof Function) this._visibleGetter = visible;
else if (visible instanceof Object && visible.get) this._visibleGetter = visible.get.bind(visible);
else {
this._visibleGetter = null;
this.visible = visible;
}
return this;
};
StateModifier.prototype.setVisible = function(value) {
this._modifier.visible = value;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment