Skip to content

Instantly share code, notes, and snippets.

@alexpts
Created May 23, 2016 05:34
Show Gist options
  • Save alexpts/9d57460868f84edc7077f2256b8cf2f9 to your computer and use it in GitHub Desktop.
Save alexpts/9d57460868f84edc7077f2256b8cf2f9 to your computer and use it in GitHub Desktop.
Example jquery module
(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