Comment 4 for bug 460623

Revision history for this message
Aurium (aurium) wrote :

Please, see the code down. I was thinking in a way to help the InkWeb grow and help user needs related to this feature request:
(what you think?)

// makeSimpleStyleSetTestMethods
// Dinamicaly create methods to set a style value and test if
// the style configuration was applied
InkWeb.makeSimpleStyleSetTestMethods = function ( method, att, val ) {
  var code = 'this.setStyle(el, "'+att+'", "'+val+'")';
  this[method] = new Function( "el", code );
  this[method].inkWeb = this;
  code += 'var att = this.inkWeb.getStyle(el, "'+att+'");'
  code += 'return att && display.match("'+val+'");'
  this[method].wasApplied = new Function( "el", code );
}

InkWeb.makeSimpleStyleSetTestMethods( "hide", "display", "none" );
/* The above line will create this:
 * InkWeb.hide = function (el) {
 * this.setStyle(el, "display", "none");
 * }
 * InkWeb.hide.wasApplied (el) {
 * var display = this.inkWeb.getStyle(el, "display");
 * return display && display.match("none");
 * }
 */

InkWeb.makeSimpleStyleSetTestMethods( "show", "display", "inline" );

InkWeb.toggleStats = function ( el, method1, method2 ) {
  if(this[method1].wasApplied(el)) {
    this.method2(el);
  } else {
    this.method1(el);
  }
}

// if we need:

InkWeb.toggleVisible(el) {
  this.toggleStats( el, hide, show );
}