Skip to content

Instantly share code, notes, and snippets.

@talves
Forked from markmarijnissen/AddVisibility.js
Created August 21, 2014 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talves/dfa6547a530768147c37 to your computer and use it in GitHub Desktop.
Save talves/dfa6547a530768147c37 to your computer and use it in GitHub Desktop.
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