Add autoplay video and play uploaded video feature.

This commit is contained in:
BoHung Chiu 2021-08-01 16:18:25 +08:00
parent d6d103973d
commit bea9c1020c
27 changed files with 6043 additions and 38 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,496 @@
/*
* Playlist Object for the jPlayer Plugin
* http://www.jplayer.org
*
* Copyright (c) 2009 - 2014 Happyworm Ltd
* Licensed under the MIT license.
* http://www.opensource.org/licenses/MIT
*
* Author: Mark J Panaghiston
* Version: 2.4.1
* Date: 19th November 2014
*
* Requires:
* - jQuery 1.7.0+
* - jPlayer 2.8.2+
*/
/*global jPlayerPlaylist:true */
(function($, undefined) {
jPlayerPlaylist = function(cssSelector, playlist, options) {
var self = this;
this.current = 0;
this.loop = false; // Flag used with the jPlayer repeat event
this.shuffled = false;
this.removing = false; // Flag is true during remove animation, disabling the remove() method until complete.
this.cssSelector = $.extend({}, this._cssSelector, cssSelector); // Object: Containing the css selectors for jPlayer and its cssSelectorAncestor
this.options = $.extend(true, {
keyBindings: {
next: {
key: 221, // ]
fn: function() {
self.next();
}
},
previous: {
key: 219, // [
fn: function() {
self.previous();
}
},
shuffle: {
key: 83, // s
fn: function() {
self.shuffle();
}
}
},
stateClass: {
shuffled: "jp-state-shuffled"
}
}, this._options, options); // Object: The jPlayer constructor options for this playlist and the playlist options
this.playlist = []; // Array of Objects: The current playlist displayed (Un-shuffled or Shuffled)
this.original = []; // Array of Objects: The original playlist
this._initPlaylist(playlist); // Copies playlist to this.original. Then mirrors this.original to this.playlist. Creating two arrays, where the element pointers match. (Enables pointer comparison.)
// Setup the css selectors for the extra interface items used by the playlist.
this.cssSelector.details = this.cssSelector.cssSelectorAncestor + " .jp-details"; // Note that jPlayer controls the text in the title element.
this.cssSelector.playlist = this.cssSelector.cssSelectorAncestor + " .jp-playlist";
this.cssSelector.next = this.cssSelector.cssSelectorAncestor + " .jp-next";
this.cssSelector.previous = this.cssSelector.cssSelectorAncestor + " .jp-previous";
this.cssSelector.shuffle = this.cssSelector.cssSelectorAncestor + " .jp-shuffle";
this.cssSelector.shuffleOff = this.cssSelector.cssSelectorAncestor + " .jp-shuffle-off";
// Override the cssSelectorAncestor given in options
this.options.cssSelectorAncestor = this.cssSelector.cssSelectorAncestor;
// Override the default repeat event handler
this.options.repeat = function(event) {
self.loop = event.jPlayer.options.loop;
};
// Create a ready event handler to initialize the playlist
$(this.cssSelector.jPlayer).bind($.jPlayer.event.ready, function() {
self._init();
});
// Create an ended event handler to move to the next item
$(this.cssSelector.jPlayer).bind($.jPlayer.event.ended, function() {
self.next();
});
// Create a play event handler to pause other instances
$(this.cssSelector.jPlayer).bind($.jPlayer.event.play, function() {
$(this).jPlayer("pauseOthers");
});
// Create a resize event handler to show the title in full screen mode.
$(this.cssSelector.jPlayer).bind($.jPlayer.event.resize, function(event) {
if(event.jPlayer.options.fullScreen) {
$(self.cssSelector.details).show();
} else {
$(self.cssSelector.details).hide();
}
});
// Create click handlers for the extra buttons that do playlist functions.
$(this.cssSelector.previous).click(function(e) {
e.preventDefault();
self.previous();
self.blur(this);
});
$(this.cssSelector.next).click(function(e) {
e.preventDefault();
self.next();
self.blur(this);
});
$(this.cssSelector.shuffle).click(function(e) {
e.preventDefault();
if(self.shuffled && $(self.cssSelector.jPlayer).jPlayer("option", "useStateClassSkin")) {
self.shuffle(false);
} else {
self.shuffle(true);
}
self.blur(this);
});
$(this.cssSelector.shuffleOff).click(function(e) {
e.preventDefault();
self.shuffle(false);
self.blur(this);
}).hide();
// Put the title in its initial display state
if(!this.options.fullScreen) {
$(this.cssSelector.details).hide();
}
// Remove the empty <li> from the page HTML. Allows page to be valid HTML, while not interfereing with display animations
$(this.cssSelector.playlist + " ul").empty();
// Create .on() handlers for the playlist items along with the free media and remove controls.
this._createItemHandlers();
// Instance jPlayer
$(this.cssSelector.jPlayer).jPlayer(this.options);
};
jPlayerPlaylist.prototype = {
_cssSelector: { // static object, instanced in constructor
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
},
_options: { // static object, instanced in constructor
playlistOptions: {
autoPlay: false,
loopOnPrevious: false,
shuffleOnLoop: true,
enableRemoveControls: false,
displayTime: 'slow',
addTime: 'fast',
removeTime: 'fast',
shuffleTime: 'slow',
itemClass: "jp-playlist-item",
freeGroupClass: "jp-free-media",
freeItemClass: "jp-playlist-item-free",
removeItemClass: "jp-playlist-item-remove"
}
},
option: function(option, value) { // For changing playlist options only
if(value === undefined) {
return this.options.playlistOptions[option];
}
this.options.playlistOptions[option] = value;
switch(option) {
case "enableRemoveControls":
this._updateControls();
break;
case "itemClass":
case "freeGroupClass":
case "freeItemClass":
case "removeItemClass":
this._refresh(true); // Instant
this._createItemHandlers();
break;
}
return this;
},
_init: function() {
var self = this;
this._refresh(function() {
if(self.options.playlistOptions.autoPlay) {
self.play(self.current);
} else {
self.select(self.current);
}
});
},
_initPlaylist: function(playlist) {
this.current = 0;
this.shuffled = false;
this.removing = false;
this.original = $.extend(true, [], playlist); // Copy the Array of Objects
this._originalPlaylist();
},
_originalPlaylist: function() {
var self = this;
this.playlist = [];
// Make both arrays point to the same object elements. Gives us 2 different arrays, each pointing to the same actual object. ie., Not copies of the object.
$.each(this.original, function(i) {
self.playlist[i] = self.original[i];
});
},
_refresh: function(instant) {
/* instant: Can be undefined, true or a function.
* undefined -> use animation timings
* true -> no animation
* function -> use animation timings and excute function at half way point.
*/
var self = this;
if(instant && !$.isFunction(instant)) {
$(this.cssSelector.playlist + " ul").empty();
$.each(this.playlist, function(i) {
$(self.cssSelector.playlist + " ul").append(self._createListItem(self.playlist[i]));
});
this._updateControls();
} else {
var displayTime = $(this.cssSelector.playlist + " ul").children().length ? this.options.playlistOptions.displayTime : 0;
$(this.cssSelector.playlist + " ul").slideUp(displayTime, function() {
var $this = $(this);
$(this).empty();
$.each(self.playlist, function(i) {
$this.append(self._createListItem(self.playlist[i]));
});
self._updateControls();
if($.isFunction(instant)) {
instant();
}
if(self.playlist.length) {
$(this).slideDown(self.options.playlistOptions.displayTime);
} else {
$(this).show();
}
});
}
},
_createListItem: function(media) {
var self = this;
// Wrap the <li> contents in a <div>
var listItem = "<li><div>";
// Create remove control
listItem += "<a href='javascript:;' class='" + this.options.playlistOptions.removeItemClass + "'>&times;</a>";
// Create links to free media
if(media.free) {
var first = true;
listItem += "<span class='" + this.options.playlistOptions.freeGroupClass + "'>(";
$.each(media, function(property,value) {
if($.jPlayer.prototype.format[property]) { // Check property is a media format.
if(first) {
first = false;
} else {
listItem += " | ";
}
listItem += "<a class='" + self.options.playlistOptions.freeItemClass + "' href='" + value + "' tabindex='-1'>" + property + "</a>";
}
});
listItem += ")</span>";
}
// The title is given next in the HTML otherwise the float:right on the free media corrupts in IE6/7
listItem += "<a href='javascript:;' class='" + this.options.playlistOptions.itemClass + "' tabindex='0'>" + media.title + (media.artist ? " <span class='jp-artist'>by " + media.artist + "</span>" : "") + "</a>";
listItem += "</div></li>";
return listItem;
},
_createItemHandlers: function() {
var self = this;
// Create live handlers for the playlist items
$(this.cssSelector.playlist).off("click", "a." + this.options.playlistOptions.itemClass).on("click", "a." + this.options.playlistOptions.itemClass, function(e) {
e.preventDefault();
var index = $(this).parent().parent().index();
if(self.current !== index) {
self.play(index);
} else {
$(self.cssSelector.jPlayer).jPlayer("play");
}
self.blur(this);
});
// Create live handlers that disable free media links to force access via right click
$(this.cssSelector.playlist).off("click", "a." + this.options.playlistOptions.freeItemClass).on("click", "a." + this.options.playlistOptions.freeItemClass, function(e) {
e.preventDefault();
$(this).parent().parent().find("." + self.options.playlistOptions.itemClass).click();
self.blur(this);
});
// Create live handlers for the remove controls
$(this.cssSelector.playlist).off("click", "a." + this.options.playlistOptions.removeItemClass).on("click", "a." + this.options.playlistOptions.removeItemClass, function(e) {
e.preventDefault();
var index = $(this).parent().parent().index();
self.remove(index);
self.blur(this);
});
},
_updateControls: function() {
if(this.options.playlistOptions.enableRemoveControls) {
$(this.cssSelector.playlist + " ." + this.options.playlistOptions.removeItemClass).show();
} else {
$(this.cssSelector.playlist + " ." + this.options.playlistOptions.removeItemClass).hide();
}
if(this.shuffled) {
$(this.cssSelector.jPlayer).jPlayer("addStateClass", "shuffled");
} else {
$(this.cssSelector.jPlayer).jPlayer("removeStateClass", "shuffled");
}
if($(this.cssSelector.shuffle).length && $(this.cssSelector.shuffleOff).length) {
if(this.shuffled) {
$(this.cssSelector.shuffleOff).show();
$(this.cssSelector.shuffle).hide();
} else {
$(this.cssSelector.shuffleOff).hide();
$(this.cssSelector.shuffle).show();
}
}
},
_highlight: function(index) {
if(this.playlist.length && index !== undefined) {
$(this.cssSelector.playlist + " .jp-playlist-current").removeClass("jp-playlist-current");
$(this.cssSelector.playlist + " li:nth-child(" + (index + 1) + ")").addClass("jp-playlist-current").find(".jp-playlist-item").addClass("jp-playlist-current");
// $(this.cssSelector.details + " li").html("<span class='jp-title'>" + this.playlist[index].title + "</span>" + (this.playlist[index].artist ? " <span class='jp-artist'>by " + this.playlist[index].artist + "</span>" : ""));
}
},
setPlaylist: function(playlist) {
this._initPlaylist(playlist);
this._init();
},
add: function(media, playNow) {
$(this.cssSelector.playlist + " ul").append(this._createListItem(media)).find("li:last-child").hide().slideDown(this.options.playlistOptions.addTime);
this._updateControls();
this.original.push(media);
this.playlist.push(media); // Both array elements share the same object pointer. Comforms with _initPlaylist(p) system.
if(playNow) {
this.play(this.playlist.length - 1);
} else {
if(this.original.length === 1) {
this.select(0);
}
}
},
remove: function(index) {
var self = this;
if(index === undefined) {
this._initPlaylist([]);
this._refresh(function() {
$(self.cssSelector.jPlayer).jPlayer("clearMedia");
});
return true;
} else {
if(this.removing) {
return false;
} else {
index = (index < 0) ? self.original.length + index : index; // Negative index relates to end of array.
if(0 <= index && index < this.playlist.length) {
this.removing = true;
$(this.cssSelector.playlist + " li:nth-child(" + (index + 1) + ")").slideUp(this.options.playlistOptions.removeTime, function() {
$(this).remove();
if(self.shuffled) {
var item = self.playlist[index];
$.each(self.original, function(i) {
if(self.original[i] === item) {
self.original.splice(i, 1);
return false; // Exit $.each
}
});
self.playlist.splice(index, 1);
} else {
self.original.splice(index, 1);
self.playlist.splice(index, 1);
}
if(self.original.length) {
if(index === self.current) {
self.current = (index < self.original.length) ? self.current : self.original.length - 1; // To cope when last element being selected when it was removed
self.select(self.current);
} else if(index < self.current) {
self.current--;
}
} else {
$(self.cssSelector.jPlayer).jPlayer("clearMedia");
self.current = 0;
self.shuffled = false;
self._updateControls();
}
self.removing = false;
});
}
return true;
}
}
},
select: function(index) {
index = (index < 0) ? this.original.length + index : index; // Negative index relates to end of array.
if(0 <= index && index < this.playlist.length) {
this.current = index;
this._highlight(index);
$(this.cssSelector.jPlayer).jPlayer("setMedia", this.playlist[this.current]);
} else {
this.current = 0;
}
},
play: function(index) {
index = (index < 0) ? this.original.length + index : index; // Negative index relates to end of array.
if(0 <= index && index < this.playlist.length) {
if(this.playlist.length) {
this.select(index);
$(this.cssSelector.jPlayer).jPlayer("play");
}
} else if(index === undefined) {
$(this.cssSelector.jPlayer).jPlayer("play");
}
},
pause: function() {
$(this.cssSelector.jPlayer).jPlayer("pause");
},
next: function() {
var index = (this.current + 1 < this.playlist.length) ? this.current + 1 : 0;
if(this.loop) {
// See if we need to shuffle before looping to start, and only shuffle if more than 1 item.
if(index === 0 && this.shuffled && this.options.playlistOptions.shuffleOnLoop && this.playlist.length > 1) {
this.shuffle(true, true); // playNow
} else {
this.play(index);
}
} else {
// The index will be zero if it just looped round
if(index > 0) {
this.play(index);
}
}
},
previous: function() {
var index = (this.current - 1 >= 0) ? this.current - 1 : this.playlist.length - 1;
if(this.loop && this.options.playlistOptions.loopOnPrevious || index < this.playlist.length - 1) {
this.play(index);
}
},
shuffle: function(shuffled, playNow) {
var self = this;
if(shuffled === undefined) {
shuffled = !this.shuffled;
}
if(shuffled || shuffled !== this.shuffled) {
$(this.cssSelector.playlist + " ul").slideUp(this.options.playlistOptions.shuffleTime, function() {
self.shuffled = shuffled;
if(shuffled) {
self.playlist.sort(function() {
return 0.5 - Math.random();
});
} else {
self._originalPlaylist();
}
self._refresh(true); // Instant
if(playNow || !$(self.cssSelector.jPlayer).data("jPlayer").status.paused) {
self.play(0);
} else {
self.select(0);
}
$(this).slideDown(self.options.playlistOptions.shuffleTime);
});
}
},
blur: function(that) {
if($(this.cssSelector.jPlayer).jPlayer("option", "autoBlur")) {
$(that).blur();
}
}
};
})(jQuery);

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,338 @@
/*
* jPlayerInspector Plugin for jPlayer Plugin for jQuery JavaScript Library
* http://www.jplayer.org
*
* Copyright (c) 2009 - 2014 Happyworm Ltd
* Licensed under the MIT license.
* http://www.opensource.org/licenses/MIT
*
* Author: Mark J Panaghiston
* Version: 1.0.5
* Date: 1st April 2014
*
* For use with jPlayer Version: 2.6.0+
*
* Note: Declare inspector instances after jPlayer instances. ie., Otherwise the jPlayer instance is nonsense.
*/
(function($, undefined) {
$.jPlayerInspector = {};
$.jPlayerInspector.i = 0;
$.jPlayerInspector.defaults = {
jPlayer: undefined, // The jQuery selector of the jPlayer instance to inspect.
idPrefix: "jplayer_inspector_",
visible: false
};
var methods = {
init: function(options) {
var self = this;
var $this = $(this);
var config = $.extend({}, $.jPlayerInspector.defaults, options);
$(this).data("jPlayerInspector", config);
config.id = $(this).attr("id");
config.jPlayerId = config.jPlayer.attr("id");
config.windowId = config.idPrefix + "window_" + $.jPlayerInspector.i;
config.statusId = config.idPrefix + "status_" + $.jPlayerInspector.i;
config.configId = config.idPrefix + "config_" + $.jPlayerInspector.i;
config.toggleId = config.idPrefix + "toggle_" + $.jPlayerInspector.i;
config.eventResetId = config.idPrefix + "event_reset_" + $.jPlayerInspector.i;
config.updateId = config.idPrefix + "update_" + $.jPlayerInspector.i;
config.eventWindowId = config.idPrefix + "event_window_" + $.jPlayerInspector.i;
config.eventId = {};
config.eventJq = {};
config.eventTimeout = {};
config.eventOccurrence = {};
$.each($.jPlayer.event, function(eventName,eventType) {
config.eventId[eventType] = config.idPrefix + "event_" + eventName + "_" + $.jPlayerInspector.i;
config.eventOccurrence[eventType] = 0;
});
var structure =
'<p><a href="#" id="' + config.toggleId + '">' + (config.visible ? "Hide" : "Show") + '</a> jPlayer Inspector</p>'
+ '<div id="' + config.windowId + '">'
+ '<div id="' + config.statusId + '"></div>'
+ '<div id="' + config.eventWindowId + '" style="padding:5px 5px 0 5px;background-color:#eee;border:1px dotted #000;">'
+ '<p style="margin:0 0 10px 0;"><strong>jPlayer events that have occurred over the past 1 second:</strong>'
+ '<br />(Backgrounds: <span style="padding:0 5px;background-color:#eee;border:1px dotted #000;">Never occurred</span> <span style="padding:0 5px;background-color:#fff;border:1px dotted #000;">Occurred before</span> <span style="padding:0 5px;background-color:#9f9;border:1px dotted #000;">Occurred</span> <span style="padding:0 5px;background-color:#ff9;border:1px dotted #000;">Multiple occurrences</span> <a href="#" id="' + config.eventResetId + '">reset</a>)</p>';
// MJP: Would use the next 3 lines for ease, but the events are just slapped on the page.
// $.each($.jPlayer.event, function(eventName,eventType) {
// structure += '<div id="' + config.eventId[eventType] + '" style="float:left;">' + eventName + '</div>';
// });
var eventStyle = "float:left;margin:0 5px 5px 0;padding:0 5px;border:1px dotted #000;";
// MJP: Doing it longhand so order and layout easier to control.
structure +=
'<div id="' + config.eventId[$.jPlayer.event.ready] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.setmedia] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.flashreset] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.resize] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.repeat] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.click] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.warning] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.loadstart] + '" style="clear:left;' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.progress] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.timeupdate] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.volumechange] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.error] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.play] + '" style="clear:left;' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.pause] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.waiting] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.playing] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.seeking] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.seeked] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.ended] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.loadeddata] + '" style="clear:left;' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.loadedmetadata] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.canplay] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.canplaythrough] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.suspend] + '" style="clear:left;' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.abort] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.emptied] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.stalled] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.ratechange] + '" style="' + eventStyle + '"></div>'
+ '<div id="' + config.eventId[$.jPlayer.event.durationchange] + '" style="' + eventStyle + '"></div>'
+ '<div style="clear:both"></div>';
// MJP: Would like a check here in case we missed an event.
// MJP: Check fails, since it is not on the page yet.
/* $.each($.jPlayer.event, function(eventName,eventType) {
if($("#" + config.eventId[eventType])[0] === undefined) {
structure += '<div id="' + config.eventId[eventType] + '" style="clear:left;' + eventStyle + '">' + eventName + '</div>';
}
});
*/
structure +=
'</div>'
+ '<p><a href="#" id="' + config.updateId + '">Update</a> jPlayer Inspector</p>'
+ '<div id="' + config.configId + '"></div>'
+ '</div>';
$(this).html(structure);
config.windowJq = $("#" + config.windowId);
config.statusJq = $("#" + config.statusId);
config.configJq = $("#" + config.configId);
config.toggleJq = $("#" + config.toggleId);
config.eventResetJq = $("#" + config.eventResetId);
config.updateJq = $("#" + config.updateId);
$.each($.jPlayer.event, function(eventName,eventType) {
config.eventJq[eventType] = $("#" + config.eventId[eventType]);
config.eventJq[eventType].text(eventName + " (" + config.eventOccurrence[eventType] + ")"); // Sets the text to the event name and (0);
config.jPlayer.bind(eventType + ".jPlayerInspector", function(e) {
config.eventOccurrence[e.type]++;
if(config.eventOccurrence[e.type] > 1) {
config.eventJq[e.type].css("background-color","#ff9");
} else {
config.eventJq[e.type].css("background-color","#9f9");
}
config.eventJq[e.type].text(eventName + " (" + config.eventOccurrence[e.type] + ")");
// The timer to handle the color
clearTimeout(config.eventTimeout[e.type]);
config.eventTimeout[e.type] = setTimeout(function() {
config.eventJq[e.type].css("background-color","#fff");
}, 1000);
// The timer to handle the occurences.
setTimeout(function() {
config.eventOccurrence[e.type]--;
config.eventJq[e.type].text(eventName + " (" + config.eventOccurrence[e.type] + ")");
}, 1000);
if(config.visible) { // Update the status, if inspector open.
$this.jPlayerInspector("updateStatus");
}
});
});
config.jPlayer.bind($.jPlayer.event.ready + ".jPlayerInspector", function(e) {
$this.jPlayerInspector("updateConfig");
});
config.toggleJq.click(function() {
if(config.visible) {
$(this).text("Show");
config.windowJq.hide();
config.statusJq.empty();
config.configJq.empty();
} else {
$(this).text("Hide");
config.windowJq.show();
config.updateJq.click();
}
config.visible = !config.visible;
$(this).blur();
return false;
});
config.eventResetJq.click(function() {
$.each($.jPlayer.event, function(eventName,eventType) {
config.eventJq[eventType].css("background-color","#eee");
});
$(this).blur();
return false;
});
config.updateJq.click(function() {
$this.jPlayerInspector("updateStatus");
$this.jPlayerInspector("updateConfig");
return false;
});
if(!config.visible) {
config.windowJq.hide();
} else {
// config.updateJq.click();
}
$.jPlayerInspector.i++;
return this;
},
destroy: function() {
$(this).data("jPlayerInspector") && $(this).data("jPlayerInspector").jPlayer.unbind(".jPlayerInspector");
$(this).empty();
},
updateConfig: function() { // This displays information about jPlayer's configuration in inspector
var jPlayerInfo = "<p>This jPlayer instance is running in your browser where:<br />"
for(i = 0; i < $(this).data("jPlayerInspector").jPlayer.data("jPlayer").solutions.length; i++) {
var solution = $(this).data("jPlayerInspector").jPlayer.data("jPlayer").solutions[i];
jPlayerInfo += "&nbsp;jPlayer's <strong>" + solution + "</strong> solution is";
if($(this).data("jPlayerInspector").jPlayer.data("jPlayer")[solution].used) {
jPlayerInfo += " being <strong>used</strong> and will support:<strong>";
for(format in $(this).data("jPlayerInspector").jPlayer.data("jPlayer")[solution].support) {
if($(this).data("jPlayerInspector").jPlayer.data("jPlayer")[solution].support[format]) {
jPlayerInfo += " " + format;
}
}
jPlayerInfo += "</strong><br />";
} else {
jPlayerInfo += " <strong>not required</strong><br />";
}
}
jPlayerInfo += "</p>";
if($(this).data("jPlayerInspector").jPlayer.data("jPlayer").html.active) {
if($(this).data("jPlayerInspector").jPlayer.data("jPlayer").flash.active) {
jPlayerInfo += "<strong>Problem with jPlayer since both HTML5 and Flash are active.</strong>";
} else {
jPlayerInfo += "The <strong>HTML5 is active</strong>.";
}
} else {
if($(this).data("jPlayerInspector").jPlayer.data("jPlayer").flash.active) {
jPlayerInfo += "The <strong>Flash is active</strong>.";
} else {
jPlayerInfo += "No solution is currently active. jPlayer needs a setMedia().";
}
}
jPlayerInfo += "</p>";
var formatType = $(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.formatType;
jPlayerInfo += "<p><code>status.formatType = '" + formatType + "'</code><br />";
if(formatType) {
jPlayerInfo += "<code>Browser canPlay('" + $.jPlayer.prototype.format[formatType].codec + "')</code>";
} else {
jPlayerInfo += "</p>";
}
jPlayerInfo += "<p><code>status.src = '" + $(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.src + "'</code></p>";
jPlayerInfo += "<p><code>status.media = {<br />";
for(prop in $(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.media) {
jPlayerInfo += "&nbsp;" + prop + ": " + $(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.media[prop] + "<br />"; // Some are strings
}
jPlayerInfo += "};</code></p>"
jPlayerInfo += "<p>";
jPlayerInfo += "<code>status.videoWidth = '" + $(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.videoWidth + "'</code>";
jPlayerInfo += " | <code>status.videoHeight = '" + $(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.videoHeight + "'</code>";
jPlayerInfo += "<br /><code>status.width = '" + $(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.width + "'</code>";
jPlayerInfo += " | <code>status.height = '" + $(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.height + "'</code>";
jPlayerInfo += "</p>";
+ "<p>Raw browser test for HTML5 support. Should equal a function if HTML5 is available.<br />";
if($(this).data("jPlayerInspector").jPlayer.data("jPlayer").html.audio.available) {
jPlayerInfo += "<code>htmlElement.audio.canPlayType = " + (typeof $(this).data("jPlayerInspector").jPlayer.data("jPlayer").htmlElement.audio.canPlayType) +"</code><br />"
}
if($(this).data("jPlayerInspector").jPlayer.data("jPlayer").html.video.available) {
jPlayerInfo += "<code>htmlElement.video.canPlayType = " + (typeof $(this).data("jPlayerInspector").jPlayer.data("jPlayer").htmlElement.video.canPlayType) +"</code>";
}
jPlayerInfo += "</p>";
jPlayerInfo += "<p>This instance is using the constructor options:<br />"
+ "<code>$('#" + $(this).data("jPlayerInspector").jPlayer.data("jPlayer").internal.self.id + "').jPlayer({<br />"
+ "&nbsp;swfPath: '" + $(this).data("jPlayerInspector").jPlayer.jPlayer("option", "swfPath") + "',<br />"
+ "&nbsp;solution: '" + $(this).data("jPlayerInspector").jPlayer.jPlayer("option", "solution") + "',<br />"
+ "&nbsp;supplied: '" + $(this).data("jPlayerInspector").jPlayer.jPlayer("option", "supplied") + "',<br />"
+ "&nbsp;preload: '" + $(this).data("jPlayerInspector").jPlayer.jPlayer("option", "preload") + "',<br />"
+ "&nbsp;volume: " + $(this).data("jPlayerInspector").jPlayer.jPlayer("option", "volume") + ",<br />"
+ "&nbsp;muted: " + $(this).data("jPlayerInspector").jPlayer.jPlayer("option", "muted") + ",<br />"
+ "&nbsp;backgroundColor: '" + $(this).data("jPlayerInspector").jPlayer.jPlayer("option", "backgroundColor") + "',<br />"
+ "&nbsp;cssSelectorAncestor: '" + $(this).data("jPlayerInspector").jPlayer.jPlayer("option", "cssSelectorAncestor") + "',<br />"
+ "&nbsp;cssSelector: {";
var cssSelector = $(this).data("jPlayerInspector").jPlayer.jPlayer("option", "cssSelector");
for(prop in cssSelector) {
// jPlayerInfo += "<br />&nbsp;&nbsp;" + prop + ": '" + cssSelector[prop] + "'," // This works too of course, but want to use option method for deep keys.
jPlayerInfo += "<br />&nbsp;&nbsp;" + prop + ": '" + $(this).data("jPlayerInspector").jPlayer.jPlayer("option", "cssSelector." + prop) + "',"
}
jPlayerInfo = jPlayerInfo.slice(0, -1); // Because the sloppy comma was bugging me.
jPlayerInfo += "<br />&nbsp;},<br />"
+ "&nbsp;errorAlerts: " + $(this).data("jPlayerInspector").jPlayer.jPlayer("option", "errorAlerts") + ",<br />"
+ "&nbsp;warningAlerts: " + $(this).data("jPlayerInspector").jPlayer.jPlayer("option", "warningAlerts") + "<br />"
+ "});</code></p>";
$(this).data("jPlayerInspector").configJq.html(jPlayerInfo);
return this;
},
updateStatus: function() { // This displays information about jPlayer's status in the inspector
$(this).data("jPlayerInspector").statusJq.html(
"<p>jPlayer is " +
($(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.paused ? "paused" : "playing") +
" at time: " + Math.floor($(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.currentTime*10)/10 + "s." +
" (d: " + Math.floor($(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.duration*10)/10 + "s" +
", sp: " + Math.floor($(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.seekPercent) + "%" +
", cpr: " + Math.floor($(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.currentPercentRelative) + "%" +
", cpa: " + Math.floor($(this).data("jPlayerInspector").jPlayer.data("jPlayer").status.currentPercentAbsolute) + "%)</p>"
);
return this;
}
};
$.fn.jPlayerInspector = function( method ) {
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.jPlayerInspector' );
}
};
})(jQuery);

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,579 @@
/*
* jPlayer Player Plugin for Popcorn JavaScript Library
* http://www.jplayer.org
*
* Copyright (c) 2012 - 2014 Happyworm Ltd
* Licensed under the MIT license.
* http://opensource.org/licenses/MIT
*
* Author: Mark J Panaghiston
* Version: 1.1.6
* Date: 27th November 2014
*
* For Popcorn Version: 1.3
* For jPlayer Version: 2.9.0
* Requires: jQuery 1.7+
* Note: jQuery dependancy cannot be removed since jPlayer 2 is a jQuery plugin. Use of jQuery will be kept to a minimum.
*/
(function(Popcorn) {
var JQUERY_SCRIPT = '//code.jquery.com/jquery-1.11.1.min.js', // Used if jQuery not already present.
JPLAYER_SCRIPT = '//code.jplayer.org/2.9.0/jplayer/jquery.jplayer.min.js', // Used if jPlayer not already present.
JPLAYER_SWFPATH = '//code.jplayer.org/2.9.0/jplayer/jquery.jplayer.swf', // Used if not specified in jPlayer options via SRC Object.
SOLUTION = 'html,flash', // The default solution option.
DEBUG = false, // Decided to leave the debugging option and console output in for the time being. Overhead is trivial.
jQueryDownloading = false, // Flag to stop multiple instances from each pulling in jQuery, thus corrupting it.
jPlayerDownloading = false, // Flag to stop multiple instances from each pulling in jPlayer, thus corrupting it.
format = { // Duplicate of jPlayer 2.5.0 object, to avoid always requiring jQuery and jPlayer to be loaded before performing the _canPlayType() test.
mp3: {
codec: 'audio/mpeg',
flashCanPlay: true,
media: 'audio'
},
m4a: { // AAC / MP4
codec: 'audio/mp4; codecs="mp4a.40.2"',
flashCanPlay: true,
media: 'audio'
},
m3u8a: { // AAC / MP4 / Apple HLS
codec: 'application/vnd.apple.mpegurl; codecs="mp4a.40.2"',
flashCanPlay: false,
media: 'audio'
},
m3ua: { // M3U
codec: 'audio/mpegurl',
flashCanPlay: false,
media: 'audio'
},
oga: { // OGG
codec: 'audio/ogg; codecs="vorbis, opus"',
flashCanPlay: false,
media: 'audio'
},
flac: { // FLAC
codec: 'audio/x-flac',
flashCanPlay: false,
media: 'audio'
},
wav: { // PCM
codec: 'audio/wav; codecs="1"',
flashCanPlay: false,
media: 'audio'
},
webma: { // WEBM
codec: 'audio/webm; codecs="vorbis"',
flashCanPlay: false,
media: 'audio'
},
fla: { // FLV / F4A
codec: 'audio/x-flv',
flashCanPlay: true,
media: 'audio'
},
rtmpa: { // RTMP AUDIO
codec: 'audio/rtmp; codecs="rtmp"',
flashCanPlay: true,
media: 'audio'
},
m4v: { // H.264 / MP4
codec: 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"',
flashCanPlay: true,
media: 'video'
},
m3u8v: { // H.264 / AAC / MP4 / Apple HLS
codec: 'application/vnd.apple.mpegurl; codecs="avc1.42E01E, mp4a.40.2"',
flashCanPlay: false,
media: 'video'
},
m3uv: { // M3U
codec: 'audio/mpegurl',
flashCanPlay: false,
media: 'video'
},
ogv: { // OGG
codec: 'video/ogg; codecs="theora, vorbis"',
flashCanPlay: false,
media: 'video'
},
webmv: { // WEBM
codec: 'video/webm; codecs="vorbis, vp8"',
flashCanPlay: false,
media: 'video'
},
flv: { // FLV / F4V
codec: 'video/x-flv',
flashCanPlay: true,
media: 'video'
},
rtmpv: { // RTMP VIDEO
codec: 'video/rtmp; codecs="rtmp"',
flashCanPlay: true,
media: 'video'
}
},
isObject = function(val) { // Basic check for Object
if(val && typeof val === 'object' && val.hasOwnProperty) {
return true;
} else {
return false;
}
},
getMediaType = function(url) { // Function to gleam the media type from the URL
var mediaType = false;
if(/\.mp3$/i.test(url)) {
mediaType = 'mp3';
} else if(/\.mp4$/i.test(url) || /\.m4v$/i.test(url)) {
mediaType = 'm4v';
} else if(/\.m4a$/i.test(url)) {
mediaType = 'm4a';
} else if(/\.ogg$/i.test(url) || /\.oga$/i.test(url)) {
mediaType = 'oga';
} else if(/\.ogv$/i.test(url)) {
mediaType = 'ogv';
} else if(/\.webm$/i.test(url)) {
mediaType = 'webmv';
}
return mediaType;
},
getSupplied = function(url) { // Function to generate a supplied option from an src object. ie., When supplied not specified.
var supplied = '',
separator = '';
if(isObject(url)) {
// Generate supplied option from object's properties. Non-format properties would be ignored by jPlayer. Order is unpredictable.
for(var prop in url) {
if(url.hasOwnProperty(prop)) {
supplied += separator + prop;
separator = ',';
}
}
}
if(DEBUG) console.log('getSupplied(): Generated: supplied = "' + supplied + '"');
return supplied;
};
Popcorn.player( 'jplayer', {
_canPlayType: function( containerType, url ) {
// url : Either a String or an Object structured similar a jPlayer media object. ie., As used by setMedia in jPlayer.
// The url object may also contain a solution and supplied property.
// Define the src object structure here!
var cType = containerType.toLowerCase(),
srcObj = {
media:{},
options:{}
},
rVal = false, // Only a boolean false means it is not supported.
mediaType;
if(cType !== 'video' && cType !== 'audio') {
if(typeof url === 'string') {
// Check it starts with http, so the URL is absolute... Well, it is not a perfect check.
if(/^http.*/i.test(url)) {
mediaType = getMediaType(url);
if(mediaType) {
srcObj.media[mediaType] = url;
srcObj.options.solution = SOLUTION;
srcObj.options.supplied = mediaType;
}
}
} else {
srcObj = url; // Assume the url is an src object.
}
// Check for Object and appropriate minimum data structure.
if(isObject(srcObj) && isObject(srcObj.media)) {
if(!isObject(srcObj.options)) {
srcObj.options = {};
}
if(!srcObj.options.solution) {
srcObj.options.solution = SOLUTION;
}
if(!srcObj.options.supplied) {
srcObj.options.supplied = getSupplied(srcObj.media);
}
// Figure out how jPlayer will play it.
// This may not work properly when both audio and video is supplied. ie., A media player. But it should return truethy and jPlayer can figure it out.
var solution = srcObj.options.solution.toLowerCase().split(","), // Create the solution array, with prority based on the order of the solution string.
supplied = srcObj.options.supplied.toLowerCase().split(","); // Create the supplied formats array, with prority based on the order of the supplied formats string.
for(var sol = 0; sol < solution.length; sol++) {
var solutionType = solution[sol].replace(/^\s+|\s+$/g, ""), //trim
checkingHtml = solutionType === 'html',
checkingFlash = solutionType === 'flash',
mediaElem;
for(var fmt = 0; fmt < supplied.length; fmt++) {
mediaType = supplied[fmt].replace(/^\s+|\s+$/g, ""); //trim
if(format[mediaType]) { // Check format is valid.
// Create an HTML5 media element for the type of media.
if(!mediaElem && checkingHtml) {
mediaElem = document.createElement(format[mediaType].media);
}
// See if the HTML5 media element can play the MIME / Codec type.
// Flash also returns the object if the format is playable, so it is truethy, but that html property is false.
// This assumes Flash is available, but that should be dealt with by jPlayer if that happens.
var htmlCanPlay = !!(mediaElem && mediaElem.canPlayType && mediaElem.canPlayType(format[mediaType].codec)),
htmlWillPlay = htmlCanPlay && checkingHtml,
flashWillPlay = format[mediaType].flashCanPlay && checkingFlash;
// The first one found will match what jPlayer uses.
if(htmlWillPlay || flashWillPlay) {
rVal = {
html: htmlWillPlay,
type: mediaType
};
sol = solution.length; // Exit solution loop
fmt = supplied.length; // Exit supplied loop
}
}
}
}
}
}
return rVal;
},
// _setup: function( options ) { // Warning: options is deprecated.
_setup: function() {
var media = this,
myPlayer, // The jQuery selector of the jPlayer element. Usually a <div>
jPlayerObj, // The jPlayer data instance. For performance and DRY code.
mediaType = 'unknown',
jpMedia = {},
jpOptions = {},
ready = false, // Used during init to override the annoying duration dependance in the track event padding during Popcorn's isReady(). ie., We is ready after loadeddata and duration can then be set real value at leisure.
duration = 0, // For the durationchange event with both HTML5 and Flash solutions. Used with 'ready' to keep control during the Popcorn isReady() via loadeddata event. (Duration=0 is bad.)
durationchangeId = null, // A timeout ID used with delayed durationchange event. (Because of the duration=NaN fudge to avoid Popcorn track event corruption.)
canplaythrough = false,
error = null, // The MediaError object.
dispatchDurationChange = function() {
if(ready) {
if(DEBUG) console.log('Dispatched event : durationchange : ' + duration);
media.dispatchEvent('durationchange');
} else {
if(DEBUG) console.log('DELAYED EVENT (!ready) : durationchange : ' + duration);
clearTimeout(durationchangeId); // Stop multiple triggers causing multiple timeouts running in parallel.
durationchangeId = setTimeout(dispatchDurationChange, 250);
}
},
jPlayerFlashEventsPatch = function() {
/* Events already supported by jPlayer Flash:
* loadstart
* loadedmetadata (M4A, M4V)
* progress
* play
* pause
* seeking
* seeked
* timeupdate
* ended
* volumechange
* error <- See the custom handler in jPlayerInit()
*/
/* Events patched:
* loadeddata
* durationchange
* canplaythrough
* playing
*/
/* Events NOT patched:
* suspend
* abort
* emptied
* stalled
* loadedmetadata (MP3)
* waiting
* canplay
* ratechange
*/
// Triggering patched events through the jPlayer Object so the events are homogeneous. ie., The contain the event.jPlayer data structure.
var checkDuration = function(event) {
if(event.jPlayer.status.duration !== duration) {
duration = event.jPlayer.status.duration;
dispatchDurationChange();
}
},
checkCanPlayThrough = function(event) {
if(!canplaythrough && event.jPlayer.status.seekPercent === 100) {
canplaythrough = true;
setTimeout(function() {
if(DEBUG) console.log('Trigger : canplaythrough');
jPlayerObj._trigger($.jPlayer.event.canplaythrough);
}, 0);
}
};
myPlayer.bind($.jPlayer.event.loadstart, function() {
setTimeout(function() {
if(DEBUG) console.log('Trigger : loadeddata');
jPlayerObj._trigger($.jPlayer.event.loadeddata);
}, 0);
})
.bind($.jPlayer.event.progress, function(event) {
checkDuration(event);
checkCanPlayThrough(event);
})
.bind($.jPlayer.event.timeupdate, function(event) {
checkDuration(event);
checkCanPlayThrough(event);
})
.bind($.jPlayer.event.play, function() {
setTimeout(function() {
if(DEBUG) console.log('Trigger : playing');
jPlayerObj._trigger($.jPlayer.event.playing);
}, 0);
});
if(DEBUG) console.log('Created CUSTOM event handlers for FLASH');
},
jPlayerInit = function() {
(function($) {
myPlayer = $('#' + media.id);
if(typeof media.src === 'string') {
mediaType = getMediaType(media.src);
jpMedia[mediaType] = media.src;
jpOptions.supplied = mediaType;
jpOptions.solution = SOLUTION;
} else if(isObject(media.src)) {
jpMedia = isObject(media.src.media) ? media.src.media : {};
jpOptions = isObject(media.src.options) ? media.src.options : {};
jpOptions.solution = jpOptions.solution || SOLUTION;
jpOptions.supplied = jpOptions.supplied || getSupplied(media.src.media);
}
// Allow the swfPath to be set to local server. ie., If the jPlayer Plugin is local and already on the page, then you can also use the local SWF.
jpOptions.swfPath = jpOptions.swfPath || JPLAYER_SWFPATH;
myPlayer.bind($.jPlayer.event.ready, function(event) {
if(event.jPlayer.flash.used) {
jPlayerFlashEventsPatch();
}
// Set the media andd load it, so that the Flash solution behaves similar to HTML5 solution.
// This also allows the loadstart event to be used to know jPlayer is ready.
$(this).jPlayer('setMedia', jpMedia).jPlayer('load');
});
// Do not auto-bubble the reserved events, nor the loadeddata and durationchange event, since the duration must be carefully handled when loadeddata event occurs.
// See the duration property code for more details. (Ranting.)
var reservedEvents = $.jPlayer.reservedEvent + ' loadeddata durationchange',
reservedEvent = reservedEvents.split(/\s+/g);
// Generate event handlers for all the standard HTML5 media events. (Except durationchange)
var bindEvent = function(name) {
myPlayer.bind($.jPlayer.event[name], function(event) {
if(DEBUG) console.log('Dispatched event: ' + name + (event && event.jPlayer ? ' (' + event.jPlayer.status.currentTime + 's)' : '')); // Must be after dispatch for some reason on Firefox/Opera
media.dispatchEvent(name);
});
if(DEBUG) console.log('Created event handler for: ' + name);
};
for(var eventName in $.jPlayer.event) {
if($.jPlayer.event.hasOwnProperty(eventName)) {
var nativeEvent = true;
for(var iRes in reservedEvent) {
if(reservedEvent.hasOwnProperty(iRes)) {
if(reservedEvent[iRes] === eventName) {
nativeEvent = false;
break;
}
}
}
if(nativeEvent) {
bindEvent(eventName);
} else {
if(DEBUG) console.log('Skipped auto event handler creation for: ' + eventName);
}
}
}
myPlayer.bind($.jPlayer.event.loadeddata, function(event) {
if(DEBUG) console.log('Dispatched event: loadeddata' + (event && event.jPlayer ? ' (' + event.jPlayer.status.currentTime + 's)' : ''));
media.dispatchEvent('loadeddata');
ready = true;
});
if(DEBUG) console.log('Created CUSTOM event handler for: loadeddata');
myPlayer.bind($.jPlayer.event.durationchange, function(event) {
duration = event.jPlayer.status.duration;
dispatchDurationChange();
});
if(DEBUG) console.log('Created CUSTOM event handler for: durationchange');
// The error event is a special case. Plus jPlayer error event assumes it is a broken URL. (It could also be a decoder error... Or aborted or a Network error.)
myPlayer.bind($.jPlayer.event.error, function(event) {
// Not sure how to handle the error situation. Popcorn does not appear to have the error or error.code property documented here: http://popcornjs.org/popcorn-docs/media-methods/
// If any error event happens, then something has gone pear shaped.
error = event.jPlayer.error; // Saving object pointer, not a copy of the object. Possible garbage collection issue... But the player is dead anyway, so don't care.
if(error.type === $.jPlayer.error.URL) {
error.code = 4; // MEDIA_ERR_SRC_NOT_SUPPORTED since jPlayer makes this assumption. It is the most common error, then the decode error. Never seen either of the other 2 error types occur.
} else {
error.code = 0; // It was a jPlayer error, not an HTML5 media error.
}
if(DEBUG) console.log('Dispatched event: error');
if(DEBUG) console.dir(error);
media.dispatchEvent('error');
});
if(DEBUG) console.log('Created CUSTOM event handler for: error');
Popcorn.player.defineProperty( media, 'error', {
set: function() {
// Read-only property
return error;
},
get: function() {
return error;
}
});
Popcorn.player.defineProperty( media, 'currentTime', {
set: function( val ) {
if(jPlayerObj.status.paused) {
myPlayer.jPlayer('pause', val);
} else {
myPlayer.jPlayer('play', val);
}
return val;
},
get: function() {
return jPlayerObj.status.currentTime;
}
});
/* The joy of duration and the loadeddata event isReady() handler
* The duration is assumed to be a NaN or a valid duration.
* jPlayer uses zero instead of a NaN and this screws up the Popcorn track event start/end arrays padding.
* This line here:
* videoDurationPlus = duration != duration ? Number.MAX_VALUE : duration + 1;
* Not sure why it is not simply:
* videoDurationPlus = Number.MAX_VALUE; // Who cares if the padding is close to the real duration?
* So if you trigger loadeddata before the duration is correct, the track event padding is screwed up. (It pads the start, not the end... Well, duration+1 = 0+1 = 1s)
* That line makes the MP3 Flash fallback difficult to setup. The whole MP3 will need to load before the duration is known.
* Planning on using a NaN for duration until a >0 value is found... Except with MP3, where seekPercent must be 100% before setting the duration.
* Why not just use a NaN during init... And then correct the duration later?
*/
Popcorn.player.defineProperty( media, 'duration', {
set: function() {
// Read-only property
if(ready) {
return duration;
} else {
return NaN;
}
},
get: function() {
if(ready) {
return duration; // Popcorn has initialized, we can now use duration zero or whatever without fear.
} else {
return NaN; // Keep the duration a NaN until after loadeddata event has occurred. Otherwise Popcorn track event padding is corrupted.
}
}
});
Popcorn.player.defineProperty( media, 'muted', {
set: function( val ) {
myPlayer.jPlayer('mute', val);
return jPlayerObj.options.muted;
},
get: function() {
return jPlayerObj.options.muted;
}
});
Popcorn.player.defineProperty( media, 'volume', {
set: function( val ) {
myPlayer.jPlayer('volume', val);
return jPlayerObj.options.volume;
},
get: function() {
return jPlayerObj.options.volume;
}
});
Popcorn.player.defineProperty( media, 'paused', {
set: function() {
// Read-only property
return jPlayerObj.status.paused;
},
get: function() {
return jPlayerObj.status.paused;
}
});
media.play = function() {
myPlayer.jPlayer('play');
};
media.pause = function() {
myPlayer.jPlayer('pause');
};
myPlayer.jPlayer(jpOptions); // Instance jPlayer. Note that the options should not have a ready event defined... Kill it by default?
jPlayerObj = myPlayer.data('jPlayer');
}(jQuery));
},
jPlayerCheck = function() {
if (!jQuery.jPlayer) {
if (!jPlayerDownloading) {
jPlayerDownloading = true;
Popcorn.getScript(JPLAYER_SCRIPT, function() {
jPlayerDownloading = false;
jPlayerInit();
});
} else {
setTimeout(jPlayerCheck, 250);
}
} else {
jPlayerInit();
}
},
jQueryCheck = function() {
if (!window.jQuery) {
if (!jQueryDownloading) {
jQueryDownloading = true;
Popcorn.getScript(JQUERY_SCRIPT, function() {
jQueryDownloading = false;
jPlayerCheck();
});
} else {
setTimeout(jQueryCheck, 250);
}
} else {
jPlayerCheck();
}
};
jQueryCheck();
},
_teardown: function() {
jQuery('#' + this.id).jPlayer('destroy');
}
});
}(Popcorn));

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,555 @@
/*! Blue Monday Skin for jPlayer 2.9.2 ~ (c) 2009-2014 Happyworm Ltd ~ MIT License */
/*
* Skin for jPlayer Plugin (jQuery JavaScript Library)
* http://www.jplayer.org
*
* Skin Name: Blue Monday
*
* Copyright (c) 2010 - 2014 Happyworm Ltd
* Licensed under the MIT license.
* - http://www.opensource.org/licenses/mit-license.php
*
* Author: Silvia Benvenuti
* Skin Version: 5.1 (jPlayer 2.8.0)
* Date: 13th November 2014
*/
.jp-audio *:focus,
.jp-audio-stream *:focus,
.jp-video *:focus {
/* Disable the browser focus highlighting. */
outline: none; }
.jp-audio button::-moz-focus-inner,
.jp-audio-stream button::-moz-focus-inner,
.jp-video button::-moz-focus-inner {
/* Disable the browser CSS3 focus highlighting. */
border: 0; }
.jp-audio,
.jp-audio-stream,
.jp-video {
font-size: 16px;
font-family: Verdana, Arial, sans-serif;
line-height: 1.6;
color: #666;
border: 1px solid #009be3;
background-color: #eee; }
.jp-audio {
width: 420px; }
.jp-audio-stream {
width: 182px; }
.jp-video-270p {
width: 480px; }
.jp-video-360p {
width: 640px; }
.jp-video-full {
/* Rules for IE6 (full-screen) */
width: 480px;
height: 270px;
/* Rules for IE7 (full-screen) - Otherwise the relative container causes other page items that are not position:static (default) to appear over the video/gui. */
position: static !important;
position: relative; }
/* The z-index rule is defined in this manner to enable Popcorn plugins that add overlays to video area. EG. Subtitles. */
.jp-video-full div div {
z-index: 1000; }
.jp-video-full .jp-jplayer {
top: 0;
left: 0;
position: fixed !important;
position: relative;
/* Rules for IE6 (full-screen) */
overflow: hidden; }
.jp-video-full .jp-gui {
position: fixed !important;
position: static;
/* Rules for IE6 (full-screen) */
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1001;
/* 1 layer above the others. */ }
.jp-video-full .jp-interface {
position: absolute !important;
position: relative;
/* Rules for IE6 (full-screen) */
bottom: 0;
left: 0; }
.jp-interface {
position: relative;
background-color: #eee;
width: 100%; }
.jp-audio .jp-interface {
height: 80px; }
.jp-audio-stream .jp-interface {
height: 80px; }
.jp-video .jp-interface {
border-top: 1px solid #009be3; }
/* @group CONTROLS */
.jp-controls-holder {
clear: both;
width: 100%;
margin: 0 auto;
position: relative;
overflow: hidden;
top: -8px;
/* This negative value depends on the size of the text in jp-currentTime and jp-duration */ }
.jp-interface .jp-controls {
margin: 0;
padding: 0;
overflow: hidden; }
.jp-audio .jp-controls {
width: 380px;
padding: 20px 20px 0 20px; }
.jp-audio-stream .jp-controls {
position: absolute;
top: 20px;
left: 20px;
width: 142px; }
.jp-video .jp-type-single .jp-controls {
width: 78px;
margin-left: 200px; }
.jp-video .jp-type-playlist .jp-controls {
width: 134px;
margin-left: 172px; }
.jp-video .jp-controls {
float: left; }
.jp-controls button {
display: block;
float: left;
overflow: hidden;
text-indent: -9999px;
border: none;
cursor: pointer; }
.jp-play {
width: 40px;
height: 40px; }
.jp-play {
background: url("/assets/jplayer.blue.monday.jpg") 0 0 no-repeat; }
.jp-play:focus {
background: url("/assets/jplayer.blue.monday.jpg") -41px 0 no-repeat; }
.jp-state-playing .jp-play {
background: url("/assets/jplayer.blue.monday.jpg") 0 -42px no-repeat; }
.jp-state-playing .jp-play:focus {
background: url("/assets/jplayer.blue.monday.jpg") -41px -42px no-repeat; }
.jp-stop, .jp-previous, .jp-next {
width: 28px;
height: 28px;
margin-top: 6px; }
.jp-stop {
background: url("/assets/jplayer.blue.monday.jpg") 0 -83px no-repeat;
margin-left: 10px; }
.jp-stop:focus {
background: url("/assets/jplayer.blue.monday.jpg") -29px -83px no-repeat; }
.jp-previous {
background: url("/assets/jplayer.blue.monday.jpg") 0 -112px no-repeat; }
.jp-previous:focus {
background: url("/assets/jplayer.blue.monday.jpg") -29px -112px no-repeat; }
.jp-next {
background: url("/assets/jplayer.blue.monday.jpg") 0 -141px no-repeat; }
.jp-next:focus {
background: url("/assets/jplayer.blue.monday.jpg") -29px -141px no-repeat; }
/* @end */
/* @group progress bar */
.jp-progress {
overflow: hidden;
background-color: #ddd; }
.jp-audio .jp-progress {
position: absolute;
top: 32px;
height: 15px; }
.jp-audio .jp-type-single .jp-progress {
left: 110px;
width: 186px; }
.jp-audio .jp-type-playlist .jp-progress {
left: 166px;
width: 130px; }
.jp-video .jp-progress {
top: 0px;
left: 0px;
width: 100%;
height: 10px; }
.jp-seek-bar {
background: url("/assets/jplayer.blue.monday.jpg") 0 -202px repeat-x;
width: 0px;
height: 100%;
cursor: pointer; }
.jp-play-bar {
background: url("/assets/jplayer.blue.monday.jpg") 0 -218px repeat-x;
width: 0px;
height: 100%; }
/* The seeking class is added/removed inside jPlayer */
.jp-seeking-bg {
background: url("/assets/jplayer.blue.monday.seeking.gif"); }
/* @end */
/* @group volume controls */
.jp-state-no-volume .jp-volume-controls {
display: none; }
.jp-volume-controls {
position: absolute;
top: 32px;
left: 308px;
width: 200px; }
.jp-audio-stream .jp-volume-controls {
left: 70px; }
.jp-video .jp-volume-controls {
top: 12px;
left: 50px; }
.jp-volume-controls button {
display: block;
position: absolute;
overflow: hidden;
text-indent: -9999px;
border: none;
cursor: pointer; }
.jp-mute,
.jp-volume-max {
width: 18px;
height: 15px; }
.jp-volume-max {
left: 74px; }
.jp-mute {
background: url("/assets/jplayer.blue.monday.jpg") 0 -170px no-repeat; }
.jp-mute:focus {
background: url("/assets/jplayer.blue.monday.jpg") -19px -170px no-repeat; }
.jp-state-muted .jp-mute {
background: url("/assets/jplayer.blue.monday.jpg") -60px -170px no-repeat; }
.jp-state-muted .jp-mute:focus {
background: url("/assets/jplayer.blue.monday.jpg") -79px -170px no-repeat; }
.jp-volume-max {
background: url("/assets/jplayer.blue.monday.jpg") 0 -186px no-repeat; }
.jp-volume-max:focus {
background: url("/assets/jplayer.blue.monday.jpg") -19px -186px no-repeat; }
.jp-volume-bar {
position: absolute;
overflow: hidden;
background: url("/assets/jplayer.blue.monday.jpg") 0 -250px repeat-x;
top: 5px;
left: 22px;
width: 46px;
height: 5px;
cursor: pointer; }
.jp-volume-bar-value {
background: url("/assets/jplayer.blue.monday.jpg") 0 -256px repeat-x;
width: 0px;
height: 5px; }
/* @end */
/* @group current time and duration */
.jp-audio .jp-time-holder {
position: absolute;
top: 50px; }
.jp-audio .jp-type-single .jp-time-holder {
left: 110px;
width: 186px; }
.jp-audio .jp-type-playlist .jp-time-holder {
left: 166px;
width: 130px; }
.jp-current-time,
.jp-duration {
width: 60px;
font-size: .64em;
font-style: oblique; }
.jp-current-time {
float: left;
display: inline;
cursor: default; }
.jp-duration {
float: right;
display: inline;
text-align: right;
cursor: pointer; }
.jp-video .jp-current-time {
margin-left: 20px; }
.jp-video .jp-duration {
margin-right: 20px; }
/* @end */
/* @group playlist */
.jp-details {
font-weight: bold;
text-align: center;
cursor: default; }
.jp-details,
.jp-playlist {
width: 100%;
background-color: #ccc;
border-top: 1px solid #009be3; }
.jp-type-single .jp-details,
.jp-type-playlist .jp-details {
border-top: none; }
.jp-details .jp-title {
margin: 0;
padding: 5px 20px;
font-size: .72em;
font-weight: bold; }
.jp-playlist ul {
list-style-type: none;
margin: 0;
padding: 0 20px;
font-size: .72em; }
.jp-playlist li {
padding: 5px 0 4px 20px;
border-bottom: 1px solid #eee; }
.jp-playlist li div {
display: inline; }
/* Note that the first-child (IE6) and last-child (IE6/7/8) selectors do not work on IE */
div.jp-type-playlist div.jp-playlist li:last-child {
padding: 5px 0 5px 20px;
border-bottom: none; }
div.jp-type-playlist div.jp-playlist li.jp-playlist-current {
list-style-type: square;
list-style-position: inside;
padding-left: 7px; }
div.jp-type-playlist div.jp-playlist a {
color: #333;
text-decoration: none; }
div.jp-type-playlist div.jp-playlist a:hover {
color: #0d88c1; }
div.jp-type-playlist div.jp-playlist a.jp-playlist-current {
color: #0d88c1; }
div.jp-type-playlist div.jp-playlist a.jp-playlist-item-remove {
float: right;
display: inline;
text-align: right;
margin-right: 10px;
font-weight: bold;
color: #666; }
div.jp-type-playlist div.jp-playlist a.jp-playlist-item-remove:hover {
color: #0d88c1; }
div.jp-type-playlist div.jp-playlist span.jp-free-media {
float: right;
display: inline;
text-align: right;
margin-right: 10px; }
div.jp-type-playlist div.jp-playlist span.jp-free-media a {
color: #666; }
div.jp-type-playlist div.jp-playlist span.jp-free-media a:hover {
color: #0d88c1; }
span.jp-artist {
font-size: .8em;
color: #666; }
/* @end */
.jp-video-play {
width: 100%;
overflow: hidden;
/* Important for nested negative margins to work in modern browsers */
cursor: pointer;
background-color: transparent;
/* Makes IE9 work with the active area over the whole video area. IE6/7/8 only have the button as active area. */ }
.jp-video-270p .jp-video-play {
margin-top: -270px;
height: 270px; }
.jp-video-360p .jp-video-play {
margin-top: -360px;
height: 360px; }
.jp-video-full .jp-video-play {
height: 100%; }
.jp-video-play-icon {
position: relative;
display: block;
width: 112px;
height: 100px;
margin-left: -56px;
margin-top: -50px;
left: 50%;
top: 50%;
background: url("/assets/jplayer.blue.monday.video.play.png") 0 0 no-repeat;
text-indent: -9999px;
border: none;
cursor: pointer; }
.jp-video-play-icon:focus, .jp-video-play-icon:hover {
background: url("/assets/jplayer.blue.monday.video.play.png") 0 -100px no-repeat; }
.jp-state-playing .jp-video-play-icon {
background: url("/assets/jplayer.blue.monday.video.pause.png") 0 0 no-repeat;}
.jp-state-playing .jp-video-play-icon:focus, .jp-state-playing .jp-video-play-icon:hover {
background: url("/assets/jplayer.blue.monday.video.pause.png") 0 -105px no-repeat; }
.jp-jplayer audio,
.jp-jplayer {
width: 0px;
height: 0px; }
.jp-jplayer {
background-color: #000000; }
/* @group TOGGLES */
/* The audio toggles are nested inside jp-time-holder */
.jp-toggles {
padding: 0;
margin: 0 auto;
overflow: hidden; }
.jp-audio .jp-type-single .jp-toggles {
width: 25px; }
.jp-audio .jp-type-playlist .jp-toggles {
width: 55px;
margin: 0;
position: absolute;
left: 325px;
top: 50px; }
.jp-video .jp-toggles {
position: absolute;
left: 280px;
margin: 0;
margin-top: 10px;
width: 100px; }
.jp-toggles button {
display: block;
float: left;
width: 25px;
height: 18px;
text-indent: -9999px;
line-height: 100%;
/* need this for IE6 */
border: none;
cursor: pointer; }
.jp-full-screen {
background: url("/assets/jplayer.blue.monday.jpg") 0 -310px no-repeat;
margin-left: 20px; }
.jp-full-screen:focus {
background: url("/assets/jplayer.blue.monday.jpg") -30px -310px no-repeat; }
.jp-state-full-screen .jp-full-screen {
background: url("/assets/jplayer.blue.monday.jpg") -60px -310px no-repeat; }
.jp-state-full-screen .jp-full-screen:focus {
background: url("/assets/jplayer.blue.monday.jpg") -90px -310px no-repeat; }
.jp-repeat {
background: url("/assets/jplayer.blue.monday.jpg") 0 -290px no-repeat; }
.jp-repeat:focus {
background: url("/assets/jplayer.blue.monday.jpg") -30px -290px no-repeat; }
.jp-state-looped .jp-repeat {
background: url("/assets/jplayer.blue.monday.jpg") -60px -290px no-repeat; }
.jp-state-looped .jp-repeat:focus {
background: url("/assets/jplayer.blue.monday.jpg") -90px -290px no-repeat; }
.jp-shuffle {
background: url("/assets/jplayer.blue.monday.jpg") 0 -270px no-repeat;
margin-left: 5px; }
.jp-shuffle:focus {
background: url("/assets/jplayer.blue.monday.jpg") -30px -270px no-repeat; }
.jp-state-shuffled .jp-shuffle {
background: url("/assets/jplayer.blue.monday.jpg") -60px -270px no-repeat; }
.jp-state-shuffled .jp-shuffle:focus {
background: url("/assets/jplayer.blue.monday.jpg") -90px -270px no-repeat; }
/* @end */
/* @group NO SOLUTION error feedback */
.jp-no-solution {
padding: 5px;
font-size: .8em;
background-color: #eee;
border: 2px solid #009be3;
color: #000;
display: none; }
.jp-no-solution a {
color: #000; }
.jp-no-solution span {
font-size: 1em;
display: block;
text-align: center;
font-weight: bold; }
/* @end */

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,12 @@
class AdBannersController < ApplicationController
def self.custom_widget_data
ac = ActionController::Base.new
ac.render_to_string("ad_banners/custom_widget_data",:locals=>{:@custom_data_field=>@custom_data_field,:@field_name=>@field_name})
end
def widget
adbanner = Banner.find(OrbitHelper.widget_custom_value)
widget = OrbitHelper.get_current_widget
if widget.widget_type == "ad_banner_widget2_video"
if widget.widget_type.include?("_video")
return video_widget(adbanner)
else
return image_widget(adbanner)
@ -61,7 +65,12 @@ class AdBannersController < ApplicationController
end
def video_widget(adbanner)
subpart = OrbitHelper.get_current_widget
custom_data_field = subpart.custom_data_field || {}
@autoplay_video = custom_data_field[:autoplay_video] == "1" rescue false
@hide_video_tools = custom_data_field[:hide_video_tools] == "1" rescue false
images = []
has_jplayer = false
adbanner.ad_images.can_display.asc(:sort_number).each_with_index do |ad_b,i|
if ad_b.language_enabled.include?(I18n.locale.to_s)
image_link = OrbitHelper.is_mobile_view ? ad_b.file.mobile.url : ad_b.file.url
@ -88,9 +97,24 @@ class AdBannersController < ApplicationController
</a>
<div class='w-ad-banner__caption_text'>#{ad_b.title}</div>
</div>"
else ad_b.exchange_item == "2"
elsif ad_b.exchange_item == "3"
klass = (i == 0 ? "active" : "")
video_url = ad_b.video_file.url
title = (ad_b.title.blank? ? File.basename(video_file) : ad_b.title)
image_html = "<div class=\"w-ba-banner__slide #{klass} jplayer_slide\"
data-link=\"#{ad_b.out_link || "#"}'\"
data-cycle-title=\"#{ad_b.title}\"
data-cycle-desc=\"#{context}\"
data-overlay-template=\"<h3>#{ad_b.title}</h3><p>#{context}</p>\"
data-target=\"#{target}\"
style=\"height: 100%;\"
>
#{ render_to_string(partial: "admin/ad_images/jplayer",locals:{i: i,file_name: title,file_url: video_url,:@autoplay_video=>(@autoplay_video && i == 0),:@apply_autoplay_script=>@autoplay_video,:@hide_video_tools=>@hide_video_tools}, layout: false).to_str }
</div>"
has_jplayer = true
elsif ad_b.exchange_item == "2"
youtube_url = format_url(ad_b.youtube,i)
image_html = "<div class=\"w-ba-banner__slide #{klass} youtube\"
image_html = "<div class=\"w-ba-banner__slide #{klass} youtube youtube_slide\"
data-yt-binded=\"0\"
data-youtube-id=\"ytplayer#{i}\"
data-link=\"#{ad_b.out_link || "#"}'\"
@ -115,6 +139,12 @@ class AdBannersController < ApplicationController
}
end
end
extra_before_html = ""
extra_after_html = ""
if has_jplayer
extra_before_html = "<link href=\"/assets/ad_banner/jplayer.blue.monday.min.css\" rel=\"stylesheet\">"
extra_after_html = "<script src=\"/assets/ad_banner/jquery.jplayer.min.js\"></script>"
end
{
"extras" => {
"ad_fx" => adbanner.ad_fx,
@ -122,7 +152,12 @@ class AdBannersController < ApplicationController
"title" => adbanner.title,
"timeout" => (adbanner.timeout * 1000),
"more" => "More",
"desc" => adbanner.title
"desc" => adbanner.title,
"extra_brefore_html" => extra_before_html,
"extra_after_html" => extra_after_html,
"extra_ready_script" => (@autoplay_video ? "if(i == 0) event.target.mute().playVideo();" : ""),
"extra_state_chnage_script" => (@autoplay_video ? "if(event.data == YT.PlayerState.ENDED){ var current_cycle; cyclediv.cycle(\"pause\") && cyclediv.cycle(\"next\") && (current_cycle=cyclediv.find(\".cycle-slide-active\"), (current_cycle.hasClass(\"jplayer_slide\") ? current_cycle.find('.jp-jplayer').jPlayer(\"mute\", true).jPlayer(\"play\",0) : current_cycle.find('iframe').data(\"yt_player\").mute().playVideo()));}" : ""),
"extra_document_ready_script" => (@autoplay_video ? "opts.API.pause() && opts.API.jump(0);" : "")
},
"images" => images
}

View File

@ -11,7 +11,7 @@ class Admin::AdImagesController < Admin::AdBannersController
def edit
@ad_image = AdImage.find(params[:id])
@item = [[t('image'),"1"],[t('video'),"2"]]
@item = [[t('image'),"1"],['Youtube',"2"],[t('video'),"3"]]
@item_choose = @ad_image.exchange_item
if can_edit_or_delete?(@ad_image.banner)
@ad_banner = @ad_image.banner
@ -29,7 +29,7 @@ class Admin::AdImagesController < Admin::AdBannersController
def new
@ad_image = AdImage.new
@ad_banner = Banner.find(params[:banner_id])
@item = [[t('image'),"1"],[t('video'),"2"]]
@item = [[t('image'),"1"],['Youtube',"2"],[t('video'),"3"]]
if can_edit_or_delete?(@ad_banner)
@tags = @module_app.tags || []
@ad_image.postdate = Date.today

View File

@ -5,6 +5,7 @@ class AdImage
include Mongoid::Timestamps
mount_uploader :file, ImageUploader
mount_uploader :video_file, AssetUploader
field :title, type: String, localize: true
field :context, type: String, localize: true

View File

@ -0,0 +1,28 @@
<div class="hide" id="banner_data">
<div class="control-group input-content">
<label class="control-label muted" for="autoplay_video"><%=t("ad_banner.autoplay_video")%> :</label>
<div class="controls">
<%= hidden_field_tag("#{@field_name}[custom_data_field][autoplay_video]","0") %>
<%= check_box_tag("#{@field_name}[custom_data_field][autoplay_video]", "1" ,(@custom_data_field["autoplay_video"] == "1" rescue false), :id=>"autoplay_video" )%>
</div>
</div>
<div class="control-group input-content">
<label class="control-label muted" for="hide_video_tools"><%=t("ad_banner.hide_video_tools")%> :</label>
<div class="controls">
<%= hidden_field_tag("#{@field_name}[custom_data_field][hide_video_tools]","0") %>
<%= check_box_tag("#{@field_name}[custom_data_field][hide_video_tools]", "1" ,(@custom_data_field["hide_video_tools"] == "1" rescue false), :id=>"hide_video_tools" )%>
</div>
</div>
</div>
<script>
if($('#page_layout').val().indexOf("_video") != -1){
$("#banner_data").removeClass("hide");
}
$('#page_layout').on("change",function(){
if($(this).val().indexOf("_video") != -1){
$("#banner_data").removeClass("hide");
}else{
$("#banner_data").addClass("hide");
}
})
</script>

View File

@ -53,8 +53,13 @@
<td>
<% if image.exchange_item == "1" %>
<%= image_tag image.file.thumb, :class => "banner-image" %>
<% else %>
<% elsif image.exchange_item == "2" %>
<iframe height="140" src="<%= image.embed_url %>"></iframe>
<% elsif image.exchange_item == "3" %>
<video width="320" height="240" controls>
<source src="<%= image.video_file.url %>" type="video/mp4">
Your browser does not support the video tag.
</video>
<% end %>
</td>
<td>

View File

@ -1,6 +1,7 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %>
<%= stylesheet_link_tag "ad_banner/jplayer.blue.monday.min" %>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
@ -8,8 +9,16 @@
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
<%= javascript_include_tag "lib/module-area" %>
<%= javascript_include_tag "validator" %>
<%= javascript_include_tag "ad_banner/jquery.jplayer.min" %>
<% end %>
<style type="text/css">
.fileupload .video-thumbnail{
max-height: none;
display: inline-block;
width: 30em;
height: 20em;
}
</style>
<%#= f.error_messages %>
<!-- Input Area -->
@ -51,7 +60,7 @@
<span class="btn btn-file">
<span class="fileupload-new"><%= t(:select_image) %></span>
<span class="fileupload-exists"><%= t(:change) %></span>
<%= f.file_field :file %>
<%= f.file_field :file, accept: "image/*" %>
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload"><%= t(:cancel) %></a>
<div class="controls" data-toggle="buttons-checkbox">
@ -73,6 +82,32 @@
</div>
</div>
</div>
<div id="exchange_item_3" style="display:none">
<!-- Images Upload -->
<div class="control-group">
<label class="control-label muted"><%= t(:video) %></label>
<div class="controls">
<div class="fileupload fileupload-new clearfix <%= 'fileupload-edit' if @ad_image.file.file %>" data-provides="fileupload">
<div class="fileupload-new video-thumbnail thumbnail pull-left">
<%= render partial: "jplayer",locals:{i: 1,file_name: f.object["video_file"],file_url: f.object.video_file.url,not_ready: true } %>
</div>
<div class="fileupload-preview fileupload-exists thumbnail pull-left"></div>
<span class="btn btn-file">
<span class="fileupload-new"><%= t("ad_banner.select_video") %></span>
<span class="fileupload-exists"><%= t(:change) %></span>
<%= f.file_field :video_file, accept: "video/mp4,video/x-m4v,video/ogg,video/webm" %>
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload"><%= t(:cancel) %></a>
<div class="controls" data-toggle="buttons-checkbox">
<label class="checkbox inline btn btn-danger fileupload-remove">
<%= f.check_box :remove_file %><%= t(:remove) %>
</label>
</div>
</div>
</div>
</div>
</div>
<!-- Title-->
<div class="control-group">
<label for="first_name" class="control-label muted" function="field_label"><%= t("title")%></label>
@ -196,11 +231,31 @@
{
if(document.getElementById("ad_image_exchange_item").value == "")
{
alert("½Ð¥ý¿ï¾ÜÃþ«¬");
alert("<%= t('ad_banner.please_choose_exchange_item') %>");
return false;
}
return true;
}
$(document).ready(function(){
jplayer_ready_func();
$('#ad_image_video_file').change(function(){
var file = this.files ? this.files[0] : null;
var value = this.value;
if(file || value){
var file_name = file ? file.name : value.split(/[\/\\]/).last();
var type = get_video_type(file_name);
var file_url = window.URL ? window.URL.createObjectURL(file) : "file://"+ value;
$("#jquery_jplayer_1").parents('.fileupload-new').css('display','');
$("#jquery_jplayer_1").jPlayer('destroy');
jPlayer_1_data["title"] = file_name;
jPlayer_1_data[type] = file_url;
$("#jquery_jplayer_1").jPlayer(jPlayer_1);
}
})
$('#exchange_item_3 [data-dismiss="fileupload"]').on("click",function(){
$("#jquery_jplayer_1").parents('.fileupload-new').css('display','none');
})
})
</script>

View File

@ -0,0 +1,314 @@
<%= javascript_include_tag "ad_banner/jplayer_front" %>
<style type="text/css">
@media screen and (max-width: 500px) {
/* jplayer */
.jp-video video, .jp-audio, .jp-controls-holder {
width: 100% !important;
}
.jp-video, .jp-video > div, .jp-video img {
height: auto !important;
width: 100% !important;
}
.jp-video-360p {
max-width: 570px !important;
}
.jp-video-270p {
max-width: 480px !important;
}
.jp-progress {
width: 130px;
}
}
.jp-interface{
bottom: 0;
height: 6em;
position: absolute;
}
.jp-video-play,.jp-jplayer{
height: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding-bottom: 6em;
}
.jp-gui{
width: 100%;
height: 100%;
}
.jp-jplayer{
width: 100%;
position: absolute;
}
.jp-type-single{
position: relative;
height: 100%;
}
.jp-video{
width: 100%;
height: 100%;
}
[id^="jp_video_"]{
height: 100%;
}
.jp-video.hide-ui .jp-jplayer,.jp-video.hide-ui .jp-video-play{
padding-bottom: 0em;
}
.jp-video.hide-ui .jp-gui{
display: none;
}
.jp-video.hide-ui [id^="jp_video_"]{
cursor: none;
}
.jp-no-solution
position: absolute;
width: 100%;
display: block;
}
</style>
<div id="jp_container_<%= i %>" class="jp-video hide-ui" role="application" aria-label="media player">
<div class="jp-type-single">
<div id="jquery_jplayer_<%= i %>" class="jp-jplayer"></div>
<div class="jp-gui">
<div class="jp-video-play">
<button class="jp-video-play-icon" role="button" tabindex="0">play</button>
</div>
<div class="jp-interface">
<div class="jp-progress">
<div class="jp-seek-bar">
<div class="jp-play-bar"></div>
</div>
</div>
<div class="jp-current-time" role="timer" aria-label="time">&nbsp;</div>
<div class="jp-duration" role="timer" aria-label="duration">&nbsp;</div>
<div class="jp-controls-holder">
<div class="jp-controls">
<button class="jp-play" role="button" tabindex="0">play</button>
<button class="jp-stop" role="button" tabindex="0">stop</button>
</div>
<div class="jp-volume-controls">
<button class="jp-mute" role="button" tabindex="0">mute</button>
<button class="jp-volume-max" role="button" tabindex="0">max volume</button>
<div class="jp-volume-bar">
<div class="jp-volume-bar-value"></div>
</div>
</div>
<div class="jp-toggles">
<button class="jp-repeat" role="button" tabindex="0">repeat</button>
<button class="jp-full-screen" role="button" tabindex="0">full screen</button>
</div>
</div>
<div class="jp-details">
<div class="jp-title" aria-label="title">&nbsp;</div>
</div>
</div>
</div>
<div class="jp-no-solution">
<span>Update Required</span>
To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.
</div>
</div>
</div>
<script type="text/javascript">
if (typeof(get_video_type)=='undefined'){
function get_video_type(file_name){
var type;
if(file_name){
if(file_name.match(/\.(ogg|ogv)/)){
type = "ogv";
}else if(file_name.match(/\.webm/)){
type = "webmv";
}else{
type = "m4v";
}
return type;
}else{
return "";
}
}
}
var play_<%= i %>_flag = false;
function ad_call_on_play_jplayer_<%= i %>(ele){
var cyclediv = $(ele).parents("div.cycle-slideshow").eq(0);
if(cyclediv.length == 1){
cyclediv[0].need_resume = !(cyclediv.hasClass("cycle-paused"));
var widget = cyclediv.parents('.w-ba-banner').eq(0);
widget.find(".pause-slide").trigger('click');
widget.find('.banner-pager,.controlplay,.button-mid,.ad-overlay').css('visibility','hidden');
//$(ele).jPlayer("pauseOthers");
hide_jplayer_ui_<%= i %>(ele);
}
}
function ad_call_on_pause_jplayer_<%= i %>(ele){
var cyclediv = $(ele).parents("div.cycle-slideshow").eq(0);
if(cyclediv.length == 1){
var widget = cyclediv.parents('.w-ba-banner').eq(0);
if(cyclediv[0].need_resume){
widget.find(".resume-slide").trigger('click');
}
widget.find('.banner-pager,.controlplay,.button-mid,.ad-overlay').css('visibility','');
hide_jplayer_ui_<%= i %>(ele);
}
}
function hide_jplayer_ui_<%= i %>(ele) {
var jpalyer_video = $(ele).parents('.jp-video').eq(0);
jpalyer_video.find(".jp-gui").css("display","");
jpalyer_video.addClass('hide-ui');
}
function show_jplayer_ui_<%= i %>(ele) {
<% unless @hide_video_tools %>
var jpalyer_video = $(ele).parents('.jp-video').eq(0);
jpalyer_video.removeClass('hide-ui');
<% end %>
}
function click_jplayer_<%= i %>(){
$("#jp_container_<%= i %> .jp-video-play").css('display','')
if (play_<%= i %>_flag){
$("#jquery_jplayer_<%= i %>").jPlayer("pause");
}else{
$("#jquery_jplayer_<%= i %>").jPlayer("play");
}
<% unless @hide_video_tools %>
$(this).parents('.jp-video').eq(0).removeClass('hide-ui');
<% end %>
}
if (typeof(default_video_data)=='undefined'){
var default_video_data = {
ready: function () {
$(this).jPlayer("setMedia", {
title: "Big Buck Bunny Trailer",
m4v: "http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v",
ogv: "http://www.jplayer.org/video/ogv/Big_Buck_Bunny_Trailer.ogv",
webmv: "http://www.jplayer.org/video/webm/Big_Buck_Bunny_Trailer.webm",
poster: "http://www.jplayer.org/video/poster/Big_Buck_Bunny_Trailer_480x270.png"
})
},
play: function() { // To avoid multiple jPlayers playing together.
play_<%= i %>_flag = true;
ad_call_on_play_jplayer_<%= i %>(this);
},
click: function(){
click_jplayer_<%= i %>();
},
pause: function(){
play_<%= i %>_flag = false;
$(this).jPlayer("pause");
ad_call_on_pause_jplayer_<%= i %>(this);
window.console.log("pause");
},
abort: function(){
play_<%= i %>_flag = false;
<% unless @hide_video_tools %>
$(this).parents('.jp-video').eq(0).removeClass('hide-ui');
<% end %>
window.console.log("abort");
},
ended: function(){
play_<%= i %>_flag = false;
<% unless @hide_video_tools %>
$(this).parents('.jp-video').eq(0).removeClass('hide-ui');
<% end %>
<% if @apply_autoplay_script %>
var cyclediv = $(this).parents("div.cycle-slideshow").eq(0);
cyclediv.cycle("pause").cycle("next");
var current_cycle = cyclediv.find(".cycle-slide-active")
if(current_cycle.hasClass("jplayer_slide"))
current_cycle.find('.jp-jplayer').jPlayer("mute", true).jPlayer("play",0);
else
current_cycle.find('iframe').data("yt_player").mute().playVideo();
<% end %>
window.console.log("end");
},
swfPath: "/assets/ad_banner",
supplied: "webmv, ogv, m4v",
globalVolume: true,
useStateClassSkin: true,
autoBlur: false,
smoothPlayBar: true,
keyEnabled: true,
wmode: "window",
solution: "html, flash",
size: {
width: "100%",
height: "",
cssClass: ""
}
};
}
<% if file_url %>
var jPlayer_<%= i %>_name = "<%= file_name %>";
var jPlayer_<%= i %>_type = get_video_type(jPlayer_<%= i %>_name);
var jPlayer_<%= i %>_data = {
title: jPlayer_<%= i %>_name,
};
var jPlayer_<%= i %> = $.extend({},default_video_data);
jPlayer_<%= i %>_data[jPlayer_<%= i %>_type] = "<%= file_url %>";
//jPlayer_<%= i %>_data["autoPlay"] = <%= @autoplay_video == true %>;
jPlayer_<%= i %>["ready"] = function () {
$(this).jPlayer("setMedia", jPlayer_<%= i %>_data);
<% if @autoplay_video == true %>
$(this).jPlayer("mute", true).jPlayer("play",0);
<% end %>
<% unless @hide_video_tools %>
$(this).parents('.jp-video').eq(0).removeClass('hide-ui');
<% end %>
}
<% else %>
var jPlayer_<%= i %> = default_video_data;
<% end %>
function jplayer_ready_func(){
$("#jquery_jplayer_<%= i %>").jPlayer(jPlayer_<%= i %>);
if ($("#jquery_jplayer_<%= i %>").parents("div.cycle-slideshow").length>0){
$("#jquery_jplayer_<%= i %>").addClass("hide-ui");
}
$("#jquery_jplayer_<%= i %>,#jquery_jplayer_<%= i %> + .jp-gui .jp-video-play").click(function(event){
click_jplayer_<%= i %>();
event.stopPropagation();
})
$("#jquery_jplayer_<%= i %> *[id^='jp_video'],#jquery_jplayer_<%= i %>").mouseover(function( event ) {
var $this = $(this);
var wrapper = $this.parents('.jp-video').eq(0)
var video_item;
try{
video_item = $this.data('jPlayer').internal.video.jq;
}catch(e){};
if(video_item)
video_item.removeAttr('title');
<% unless @hide_video_tools %>
wrapper.removeClass('hide-ui');
<% end %>
});
function mousemove(target,callback_move,callback_stop) {
target = target || window;
$(target).mousemove((function(event) {
var t;
return function(event) {
if(typeof t !='undefined')
clearTimeout(t);
var _this = event.target;
if(callback_move){
t = setTimeout(function() {callback_move.call(_this,_this)},0);
}
if(callback_stop){
t = setTimeout(function() {
if(typeof t !='undefined'){
clearTimeout(t);
}
callback_stop.call(_this,_this);
}, 1000)
}
}
})())
}
mousemove("#jquery_jplayer_<%= i %> *[id^='jp_video'],#jquery_jplayer_<%= i %>",show_jplayer_ui_<%= i %>,hide_jplayer_ui_<%= i %>)
}
<% if defined?(not_ready).nil? || !not_ready %>
$(document).ready(function(){
jplayer_ready_func();
})
<% end %>
</script>

View File

@ -1,6 +1,10 @@
en:
ad_banner:
autoplay_video: "Autoplay Video(play mute)"
hide_video_tools: Hide video tools
select_video: Select Video
please_choose_exchange_item: Please Choose Item Type
ad_banner: Ad Banner
banner: Banner
banner_name: Banner Name

View File

@ -1,6 +1,10 @@
zh_tw:
ad_banner:
autoplay_video: "自動播放影片(會自動靜音)"
hide_video_tools: 隱藏影片工具
select_video: 選擇影片
please_choose_exchange_item: 請選擇欄位類型
ad_banner: 廣告輪播
banner: 橫幅
banner_name: 橫幅名稱

View File

@ -5,7 +5,7 @@ module AdBanner
module_label "ad_banner.ad_banner"
base_url File.expand_path File.dirname(__FILE__)
widget_methods ["widget"]
widget_settings [{"override_category_with"=>"banner","multiselect"=>false,"display_field"=>"title"}]
widget_settings [{"override_category_with"=>"banner","multiselect"=>false,"display_field"=>"title","enable_custom_widget_data"=>true}]
# models_to_cache [:banner,:ad_image]
taggable "Banner"
categorizable

View File

@ -28,8 +28,8 @@
<div class="w-ba-banner__caption banner-pager banner_caption_{{subpart-id}}"></div>
<ul class="controlplay"><a class="resume-slide active" title = "<%= (I18n.locale.to_s =="zh_tw") ? "繼續播放" : "resume" %>"><i></i></a><a class="pause-slide" title = "<%= (I18n.locale.to_s =="zh_tw") ? "暫停播放" : "pause"%>"><i></i></a></ul>
<ul class="button-mid">
<i class="fa fa-angle-left prev-button" aria-hidden="true" title = "<%= (I18n.locale.to_s =="zh_tw") ? "上一張" : "prev" %>"></i>
<i class="fa fa-angle-right next-button" aria-hidden="true" title = "<%= (I18n.locale.to_s =="zh_tw") ? "下一張" : "next" %>"></i>
<i class="fa fa-angle-left prev-button" aria-hidden="true" title = "<%= (I18n.locale.to_s =="zh_tw") ? "上一張" : "prev" %>" style="cursor: pointer;"></i>
<i class="fa fa-angle-right next-button" aria-hidden="true" title = "<%= (I18n.locale.to_s =="zh_tw") ? "下一張" : "next" %>" style="cursor: pointer;"></i>
</ul>
</div>
</div>
@ -45,53 +45,116 @@
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
$("document").ready(function(){
$("*[data-yt-binded=0]").each(function(){
$(this).attr("data-yt-binded","1");
var obj = $(this).find("iframe");
obj.attr("id",$(this).data("youtube-id") + "_" + ad_banners_count);
ad_banners_count++;
})
});
$("*[data-yt-binded=0]").each(function(){
$(this).attr("data-yt-binded","1");
var obj = $(this).find("iframe");
obj.attr("id",$(this).data("youtube-id") + "_" + ad_banners_count);
ad_banners_count++;
})
if (typeof onYouTubeIframeAPIReady !== 'function'){
if(window.yt_players == undefined)
window.yt_players = {};
$(".w-ba-banner__wrap[data-overlay=\".w-ad-banner__overlay_{{subpart-id}}\"]");
function onYouTubeIframeAPIReady(){
$(".w-ba-banner iframe[data-yt-api-binded=0]").each(function(){
$(this).attr("data-yt-api-binded","1");
new YT.Player($(this).attr("id"), {
events: {
'onStateChange': onPlayerStateChange
}
});
$(".w-ba-banner").each(function(i,banner){
var iframes = $(banner).find("iframe");
if(iframes.length > 0){
var id = $(banner).attr("data-subpart-id");
if(yt_players[id] == undefined)
yt_players[id] = {};
var remove_ids = [];
Object.keys(yt_players[id]).forEach(function(k){
var yt_player = yt_players[id][k];
if($(yt_player.getIframe()).length == 0){
yt_player.destroy();
remove_ids.push(k);
}
})
remove_ids.forEach(function(k){
delete yt_players[id][k];
})
iframes.each(function(i,iframe){
console.log($(iframe).attr("id"))
var yt_player = yt_players[id][$(iframe).attr("id")];
if(yt_player){
}else{
yt_player = new YT.Player($(iframe).attr("id"), {
events: {
'onReady': function(event){
var height = $(event.target.getIframe()).height();
var banner_wrap = $(".w-ba-banner__wrap[data-overlay=\".w-ad-banner__overlay_{{subpart-id}}\"]");
banner_wrap.height(height).css({"padding-bottom":"4em","padding-top":""});
banner_wrap.find(".cycle-carousel-wrap").css("top","3em");
delete event.target.B.onStateChange;
var onStateChange_idx = event.target.l.i.onStateChange;
onStateChange_idx.reverse();
var event_size = 3;
onStateChange_idx.forEach(function(start_idx){
event.target.l.h.splice(start_idx,event_size);
});
event.target.l.i.onStateChange = [];
event.target.l.s = event.target.l.h.length;
event.target.addEventListener('onStateChange',onPlayerStateChange);
{{extra_ready_script}}
},
'onStateChange': onPlayerStateChange
}
});
yt_players[id][$(iframe).attr("id")] = yt_player;
$(iframe).data("yt_player",yt_player);
}
})
}
})
}
function onPlayerStateChange(event){
var iframe = $(event.target.h),
cyclediv = iframe.parents("div.cycle-slideshow");
var widget = cyclediv.parents('.ba-banner-widget-youtube')
var widget = cyclediv.parents('.ba-banner-widget-youtube');
if(event.data == YT.PlayerState.PLAYING || event.data == YT.PlayerState.BUFFERING){
cyclediv[0].need_resume = !(cyclediv.hasClass("cycle-paused"));
cyclediv.cycle("pause");
widget.find('.banner-pager,.controlplay,.button-mid,.ad-overlay').css('visibility','hidden')
}else if(event.data == YT.PlayerState.PAUSED || event.data == YT.PlayerState.ENDED){
cyclediv.cycle("resume");
}else if(event.data == YT.PlayerState.UNSTARTED || event.data == YT.PlayerState.PAUSED || event.data == YT.PlayerState.ENDED){
if(cyclediv[0].need_resume)
cyclediv.cycle("resume");
widget.find('.banner-pager,.controlplay,.button-mid,.ad-overlay').css('visibility','')
}
{{extra_state_chnage_script}}
}
$(document).ready(function(){
window.onYouTubePlayerAPIReady = function() {
onYouTubeIframeAPIReady();
onYouTubeIframeAPIReady.apply(this,arguments);
};
var banner_wrap = $(".w-ba-banner__wrap[data-overlay=\".w-ad-banner__overlay_{{subpart-id}}\"]");
var opts = banner_wrap.data('cycle.opts');
banner_wrap.on('cycle-paused',function(opts){
var controlplay = $(this).nextAll(".controlplay");
if(controlplay.length != 0){
controlplay.find(".resume-slide").removeClass("active");
controlplay.find(".pause-slide").addClass("active");
}
})
banner_wrap.on('cycle-resumed',function(opts){
var controlplay = $(this).nextAll(".controlplay");
if(controlplay.length != 0){
controlplay.find(".resume-slide").addClass("active");
controlplay.find(".pause-slide").removeClass("active");
}
})
var height = opts.slides.filter('.active').height() || opts.slides.height();
banner_wrap.height(height).css("padding-bottom","");
{{extra_document_ready_script}}
$('.pause-slide').off('click').click(function(){
$(this).parent("ul").parent('.w-ba-banner').find(".cycle-slideshow").cycle('pause');
$(this).addClass('active')
$(this).parents('.controlplay').eq(0).find('.resume-slide').removeClass('active')
$(this).addClass('active');
$(this).parents('.controlplay').eq(0).find('.resume-slide').removeClass('active');
});
$('.resume-slide').off('click').click(function(){
$(this).parent("ul").parent('.w-ba-banner').find(".cycle-slideshow").cycle('resume');
$(this).addClass('active')
$(this).parents('.controlplay').eq(0).find('.pause-slide').removeClass('active')
$(this).addClass('active');
$(this).parents('.controlplay').eq(0).find('.pause-slide').removeClass('active');
});
$('.next-button').off('click').on('click',function(){
$(this).parent("ul").parent('.w-ba-banner').find(".cycle-slideshow").cycle("next");
@ -99,6 +162,18 @@ if (typeof onYouTubeIframeAPIReady !== 'function'){
$('.prev-button').off('click').on('click',function(){
$(this).parent("ul").parent('.w-ba-banner').find(".cycle-slideshow").cycle("prev");
})
var resize_timeout_id;
$(window).resize(function(){
if(resize_timeout_id){
window.clearTimeout(resize_timeout_id);
}
resize_timeout_id = window.setTimeout(function(){
var banner_wrap = $(".w-ba-banner__wrap[data-overlay=\".w-ad-banner__overlay_{{subpart-id}}\"]");
var opts = banner_wrap.data('cycle.opts');
var height = opts.slides.filter('.active').height() || opts.slides.height();
banner_wrap.height(height).css("padding-bottom","");
},300);
})
})
}
</script>