Permalink
Browse files

Aligning pull request #16 with coding conventions. Adding unit test f…

…or string based source.
  • Loading branch information...
1 parent c26f70b commit 4718f964fe430e186364a0c3defb73c9cb2e3f8a @georgepaterson committed Jun 18, 2012
Showing with 23 additions and 6 deletions.
  1. +8 −3 script/jquery.videobackground.js
  2. +15 −3 tests/video.js
@@ -160,7 +160,8 @@
compiledSource = '',
attributes = '',
data = that.data('video-options'),
- image;
+ image,
+ isArray;
if (document.createElement('video').canPlayType) {
that.settings = $.extend(true, {}, $.fn.videobackground.defaults, data, options);
if (!that.settings.initialised) {
@@ -179,11 +180,15 @@
*
*/
$.each(that.settings.videoSource, function () {
- var isArray = Object.prototype.toString.call(this) === '[object Array]';
+ isArray = Object.prototype.toString.call(this) === '[object Array]';
if (isArray && this[1] !== undefined) {
compiledSource = compiledSource + '<source src="' + this[0] + '" type="' + this[1] + '">';
} else {
- compiledSource = compiledSource + '<source src="' + (isArray ? this[0] : this) + '">';
+ if (isArray) {
+ compiledSource = compiledSource + '<source src="' + this[0] + '">';
+ } else {
+ compiledSource = compiledSource + '<source src="' + this + '">';
+ }
}
});
attributes = attributes + 'preload="' + that.settings.preload + '"';
View
@@ -6,19 +6,31 @@ $(document).ready(function () {
['../video/big-buck-bunny.ogv', 'video/ogg']];
test('init', function () {
$('<div></div>').appendTo('body').videobackground({
+ videoSource: ['../video/big-buck-bunny.mp4',
+ '../video/big-buck-bunny.webm',
+ '../video/big-buck-bunny.ogv']
+ }).remove();
+ ok(true, '.videobackground() called on element as an array of strings');
+ $('<div></div>').appendTo('body').videobackground({
videoSource: videoFiles
}).remove();
- ok(true, '.videobackground() called on element with video type');
+ ok(true, '.videobackground() called on element as an array of arrays with video type');
$('<div></div>').appendTo('body').videobackground({
videoSource: [['../video/big-buck-bunny.mp4'],
['../video/big-buck-bunny.webm'],
['../video/big-buck-bunny.ogv']]
}).remove();
- ok(true, '.videobackground() called on element without video type');
+ ok(true, '.videobackground() called on element as an array of arrays without video type');
+ $([]).appendTo('body').videobackground({
+ videoSource: ['../video/big-buck-bunny.mp4',
+ '../video/big-buck-bunny.webm',
+ '../video/big-buck-bunny.ogv']
+ }).remove();
+ ok(true, '.videobackground() as an array of strings called on empty collection');
$([]).videobackground({
videoSource: videoFiles
}).remove();
- ok(true, '.videobackground() called on empty collection');
+ ok(true, '.videobackground() as an array of arrays called on empty collection');
});
test('play', function () {
$('<div></div>').appendTo('body').videobackground({

0 comments on commit 4718f96

Please sign in to comment.