Created
August 2, 2010 22:49
-
-
Save sdesai/505474 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YUI.add('drag-gestures', function(Y) { | |
Y.log('Drag gesture support loaded', 'info', 'drag-gestures'); | |
Y.DD.Drag.prototype._prep = function() { | |
Y.log('Using DD override prep to attach gesture events', 'info', 'drag-gestures'); | |
this._dragThreshMet = false; | |
var node = this.get('node'), DDM = Y.DD.DDM; | |
node.addClass(DDM.CSS_PREFIX + '-draggable'); | |
node.on('gesturemovestart', Y.bind(this._handleMouseDownEvent, this), { | |
minDistance: 0, | |
minTime: 0 | |
}); | |
// SATYEN - CHANGES: Matt fixed clearData, so shouldn't be required | |
// node.setData('dd', true); | |
node.on('gesturemoveend', Y.bind(this._handleMouseUp, this), { standAlone: true }); | |
node.on('dragstart', Y.bind(this._fixDragStart, this)); | |
// SATYEN - CHANGES | |
// | |
// a) In general, it seems like you could move this to _setupListeners, same as you're doing for | |
// the non-gesture ddm-base impl. If not, some kind of _moveActived flag (could be shorter of course) | |
// on DDM as shown below. That way, we wouldn't need to worry about resetting it to false either. | |
// | |
// b) Aside from that, the only real change is to listen on the doc (again, as you're doing for the | |
// non-gesture ddm-base impl), instead of the node. Since you have standAlone:true, this is | |
// equivalent to what node.on("gesturemove") is doing under the hood anyway. It just makes it more | |
// explicit (and mirrors the non-gesture impl in ddm-base). | |
// | |
// c) You could also follow the same pattern for "gesturemoveend". However wasn't sure if there are any | |
// implications due to the fact that it uses "this", as in "this._handleMouseUp". Under the hood | |
// that instance method seems to call DDM._end() anyway, so maybe it could just call something | |
// directly on DDM, instead of going through this - like move does. | |
// | |
// d) TESTING: | |
// | |
// - With latest, and modifying sandbox, I tested sandbox/dd/index.php and that seems fine | |
// on the desktop (only 1 move listener added). However it's busted on the iphone emulator - | |
// figured that was something to do with the pending conditional loading stuff. delegate.php | |
// also seems to be broken (before my changes). | |
// | |
// - If I roll back to prior to the conditional stuff (yui3-2458), there's no drag-gestures of course, | |
// but a similar change in drag.js works fine, on both desktop and iphone emulator. Delegate also works. | |
// | |
// However, other loader/attach based stuff is broken. E.g. one of the two Y instances on | |
// sandbox/dd/index.php doesn't create drag instances. This was broken | |
// in d638a12fe1b2b8db03c67d7bad8c1bb30c3d8008 but *is* fixed in the latest. | |
if (!DDM._moveActivated) { | |
// SATYEN - CHANGES: Use doc, instead of node, just to be explicit, and mirror non-gesture impl. | |
// node.on('gesturemove', Y.throttle(Y.bind(DDM._move, DDM), DDM.get('throttleTime')), { standAlone: true }); | |
Y.one(Y.config.doc).on('gesturemove', Y.throttle(Y.bind(DDM._move, DDM), DDM.get('throttleTime')), { | |
standAlone: true } | |
); | |
DDM._moveActivated = true; | |
} | |
}; | |
Y.DD.DDM._setupListeners = function() { | |
this._createPG(); | |
this._active = true; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment