Last active
February 11, 2024 22:24
-
-
Save harrygreen/1087a7497dbc364ee356 to your computer and use it in GitHub Desktop.
Example AMD module for VideoTrailer instances
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
/** | |
* 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