Commit 66ddbf10 authored by Anssi Piirainen's avatar Anssi Piirainen
Browse files

cleaning up, preparing to be built using gitbot

parent 2e54765a
/**
* flowplayer.bitrateselect.js Flowplayer JavaScript plugin.
*
* This file is part of Flowplayer, http://flowplayer.org
*
* Authors:
* Daniel Rossi, danielr@electroteque.org
* Anssi Piirainen, api@iki.fi
*
* Copyright (c) 2011-2012 Flowplayer Ltd
*
* Released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*/
(function($) {
$f.addPlugin("bitrateselect", function(container, options) {
// self points to current Player instance
var self = this;
var opts = {
selectedBitrateClass: 'bitrate-selected',
pluginName: 'bitrateselect',
templateId: null,
fadeTime: 500,
seperator: " "
};
$.extend(opts, options);
var wrap = container;
// use either the element with templateId or the contents of wrap
var template = null;
var plugin = self.getPlugin(opts.pluginName) || null;
var bitrateItems = null;
function parseTemplate(values) {
var el = template;
$.each(values, function(key, val) {
//replace label with the bitrate if not set
if (key=="bitrate" || key=="label" && !values.label) {
el = el.replace("\{label\}", values.bitrate + " k").replace("%7B" +key+ "%7D", values.bitrate + " k");
}
el = el.replace("\{" +key+ "\}", val).replace("%7B" +key+ "%7D", val);
});
return el;
}
function play(bitrate) {
if (!plugin) return false;
plugin.setBitrate(bitrate);
return false;
}
function setActiveOption(el) {
wrap.children().removeClass(opts.selectedBitrateClass);
el.addClass(opts.selectedBitrateClass);
}
function buildBitrateList() {
wrap.fadeOut(opts.fadeTime).empty();
var containerWidth = $("#" + self.id()).width();
var index = 0;
var clip = self.getClip();
$.each(bitrateItems, function() {
var el = parseTemplate(this);
el = $(el);
el.attr("index", this.bitrate);
el.show();
el.click(function() {
setActiveOption(el);
play($(this).attr("index"));
if ($(this).is('a')) return false;
});
wrap.append(el);
//added seperator option back in
if (index < bitrateItems.length - 1) wrap.append(opts.seperator);
index++;
});
//if the parent div wrapper is set to display:none fade in the parent
if (wrap.parent().css('display') == "none") {
wrap.show();
// shop the parent div
wrap.parent('div').fadeIn(opts.fadeTime);
} else {
wrap.fadeIn(opts.fadeTime);
}
}
function showBitrateList() {
bitrateItems = self.getClip().bitrateItems ? self.getClip().bitrateItems : self.getClip().bitrates;
if (bitrateItems.length > 0) {
wrap = $(wrap);
//fix for #322 containers only obtainable at this point
template = opts.templateId ? $('<div>').append($(opts.templateId).clone()).remove().html() : wrap.html();
wrap.empty();
buildBitrateList();
}
}
self.onStart(function(clip) {
showBitrateList();
setActiveOption($('[index = "'+ clip.bitrate + '"]', $(wrap)));
});
return self;
});
})(jQuery);
(function(a){$f.addPlugin("bitrateselect",function(c,n){var m=this;var b={selectedBitrateClass:"bitrate-selected",pluginName:"bitrateselect",templateId:null,fadeTime:500,seperator:" "};a.extend(b,n);var e=c;var l=null;var j=m.getPlugin(b.pluginName)||null;var f=null;function h(o){var p=l;a.each(o,function(q,r){if(q=="bitrate"||q=="label"&&!o.label){p=p.replace("{label}",o.bitrate+" k").replace("%7B"+q+"%7D",o.bitrate+" k")}p=p.replace("{"+q+"}",r).replace("%7B"+q+"%7D",r)});return p}function g(o){if(!j){return false}j.setBitrate(o);return false}function d(o){e.children().removeClass(b.selectedBitrateClass);o.addClass(b.selectedBitrateClass)}function k(){e.fadeOut(b.fadeTime).empty();var q=a("#"+m.id()).width();var o=0;var p=m.getClip();a.each(f,function(){var r=h(this);r=a(r);r.attr("index",this.bitrate);r.show();r.click(function(){d(r);g(a(this).attr("index"));if(a(this).is("a")){return false}});e.append(r);if(o<f.length-1){e.append(b.seperator)}o++});if(e.parent().css("display")=="none"){e.show();e.parent("div").fadeIn(b.fadeTime)}else{e.fadeIn(b.fadeTime)}}function i(){f=m.getClip().bitrateItems?m.getClip().bitrateItems:m.getClip().bitrates;if(f.length>0){e=a(e);l=b.templateId?a("<div>").append(a(b.templateId).clone()).remove().html():e.html();e.empty();k()}}m.onStart(function(o){i();d(a('[index = "'+o.bitrate+'"]',a(e)))});return m})})(jQuery);
\ No newline at end of file
/**
* flowplayer.controls.js. Flowplayer JavaScript plugin.
*
* This file is part of Flowplayer, http://flowplayer.org
*
* Author: Tero Piirainen, <support@flowplayer.org>
* Copyright (c) 2008-2012 Flowplayer Ltd
*
* Released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*/
$f.addPlugin("controls", function(wrap, options) {
//{{{ private functions
function fixE(e) {
if (typeof e == 'undefined') { e = window.event; }
if (typeof e.layerX == 'undefined') { e.layerX = e.offsetX; }
if (typeof e.layerY == 'undefined') { e.layerY = e.offsetY; }
return e;
}
function w(e) {
return e.clientWidth;
}
function offset(e) {
return e.offsetLeft;
}
/* a generic dragger utility for hoirzontal dragging */
function Draggable(o, min, max, offset) {
var dragging = false;
function foo() { }
// callbacks
o.onDragStart = o.onDragStart || foo;
o.onDragEnd = o.onDragEnd || foo;
o.onDrag = o.onDrag || foo;
function move(x) {
var ret = true;
// must be withing [min, max]
if (x > max) { x = max; ret = false; }
if (x < min) { x = min; ret = false; }
o.style.left = x + "px";
return ret;
}
function end() {
document.onmousemove = o.ontouchmove = null;
document.onmouseup = o.ontouchend = null;
o.onDragEnd(parseInt(o.style.left, 10));
dragging = false;
}
function drag(e) {
e = e.touches ? e.touches.item(0) : e;
e = fixE(e);
var x = e.clientX - offset;
if (move(x)) {
dragging = true;
o.onDrag(x);
}
return false;
}
o.onmousedown = o.ontouchstart = function(e) {
e = fixE(e);
o.onDragStart(parseInt(o.style.left, 10));
document.onmousemove = o.ontouchmove = drag;
document.onmouseup = o.ontouchend = end;
return false;
};
this.dragTo = function(x) {
if (move(x)) {
o.onDragEnd(x);
}
};
this.setMax = function(val) {
max = val;
};
this.isDragging = function() {
return dragging;
};
return this;
}
function extend(to, from) {
if (from) {
for (key in from) {
if (key) {
to[key] = from[key];
}
}
}
}
function byClass(name) {
var els = wrap.getElementsByTagName("*");
var re = new RegExp("(^|\\s)" + name + "(\\s|$)");
for (var i = 0; i < els.length; i++) {
if (re.test(els[i].className)) {
return els[i];
}
}
}
// prefix integer with zero when nessessary
function pad(val) {
val = parseInt(val, 10);
return val >= 10 ? val : "0" + val;
}
// display seconds in hh:mm:ss format
function toTime(sec) {
var h = Math.floor(sec / 3600);
var min = Math.floor(sec / 60);
sec = sec - (min * 60);
if (h >= 1) {
min -= h * 60;
return pad(h) + ":" + pad(min) + ":" + pad(sec);
}
return pad(min) + ":" + pad(sec);
}
function getTime(time, duration) {
return "<span>" + toTime(time) + "</span> <strong>" + toTime(duration) + "</strong>";
}
//}}}
var self = this;
var opts = {
playHeadClass: 'playhead',
trackClass: 'track',
playClass: 'play',
pauseClass: 'pause',
bufferClass: 'buffer',
progressClass: 'progress',
timeClass: 'time',
muteClass: 'mute',
unmuteClass: 'unmute',
duration: 0,
template: '<a class="play">play</a>' +
'<div class="track">' +
'<div class="buffer"></div>' +
'<div class="progress"></div>' +
'<div class="playhead"></div>' +
'</div>' +
'<div class="time"></div>' +
'<a class="mute">mute</a>'
};
extend(opts, options);
if (typeof wrap == 'string') {
wrap = document.getElementById(wrap);
}
if (!wrap) { return; }
// inner HTML
if (!wrap.innerHTML.replace(/\s/g, '')) {
wrap.innerHTML = opts.template;
}
// get elements
var ball = byClass(opts.playHeadClass);
var bufferBar = byClass(opts.bufferClass);
var progressBar = byClass(opts.progressClass);
var track = byClass(opts.trackClass);
var time = byClass(opts.timeClass);
var mute = byClass(opts.muteClass);
// initial time
time.innerHTML = getTime(0, opts.duration);
// get dimensions
var trackWidth = w(track);
var ballWidth = w(ball);
// initialize draggable playhead
var head = new Draggable(ball, 0, 0, offset(wrap) + offset(track) + (ballWidth / 2));
// track click moves playHead
track.onclick = function(e) {
e = fixE(e);
if (e.target == ball) { return false; }
head.dragTo(e.layerX - ballWidth / 2);
};
// play/pause button
var play = byClass(opts.playClass);
play.onclick = function() {
if (self.isLoaded()) {
self.toggle();
} else {
self.play();
}
};
// mute/unmute button
mute.onclick = function() {
if (self.getStatus().muted) {
self.unmute();
} else {
self.mute();
}
};
// setup timer
var timer = null;
function getMax(len, total) {
return parseInt(Math.min(len / total * trackWidth, trackWidth - ballWidth / 2), 10);
}
self.onStart(function(clip) {
var duration = clip.duration || 0;
// clear previous timer
clearInterval(timer);
// begin timer
// console.log("creating new timer, duration == " + clip.duration);
timer = setInterval(function() {
var status = self.getStatus();
if (status.time === undefined) {
clearInterval(timer);
return;
}
time.innerHTML = getTime(status.time, clip.duration);
// buffer width
var x = getMax(status.bufferEnd, duration);
bufferBar.style.width = x + "px";
head.setMax(x);
// progress width
if (!self.isPaused() && !head.isDragging()) {
x = getMax(status.time, duration);
progressBar.style.width = x + "px";
ball.style.left = (x -ballWidth / 2) + "px";
}
}, 100);
});
self.onBegin(function() {
play.className = opts.pauseClass;
});
// pause / resume states
self.onPause(function() {
play.className = opts.playClass;
});
self.onResume(function() {
play.className = opts.pauseClass;
});
// mute / unmute states
self.onMute(function() {
mute.className = opts.unmuteClass;
});
self.onUnmute(function() {
mute.className = opts.muteClass;
});
// clear timer when clip ends
self.onFinish(function(clip) {
clearInterval(timer);
});
self.onUnload(function() {
time.innerHTML = getTime(0, opts.duration);
});
ball.onDragEnd = function(x) {
var to = parseInt(x / trackWidth * 100, 10) + "%";
progressBar.style.width = x + "px";
if (self.isLoaded()) {
self.seek(to);
}
};
ball.onDrag = function(x) {
progressBar.style.width = x + "px";
};
// return player instance to enable plugin chaining
return self;
});
$f.addPlugin("controls",function(j,a){function q(w){if(typeof w=="undefined"){w=window.event}if(typeof w.layerX=="undefined"){w.layerX=w.offsetX}if(typeof w.layerY=="undefined"){w.layerY=w.offsetY}return w}function l(w){return w.clientWidth}function d(w){return w.offsetLeft}function h(w,D,G,C){var H=false;function F(){}w.onDragStart=w.onDragStart||F;w.onDragEnd=w.onDragEnd||F;w.onDrag=w.onDrag||F;function A(I){var J=true;if(I>G){I=G;J=false}if(I<D){I=D;J=false}w.style.left=I+"px";return J}function B(){document.onmousemove=w.ontouchmove=null;document.onmouseup=w.ontouchend=null;w.onDragEnd(parseInt(w.style.left,10));H=false}function E(J){J=J.touches?J.touches.item(0):J;J=q(J);var I=J.clientX-C;if(A(I)){H=true;w.onDrag(I)}return false}w.onmousedown=w.ontouchstart=function(I){I=q(I);w.onDragStart(parseInt(w.style.left,10));document.onmousemove=w.ontouchmove=E;document.onmouseup=w.ontouchend=B;return false};this.dragTo=function(I){if(A(I)){w.onDragEnd(I)}};this.setMax=function(I){G=I};this.isDragging=function(){return H};return this}function v(A,w){if(w){for(key in w){if(key){A[key]=w[key]}}}}function t(w){var B=j.getElementsByTagName("*");var C=new RegExp("(^|\\s)"+w+"(\\s|$)");for(var A=0;A<B.length;A++){if(C.test(B[A].className)){return B[A]}}}function x(w){w=parseInt(w,10);return w>=10?w:"0"+w}function f(B){var A=Math.floor(B/3600);var w=Math.floor(B/60);B=B-(w*60);if(A>=1){w-=A*60;return x(A)+":"+x(w)+":"+x(B)}return x(w)+":"+x(B)}function y(A,w){return"<span>"+f(A)+"</span> <strong>"+f(w)+"</strong>"}var n=this;var m={playHeadClass:"playhead",trackClass:"track",playClass:"play",pauseClass:"pause",bufferClass:"buffer",progressClass:"progress",timeClass:"time",muteClass:"mute",unmuteClass:"unmute",duration:0,template:'<a class="play">play</a><div class="track"><div class="buffer"></div><div class="progress"></div><div class="playhead"></div></div><div class="time"></div><a class="mute">mute</a>'};v(m,a);if(typeof j=="string"){j=document.getElementById(j)}if(!j){return}if(!j.innerHTML.replace(/\s/g,"")){j.innerHTML=m.template}var r=t(m.playHeadClass);var u=t(m.bufferClass);var o=t(m.progressClass);var p=t(m.trackClass);var g=t(m.timeClass);var e=t(m.muteClass);g.innerHTML=y(0,m.duration);var i=l(p);var s=l(r);var c=new h(r,0,0,d(j)+d(p)+(s/2));p.onclick=function(w){w=q(w);if(w.target==r){return false}c.dragTo(w.layerX-s/2)};var z=t(m.playClass);z.onclick=function(){if(n.isLoaded()){n.toggle()}else{n.play()}};e.onclick=function(){if(n.getStatus().muted){n.unmute()}else{n.mute()}};var k=null;function b(w,A){return parseInt(Math.min(w/A*i,i-s/2),10)}n.onStart(function(w){var A=w.duration||0;clearInterval(k);k=setInterval(function(){var C=n.getStatus();if(C.time===undefined){clearInterval(k);return}g.innerHTML=y(C.time,w.duration);var B=b(C.bufferEnd,A);u.style.width=B+"px";c.setMax(B);if(!n.isPaused()&&!c.isDragging()){B=b(C.time,A);o.style.width=B+"px";r.style.left=(B-s/2)+"px"}},100)});n.onBegin(function(){z.className=m.pauseClass});n.onPause(function(){z.className=m.playClass});n.onResume(function(){z.className=m.pauseClass});n.onMute(function(){e.className=m.unmuteClass});n.onUnmute(function(){e.className=m.muteClass});n.onFinish(function(w){clearInterval(k)});n.onUnload(function(){g.innerHTML=y(0,m.duration)});r.onDragEnd=function(w){var A=parseInt(w/i*100,10)+"%";o.style.width=w+"px";if(n.isLoaded()){n.seek(A)}};r.onDrag=function(w){o.style.width=w+"px"};return n});
\ No newline at end of file
/**
* flowplayer.embed.js Flowplayer JavaScript plugin.
*
* This file is part of Flowplayer, http://flowplayer.org
*
* Author: Tero Piirainen, <support@flowplayer.org>
* Copyright (c) 2008-2012 Flowplayer Ltd
*
* Released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*/
(function() {
// converts paths to absolute URL's as required in external sites
function toAbsolute(url, base) {
// http://some.com/path
if (url.substring(0, 4) == "http") { return url; }
if (base) {
return base + (base.substring(base.length -1) != "/" ? "/" : "") + url;
}
// /some/path
base = location.protocol + "//" + location.host;
if (url.substring(0, 1) == "/") { return base + url; }
// yet/another/path
var path = location.pathname;
path = path.substring(0, path.lastIndexOf("/"));
return base + path + "/" + url;
}
// Flowplayer plugin implementation
$f.addPlugin("embed", function(options) {
var self = this;
var conf = self.getConfig(true);
// default configuration for flashembed
var opts = {
width: self.getParent().clientWidth || '100%',
height: self.getParent().clientHeight || '100%',
url: toAbsolute(self.getFlashParams().src),
index: -1,
allowfullscreen: true,
allowscriptaccess: 'always'
};
// override defaults
$f.extend(opts, options);
opts.src = opts.url;
opts.w3c = true;
// not needed for external objects
delete conf.playerId;
delete opts.url;
delete opts.index;
// construct HTML code for the configuration
this.getEmbedCode = function(runnable, index) {
// selected clip only: given in argument or in configuration
index = typeof index == 'number' ? index : opts.index;
if (index >= 0) {
conf.playlist = [ self.getPlaylist()[index] ];
}
// setup absolute path for each clip
index = 0;
$f.each(conf.playlist, function() {
conf.playlist[index++].url = toAbsolute(this.url, this.baseUrl);
});
var html = flashembed.getHTML(opts, {config: conf});
if (!runnable) {
html = html.replace(/\</g, "&lt;").replace(/\>/g, "&gt;");
}
return html;
};
return self;
});
})();
(function(){function a(b,c){if(b.substring(0,4)=="http"){return b}if(c){return c+(c.substring(c.length-1)!="/"?"/":"")+b}c=location.protocol+"//"+location.host;if(b.substring(0,1)=="/"){return c+b}var d=location.pathname;d=d.substring(0,d.lastIndexOf("/"));return c+d+"/"+b}$f.addPlugin("embed",function(d){var b=this;var c=b.getConfig(true);var e={width:b.getParent().clientWidth||"100%",height:b.getParent().clientHeight||"100%",url:a(b.getFlashParams().src),index:-1,allowfullscreen:true,allowscriptaccess:"always"};$f.extend(e,d);e.src=e.url;e.w3c=true;delete c.playerId;delete e.url;delete e.index;this.getEmbedCode=function(h,f){f=typeof f=="number"?f:e.index;if(f>=0){c.playlist=[b.getPlaylist()[f]]}f=0;$f.each(c.playlist,function(){c.playlist[f++].url=a(this.url,this.baseUrl)});var g=flashembed.getHTML(e,{config:c});if(!h){g=g.replace(/\</g,"&lt;").replace(/\>/g,"&gt;")}return g};return b})})();
\ No newline at end of file
This diff is collapsed.