1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-24 02:27:19 +00:00

Added a video embed macro

Playing videos makes it easier to verify that a particular tiddler
hasn't been inadvertently refreshed (which would cause the video to
reload)
This commit is contained in:
Jeremy Ruston 2012-02-01 12:36:40 +00:00
parent 6996f255ca
commit 121907fd36
2 changed files with 41 additions and 0 deletions

View File

@ -96,6 +96,7 @@ var App = function() {
this.store.installMacro(require("./macros/story.js").macro);
this.store.installMacro(require("./macros/tiddler.js").macro);
this.store.installMacro(require("./macros/version.js").macro);
this.store.installMacro(require("./macros/video.js").macro);
this.store.installMacro(require("./macros/view.js").macro);
// Set up navigation if we're in the browser
if(this.isBrowser) {

40
js/macros/video.js Normal file
View File

@ -0,0 +1,40 @@
/*\
title: js/macros/video.js
\*/
(function(){
/*jslint node: true */
"use strict";
var utils = require("../Utils.js");
exports.macro = {
name: "video",
types: ["text/html","text/plain"],
params: {
src: {byName: "default", type: "text", optional: false},
type: {byName: true, type: "text", optional: true},
width: {byName: true, type: "text", optional: true},
height: {byName: true, type: "text", optional: true}
},
render: function(type,tiddler,store,params) {
var videoType = params.type || "vimeo",
videoWidth = params.width || 640,
videoHeight = params.height || 360;
if(type === "text/html") {
switch(videoType) {
case "vimeo":
return "<iframe src='http://player.vimeo.com/video/" + params.src + "?autoplay=0' width='" + videoWidth + "' height='" + videoHeight + "' frameborder='0'></iframe>";
case "youtube":
return "<iframe type='text/html' width='" + videoWidth + "' height='" + videoHeight + "' src='http://www.youtube.com/embed/" + params.src + "' frameborder='0'></iframe>";
case "archiveorg":
return "<iframe src='http://www.archive.org/embed/" + params.src + "' width='" + videoWidth + "' height='" + videoHeight + "' frameborder='0'></iframe>";
}
} else if (type === "text/plain") {
return ""; // Not really sure how to render a video into plain text...
}
}
};
})();