forked from Botanical/BotanJS
104 lines
2.9 KiB
JavaScript
104 lines
2.9 KiB
JavaScript
(function(){
|
|
var ns = __namespace( "Astro.Blog.Components.Video" );
|
|
|
|
/** @type {System.utils.IKey} */
|
|
var IKey = __import( "System.utils.IKey" );
|
|
/** @type {Dandelion} */
|
|
var Dand = __import( "Dandelion" );
|
|
/** @type {Dandelion.IDOMElement} */
|
|
var IDOMElement = __import( "Dandelion.IDOMElement" );
|
|
/** @type {Astro.Bootstrap} */
|
|
var Bootstrap = __import( "Astro.Bootstrap" );
|
|
/** @type {Astro.Blog.Config} */
|
|
var Config = __import( "Astro.Blog.Config" );
|
|
|
|
var getData = __import( "System.Net.getData" );
|
|
|
|
var v_current = { player: false, mask: false, stage: false, listener: false };
|
|
|
|
var init = function()
|
|
{
|
|
var conf = Config.get( "Video" );
|
|
if( conf )
|
|
{
|
|
for( var i in conf )
|
|
{
|
|
var type = conf[i];
|
|
var vid = Dand.id( type );
|
|
if( !vid ) continue;
|
|
|
|
type = type.split( "_" )[0];
|
|
|
|
// showVimeoPlayer / showYoutubePlayer
|
|
var cfunc = function( e ) { createPlayer( this.vid, "//www.youtube.com/embed/" ); };
|
|
|
|
if( type[0] == "v" )
|
|
{
|
|
getVimeoThumbnail( vid );
|
|
cfunc = function( e ) { createPlayer( this.vid, "//player.vimeo.com/video/" ); };
|
|
}
|
|
|
|
vid.onclick = cfunc.bind({ vid: vid });
|
|
}
|
|
}
|
|
};
|
|
|
|
var createPlayer = function ( vtag, url )
|
|
{
|
|
// Remove previous playing video if exists
|
|
if( v_current.stage )
|
|
{
|
|
v_current.stage.removeChild( v_current.player );
|
|
v_current.stage.appendChild( v_current.mask );
|
|
v_current.stage.onclick = v_current.listener;
|
|
}
|
|
|
|
// Remove mask
|
|
( v_current.stage = vtag ).removeChild( v_current.mask = vtag.firstChild );
|
|
|
|
v_current.player = Dand.wrapna(
|
|
"iframe"
|
|
, IKey.quickDef(
|
|
"src" , url + vtag.getAttribute( "value" ) + "?autoplay=1"
|
|
, "mozallowfullscreen" , ""
|
|
, "allowFullScreen" , ""
|
|
, "webkitAllowFullScreen" , ""
|
|
, "frameborder" , 0
|
|
, "width" , vtag.clientWidth
|
|
, "height" , vtag.clientHeight
|
|
)
|
|
);
|
|
vtag.appendChild(v_current.player);
|
|
|
|
// Save event listener
|
|
v_current.listener = vtag.onclick;
|
|
|
|
// disable click event
|
|
vtag.onclick = null;
|
|
|
|
// <iframe src="http://player.vimeo.com/video/VIDEO_ID" width="WIDTH" height="HEIGHT" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
|
|
// <iframe id="player" type="text/html" width="WIDTH" height="HEIGHT" src="http://www.youtube.com/embed/id" frameborder="0"></iframe>
|
|
};
|
|
|
|
var getVimeoThumbnail = function ( vtag )
|
|
{
|
|
getData(
|
|
"//vimeo.com/api/oembed.json?url=https%3A//vimeo.com/" + vtag.getAttribute( "value" )
|
|
, parseObj.bind( vtag )
|
|
, noThumb.bind( vtag )
|
|
);
|
|
};
|
|
|
|
var parseObj = function (str)
|
|
{
|
|
this.style.background = "black url(" + JSON.parse(str)["thumbnail_url"] + ") center center no-repeat";
|
|
};
|
|
|
|
var noThumb = function ()
|
|
{
|
|
|
|
};
|
|
|
|
Bootstrap.regInit( init );
|
|
})();
|