improve design patterns example

This commit is contained in:
rolux 2012-06-25 19:37:36 +02:00
parent 0b2a94778f
commit fe548c60f4

View file

@ -173,6 +173,7 @@ Ox.load(['Image', 'UI'], function() {
that.invert = function() { that.invert = function() {
that.options({inverted: !self.options.inverted}); that.options({inverted: !self.options.inverted});
return that;
}; };
return that; return that;
@ -187,9 +188,13 @@ Ox.load(['Image', 'UI'], function() {
color: [[[128, 128, 128]]] color: [[[128, 128, 128]]]
})) }))
.options(options || {}) .options(options || {})
.update({color: setColor}); .update({color: setColor})
.bindEvent({
doubleclick: function() {
that.invert();
}
});
self.inverting = false;
self.sizes = [ self.sizes = [
Ox.splitInt(self.options.size[0], self.options.color[0].length), Ox.splitInt(self.options.size[0], self.options.color[0].length),
Ox.splitInt(self.options.size[1], self.options.color.length) Ox.splitInt(self.options.size[1], self.options.color.length)
@ -201,11 +206,7 @@ Ox.load(['Image', 'UI'], function() {
color: color, color: color,
size: [self.sizes[0][x], self.sizes[1][y]] size: [self.sizes[0][x], self.sizes[1][y]]
}) })
.update({ .unbindEvent('doubleclick')
inverted: function() {
return that.invert(x, y);
}
})
.appendTo(that); .appendTo(that);
}); });
}); });
@ -222,18 +223,12 @@ Ox.load(['Image', 'UI'], function() {
$box.invert(); $box.invert();
}; };
that.invert = function(x, y) { that.invert = function() {
if (!self.inverting) {
self.inverting = true;
arguments.length && self.$boxes[y][x].invert();
self.$boxes.forEach(function(array) { self.$boxes.forEach(function(array) {
array.forEach(self.invertBox); array.forEach(self.invertBox);
}); });
self.inverting = false; that.triggerEvent('invert');
that.triggerEvent('invert') return that;
return false;
}
return that; // fixme
}; };
return that; return that;
@ -299,11 +294,7 @@ Ox.load(['Image', 'UI'], function() {
color: image.pixel(x, y).slice(0, 3), color: image.pixel(x, y).slice(0, 3),
size: [self.sizes[0][x], self.sizes[1][y]] size: [self.sizes[0][x], self.sizes[1][y]]
}) })
.bindEvent({ .unbindEvent('doubleclick')
invert: function() {
return that.invert(x, y);
}
})
.appendTo(that); .appendTo(that);
}); });
}); });