> On 10/08/05, Ryan Miller <ninjascience@gmail.com> wrote:
>> Is it possible to call the super class''s version of a function
from a
>> subclass?
>
> Not with Class.create and Object.extend, but Douglas Crockford
> describes a way to get classical inheritance in
> http://www.crockford.com/javascript/inheritance.html
I don''t know if this was resolved or what, but here was my (very quick
and hardly-tested) solution:
SnapDraggable = Class.create();
Object.extend(Object.extend(SnapDraggable.prototype,
Draggable.prototype), {
initialize: function(element) {
var options = Object.extend({
gridSize:10
}, arguments[1] || {});
Draggable.prototype.initialize.call(this, element, options);
},
draw: function(event) {
var pointer = [Event.pointerX(event), Event.pointerY(event)];
var offsets = Position.cumulativeOffset(this.element);
offsets[0] -= this.currentLeft();
offsets[1] -= this.currentTop();
var style = this.element.style;
var gridSize = this.options.gridSize;
if((!this.options.constraint) ||
(this.options.constraint==''horizontal''))
style.left = (Math.round((pointer[0] - offsets[0] -
this.offsetX)/gridSize)*gridSize) + "px";
if((!this.options.constraint) ||
(this.options.constraint==''vertical''))
style.top = (Math.round((pointer[1] - offsets[1] -
this.offsetY)/gridSize)*gridSize) + "px";
if(style.visibility=="hidden") style.visibility = "";
// fix
gecko rendering
}
});
-- Michael Daines