javascript - Get GenericSync per Surface or View -
i want scroll list bunch of surface images. when click
or touch
on surface, want surface
object being affected , (like change content
).
the way setup below have scrollview -> container -> view -> modifier -> surface
. don't know if efficient or not (maybe redundant). cannot exact object triggering event in console.log(data)
of each sync
object.
define(function(require, exports, module) { var engine = require('famous/core/engine'); var surface = require('famous/core/surface'); var containersurface = require("famous/surfaces/containersurface"); var view = require('famous/core/view'); var scrollview = require('famous/views/scrollview'); var transform = require('famous/core/transform'); var modifier = require("famous/core/modifier"); var genericsync = require("famous/inputs/genericsync"); var mousesync = require("famous/inputs/mousesync"); var touchsync = require("famous/inputs/touchsync"); var maincontext = engine.createcontext(); genericsync.register({ "mouse" : mousesync, "touch" : touchsync }); var scrollview = new scrollview({}); var listcontainer = []; var questioncontainer = []; var imgsurface = []; var sync = []; var imgmodifier = new modifier({origin: [0.5, 0.5]}); (var i=0; i<10; i++) { questioncontainer[i] = new containersurface({ size: [undefined, 300], properties:{ overflow: 'hidden' } }); imgsurface[i] = new surface({ content: '<img width="100%" src="http://placehold.it/400x300">' }); sync[i] = new genericsync( ["mouse", "touch"], {direction : genericsync.direction_x} ); questioncontainer[i].add(imgmodifier).add(imgsurface[i]); questioncontainer[i].pipe(sync[i]); questioncontainer[i].pipe(scrollview); sync[i].on("end", function(data) { console.log(data); }); listcontainer.push(questioncontainer[i]); } scrollview.sequencefrom(listcontainer); maincontext.add(scrollview); });
so how access triggering surface
or view
in case? hoping data.triggerobject.setcontent()
referenced particular surface
in array. well, such thing doesn't seem exist...
update 1:
the answer doesn't need follow code above. "high level" goals are:
generate list of surfaces images. data array.
detect click , touch event per surface , surface
basically, tried "advance" version of example https://github.com/famous/examples/blob/master/src/examples/core/view/example.js
so genericsync working aggregator of the sync classes. sync classes give useful information based on simpler events such mousedown , mousemove. means if want more information, going have make mousesync, example, give up.
if not wish write own mousesync class, take @ mousesync emits events. in event handling function, may access original event. can attach whatever wish payload emitted.. take example _handleend in mousesync.js
function _handleend(event) { if (!this._prevcoord) return; // added line.. this._payload.origin = event.origin; this._eventoutput.emit('end', this._payload); this._prevcoord = undefined; this._prevtime = undefined; }
if feels strange editing source directly , tracking changes, may want duplicate mousesync different classname eg. mymousesync , make changes file. same logic applies touchsync.
hope helps!
edit updated question:
you can use default events available through famous surfaces. these include origin property in payload.
mousedown, mousemove mouseup, touchstart, touchmove, touchend
surface.on('touchstart',function(e){ touchedsurface = e.origin; });
in of these cases, detect touch modernizr, , apply necessary events. luck!
Comments
Post a Comment