-
-
Save lenntt/cc5baa5a73f188f62f6f 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
(function( $ ) { | |
$.fn.simulateDragDrop = function(options) { | |
return this.each(function() { | |
new $.simulateDragDrop(this, options); | |
}); | |
}; | |
$.simulateDragDrop = function(elem, options) { | |
this.options = options; | |
this.simulateEvent(elem, options); | |
}; | |
$.extend($.simulateDragDrop.prototype, { | |
simulateEvent: function(elem, options) { | |
/*Simulating drag start*/ | |
var type = "dragstart"; | |
var event = this.createEvent(type); | |
this.dispatchEvent(elem, type, event); | |
/*Simulating drop*/ | |
type = "drop"; | |
var dropEvent = this.createEvent(type, {}); | |
dropEvent.dataTransfer = event.dataTransfer; | |
var target; | |
if (options.dropTargetFrame) { | |
target = $(document.querySelector(options.dropTargetFrame).contentDocument.querySelector(options.dropTarget))[0]; | |
} | |
else { | |
target = $(options.dropTarget)[0]; | |
} | |
this.dispatchEvent(target, type, dropEvent); | |
/*Simulating drag end*/ | |
type = "dragend"; | |
var dragEndEvent = this.createEvent(type, {}); | |
dragEndEvent.dataTransfer = event.dataTransfer; | |
this.dispatchEvent(elem, type, dragEndEvent); | |
}, | |
createEvent: function(type) { | |
var event = document.createEvent("CustomEvent"); | |
event.initCustomEvent(type, true, true, null); | |
event.dataTransfer = { | |
data: { | |
}, | |
types: [], | |
setData: function(type, val){ | |
this.types.push(type) | |
this.data[type] = val; | |
}, | |
getData: function(type){ | |
return this.data[type]; | |
} | |
}; | |
return event; | |
}, | |
dispatchEvent: function(elem, type, event) { | |
if(elem.dispatchEvent) { | |
elem.dispatchEvent(event); | |
}else if( elem.fireEvent ) { | |
elem.fireEvent("on"+type, event); | |
} | |
} | |
}); | |
})(jQuery); |
Can anyone tell me how to get this working in protractor?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry to appear rather dense. How do I make sure that the symbol "jQuery" being passed to the self-compiling function is resolved correctly when I pass the contents of the above file to client.execute()? I tried this in my mocha test script:
Mocha reports:
Error: unknown error: jQuery is not defined
I tried adding jQuery to the dependencies in package.json using
npm install --save jquery
, but it seems to have made no difference.