Skip to content

Instantly share code, notes, and snippets.

@harrygreen
Last active February 11, 2024 22:24
Show Gist options
  • Save harrygreen/1087a7497dbc364ee356 to your computer and use it in GitHub Desktop.
Save harrygreen/1087a7497dbc364ee356 to your computer and use it in GitHub Desktop.
Example AMD module for VideoTrailer instances
/**
* VideoTrailer Module Factory
*
* This module creates instances of the VideoTrailer module.
* A splash screen image is shown by default. When the user clicks on that, the video HTML is loaded into the wrapper element.
*
* Expects params object in this structure:
{
html: "<iframe src="http://video.ldn.timeout.com/video/THE-GRAND-BUDAPEST-HOTEL-Offici/player?layout=&read_more=1" width="668" height="400" frameborder="0" scrolling="no"></iframe>"
}
*
* @author Harry Green
*/
define('VideoTrailer', ['jquery'] ,function($){
"use strict";
function init(params) {
params.$o.each(function(){
var $video_wrapper = $(this),
params = $video_wrapper.data('params');
params.$video_wrapper = $video_wrapper;
$video_wrapper.data('instance', new VideoTrailer(params));
});
}
function VideoTrailer(params) {
var self = this;
this.$video_wrapper = params.$video_wrapper;
this.$video = $(params.html);
this.go();
}
VideoTrailer.prototype.go = function() {
this.addListeners();
}
VideoTrailer.prototype.addListeners = function() {
var self = this;
this.$video_wrapper.on('click', function(e){
self.loadVideo();
$(this).off(e);
});
}
VideoTrailer.prototype.loadVideo = function() {
this.$video_wrapper.html( this.$video );
}
return {
init: init
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment