Gitlab will be down on Friday 25th May (from 9:00 am to 12:00 )

Commit c346e65d by murtaugh

js

parent 77185c8b
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var timecode = require("./timecode.js");
class CCFrame {
constructor (elt) {
// console.log("ccframe", elt);
......@@ -82,7 +84,7 @@ class CCFrame {
return this.url;
}
_load (e) {
// console.log("iframe loaded", this, e);
console.log("iframe loaded", this, e);
if (this.iframe.contentDocument) {
var video = this.iframe.contentDocument.querySelector("video");
if (video) {
......@@ -90,7 +92,7 @@ class CCFrame {
}
var pageNumber = this.iframe.contentDocument.querySelector("input#pageNumber");
this.pageNumberInput = pageNumber;
this.pageNumber = pageNumber.value;
this.pageNumber = pageNumber && pageNumber.value;
if (pageNumber) {
console.log("iframe has pageNumber", pageNumber);
this.interval = function () {
......@@ -106,7 +108,17 @@ class CCFrame {
// }, false);
}
} else {
console.log("unable to query remote iframe content");
console.log("unable to access iframe.contentDocument");
}
if (this.iframe.contentWindow) {
var that = this;
console.log("watching iframe.contentWindow")
this.iframe.contentWindow.addEventListener("hashchange", function () {
console.log("iframe hashchange", that.iframe.contentWindow.location.hash);
})
} else {
console.log("unable to access iframe.contentWindow")
}
}
_timeupdate (e) {
......@@ -154,7 +166,9 @@ class CCFrame {
if (this.pageNumber !== null) {
return "#page="+this.pageNumber;
} else if (this.video) {
return this.video.currentTime
return "#t="+timecode.seconds_to_timecode(this.video.currentTime);
} else {
return this.iframe.contentWindow.location.hash;
}
}
set fragment (val) {
......@@ -165,7 +179,7 @@ class CCFrame {
module.exports = CCFrame;
},{}],2:[function(require,module,exports){
},{"./timecode.js":3}],2:[function(require,module,exports){
(function () {
/* some simple utilities */
......@@ -215,6 +229,22 @@ function post (url, data, callback) {
request.send(sdata);
}
function trim_parentheses (m) { return m.replace(/^\((.+)\)$/, "$1") }
function trim_brackets (m) { return m.replace(/^\[(.+)\]:?$/, "$1") }
function extract_reflink_definitions (text) {
var ret = {},
pat = /^\[([^\]]+)\]:\s+([^ \n]+)(?: +("[^"]*"|\'[^"]*\'|\([^\)]*\)|.*))?$/gm;
text.replace(pat, function (m, label, url, title) {
var mobj = {label: label, url: url, title: title};
console.log("match", mobj);
ret[label.toLowerCase()] = mobj;
})
return ret;
}
var timecode = require("./timecode.js"),
CCFrame = require("./ccframe.js"),
tcpat = /(?:(\d\d):)?(\d\d):(\d\d)(?:[.,](\d{1,3}))?/;
......@@ -238,7 +268,8 @@ CodeMirror.defineMode("ccmarkdown", function(config, parserConfig) {
var player = new CCFrame(document.getElementById("player")),
editor = CodeMirror.fromTextArea(document.getElementById("static"), {
mode: "ccmarkdown",
//mode: "ccmarkdown",
mode: "text/x-markdown",
lineNumbers: false,
lineWrapping: true,
foldGutter: true,
......@@ -248,7 +279,9 @@ var player = new CCFrame(document.getElementById("player")),
/* Keys */
editor.setOption("extraKeys", {
"Ctrl-Down": function(cm) {
cm.replaceSelection(""+timecode.seconds_to_timecode(player.currentTime));
// todo: get current url + hash... use reflink if available
console.log("player", player);
cm.replaceSelection(player.fragment); // "" + timecode.seconds_to_timecode(player.currentTime));
},
"Ctrl-Up": function(cm) {
player.toggle();
......@@ -264,22 +297,43 @@ editor.setOption("extraKeys", {
}
});
function xpandRefLink (href, reflinks) {
if (href.indexOf("#") >= 0) {
var hrefp = href.split("#", 2);
href = hrefp[0];
hsh = hrefp[1];
var reflink = reflinks[href.toLowerCase()];
if (reflink !== undefined) {
// reflink DEFINED!!!!
// console.log("REFLINK", href, reflink.url)
return reflink.url+"#"+hsh;
}
} else {
// expand non hashes too ?!
var reflink = reflinks[href.toLowerCase()];
if (reflink !== undefined) {
return reflink.url;
}
}
return href;
}
/* Map URL and timecode clicks */
function clicker (e) {
var href;
var href, hsh;
if (e.target.classList.contains("cm-link")) {
href = e.target.textContent;
var m = href.match(/^<(.+)>$/);
// console.log("m", m);
if (m) {
href = m[1];
player.src = href;
}
href = trim_parentheses(trim_brackets(e.target.textContent));
console.log("cm-link1", href);
var reflinks = extract_reflink_definitions(editor.getValue());
href = xpandRefLink(href, reflinks);
console.log("cm-link", href);
if (href) { player.src = href; }
} else if (e.target.classList.contains("cm-url")) {
href = e.target.textContent;
console.log("cm-url click", href);
href = e.target.textContent.replace(/^\(/, "").replace(/\)$/, "");
player.src = href;
href = trim_parentheses(trim_brackets(e.target.textContent));
var reflinks = extract_reflink_definitions(editor.getValue());
href = xpandRefLink(href, reflinks);
console.log("cm-url", href);
if (href) { player.src = href; }
} else if (e.target.classList.contains("cm-cctimecode")) {
player.currentTime = timecode.timecode_to_seconds(e.target.textContent);
}
......@@ -322,8 +376,9 @@ function hashchange () {
window.addEventListener("hashchange", hashchange);
hashchange();
function do_save (editor) {
var text = editor.getValue();
function do_save (e) {
// console.log("do_save", e, editor, e==editor);
var text = e.getValue();
var savebutton = gebi("save");
savebutton.classList.add("saving");
savebutton.disabled = true;
......@@ -342,7 +397,7 @@ function do_save (editor) {
}
}
gebi("save").addEventListener("click", do_save);
gebi("save").addEventListener("click", function () { do_save(editor); });
})()
......
var timecode = require("./timecode.js");
class CCFrame {
constructor (elt) {
// console.log("ccframe", elt);
......@@ -81,7 +83,7 @@ class CCFrame {
return this.url;
}
_load (e) {
// console.log("iframe loaded", this, e);
console.log("iframe loaded", this, e);
if (this.iframe.contentDocument) {
var video = this.iframe.contentDocument.querySelector("video");
if (video) {
......@@ -89,7 +91,7 @@ class CCFrame {
}
var pageNumber = this.iframe.contentDocument.querySelector("input#pageNumber");
this.pageNumberInput = pageNumber;
this.pageNumber = pageNumber.value;
this.pageNumber = pageNumber && pageNumber.value;
if (pageNumber) {
console.log("iframe has pageNumber", pageNumber);
this.interval = function () {
......@@ -105,7 +107,17 @@ class CCFrame {
// }, false);
}
} else {
console.log("unable to query remote iframe content");
console.log("unable to access iframe.contentDocument");
}
if (this.iframe.contentWindow) {
var that = this;
console.log("watching iframe.contentWindow")
this.iframe.contentWindow.addEventListener("hashchange", function () {
console.log("iframe hashchange", that.iframe.contentWindow.location.hash);
})
} else {
console.log("unable to access iframe.contentWindow")
}
}
_timeupdate (e) {
......@@ -153,7 +165,9 @@ class CCFrame {
if (this.pageNumber !== null) {
return "#page="+this.pageNumber;
} else if (this.video) {
return this.video.currentTime
return "#t="+timecode.seconds_to_timecode(this.video.currentTime);
} else {
return this.iframe.contentWindow.location.hash;
}
}
set fragment (val) {
......
......@@ -47,6 +47,22 @@ function post (url, data, callback) {
request.send(sdata);
}
function trim_parentheses (m) { return m.replace(/^\((.+)\)$/, "$1") }
function trim_brackets (m) { return m.replace(/^\[(.+)\]:?$/, "$1") }
function extract_reflink_definitions (text) {
var ret = {},
pat = /^\[([^\]]+)\]:\s+([^ \n]+)(?: +("[^"]*"|\'[^"]*\'|\([^\)]*\)|.*))?$/gm;
text.replace(pat, function (m, label, url, title) {
var mobj = {label: label, url: url, title: title};
console.log("match", mobj);
ret[label.toLowerCase()] = mobj;
})
return ret;
}
var timecode = require("./timecode.js"),
CCFrame = require("./ccframe.js"),
tcpat = /(?:(\d\d):)?(\d\d):(\d\d)(?:[.,](\d{1,3}))?/;
......@@ -70,7 +86,8 @@ CodeMirror.defineMode("ccmarkdown", function(config, parserConfig) {
var player = new CCFrame(document.getElementById("player")),
editor = CodeMirror.fromTextArea(document.getElementById("static"), {
mode: "ccmarkdown",
//mode: "ccmarkdown",
mode: "text/x-markdown",
lineNumbers: false,
lineWrapping: true,
foldGutter: true,
......@@ -80,7 +97,9 @@ var player = new CCFrame(document.getElementById("player")),
/* Keys */
editor.setOption("extraKeys", {
"Ctrl-Down": function(cm) {
cm.replaceSelection(""+timecode.seconds_to_timecode(player.currentTime));
// todo: get current url + hash... use reflink if available
console.log("player", player);
cm.replaceSelection(player.fragment); // "" + timecode.seconds_to_timecode(player.currentTime));
},
"Ctrl-Up": function(cm) {
player.toggle();
......@@ -96,22 +115,43 @@ editor.setOption("extraKeys", {
}
});
function xpandRefLink (href, reflinks) {
if (href.indexOf("#") >= 0) {
var hrefp = href.split("#", 2);
href = hrefp[0];
hsh = hrefp[1];
var reflink = reflinks[href.toLowerCase()];
if (reflink !== undefined) {
// reflink DEFINED!!!!
// console.log("REFLINK", href, reflink.url)
return reflink.url+"#"+hsh;
}
} else {
// expand non hashes too ?!
var reflink = reflinks[href.toLowerCase()];
if (reflink !== undefined) {
return reflink.url;
}
}
return href;
}
/* Map URL and timecode clicks */
function clicker (e) {
var href;
var href, hsh;
if (e.target.classList.contains("cm-link")) {
href = e.target.textContent;
var m = href.match(/^<(.+)>$/);
// console.log("m", m);
if (m) {
href = m[1];
player.src = href;
}
href = trim_parentheses(trim_brackets(e.target.textContent));
console.log("cm-link1", href);
var reflinks = extract_reflink_definitions(editor.getValue());
href = xpandRefLink(href, reflinks);
console.log("cm-link", href);
if (href) { player.src = href; }
} else if (e.target.classList.contains("cm-url")) {
href = e.target.textContent;
console.log("cm-url click", href);
href = e.target.textContent.replace(/^\(/, "").replace(/\)$/, "");
player.src = href;
href = trim_parentheses(trim_brackets(e.target.textContent));
var reflinks = extract_reflink_definitions(editor.getValue());
href = xpandRefLink(href, reflinks);
console.log("cm-url", href);
if (href) { player.src = href; }
} else if (e.target.classList.contains("cm-cctimecode")) {
player.currentTime = timecode.timecode_to_seconds(e.target.textContent);
}
......@@ -154,8 +194,9 @@ function hashchange () {
window.addEventListener("hashchange", hashchange);
hashchange();
function do_save (editor) {
var text = editor.getValue();
function do_save (e) {
// console.log("do_save", e, editor, e==editor);
var text = e.getValue();
var savebutton = gebi("save");
savebutton.classList.add("saving");
savebutton.disabled = true;
......@@ -174,7 +215,7 @@ function do_save (editor) {
}
}
gebi("save").addEventListener("click", do_save);
gebi("save").addEventListener("click", function () { do_save(editor); });
})()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment