Fix for bug #7 and removing the cause of bug #9. Will add onDragOver after release

master
Dmitry Baranovskiy 2013-09-12 12:56:46 +10:00
parent 1ed2053d59
commit 2a8f553eaf
6 changed files with 179 additions and 145 deletions

262
dist/reference.html vendored

File diff suppressed because one or more lines are too long

6
dist/savage-min.js vendored

File diff suppressed because one or more lines are too long

17
dist/savage.js vendored
View File

@ -1119,6 +1119,7 @@ var glob = {
win: window,
doc: window.document
};
Savage._.glob = glob;
var has = "hasOwnProperty",
Str = String,
toFloat = parseFloat,
@ -6493,6 +6494,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
}
var node = dragi.el.node,
o,
glob = Savage._.glob,
next = node.nextSibling,
parent = node.parentNode,
display = node.style.display;
@ -6717,10 +6719,12 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
}
return this;
};
Savage["un" + eventName] = elproto["un" + eventName] = function (fn) {
Savage["un" + eventName] =
elproto["un" + eventName] = function (fn) {
var events = this.events || [],
l = events.length;
while (l--) if (events[l].name == eventName && events[l].f == fn) {
while (l--) if (events[l].name == eventName &&
(events[l].f == fn || !fn)) {
events[l].unbind();
events.splice(l, 1);
!events.length && delete this.events;
@ -6816,16 +6820,16 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
this.mousedown(start);
return this;
};
/*\
/*
* Element.onDragOver
[ method ]
**
* Shortcut for assigning event handler for `drag.over.<id>` event, where id is id of the element (see @Element.id).
- f (function) handler for event, first argument would be the element you are dragging over
\*/
elproto.onDragOver = function (f) {
f ? eve.on("savage.drag.over." + this.id, f) : eve.unbind("savage.drag.over." + this.id);
};
// elproto.onDragOver = function (f) {
// f ? eve.on("savage.drag.over." + this.id, f) : eve.unbind("savage.drag.over." + this.id);
// };
/*\
* Element.undrag
[ method ]
@ -6840,6 +6844,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
eve.unbind("savage.drag.*." + this.id);
}
!draggable.length && Savage.unmousemove(dragMove).unmouseup(dragUp);
return this;
};
});
// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.

View File

@ -118,6 +118,7 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
}
var node = dragi.el.node,
o,
glob = Savage._.glob,
next = node.nextSibling,
parent = node.parentNode,
display = node.style.display;
@ -342,10 +343,12 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
}
return this;
};
Savage["un" + eventName] = elproto["un" + eventName] = function (fn) {
Savage["un" + eventName] =
elproto["un" + eventName] = function (fn) {
var events = this.events || [],
l = events.length;
while (l--) if (events[l].name == eventName && events[l].f == fn) {
while (l--) if (events[l].name == eventName &&
(events[l].f == fn || !fn)) {
events[l].unbind();
events.splice(l, 1);
!events.length && delete this.events;
@ -441,16 +444,16 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
this.mousedown(start);
return this;
};
/*\
/*
* Element.onDragOver
[ method ]
**
* Shortcut for assigning event handler for `drag.over.<id>` event, where id is id of the element (see @Element.id).
- f (function) handler for event, first argument would be the element you are dragging over
\*/
elproto.onDragOver = function (f) {
f ? eve.on("savage.drag.over." + this.id, f) : eve.unbind("savage.drag.over." + this.id);
};
// elproto.onDragOver = function (f) {
// f ? eve.on("savage.drag.over." + this.id, f) : eve.unbind("savage.drag.over." + this.id);
// };
/*\
* Element.undrag
[ method ]
@ -465,5 +468,6 @@ Savage.plugin(function (Savage, Element, Paper, glob) {
eve.unbind("savage.drag.*." + this.id);
}
!draggable.length && Savage.unmousemove(dragMove).unmouseup(dragUp);
return this;
};
});

View File

@ -53,6 +53,7 @@ var glob = {
win: window,
doc: window.document
};
Savage._.glob = glob;
var has = "hasOwnProperty",
Str = String,
toFloat = parseFloat,

View File

@ -499,7 +499,7 @@ describe("Element methods", function () {
expect(result1).to.be(circle);
expect(result2).to.be(circle);
};
}
};
for (var i = 0; i < elementEvents.length; i++) {
var eventName = elementEvents[i];
@ -597,22 +597,6 @@ describe("Element methods", function () {
});
it("Element.onDragOver", function() {
var rect1 = s.rect(0, 0, 10, 10);
var rect2 = s.rect(0, 0, 10, 10);
var draggedOver = 0;
rect1.drag(function() {}, function() {}, function() {});
rect2.onDragOver = function() {
draggedOver++;
};
expect(draggedOver).to.be(0);
triggerEvent(rect1, 'mousedown');
triggerEvent(rect1, 'mousemove');
triggerEvent(rect1, 'mouseup');
expect(draggedOver).to.be(1);
});
it("Element.hover, Element.unhover - no contexts", function() {
var circle = s.circle(10, 20, 30);
var eventIn = 0;
@ -636,7 +620,7 @@ describe("Element methods", function () {
expect(eventIn).to.be(1);
triggerEvent(circle, 'mouseout');
expect(eventOut).to.be(1);
// expect(result2).to.be(circle); // TODO: Make unhover return element
expect(result2).to.be(circle);
});
it("Element.hover, Element.unhover - with contexts", function() {
var circle = s.circle(10, 20, 30);
@ -663,7 +647,7 @@ describe("Element methods", function () {
expect(eventIn).to.be(1);
triggerEvent(circle, 'mouseout');
expect(eventOut).to.be(1);
// expect(result2).to.be(circle); // TODO: Make unhover return element
expect(result2).to.be(circle);
});
});