Skip to content

Commit 5774ab4

Browse files
committed
cleanup, simple opacity transition for fade-in
1 parent 458d149 commit 5774ab4

File tree

7 files changed

+100
-77
lines changed

7 files changed

+100
-77
lines changed

dist/react-drive-in.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@
1919
}
2020
.drive-in-media video,
2121
.drive-in-media img {
22+
-webkit-transition: opacity 0.5s ease-in-out;
23+
transition: opacity 0.5s ease-in-out;
2224
position: relative;
2325
}

dist/react-drive-in.js

Lines changed: 85 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ return /******/ (function(modules) { // webpackBootstrap
248248
/* 3 */
249249
/***/ function(module, exports, __webpack_require__) {
250250

251-
/** @jsx React.DOM */var Jvent = __webpack_require__(6),
252-
inherits = __webpack_require__(7),
251+
/** @jsx React.DOM */var Jvent = __webpack_require__(7),
252+
inherits = __webpack_require__(6),
253253
Timer = __webpack_require__(4),
254254
Playlist = __webpack_require__(5);
255255

@@ -393,8 +393,6 @@ return /******/ (function(modules) { // webpackBootstrap
393393
setStyles(mediaEl, {
394394
width: 'auto',
395395
height: containerH + pad + 'px'
396-
// top: '0px',
397-
// left: (-(containerH * mediaAspect - containerW) / 2) + 'px'
398396
});
399397
}
400398

@@ -420,8 +418,6 @@ return /******/ (function(modules) { // webpackBootstrap
420418
setStyles(mediaEl, {
421419
width: containerW + 'px',
422420
height: 'auto'
423-
// top: (-(containerW / mediaAspect - containerH) / 2) + 'px',
424-
// left: '0px'
425421
});
426422
}
427423
}
@@ -464,6 +460,7 @@ return /******/ (function(modules) { // webpackBootstrap
464460
this.emit('media.loading');
465461

466462
mediaEl.src = src;
463+
mediaEl.preload = 'metadata';
467464

468465
if (posterSrc) {
469466
mediaEl.poster = posterSrc;
@@ -480,7 +477,7 @@ return /******/ (function(modules) { // webpackBootstrap
480477

481478
// Fallback to a slideshow.
482479
this.slideshow = true;
483-
this.createMediaEl();
480+
this._createMediaEl();
484481
this._playImageItem(item, itemNum);
485482

486483
} else {
@@ -559,6 +556,10 @@ return /******/ (function(modules) { // webpackBootstrap
559556
mediaEl = this.mediaEl;
560557

561558
function onLoadedMetadata(data) {
559+
// Safari often stalls on first load, so kickstart it.
560+
if (mediaEl.networkState < 2) {
561+
mediaEl.load();
562+
}
562563
self._setVideoData(data);
563564
self.emit('media.metadata', data);
564565
}
@@ -573,19 +574,28 @@ return /******/ (function(modules) { // webpackBootstrap
573574

574575
function onProgress(event) {
575576
// Sort of buggy, with readyState and buffer being inconsistent...
576-
var percent = 0,
577-
ready = event.target.readyState,
578-
network = event.target.networkState,
579-
buffered = event.target.buffered,
580-
total = event.target.duration;
577+
var percent = null,
578+
video = event.target;
581579

582-
if (network === 1 && ready === 0) {
583-
percent = 100;
580+
// FF4+, Chrome
581+
if (video.buffered && video.buffered.length > 0 && video.buffered.end && video.duration) {
582+
percent = video.buffered.end(0) / video.duration;
583+
}
584+
585+
// Some browsers (e.g., FF3.6 and Safari 5) cannot calculate target.bufferered.end()
586+
// to be anything other than 0. If the byte count is available we use this instead.
587+
// Browsers that support the else if do not seem to have the bufferedBytes value and
588+
// should skip to there. Tested in Safari 5, Webkit head, FF3.6, Chrome 6, IE 7/8.
589+
else if (typeof video.bytesTotal !== 'undefined' && video.bytesTotal > 0 && typeof video.bufferedBytes !== 'undefined') {
590+
percent = video.bufferedBytes / video.bytesTotal;
591+
}
592+
593+
if (percent !== null) {
594+
percent = 100 * Math.min(1, Math.max(0, percent));
584595
}
585596

586-
if (ready > 0) {
587-
var end = buffered.end(0);
588-
percent = (end/total) * 100;
597+
if (video.networkState === 1 && video.readyState === 0) {
598+
percent = 100;
589599
}
590600

591601
self.emit('media.progress', percent);
@@ -594,13 +604,6 @@ return /******/ (function(modules) { // webpackBootstrap
594604
function onEnded() {
595605
if (!self._seeking) {
596606
self.emit('media.ended', self.currentItem);
597-
if (self.playlistLength > 1 && self.loop) {
598-
var itemNum = 0;
599-
if (self.currentItem + 1 < self.playlistLength) {
600-
itemNum = self.currentItem + 1;
601-
}
602-
self.play(itemNum);
603-
}
604607
}
605608
}
606609

@@ -649,23 +652,20 @@ return /******/ (function(modules) { // webpackBootstrap
649652

650653
function onEnded() {
651654
self.emit('media.ended', self.currentItem);
652-
if (self.playlistLength > 1 && self.loop) {
653-
var itemNum = (self.currentItem + 1 < self.playlistLength) ? self.currentItem + 1 : 0;
654-
self.play(itemNum);
655-
}
656655
}
657656

658657
this._addListener(mediaEl, 'load', onLoad);
659658
this._addListener(mediaEl, 'ended', onEnded);
660659
};
661660

662661
DriveIn.prototype._attachListeners = function() {
663-
var self = this;
662+
var self = this,
663+
mediaEl = this.mediaEl;
664664

665665
function onResize() {
666666
window.requestAnimationFrame(function () {
667667
if (self.metadataLoaded) {
668-
self._updateSize(self.mediaEl, self.currMediaType, self.mediaAspect);
668+
self._updateSize(mediaEl, self.currMediaType, self.mediaAspect);
669669
}
670670
});
671671
}
@@ -678,7 +678,18 @@ return /******/ (function(modules) { // webpackBootstrap
678678
this._attachImageListeners();
679679
}
680680

681+
this.on('media.ended', function () {
682+
if (self.playlistLength > 1 && self.loop) {
683+
var itemNum = 0;
684+
if (self.currentItem + 1 < self.playlistLength) {
685+
itemNum = self.currentItem + 1;
686+
}
687+
self.play(itemNum);
688+
}
689+
});
690+
681691
this.on('media.canplay', function () {
692+
mediaEl.style.opacity = 1;
682693
self.canplay = true;
683694
});
684695

@@ -728,10 +739,12 @@ return /******/ (function(modules) { // webpackBootstrap
728739
mediaEl = createEl('video', {
729740
height: 1,
730741
width: 1,
731-
preload: 'none'
742+
preload: 'metadata'
732743
});
733744
}
734745

746+
mediaEl.style.opacity = 0;
747+
735748
this.mediaEl = mediaEl;
736749
this.currMediaType = mediaType;
737750

@@ -769,6 +782,8 @@ return /******/ (function(modules) { // webpackBootstrap
769782
};
770783

771784
DriveIn.prototype.showPlaylist = function(rawPlaylist, options) {
785+
options = options || {};
786+
772787
if (options.hasOwnProperty('mute')) {
773788
this.mute = options.mute;
774789
}
@@ -802,6 +817,14 @@ return /******/ (function(modules) { // webpackBootstrap
802817
}
803818
};
804819

820+
DriveIn.prototype.setPlaybackRate = function(rate) {
821+
if (this.currMediaType === 'image') {
822+
return;
823+
}
824+
825+
this.mediaEl.playbackRate = rate || 1.0;
826+
};
827+
805828
DriveIn.prototype.getMedia = function() {
806829
return this.mediaEl;
807830
};
@@ -855,14 +878,6 @@ return /******/ (function(modules) { // webpackBootstrap
855878
}
856879
};
857880

858-
DriveIn.prototype.currentTime = function() {
859-
if (this.currMediaType === 'video') {
860-
return this.mediaEl.currentTime;
861-
} else {
862-
return this._slideshowTimer.currentTime();
863-
}
864-
};
865-
866881
DriveIn.prototype.seekTo = function(time) {
867882
this._seeking = true;
868883
if (this.currMediaType === 'video') {
@@ -887,8 +902,8 @@ return /******/ (function(modules) { // webpackBootstrap
887902
/* 4 */
888903
/***/ function(module, exports, __webpack_require__) {
889904

890-
/** @jsx React.DOM */var Jvent = __webpack_require__(6),
891-
inherits = __webpack_require__(7);
905+
/** @jsx React.DOM */var Jvent = __webpack_require__(7),
906+
inherits = __webpack_require__(6);
892907

893908
function Timer(callback, delay) {
894909
var self = this;
@@ -1005,6 +1020,35 @@ return /******/ (function(modules) { // webpackBootstrap
10051020

10061021
/***/ },
10071022
/* 6 */
1023+
/***/ function(module, exports, __webpack_require__) {
1024+
1025+
/** @jsx React.DOM */if (typeof Object.create === 'function') {
1026+
// implementation from standard node.js 'util' module
1027+
module.exports = function inherits(ctor, superCtor) {
1028+
ctor.super_ = superCtor
1029+
ctor.prototype = Object.create(superCtor.prototype, {
1030+
constructor: {
1031+
value: ctor,
1032+
enumerable: false,
1033+
writable: true,
1034+
configurable: true
1035+
}
1036+
});
1037+
};
1038+
} else {
1039+
// old school shim for old browsers
1040+
module.exports = function inherits(ctor, superCtor) {
1041+
ctor.super_ = superCtor
1042+
var TempCtor = function () {}
1043+
TempCtor.prototype = superCtor.prototype
1044+
ctor.prototype = new TempCtor()
1045+
ctor.prototype.constructor = ctor
1046+
}
1047+
}
1048+
1049+
1050+
/***/ },
1051+
/* 7 */
10081052
/***/ function(module, exports, __webpack_require__) {
10091053

10101054
/** @jsx React.DOM */'use strict';
@@ -1167,35 +1211,6 @@ return /******/ (function(modules) { // webpackBootstrap
11671211
module.exports = Jvent;
11681212

11691213

1170-
/***/ },
1171-
/* 7 */
1172-
/***/ function(module, exports, __webpack_require__) {
1173-
1174-
/** @jsx React.DOM */if (typeof Object.create === 'function') {
1175-
// implementation from standard node.js 'util' module
1176-
module.exports = function inherits(ctor, superCtor) {
1177-
ctor.super_ = superCtor
1178-
ctor.prototype = Object.create(superCtor.prototype, {
1179-
constructor: {
1180-
value: ctor,
1181-
enumerable: false,
1182-
writable: true,
1183-
configurable: true
1184-
}
1185-
});
1186-
};
1187-
} else {
1188-
// old school shim for old browsers
1189-
module.exports = function inherits(ctor, superCtor) {
1190-
ctor.super_ = superCtor
1191-
var TempCtor = function () {}
1192-
TempCtor.prototype = superCtor.prototype
1193-
ctor.prototype = new TempCtor()
1194-
ctor.prototype.constructor = ctor
1195-
}
1196-
}
1197-
1198-
11991214
/***/ }
12001215
/******/ ])
12011216
});

dist/react-drive-in.min.css

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

0 commit comments

Comments
 (0)