Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,516 changes: 758 additions & 758 deletions dist/amd/browsers.js

Large diffs are not rendered by default.

332 changes: 166 additions & 166 deletions dist/amd/drag.js
Original file line number Diff line number Diff line change
@@ -1,175 +1,175 @@
/*syn@0.1.1#drag*/
define(function(require, exports, module) {
var syn = require('./synthetic');
(function dragSupport() {
if (!document.body) {
syn.schedule(dragSupport, 1);
return;
}
var div = document.createElement('div');
document.body.appendChild(div);
syn.helpers.extend(div.style, {
width: '100px',
height: '10000px',
backgroundColor: 'blue',
position: 'absolute',
top: '10px',
left: '0px',
zIndex: 19999
});
document.body.scrollTop = 11;
if (!document.elementFromPoint) {
return;
}
var el = document.elementFromPoint(3, 1);
if (el === div) {
syn.support.elementFromClient = true;
} else {
syn.support.elementFromPage = true;
}
document.body.removeChild(div);
document.body.scrollTop = 0;
}());
var elementFromPoint = function (point, element) {
var clientX = point.clientX, clientY = point.clientY, win = syn.helpers.getWindow(element), el;
if (syn.support.elementFromPage) {
var off = syn.helpers.scrollOffset(win);
clientX = clientX + off.left;
clientY = clientY + off.top;
}
el = win.document.elementFromPoint ? win.document.elementFromPoint(clientX, clientY) : element;
if (el === win.document.documentElement && (point.clientY < 0 || point.clientX < 0)) {
return element;
} else {
return el;
}
}, createEventAtPoint = function (event, point, element) {
var el = elementFromPoint(point, element);
syn.trigger(el || element, event, point);
return el;
}, mouseMove = function (point, element, last) {
var el = elementFromPoint(point, element);
if (last !== el && el && last) {
var options = syn.helpers.extend({}, point);
options.relatedTarget = el;
syn.trigger(last, 'mouseout', options);
options.relatedTarget = last;
syn.trigger(el, 'mouseover', options);
/*syn@0.1.2#drag*/
define(function (require, exports, module) {
var syn = require('./synthetic');
(function dragSupport() {
if (!document.body) {
syn.schedule(dragSupport, 1);
return;
}
syn.trigger(el || element, 'mousemove', point);
return el;
}, startMove = function (start, end, duration, element, callback) {
var startTime = new Date(), distX = end.clientX - start.clientX, distY = end.clientY - start.clientY, win = syn.helpers.getWindow(element), current = elementFromPoint(start, element), cursor = win.document.createElement('div'), calls = 0, move;
move = function onmove() {
var now = new Date(), scrollOffset = syn.helpers.scrollOffset(win), fraction = (calls === 0 ? 0 : now - startTime) / duration, options = {
clientX: distX * fraction + start.clientX,
clientY: distY * fraction + start.clientY
};
calls++;
if (fraction < 1) {
syn.helpers.extend(cursor.style, {
left: options.clientX + scrollOffset.left + 2 + 'px',
top: options.clientY + scrollOffset.top + 2 + 'px'
});
current = mouseMove(options, element, current);
syn.schedule(onmove, 15);
} else {
current = mouseMove(end, element, current);
win.document.body.removeChild(cursor);
callback();
}
};
syn.helpers.extend(cursor.style, {
height: '5px',
width: '5px',
backgroundColor: 'red',
var div = document.createElement('div');
document.body.appendChild(div);
syn.helpers.extend(div.style, {
width: '100px',
height: '10000px',
backgroundColor: 'blue',
position: 'absolute',
zIndex: 19999,
fontSize: '1px'
});
win.document.body.appendChild(cursor);
move();
}, startDrag = function (start, end, duration, element, callback) {
createEventAtPoint('mousedown', start, element);
startMove(start, end, duration, element, function () {
createEventAtPoint('mouseup', end, element);
callback();
top: '10px',
left: '0px',
zIndex: 19999
});
}, center = function (el) {
var j = syn.jquery()(el), o = j.offset();
return {
pageX: o.left + j.outerWidth() / 2,
pageY: o.top + j.outerHeight() / 2
};
}, convertOption = function (option, win, from) {
var page = /(\d+)[x ](\d+)/, client = /(\d+)X(\d+)/, relative = /([+-]\d+)[xX ]([+-]\d+)/, parts;
if (typeof option === 'string' && relative.test(option) && from) {
var cent = center(from);
parts = option.match(relative);
option = {
pageX: cent.pageX + parseInt(parts[1]),
pageY: cent.pageY + parseInt(parts[2])
};
}
if (typeof option === 'string' && page.test(option)) {
parts = option.match(page);
option = {
pageX: parseInt(parts[1]),
pageY: parseInt(parts[2])
};
}
if (typeof option === 'string' && client.test(option)) {
parts = option.match(client);
option = {
clientX: parseInt(parts[1]),
clientY: parseInt(parts[2])
};
document.body.scrollTop = 11;
if (!document.elementFromPoint) {
return;
}
if (typeof option === 'string') {
option = syn.jquery()(option, win.document)[0];
}
if (option.nodeName) {
option = center(option);
}
if (option.pageX) {
var off = syn.helpers.scrollOffset(win);
option = {
clientX: option.pageX - off.left,
clientY: option.pageY - off.top
};
var el = document.elementFromPoint(3, 1);
if (el === div) {
syn.support.elementFromClient = true;
} else {
syn.support.elementFromPage = true;
}
return option;
}, adjust = function (from, to, win) {
if (from.clientY < 0) {
var off = syn.helpers.scrollOffset(win);
var top = off.top + from.clientY - 100, diff = top - off.top;
if (top > 0) {
document.body.removeChild(div);
document.body.scrollTop = 0;
}());
var elementFromPoint = function (point, element) {
var clientX = point.clientX, clientY = point.clientY, win = syn.helpers.getWindow(element), el;
if (syn.support.elementFromPage) {
var off = syn.helpers.scrollOffset(win);
clientX = clientX + off.left;
clientY = clientY + off.top;
}
el = win.document.elementFromPoint ? win.document.elementFromPoint(clientX, clientY) : element;
if (el === win.document.documentElement && (point.clientY < 0 || point.clientX < 0)) {
return element;
} else {
top = 0;
diff = -off.top;
return el;
}
}, createEventAtPoint = function (event, point, element) {
var el = elementFromPoint(point, element);
syn.trigger(el || element, event, point);
return el;
}, mouseMove = function (point, element, last) {
var el = elementFromPoint(point, element);
if (last !== el && el && last) {
var options = syn.helpers.extend({}, point);
options.relatedTarget = el;
syn.trigger(last, 'mouseout', options);
options.relatedTarget = last;
syn.trigger(el, 'mouseover', options);
}
from.clientY = from.clientY - diff;
to.clientY = to.clientY - diff;
syn.helpers.scrollOffset(win, {
top: top,
left: off.left
syn.trigger(el || element, 'mousemove', point);
return el;
}, startMove = function (start, end, duration, element, callback) {
var startTime = new Date(), distX = end.clientX - start.clientX, distY = end.clientY - start.clientY, win = syn.helpers.getWindow(element), current = elementFromPoint(start, element), cursor = win.document.createElement('div'), calls = 0, move;
move = function onmove() {
var now = new Date(), scrollOffset = syn.helpers.scrollOffset(win), fraction = (calls === 0 ? 0 : now - startTime) / duration, options = {
clientX: distX * fraction + start.clientX,
clientY: distY * fraction + start.clientY
};
calls++;
if (fraction < 1) {
syn.helpers.extend(cursor.style, {
left: options.clientX + scrollOffset.left + 2 + 'px',
top: options.clientY + scrollOffset.top + 2 + 'px'
});
current = mouseMove(options, element, current);
syn.schedule(onmove, 15);
} else {
current = mouseMove(end, element, current);
win.document.body.removeChild(cursor);
callback();
}
};
syn.helpers.extend(cursor.style, {
height: '5px',
width: '5px',
backgroundColor: 'red',
position: 'absolute',
zIndex: 19999,
fontSize: '1px'
});
win.document.body.appendChild(cursor);
move();
}, startDrag = function (start, end, duration, element, callback) {
createEventAtPoint('mousedown', start, element);
startMove(start, end, duration, element, function () {
createEventAtPoint('mouseup', end, element);
callback();
});
}, center = function (el) {
var j = syn.jquery()(el), o = j.offset();
return {
pageX: o.left + j.outerWidth() / 2,
pageY: o.top + j.outerHeight() / 2
};
}, convertOption = function (option, win, from) {
var page = /(\d+)[x ](\d+)/, client = /(\d+)X(\d+)/, relative = /([+-]\d+)[xX ]([+-]\d+)/, parts;
if (typeof option === 'string' && relative.test(option) && from) {
var cent = center(from);
parts = option.match(relative);
option = {
pageX: cent.pageX + parseInt(parts[1]),
pageY: cent.pageY + parseInt(parts[2])
};
}
if (typeof option === 'string' && page.test(option)) {
parts = option.match(page);
option = {
pageX: parseInt(parts[1]),
pageY: parseInt(parts[2])
};
}
if (typeof option === 'string' && client.test(option)) {
parts = option.match(client);
option = {
clientX: parseInt(parts[1]),
clientY: parseInt(parts[2])
};
}
if (typeof option === 'string') {
option = syn.jquery()(option, win.document)[0];
}
if (option.nodeName) {
option = center(option);
}
if (option.pageX) {
var off = syn.helpers.scrollOffset(win);
option = {
clientX: option.pageX - off.left,
clientY: option.pageY - off.top
};
}
return option;
}, adjust = function (from, to, win) {
if (from.clientY < 0) {
var off = syn.helpers.scrollOffset(win);
var top = off.top + from.clientY - 100, diff = top - off.top;
if (top > 0) {
} else {
top = 0;
diff = -off.top;
}
from.clientY = from.clientY - diff;
to.clientY = to.clientY - diff;
syn.helpers.scrollOffset(win, {
top: top,
left: off.left
});
}
};
syn.helpers.extend(syn.init.prototype, {
_move: function (from, options, callback) {
var win = syn.helpers.getWindow(from), fro = convertOption(options.from || from, win, from), to = convertOption(options.to || options, win, from);
if (options.adjust !== false) {
adjust(fro, to, win);
}
startMove(fro, to, options.duration || 500, from, callback);
},
_drag: function (from, options, callback) {
var win = syn.helpers.getWindow(from), fro = convertOption(options.from || from, win, from), to = convertOption(options.to || options, win, from);
if (options.adjust !== false) {
adjust(fro, to, win);
}
startDrag(fro, to, options.duration || 500, from, callback);
}
};
syn.helpers.extend(syn.init.prototype, {
_move: function (from, options, callback) {
var win = syn.helpers.getWindow(from), fro = convertOption(options.from || from, win, from), to = convertOption(options.to || options, win, from);
if (options.adjust !== false) {
adjust(fro, to, win);
}
startMove(fro, to, options.duration || 500, from, callback);
},
_drag: function (from, options, callback) {
var win = syn.helpers.getWindow(from), fro = convertOption(options.from || from, win, from), to = convertOption(options.to || options, win, from);
if (options.adjust !== false) {
adjust(fro, to, win);
}
startDrag(fro, to, options.duration || 500, from, callback);
}
});
});
});
});
Loading