initialize: function() { bind(this.el, 'click', this.onClick); bind(this.el, 'touchstart', this.onTouchStart); bind(this.el, 'touchmove', this.onTouchMove); bind(this.el, 'touchend', this.onTouchEnd); this.el.autoplay = true; },
App.prototype.bindEvents = function() { this.camera.once('configured', this.storage.check); this.storage.once('checked:healthy', this.geolocationWatch); bind(this.doc, 'visibilitychange', this.onVisibilityChange); bind(this.win, 'beforeunload', this.onBeforeUnload); this.on('focus', this.onFocus); this.on('blur', this.onBlur); debug('events bound'); };
render: function() { var l10n = navigator.mozL10n; this.el.innerHTML = this.template({ retake: l10n.get('retake-button'), select: l10n.get('select-button') }); // Get elements this.els.mediaFrame = this.find('.js-media-frame'); this.els.retake = this.find('.js-retake'); this.els.select = this.find('.js-select'); // Events bind(this.els.retake, 'click', this.onButtonClick); bind(this.els.select, 'click', this.onButtonClick); return this; },
test('utils.bind binds to object', function () { var obj = { propName: 'aframe', getProp: function (arg) { return this.propName; } }; assert.equal(obj.getProp(), bind(obj.getProp, obj)()); });
test('utils.bind accepts and handles additional arguments properly', function () { var firstArg = 'awesome'; var secondArg = {}; var obj = { propName: 'aframe', getPropertyByCallback: function (arg1, arg2, arg3) { assert.equal(arg1, firstArg); assert.equal(arg2, secondArg); assert.equal(arg3, obj.propName); } }; var bound = bind(obj.getPropertyByCallback, obj, firstArg, secondArg); bound(obj.propName); });
test('utils.bind binds properly when called by other object', function () { var obj = { propName: 'aframe', getProp: function (arg) { return this.propName; }, getPropByCallback: function (cb) { return cb(); } }; var obj2 = { propName: 'webvr' }; var bound = bind(obj.getProp, obj2); assert.equal(obj2.propName, bound()); assert.equal(obj2.propName, obj.getPropByCallback(bound)); });