Skip to content

Commit 3e523ba

Browse files
committed
Release v0.2.1
1 parent 8d9db2f commit 3e523ba

File tree

5 files changed

+89
-75
lines changed

5 files changed

+89
-75
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 0.2.1
2+
* Code refactoring.
3+
* Updated devDependencies.
4+
15
### 0.2.0
26
* Lots of updates since 0.1.0.
37
* Improved code linting.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vide",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"homepage": "http://vodkabears.github.io/vide/",
55
"authors": [
66
"Ilya Makarov <[email protected]>"

dist/jquery.vide.js

Lines changed: 81 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* Vide - v0.2.0
2+
* Vide - v0.2.1
33
* Easy as hell jQuery plugin for video backgrounds.
44
* http://vodkabears.github.io/vide/
55
*
66
* Made by Ilya Makarov
77
* Under MIT License
88
*/
9-
;(function($, window, document, navigator) {
9+
!(function($, window, document, navigator) {
1010
"use strict";
1111

1212
/**
@@ -37,7 +37,12 @@
3737
* @private
3838
*/
3939
function parseOptions(str) {
40-
var obj = {}, arr, i, len, prop, val, delimiterIndex, option;
40+
var obj = {},
41+
delimiterIndex,
42+
option,
43+
prop, val,
44+
arr, len,
45+
i;
4146

4247
// remove spaces around delimiters and split
4348
arr = str.replace(/\s*:\s*/g, ":").replace(/\s*,\s*/g, ",").split(",");
@@ -90,13 +95,13 @@
9095
* @private
9196
*/
9297
function parsePosition(str) {
93-
// convert anything to the string
9498
str = "" + str;
9599

96100
// default value is a center
97101
var args = str.split(/\s+/),
98102
x = "50%", y = "50%",
99-
i, len, arg;
103+
len, arg,
104+
i;
100105

101106
for (i = 0, len = args.length; i < len; i++) {
102107
arg = args[i];
@@ -153,9 +158,7 @@
153158
* @constructor
154159
*/
155160
function Vide(element, path, options) {
156-
this.element = $(element);
157-
this._defaults = defaults;
158-
this._name = pluginName;
161+
this.$element = $(element);
159162

160163
// parse path
161164
if (typeof path === "string") {
@@ -191,13 +194,13 @@
191194
* @public
192195
*/
193196
Vide.prototype.init = function() {
194-
var that = this,
195-
position = parsePosition(this.settings.position),
196-
poster,
197-
sources;
197+
var vide = this,
198+
position = parsePosition(vide.settings.position),
199+
sources,
200+
poster;
198201

199202
// Set video wrapper styles
200-
this.wrapper = $("<div>").css({
203+
vide.$wrapper = $("<div>").css({
201204
"position": "absolute",
202205
"z-index": -1,
203206
"top": 0,
@@ -214,78 +217,78 @@
214217
});
215218

216219
// Get poster path
217-
poster = this.path;
218-
if (typeof this.path === "object") {
219-
if (this.path.poster) {
220-
poster = this.path.poster;
220+
poster = vide.path;
221+
if (typeof vide.path === "object") {
222+
if (vide.path.poster) {
223+
poster = vide.path.poster;
221224
} else {
222-
if (this.path.mp4) {
223-
poster = this.path.mp4;
224-
} else if (this.path.webm) {
225-
poster = this.path.webm;
226-
} else if (this.path.ogv) {
227-
poster = this.path.ogv;
225+
if (vide.path.mp4) {
226+
poster = vide.path.mp4;
227+
} else if (vide.path.webm) {
228+
poster = vide.path.webm;
229+
} else if (vide.path.ogv) {
230+
poster = vide.path.ogv;
228231
}
229232
}
230233
}
231234

232235
// Set video poster
233-
if (this.settings.posterType === "detect") {
236+
if (vide.settings.posterType === "detect") {
234237
findPoster(poster, function(url) {
235-
that.wrapper.css("background-image", "url(" + url + ")");
238+
vide.$wrapper.css("background-image", "url(" + url + ")");
236239
});
237-
} else if (this.settings.posterType !== "none") {
238-
this.wrapper
239-
.css("background-image", "url(" + poster + "." + this.settings.posterType + ")");
240+
} else if (vide.settings.posterType !== "none") {
241+
vide.$wrapper
242+
.css("background-image", "url(" + poster + "." + vide.settings.posterType + ")");
240243
}
241244

242245
// if parent element has a static position, make it relative
243-
if (this.element.css("position") === "static") {
244-
this.element.css("position", "relative");
246+
if (vide.$element.css("position") === "static") {
247+
vide.$element.css("position", "relative");
245248
}
246249

247-
this.element.prepend(this.wrapper);
250+
vide.$element.prepend(vide.$wrapper);
248251

249252
if (!isIOS && !isAndroid) {
250253
sources = "";
251254

252-
if (typeof this.path === "object") {
253-
if (this.path.mp4) {
254-
sources += "<source src='" + this.path.mp4 + ".mp4' type='video/mp4'>";
255+
if (typeof vide.path === "object") {
256+
if (vide.path.mp4) {
257+
sources += "<source src='" + vide.path.mp4 + ".mp4' type='video/mp4'>";
255258
}
256-
if (this.path.webm) {
257-
sources += "<source src='" + this.path.webm + ".webm' type='video/webm'>";
259+
if (vide.path.webm) {
260+
sources += "<source src='" + vide.path.webm + ".webm' type='video/webm'>";
258261
}
259-
if (this.path.ogv) {
260-
sources += "<source src='" + this.path.ogv + ".ogv' type='video/ogv'>";
262+
if (vide.path.ogv) {
263+
sources += "<source src='" + vide.path.ogv + ".ogv' type='video/ogv'>";
261264
}
262265

263-
this.video = $("<video>" + sources + "</video>");
266+
vide.$video = $("<video>" + sources + "</video>");
264267
} else {
265-
this.video = $("<video>" +
266-
"<source src='" + this.path + ".mp4' type='video/mp4'>" +
267-
"<source src='" + this.path + ".webm' type='video/webm'>" +
268-
"<source src='" + this.path + ".ogv' type='video/ogg'>" +
268+
vide.$video = $("<video>" +
269+
"<source src='" + vide.path + ".mp4' type='video/mp4'>" +
270+
"<source src='" + vide.path + ".webm' type='video/webm'>" +
271+
"<source src='" + vide.path + ".ogv' type='video/ogg'>" +
269272
"</video>");
270273
}
271274

272275
// Disable visibility, while loading
273-
this.video.css("visibility", "hidden");
276+
vide.$video.css("visibility", "hidden");
274277

275278
// Set video properties
276-
this.video.prop({
277-
autoplay: this.settings.autoplay,
278-
loop: this.settings.loop,
279-
volume: this.settings.volume,
280-
muted: this.settings.muted,
281-
playbackRate: this.settings.playbackRate
279+
vide.$video.prop({
280+
autoplay: vide.settings.autoplay,
281+
loop: vide.settings.loop,
282+
volume: vide.settings.volume,
283+
muted: vide.settings.muted,
284+
playbackRate: vide.settings.playbackRate
282285
});
283286

284287
// Append video
285-
this.wrapper.append(this.video);
288+
vide.$wrapper.append(vide.$video);
286289

287290
// Video alignment
288-
this.video.css({
291+
vide.$video.css({
289292
"margin": "auto",
290293
"position": "absolute",
291294
"z-index": -1,
@@ -297,15 +300,15 @@
297300
});
298301

299302
// resize video, when it's loaded
300-
this.video.bind("loadedmetadata." + pluginName, function() {
301-
that.video.css("visibility", "visible");
302-
that.resize();
303+
vide.$video.bind("loadedmetadata." + pluginName, function() {
304+
vide.$video.css("visibility", "visible");
305+
vide.resize();
303306
});
304307

305308
// resize event is available only for 'window',
306309
// use another code solutions to detect DOM elements resizing
307-
$(this.element).bind("resize." + pluginName, function() {
308-
that.resize();
310+
vide.$element.bind("resize." + pluginName, function() {
311+
vide.resize();
309312
});
310313
}
311314
};
@@ -316,34 +319,34 @@
316319
* @public
317320
*/
318321
Vide.prototype.getVideoObject = function() {
319-
return this.video ? this.video[0] : null;
322+
return this.$video ? this.$video[0] : null;
320323
};
321324

322325
/**
323326
* Resize video background
324327
* @public
325328
*/
326329
Vide.prototype.resize = function() {
327-
if (!this.video) {
330+
if (!this.$video) {
328331
return;
329332
}
330333

331334
var
332335
// get native video size
333-
videoHeight = this.video[0].videoHeight,
334-
videoWidth = this.video[0].videoWidth,
336+
videoHeight = this.$video[0].videoHeight,
337+
videoWidth = this.$video[0].videoWidth,
335338

336339
// get wrapper size
337-
wrapperHeight = this.wrapper.height(),
338-
wrapperWidth = this.wrapper.width();
340+
wrapperHeight = this.$wrapper.height(),
341+
wrapperWidth = this.$wrapper.width();
339342

340343
if (wrapperWidth / videoWidth > wrapperHeight / videoHeight) {
341-
this.video.css({
344+
this.$video.css({
342345
"width": wrapperWidth + 2, // +2 pixels to prevent empty space after transformation
343346
"height": "auto"
344347
});
345348
} else {
346-
this.video.css({
349+
this.$video.css({
347350
"width": "auto",
348351
"height": wrapperHeight + 2 // +2 pixels to prevent empty space after transformation
349352
});
@@ -355,14 +358,15 @@
355358
* @public
356359
*/
357360
Vide.prototype.destroy = function() {
358-
this.element.unbind(pluginName);
359-
if (this.video) {
360-
this.video.unbind(pluginName);
361+
this.$element.unbind(pluginName);
362+
363+
if (this.$video) {
364+
this.$video.unbind(pluginName);
361365
}
362366

363367
delete $[pluginName].lookup[this.index];
364-
this.element.removeData(pluginName);
365-
this.wrapper.remove();
368+
this.$element.removeData(pluginName);
369+
this.$wrapper.remove();
366370
};
367371

368372
/**
@@ -383,12 +387,16 @@
383387
*/
384388
$.fn[pluginName] = function(path, options) {
385389
var instance;
390+
386391
this.each(function() {
387392
instance = $.data(this, pluginName);
393+
388394
if (instance) {
395+
389396
// destroy plugin instance if exists
390397
instance.destroy();
391398
}
399+
392400
// create plugin instance
393401
instance = new Vide(this, path, options);
394402
instance.index = $[pluginName].lookup.push(instance) - 1;
@@ -399,10 +407,12 @@
399407
};
400408

401409
$(document).ready(function() {
410+
402411
// window resize event listener
403412
$(window).bind("resize." + pluginName, function() {
404-
for (var len = $[pluginName].lookup.length, instance, i = 0; i < len; i++) {
413+
for (var len = $[pluginName].lookup.length, i = 0, instance; i < len; i++) {
405414
instance = $[pluginName].lookup[i];
415+
406416
if (instance) {
407417
instance.resize();
408418
}

dist/jquery.vide.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vide.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"responsive",
1111
"declarative"
1212
],
13-
"version": "0.2.0",
13+
"version": "0.2.1",
1414
"author": {
1515
"name": "Ilya Makarov",
1616
"email": "[email protected]",

0 commit comments

Comments
 (0)