Created
May 23, 2016 05:34
-
-
Save alexpts/9d57460868f84edc7077f2256b8cf2f9 to your computer and use it in GitHub Desktop.
Example jquery module
This file contains 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 ($) { | |
var $document = $(document); | |
var PlayMp4 = function () { | |
/** | |
* @param {Event} event | |
* @private | |
*/ | |
var _stop = function (event) { | |
event.preventDefault(); | |
var $itemContent = $(this).find('.media_wrap').removeClass('play'); | |
var video = $itemContent.find('video')[0]; | |
video.pause(); | |
video.currentTime = 0; | |
}; | |
/** | |
* @param {Event} event | |
* @private | |
*/ | |
var _play = function (event) { | |
event.preventDefault(); | |
var $itemContent = $(this).closest('.media_wrap'); | |
$itemContent.addClass('play').find('video')[0].play(); | |
}; | |
return { | |
on: function () { | |
$document | |
.on('click', '.media_wrap .vine-play', _play) | |
.on('click', '.media_wrap .coub-play', _play) | |
.on('mouseleave', '.item[data-type="vine"]', _stop) | |
.on('mouseleave', '.item[data-type="coub"]', _stop); | |
}, | |
off: function () { | |
$document | |
.off('click', '.media_wrap .vine-play', _play) | |
.off('click', '.media_wrap .coub-play', _play) | |
.off('mouseleave', '.item[data-type="vine"]', _stop) | |
.off('mouseleave', '.item[data-type="coub"]', _stop); | |
}, | |
}; | |
}; | |
$(document).trigger('js.load', ['content.play-mp4', PlayMp4]); | |
})(window.jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment