Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from butter with <3 #22

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 78 additions & 62 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,10 @@ var vlcs = {},
path = require('path'),
relbase = "./"+path.relative(path.dirname(require.main.filename), __dirname),
sleepId;

require('jquery-ui/sortable');
try{var powerSaveBlocker=require('remote').require('power-save-blocker')}catch(ex){var sleep=require('computer-sleep/sleep')}

// inject css
if (!$("link[href='"+relbase+"/css/general.css']").length) {
$('<link href="'+relbase+'/css/general.css" rel="stylesheet">').appendTo("head");
window.document.styleSheets[0].addRule('.wcp-menu-items::-webkit-scrollbar','width: 44px !important;');
window.document.styleSheets[0].addRule('.wcp-menu-items::-webkit-scrollbar-track','background-color: #696969 !important; border-right: 13px solid rgba(0, 0, 0, 0); border-left: 21px solid rgba(0, 0, 0, 0); background-clip: padding-box; -webkit-box-shadow: none !important;');
window.document.styleSheets[0].addRule('.wcp-menu-items::-webkit-scrollbar-thumb','background-color: #e5e5e5; border-right: 13px solid rgba(0, 0, 0, 0); border-left: 21px solid rgba(0, 0, 0, 0); background-clip: padding-box; -webkit-box-shadow: none !important;');
window.document.styleSheets[0].addRule('.wcp-menu-items::-webkit-scrollbar-thumb:hover','background-color: #e5e5e5 !important; border-right: 13px solid rgba(0, 0, 0, 0); border-left: 21px solid rgba(0, 0, 0, 0); background-clip: padding-box; -webkit-box-shadow: none !important;');
window.document.styleSheets[0].addRule('.wcp-menu-items::-webkit-scrollbar-thumb:active','background-color: #e5e5e5 !important; border-right: 13px solid rgba(0, 0, 0, 0); border-left: 21px solid rgba(0, 0, 0, 0); background-clip: padding-box; -webkit-box-shadow: none !important;');
}

// deinitializate when page changed
window.onbeforeunload = function(e) {
// stop all players
Expand Down Expand Up @@ -74,21 +64,21 @@ function wjs(context) {
if (this.context.substring(0,1) == "#") {
if (window.document.getElementById(this.context.substring(1)).firstChild) {
this.wrapper = window.document.getElementById(this.context.substring(1));
this.canvas = this.wrapper.firstChild.firstChild;
this.wrapper = $(this.wrapper);
}
this.allElements = [window.document.getElementById(this.context.substring(1))];
} else {
if (this.context.substring(0,1) == ".") this.allElements = window.document.getElementsByClassName(this.context.substring(1));
else this.allElements = window.document.getElementsByTagName(this.context);
this.wrapper = this.allElements[0];
this.canvas = this.wrapper.firstChild.firstChild;
this.wrapper = $(this.wrapper);
}
if (vlcs[this.context]) {
this.vlc = vlcs[this.context].vlc;
this.renderer = vlcs[this.context].renderer;
}

this.canvas = $('canvas', this.wrapper)[0]
return this;
}

Expand Down Expand Up @@ -207,27 +197,49 @@ wjs.prototype.prev = function() {
if (noDisabled) return false;

this.playItem(i);

return this;
} else return false;
}

wjs.prototype.addPlayer = function(wcpSettings) {

if (wcpSettings) newid = (typeof wcpSettings["id"] === "undefined") ? "webchimera" : wcpSettings["id"]; // if no id set, default to "webchimera"
else newid = "webchimera";

if (window.document.getElementById(newid) !== null) {
for (i = 2; window.document.getElementById(newid +i) !== null; i++) { }
newid = newid +i;
var wcjsCSS = wcpSettings.css || relbase + '/css/general.css';
var customCSS = wcpSettings.customCSS;
// inject css
if (!$("link[href='"+ wcjsCSS +"']").length) {
$('<link href="'+ wcjsCSS +'" rel="stylesheet">').appendTo("head");
window.document.styleSheets[0].addRule('.wcp-menu-items::-webkit-scrollbar','width: 44px !important;');
window.document.styleSheets[0].addRule('.wcp-menu-items::-webkit-scrollbar-track','background-color: #696969 !important; border-right: 13px solid rgba(0, 0, 0, 0); border-left: 21px solid rgba(0, 0, 0, 0); background-clip: padding-box; -webkit-box-shadow: none !important;');
window.document.styleSheets[0].addRule('.wcp-menu-items::-webkit-scrollbar-thumb','background-color: #e5e5e5; border-right: 13px solid rgba(0, 0, 0, 0); border-left: 21px solid rgba(0, 0, 0, 0); background-clip: padding-box; -webkit-box-shadow: none !important;');
window.document.styleSheets[0].addRule('.wcp-menu-items::-webkit-scrollbar-thumb:hover','background-color: #e5e5e5 !important; border-right: 13px solid rgba(0, 0, 0, 0); border-left: 21px solid rgba(0, 0, 0, 0); background-clip: padding-box; -webkit-box-shadow: none !important;');
window.document.styleSheets[0].addRule('.wcp-menu-items::-webkit-scrollbar-thumb:active','background-color: #e5e5e5 !important; border-right: 13px solid rgba(0, 0, 0, 0); border-left: 21px solid rgba(0, 0, 0, 0); background-clip: padding-box; -webkit-box-shadow: none !important;');
}


if (customCSS && !$("link[href='"+ customCSS +"']").length) {
$('<link href="'+ customCSS +'" rel="stylesheet">').appendTo("head");
}

var attach = (!wcpSettings || typeof wcpSettings.attach === 'undefined') ? true : wcpSettings.attach;

if (attach) {
newid = wcpSettings.id || 'webchimera';
} else {
if (wcpSettings) newid = (typeof wcpSettings["id"] === "undefined") ? "webchimera" : wcpSettings["id"]; // if no id set, default to "webchimera"
else newid = "webchimera";

if (! attach && window.document.getElementById(newid) !== null) {
for (i = 2; window.document.getElementById(newid +i) !== null; i++) { }
newid = newid +i;
}
}


if (typeof newid === 'string') {
if (newid.substring(0,1) == "#") var targetid = ' id="'+newid.substring(1)+'" class="wcp-wrapper"';
else if (newid.substring(0,1) == ".") { var targetid = ' id="webchimera" class="'+newid.substring(1)+' wcp-wrapper"'; newid = "#webchimera"; }
else { var targetid = ' id="'+newid+'" class="wcp-wrapper"'; newid = "#"+newid; }
} else { var targetid = ' id="webchimera" class="wcp-wrapper"'; newid = "#webchimera"; }

vlcs[newid] = {};
vlcs[newid].events = new events.EventEmitter();

Expand All @@ -247,23 +259,26 @@ wjs.prototype.addPlayer = function(wcpSettings) {
opts[newid].zoom = 1;
if (typeof opts[newid].allowFullscreen === 'undefined') opts[newid].allowFullscreen = true;

playerbody = '<div' + targetid + ' style="height: 100%"><div class="wcp-center" style="overflow: hidden"><canvas class="wcp-canvas wcp-center"></canvas></div><div class="wcp-surface"></div><div class="wcp-menu wcp-playlist wcp-center"><div class="wcp-menu-close"></div><div class="wcp-menu-title">Playlist Menu</div><ul class="wcp-menu-items wcp-playlist-items"></ul></div><div class="wcp-menu wcp-subtitles wcp-center"><div class="wcp-menu-close"></div><div class="wcp-menu-title">Subtitle Menu</div><ul class="wcp-menu-items wcp-subtitles-items"></ul></div><div class="wcp-pause-anim wcp-center"><i class="wcp-anim-basic wcp-anim-icon-play"></i></div><div class="wcp-titlebar"><span class="wcp-title"></span></div><div class="wcp-toolbar"><div></div><div class="wcp-progress-bar"><div class="wcp-progress-seen"></div><div class="wcp-progress-pointer"></div></div><div class="wcp-button wcp-left wcp-prev" style="display: none"></div><div class="wcp-button wcp-left wcp-pause"></div><div class="wcp-button wcp-left wcp-next" style="display: none"></div><div class="wcp-button wcp-left wcp-vol-button wcp-volume-medium"></div><div class="wcp-vol-control"><div class="wcp-vol-bar"><div class="wcp-vol-bar-full"></div><div class="wcp-vol-bar-pointer"></div></div></div><div class="wcp-time"><span class="wcp-time-current"></span><span class="wcp-time-total"></span></div><div class="wcp-button wcp-right wcp-maximize"';
if (!opts[newid].allowFullscreen) playerbody += ' style="cursor: not-allowed; color: rgba(123,123,123,0.6);"';
playerbody += '></div><div class="wcp-button wcp-right wcp-playlist-but"></div><div class="wcp-button wcp-right wcp-subtitle-but"></div></div><div class="wcp-status"></div><div class="wcp-notif"></div><div class="wcp-subtitle-text"></div><div class="wcp-tooltip"><div class="wcp-tooltip-arrow"></div><div class="wcp-tooltip-inner">00:00</div></div></div>';

if (! attach) {
playerbody = '<div' + targetid + ' style="height: 100%"><div class="wcp-center" style="overflow: hidden"><canvas class="wcp-canvas wcp-center"></canvas></div><div class="wcp-surface"></div><div class="wcp-menu wcp-playlist wcp-center"><div class="wcp-menu-close"></div><div class="wcp-menu-title">Playlist Menu</div><ul class="wcp-menu-items wcp-playlist-items"></ul></div><div class="wcp-menu wcp-subtitles wcp-center"><div class="wcp-menu-close"></div><div class="wcp-menu-title">Subtitle Menu</div><ul class="wcp-menu-items wcp-subtitles-items"></ul></div><div class="wcp-pause-anim wcp-center"><i class="wcp-anim-basic wcp-anim-icon-play"></i></div><div class="wcp-titlebar"><span class="wcp-title"></span></div><div class="wcp-toolbar"><div></div><div class="wcp-progress-bar"><div class="wcp-progress-seen"></div><div class="wcp-progress-pointer"></div></div><div class="wcp-button wcp-left wcp-prev" style="display: none"></div><div class="wcp-button wcp-left wcp-pause"></div><div class="wcp-button wcp-left wcp-next" style="display: none"></div><div class="wcp-button wcp-left wcp-vol-button wcp-volume-medium"></div><div class="wcp-vol-control"><div class="wcp-vol-bar"><div class="wcp-vol-bar-full"></div><div class="wcp-vol-bar-pointer"></div></div></div><div class="wcp-time"><span class="wcp-time-current"></span><span class="wcp-time-total"></span></div><div class="wcp-button wcp-right wcp-maximize"';
if (!opts[newid].allowFullscreen) playerbody += ' style="cursor: not-allowed; color: rgba(123,123,123,0.6);"';
playerbody += '></div><div class="wcp-button wcp-right wcp-playlist-but"></div><div class="wcp-button wcp-right wcp-subtitle-but"></div></div><div class="wcp-status"></div><div class="wcp-notif"></div><div class="wcp-subtitle-text"></div><div class="wcp-tooltip"><div class="wcp-tooltip-arrow"></div><div class="wcp-tooltip-inner">00:00</div></div></div>';
$(this.context).each(function(ij,el) { if (!$(el).hasClass("webchimeras")) $(el).addClass("webchimeras"); el.innerHTML = playerbody; });
}

opts[newid].currentSub = 0;
opts[newid].trackSub = -1;
$(this.context).each(function(ij,el) { if (!$(el).hasClass("webchimeras")) $(el).addClass("webchimeras"); el.innerHTML = playerbody; });

var wjse = wjs(newid);

if (vlcs[newid].multiscreen) {
vlcs[newid].multiscreen = (typeof wcpSettings["multiscreen"] === "undefined") ? false : wcpSettings["multiscreen"];
$(newid).find(".wcp-toolbar").hide(0);
$(newid).find(".wcp-tooltip").hide(0);
wjs(newid).wrapper.css({cursor: 'pointer'});
wjse.wrapper.css({cursor: 'pointer'});
}
wjs(newid).canvas = $(newid)[0].firstChild.firstChild;

wjse.canvas = $(newid)[0].firstChild.firstChild;

// resize video when window is resized
if (firstTime) {
Expand All @@ -280,7 +295,7 @@ wjs.prototype.addPlayer = function(wcpSettings) {
}(newid));
}

wjs(newid).wrapper.find(".wcp-menu-close").click(function() {
wjse.wrapper.find(".wcp-menu-close").click(function() {
if ($(this).parents(".wcp-wrapper").find(".wcp-playlist").is(":visible")) {
$(".wcp-playlist-items").sortable("destroy");
$(this).parents(".wcp-wrapper").find(".wcp-playlist").hide(0);
Expand All @@ -290,7 +305,7 @@ wjs.prototype.addPlayer = function(wcpSettings) {
});

// toolbar button actions
wjs(newid).wrapper.find(".wcp-button").click(function() {
wjse.wrapper.find(".wcp-button").click(function() {
wjsPlayer = getContext(this);
vlc = wjsPlayer.vlc;
buttonClass = this.className.replace("wcp-button","").replace("wcp-left","").replace("wcp-vol-button","").replace("wcp-right","").split(" ").join("");
Expand All @@ -316,7 +331,7 @@ wjs.prototype.addPlayer = function(wcpSettings) {
});

// surface click actions
wjs(newid).wrapper.find(".wcp-surface").click(function() {
wjse.wrapper.find(".wcp-surface").click(function() {
wjsPlayer = getContext(this);
if (wjsPlayer.stateInt() == 6) {
wjsPlayer.find(".wcp-replay").trigger("click");
Expand All @@ -331,25 +346,25 @@ wjs.prototype.addPlayer = function(wcpSettings) {
}
if ([5].indexOf(wjsPlayer.vlc.state) > -1 && !wjsPlayer.playing() && wjsPlayer.itemCount() > 0) wjsPlayer.play().animatePause();
});
wjs(newid).wrapper.find(".wcp-surface").dblclick(function() {

wjse.wrapper.find(".wcp-surface").dblclick(function() {
wjsPlayer = getContext(this);
if (opts[wjsPlayer.context].allowFullscreen) {
wjsPlayer.find(".wcp-anim-basic").finish();
wjsPlayer.find(".wcp-pause-anim").finish();
wjsPlayer.toggleFullscreen();
}
});
wjs(newid).wrapper.parent().bind("mousemove",function(e) {

wjse.wrapper.parent().bind("mousemove",function(e) {
wjsPlayer = getContext(this);
if (opts[wjsPlayer.context].uiHidden === false) {
if (vlcs[wjsPlayer.context].multiscreen && window.document.webkitFullscreenElement == null) {
wjsPlayer.wrapper.css({cursor: 'pointer'});
} else {
clearTimeout(vlcs[wjsPlayer.context].hideUI);
wjsPlayer.wrapper.css({cursor: 'default'});

if (window.document.webkitFullscreenElement == null) {
if (["both","minimized"].indexOf(opts[wjsPlayer.context].titleBar) > -1) {
wjsPlayer.find(".wcp-titlebar").stop().show(0);
Expand All @@ -363,7 +378,7 @@ wjs.prototype.addPlayer = function(wcpSettings) {
if (wjsPlayer.find(".wcp-notif").css("top") == "10px") wjsPlayer.find(".wcp-notif").css("top", "35px");
}
}

wjsPlayer.find(".wcp-toolbar").stop().show(0);
if (!volDrag && !seekDrag) {
if ($(wjsPlayer.find(".wcp-toolbar").selector + ":hover").length > 0) {
Expand All @@ -374,62 +389,62 @@ wjs.prototype.addPlayer = function(wcpSettings) {
}
} else wjsPlayer.wrapper.css({cursor: 'default'});
});

/* Progress and Volume Bars */
wjs(newid).wrapper.find(".wcp-progress-bar").hover(function(arg1) {
wjse.wrapper.find(".wcp-progress-bar").hover(function(arg1) {
return progressHoverIn.call(getContext(this),arg1);
}, function(e) {
if (!seekDrag) sel.call(this,".wcp-tooltip").hide(0);
});

wjs(newid).wrapper.find(".wcp-progress-bar").bind("mousemove",function(arg1) {
wjse.wrapper.find(".wcp-progress-bar").bind("mousemove",function(arg1) {
return progressMouseMoved.call(getContext(this),arg1);
});

wjs(newid).wrapper.find(".wcp-progress-bar").bind("mousedown", function(e) {
wjse.wrapper.find(".wcp-progress-bar").bind("mousedown", function(e) {
seekDrag = true;
var rect = $(this).parents(".wcp-wrapper")[0].getBoundingClientRect();
p = (e.pageX - rect.left) / $(this).width();
sel.call(this,".wcp-progress-seen").css("width", (p*100)+"%");
});

wjs(newid).wrapper.find(".wcp-vol-bar").bind("mousedown", function(e) {
wjse.wrapper.find(".wcp-vol-bar").bind("mousedown", function(e) {
volDrag = true;
var rect = sel.call(this,".wcp-vol-bar")[0].getBoundingClientRect();
p = (e.pageX - rect.left) / $(this).width();
getContext(this).volume(Math.floor(p*200)+5);
});

wjs(newid).wrapper.find(".wcp-vol-button").hover(function() {
wjse.wrapper.find(".wcp-vol-button").hover(function() {
$(sel.call(this,".wcp-vol-control")).animate({ width: 133 },200);
},function() {
if (!$($(sel.call(this,".wcp-vol-control")).selector + ":hover").length > 0 && !volDrag) {
$(sel.call(this,".wcp-vol-control")).animate({ width: 0 },200);
}
});

wjs(newid).wrapper.find('.wcp-vol-control').mouseout(function() {
wjse.wrapper.find('.wcp-vol-control').mouseout(function() {
if (!$(sel.call(this,".wcp-vol-button").selector + ":hover").length > 0 && !$(sel.call(this,".wcp-vol-bar").selector + ":hover").length > 0 && !$(sel.call(this,".wcp-vol-control").selector + ":hover").length > 0 && !volDrag) {
sel.call(this,".wcp-vol-control").animate({ width: 0 },200);
}
});

// set initial status message font size
fontSize = calcFontSize(wjs(newid));
fontSize = calcFontSize(wjse);

wjs(newid).wrapper.find(".wcp-status").css('fontSize', fontSize);
wjs(newid).wrapper.find(".wcp-notif").css('fontSize', fontSize);
wjs(newid).wrapper.find(".wcp-subtitle-text").css('fontSize', fontSize);
wjse.wrapper.find(".wcp-status").css('fontSize', fontSize);
wjse.wrapper.find(".wcp-notif").css('fontSize', fontSize);
wjse.wrapper.find(".wcp-subtitle-text").css('fontSize', fontSize);

// create player and attach event handlers
wjsPlayer = wjs(newid);
wjsPlayer = wjse;
vlcs[newid].hideUI = setTimeout(function(i) { return function() { hideUI.call(players[i]); } }(newid),6000);
vlcs[newid].timestampUI = 0;
vlcs[newid].renderer = require("wcjs-renderer");

// set default network-caching to 10 seconds
if (!wcpSettings["buffer"]) wcpSettings["buffer"] = 10000;

if (!wcpSettings["vlcArgs"]) wcpSettings["vlcArgs"] = ["--network-caching="+wcpSettings["buffer"]];
else {
var checkBuffer = wcpSettings["vlcArgs"].some(function(el,ij) {
Expand All @@ -438,8 +453,9 @@ wjs.prototype.addPlayer = function(wcpSettings) {
if (!checkBuffer) wcpSettings["vlcArgs"].push("--network-caching="+wcpSettings["buffer"]);
}

if (wcpSettings && wcpSettings["vlcArgs"]) vlcs[newid].vlc = vlcs[newid].renderer.init(wjs(newid).canvas,wcpSettings["vlcArgs"]);
else vlcs[newid].vlc = vlcs[newid].renderer.init(wjs(newid).canvas);
wjse.canvas = $('canvas', wjse.wrapper)[0]
if (wcpSettings && wcpSettings["vlcArgs"]) vlcs[newid].vlc = vlcs[newid].renderer.init(wjse.canvas,wcpSettings["vlcArgs"]);
else vlcs[newid].vlc = vlcs[newid].renderer.init(wjse.canvas);

vlcs[newid].vlc.events.on("FrameSetup",function(i) {
return function(width, height, pixelFormat, videoFrame) {
Expand Down Expand Up @@ -574,7 +590,7 @@ wjs.prototype.addPlayer = function(wcpSettings) {

// set playlist mode to single playback, the player has it's own playlist mode feature
vlcs[newid].vlc.playlist.mode = vlcs[newid].vlc.playlist.Single;

players[newid] = new wjs(newid);

return players[newid];
Expand Down Expand Up @@ -1549,10 +1565,10 @@ function printPlaylist() {
plstring = plstring.split(' ').join(' ');
plstring = plstring.split(' ').join(' ');
plstring = plstring.split(' ').join(' ');

// capitalize first letter
plstring = plstring.charAt(0).toUpperCase() + plstring.slice(1);

if (plstring != this.itemDesc(oi).title) this.vlc.playlist.items[oi].title = "[custom]"+plstring;
}
generatePlaylist += '<li class="wcp-menu-item wcp-playlist-item';
Expand Down Expand Up @@ -1832,4 +1848,4 @@ wjs.prototype.onStateInt=function(wjsFunction){vlcs[this.context].events.on('Sta
wjs.prototype.onTime=function(wjsFunction){this.catchEvent("TimeChanged",wjsFunction);return this}
wjs.prototype.onPosition=function(wjsFunction){this.catchEvent("PositionChanged",wjsFunction);return this}
wjs.prototype.onFrameSetup=function(wjsFunction){vlcs[this.context].events.on('FrameSetup',wjsFunction);return this}
module.exports = wjs;
module.exports = wjs;