@@ -188,23 +188,24 @@ export default class EventController {
188188 /**
189189 * Adds an eventListener for each DOM element that matches the
190190 * criteria.
191- * @param {string } [eventType=mousemove] type of the event that
192- * should be listened for
191+ * @param {string } eventType type of the event that
192+ * should be listened for. If null, you have to react to events
193+ * manually, running doEvent(event).
193194 * @param {function } [modificationFunction=args=>\[]] - returns
194195 * an array of css changes. args contain absolute transformation
195196 * origin and mouse position, both in arrays, and others.
196197 * See {TransformationFunctions} for examples and predefined
197198 * functions
198199 * @param {string } [additionalFilter='*'] - css query that has to
199- * apply additionaly to the one passed in the constructor
200+ * apply additionally to the one passed in the constructor
200201 * @param {function } [postFunction = (event, element)=>{}] - optional
201202 * function that runs after the css change is successfully
202- * handeled internally. See {PostTransformFunctions} for examples
203+ * handled internally. See {PostTransformFunctions} for examples
203204 * and predefined functions.
204205 * @returns {void }
205206 */
206207 listenToChangeCss (
207- eventType = 'mousemove' ,
208+ eventType ,
208209 modificationFunction = args => [ ] ,
209210 additionalFilter = '*' ,
210211 postFunction = ( controller , event , element ) => { }
@@ -213,12 +214,39 @@ export default class EventController {
213214 this . eventControlElements
214215 . filter ( ece => ece . domElement . matches ( additionalFilter ) )
215216 . forEach ( ece => {
216- document . addEventListener ( eventType , event => {
217+ /**
218+ * Function that will be run on events, when calling
219+ * doEvent or on events of eventType
220+ * @param {event } event
221+ */
222+ const run = ( event ) => {
217223 this . _modify ( event , ece , modificationFunction ) ;
218224 postFunction . call ( this , event , ece ) ;
219- } ) ;
220- }
221- ) ;
225+ } ;
226+
227+ if ( eventType !== null ) {
228+ document . addEventListener ( eventType , run ) ;
229+ }
230+
231+ ece . doEvent = run ;
232+ } ) ;
233+ }
234+
235+ /**
236+ * runs modification functions and postfunctions for all
237+ * EventControlElements, if they have previously been passed via
238+ * listenToChangeCss
239+ * @param {event } event
240+ * @returns {void }
241+ */
242+ doEvent ( event ) {
243+ this . eventControlElements
244+ . forEach ( ece => {
245+ // only if doEvent was set by listenToChangeCss
246+ if ( ece . doEvent !== undefined ) {
247+ ece . doEvent ( event ) ;
248+ }
249+ } ) ;
222250 }
223251
224252 /**
0 commit comments