From 8794207e1d78a32b28f742422e34f34ed40f3f28 Mon Sep 17 00:00:00 2001 From: Sanjay Bhangar Date: Tue, 27 Mar 2018 17:56:21 +0530 Subject: [PATCH] allow loading of yaml with url param textb= --- example/example.js | 32 ++- example/index.html | 551 +------------------------------------------- lib/js-yaml.min.js | 1 + lib/json-to-html.js | 90 ++++++++ 4 files changed, 125 insertions(+), 549 deletions(-) create mode 100644 lib/js-yaml.min.js create mode 100644 lib/json-to-html.js diff --git a/example/example.js b/example/example.js index 852a6d9..73bf5a9 100644 --- a/example/example.js +++ b/example/example.js @@ -188,8 +188,38 @@ var slides = [], activeAudio, timeout; +let textbUrl = new URLSearchParams(window.location.search).get('textb') || 'https://textb.org/r/housingplaylist2/' + +// use raw version of page +textbUrl = textbUrl.replace('/t/', '/r/') +if (!textbUrl.endsWith('/')) textbUrl += '/' + +fetch(textbUrl) + .then(response => response.text()) + .then(loadYaml) + .then(init) + .catch(err => { + console.log('error', err) + alert('error loading YAML') + }) + + +function loadYaml(txt) { + const html = txt.split('\n\n') + .filter(chunk => chunk.trim()) + .map(chunk => { + const obj = jsyaml.load(chunk) + return obj + }) + .map(jsonToHTML) + .join('') + document.body.innerHTML = ` +
+ ${html} + ` + return true +} -init() function init() { document.querySelectorAll('.slide').forEach(function(slide, idx) { diff --git a/example/index.html b/example/index.html index 8a4c29c..31a42dd 100644 --- a/example/index.html +++ b/example/index.html @@ -1,554 +1,9 @@ -
-
- - -
- -
- FROM JANTA COLONY TO JANTA COLONY -
- - - -
- - - -
- -
- At first, three stories from the year 1950 in Bombay -
- - - -
- - - -
- -
- -
- - - -
- - - -
- -
- ONE -
- - - -
- - - -
- -
- -
- - -
- - -
- - - -
- -
- The Greater Bombay Tenant's Association is formed in April 1950 -
- - -
- - -
- - - -
- -
- It demands the "rationing" of living space in Bombay -
- - -
- - -
- -
- - - -
- -
- One week later, 250 people removed from Mahim causeway -
- - -
- - -
- - - -
- -
- occupy Samudra Mahal in Worli -
- - -
- - -
- - - -
- -
- -
- - -
- - -
- - - -
- -
- It is reoccupied one day later. -
- - -
- - -
- - - -
- -
- 5 days after that, a govt. conference on the "squatter issue" was held. -
- - -
- - -
- - - -
- -
- It refers to the 1949 survey of homeless done by TISS as its main source. -
- - - -
- - - -
- -
- Three months later, a proposal is made to create a "Poor Man's Colony" in Mankhurd. -
- - -
- - -
- - - -
- -
- For 4,000 families, "Between Sion and Trombay" -
- - -
- - -
- - - -
- -
- In an area known as Manbudruk, in Farsi, big brother of Mankhurd. -
- - -
- - -
- - - -
- -
- In another year the squatter population has doubled to 75,000 -
- - -
- - -
- - - -
- -
- On December there are evictions of 1,700 huts at Sion Circle, out of which 500 moved to Mankhurd. -
- - -
- - -
- - - -
- -
- The following year there are many people who refuse to be transported to Mankhurd. -
- - -
- - -
- - - -
- -
- On a national level, in 1954 Nehru had decided he was against paying compensation in such cases. -
- - -
- - -
- - - -
- -
- A better idea, he is quoted in TOI, is "to burn them". -
- - -
- - -
- - - -
- -
- -
- - - -
- - - -
- -
- Meanwhile in April 1950, the limits of Bombay city have been officially extended. -
- - -
- - -
- - - -
- -
- -
- - -
- - -
- - - -
- -
- -
- - - -
- - - -
- -
- OK, Lets watch a three minute version of Raj Kapoor's Sree 420 -
- - -
- - -
- - - -
- -
- -
- - -
- - -
- - - -
- -
- Abbas -
- - -
- - -
- - - -
- -
- In Mani Kaul Satah se Uthata -
- - -
- - -
- - - -
- -
- In Guru Dutt's first film. Mr and Mrs 55 -
- - -
- - -
- - - -
- -
- This is Shastri Nagar, Bandra, where 16 years later Anand Patwardhan would shoot Hamara Shehar. -
- - -
- - -
- - - -
- -
- -
- - -
- - -
- - - -
- -
- Cut to: Vidhu Vinod Chopra's first film, on Mankhurd Children's Home. -
- - -
- - -
- - - -
- -
- A Deonar Farm Road rumour: One Evening in the mid-fifties, Homi Bhabha, Raj Kapoor and Jamshedji Tata were having tea. With Nehru. -
- - - -
- -
- - - -
- -
- All three shared their cultural, scientific and industrial vision with Nehru, who gave them in turn land for RK Studios, BARC and TISS. -
- - - -
- - - -
- -
- -
- - -
- - -
- - - -
- -
- -
- - -
- - -
- - - -
- -
- -
- - -
- - -
- - - -
- -
- -
- - -
- - -
- - - - - + + + diff --git a/lib/js-yaml.min.js b/lib/js-yaml.min.js new file mode 100644 index 0000000..7ca0184 --- /dev/null +++ b/lib/js-yaml.min.js @@ -0,0 +1 @@ +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).jsyaml=e()}}(function(){return function o(a,s,c){function u(n,e){if(!s[n]){if(!a[n]){var t="function"==typeof require&&require;if(!e&&t)return t(n,!0);if(l)return l(n,!0);var i=new Error("Cannot find module '"+n+"'");throw i.code="MODULE_NOT_FOUND",i}var r=s[n]={exports:{}};a[n][0].call(r.exports,function(e){var t=a[n][1][e];return u(t||e)},r,r.exports,o,a,s,c)}return s[n].exports}for(var l="function"==typeof require&&require,e=0;e=i.flowLevel;switch($(r,n,i.indent,t,function(e){return function(e,t){var n,i;for(n=0,i=e.implicitTypes.length;n"+G(r,i.indent)+V(L(function(e,t){var n,i,r=/(\n+)([^\n]*)/g,o=(s=e.indexOf("\n"),s=-1!==s?s:e.length,r.lastIndex=s,Z(e.slice(0,s),t)),a="\n"===e[0]||" "===e[0];var s;for(;i=r.exec(e);){var c=i[1],u=i[2];n=" "===u[0],o+=c+(a||n||""===u?"":"\n")+Z(u,t),a=n}return o}(r,t),e));case K:return'"'+function(e){for(var t,n,i,r="",o=0;ot&&o tag resolver accepts not "'+c+'" style');i=s.represent[c](t,c)}e.dump=i}return!0}return!1}function J(e,t,n,i,r,o){e.tag=null,e.dump=n,z(e,n,!1)||z(e,n,!0);var a=l.call(e.dump);i&&(i=e.flowLevel<0||e.flowLevel>t);var s,c,u="[object Object]"===a||"[object Array]"===a;if(u&&(c=-1!==(s=e.duplicates.indexOf(n))),(null!==e.tag&&"?"!==e.tag||c||2!==e.indent&&0 "+e.dump)}return!0}function Q(e,t){var n,i,r=[],o=[];for(function e(t,n,i){var r,o,a;if(null!==t&&"object"==typeof t)if(-1!==(o=n.indexOf(t)))-1===i.indexOf(o)&&i.push(o);else if(n.push(t),Array.isArray(t))for(o=0,a=t.length;ot)&&0!==i)_(e,"bad indentation of a sequence entry");else if(e.lineIndentt?d=1:e.lineIndent===t?d=0:e.lineIndentt?d=1:e.lineIndent===t?d=0:e.lineIndentt)&&(B(e,t,b,!0,r)&&(m?d=e.result:h=e.result),m||(L(e,l,p,f,d,h,o,a),f=d=h=null),U(e,!0,-1),s=e.input.charCodeAt(e.position)),e.lineIndent>t&&0!==s)_(e,"bad indentation of a mapping entry");else if(e.lineIndentl&&(l=e.lineIndent),j(o))p++;else{if(e.lineIndent>10),56320+(c-65536&1023)),e.position++}else _(e,"unknown escape sequence");n=i=e.position}else j(s)?(M(e,n,i,!0),Y(e,U(e,!1,t)),n=i=e.position):e.position===e.lineStart&&q(e)?_(e,"unexpected end of the document within a double quoted scalar"):(e.position++,i=e.position)}_(e,"unexpected end of the stream within a double quoted scalar")}(e,p)?m=!0:!function(e){var t,n,i;if(42!==(i=e.input.charCodeAt(e.position)))return!1;for(i=e.input.charCodeAt(++e.position),t=e.position;0!==i&&!I(i)&&!E(i);)i=e.input.charCodeAt(++e.position);return e.position===t&&_(e,"name of an alias node must contain at least one character"),n=e.input.slice(t,e.position),e.anchorMap.hasOwnProperty(n)||_(e,'unidentified alias "'+n+'"'),e.result=e.anchorMap[n],U(e,!0,-1),!0}(e)?function(e,t,n){var i,r,o,a,s,c,u,l,p=e.kind,f=e.result;if(I(l=e.input.charCodeAt(e.position))||E(l)||35===l||38===l||42===l||33===l||124===l||62===l||39===l||34===l||37===l||64===l||96===l)return!1;if((63===l||45===l)&&(I(i=e.input.charCodeAt(e.position+1))||n&&E(i)))return!1;for(e.kind="scalar",e.result="",r=o=e.position,a=!1;0!==l;){if(58===l){if(I(i=e.input.charCodeAt(e.position+1))||n&&E(i))break}else if(35===l){if(I(e.input.charCodeAt(e.position-1)))break}else{if(e.position===e.lineStart&&q(e)||n&&E(l))break;if(j(l)){if(s=e.line,c=e.lineStart,u=e.lineIndent,U(e,!1,-1),e.lineIndent>=t){a=!0,l=e.input.charCodeAt(e.position);continue}e.position=o,e.line=s,e.lineStart=c,e.lineIndent=u;break}}a&&(M(e,r,o,!1),Y(e,e.line-s),r=o=e.position,a=!1),S(l)||(o=e.position+1),l=e.input.charCodeAt(++e.position)}return M(e,r,o,!1),!!e.result||(e.kind=p,e.result=f,!1)}(e,p,x===n)&&(m=!0,null===e.tag&&(e.tag="?")):(m=!0,null===e.tag&&null===e.anchor||_(e,"alias node should not have any properties")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===d&&(m=s&&R(e,f))),null!==e.tag&&"!"!==e.tag)if("?"===e.tag){for(c=0,u=e.implicitTypes.length;c tag; it should be "'+l.kind+'", not "'+e.kind+'"'),l.resolve(e.result)?(e.result=l.construct(e.result),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):_(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")):_(e,"unknown tag !<"+e.tag+">");return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||m}function K(e){var t,n,i,r,o=e.position,a=!1;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap={},e.anchorMap={};0!==(r=e.input.charCodeAt(e.position))&&(U(e,!0,-1),r=e.input.charCodeAt(e.position),!(0t/2-1){n=" ... ",i+=5;break}for(r="",o=this.position;ot/2-1){r=" ... ",o-=5;break}return a=this.buffer.slice(i,o),s.repeat(" ",e)+n+a+r+"\n"+s.repeat(" ",e+this.position-i+n.length)+"^"},i.prototype.toString=function(e){var t,n="";return this.name&&(n+='in "'+this.name+'" '),n+="at line "+(this.line+1)+", column "+(this.column+1),e||(t=this.getSnippet())&&(n+=":\n"+t),n},t.exports=i},{"./common":2}],7:[function(e,t,n){"use strict";var i=e("./common"),r=e("./exception"),o=e("./type");function a(e,t,i){var r=[];return e.include.forEach(function(e){i=a(e,t,i)}),e[t].forEach(function(n){i.forEach(function(e,t){e.tag===n.tag&&e.kind===n.kind&&r.push(t)}),i.push(n)}),i.filter(function(e,t){return-1===r.indexOf(t)})}function s(e){this.include=e.include||[],this.implicit=e.implicit||[],this.explicit=e.explicit||[],this.implicit.forEach(function(e){if(e.loadKind&&"scalar"!==e.loadKind)throw new r("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.")}),this.compiledImplicit=a(this,"implicit",[]),this.compiledExplicit=a(this,"explicit",[]),this.compiledTypeMap=function(){var e,t,n={scalar:{},sequence:{},mapping:{},fallback:{}};function i(e){n[e.kind][e.tag]=n.fallback[e.tag]=e}for(e=0,t=arguments.length;e>16&255),s.push(a>>8&255),s.push(255&a)),a=a<<6|o.indexOf(i.charAt(t));return 0==(n=r%4*6)?(s.push(a>>16&255),s.push(a>>8&255),s.push(255&a)):18===n?(s.push(a>>10&255),s.push(a>>2&255)):12===n&&s.push(a>>4&255),c?c.from?c.from(s):new c(s):s},predicate:function(e){return c&&c.isBuffer(e)},represent:function(e){var t,n,i="",r=0,o=e.length,a=u;for(t=0;t>18&63],i+=a[r>>12&63],i+=a[r>>6&63],i+=a[63&r]),r=(r<<8)+e[t];return 0==(n=o%3)?(i+=a[r>>18&63],i+=a[r>>12&63],i+=a[r>>6&63],i+=a[63&r]):2===n?(i+=a[r>>10&63],i+=a[r>>4&63],i+=a[r<<2&63],i+=a[64]):1===n&&(i+=a[r>>2&63],i+=a[r<<4&63],i+=a[64],i+=a[64]),i}})},{"../type":13}],15:[function(e,t,n){"use strict";var i=e("../type");t.exports=new i("tag:yaml.org,2002:bool",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t=e.length;return 4===t&&("true"===e||"True"===e||"TRUE"===e)||5===t&&("false"===e||"False"===e||"FALSE"===e)},construct:function(e){return"true"===e||"True"===e||"TRUE"===e},predicate:function(e){return"[object Boolean]"===Object.prototype.toString.call(e)},represent:{lowercase:function(e){return e?"true":"false"},uppercase:function(e){return e?"TRUE":"FALSE"},camelcase:function(e){return e?"True":"False"}},defaultStyle:"lowercase"})},{"../type":13}],16:[function(e,t,n){"use strict";var i=e("../common"),r=e("../type"),o=new RegExp("^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var a=/^[-+]?[0-9]+e/;t.exports=new r("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(e){return null!==e&&!(!o.test(e)||"_"===e[e.length-1])},construct:function(e){var t,n,i,r;return n="-"===(t=e.replace(/_/g,"").toLowerCase())[0]?-1:1,r=[],0<="+-".indexOf(t[0])&&(t=t.slice(1)),".inf"===t?1===n?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===t?NaN:0<=t.indexOf(":")?(t.split(":").forEach(function(e){r.unshift(parseFloat(e,10))}),t=0,i=1,r.forEach(function(e){t+=e*i,i*=60}),n*t):n*parseFloat(t,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||i.isNegativeZero(e))},represent:function(e,t){var n;if(isNaN(e))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(i.isNegativeZero(e))return"-0.0";return n=e.toString(10),a.test(n)?n.replace("e",".e"):n},defaultStyle:"lowercase"})},{"../common":2,"../type":13}],17:[function(e,t,n){"use strict";var i=e("../common"),r=e("../type");t.exports=new r("tag:yaml.org,2002:int",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,i,r,o=e.length,a=0,s=!1;if(!o)return!1;if("-"!==(t=e[a])&&"+"!==t||(t=e[++a]),"0"===t){if(a+1===o)return!0;if("b"===(t=e[++a])){for(a++;a + ${slideData.title} + + ` + if (slideData.video) { + video = getVideoHtml(slideData.video) + } + + if (slideData.audio) { + audio = getAudioHtml(slideData.audio) + } + + const duration = `data-duration="${slideData.duration ? slideData.duration : 5}"` + return ` +
+ ${title} + ${video} + ${audio} +
+ ` + } + + function getVideoHtml(videoData) { + let urls = [] + let volume = '' + if (typeof(videoData) === 'string') { + urls.push(videoData) + } else { // video is an object + if (videoData.hasOwnProperty('url')) { + urls.push(videoData.url) + } else if (videoData.hasOwnProperty('zoom')) { + urls = videoData.zoom + } + if (videoData.volume) { + volume = `data-volume="${videoData.volume}"` + } + } + const urlsHtml = urls.map((url, index) => { + return `data-url_${index}="${makeEmbed(url)}"` + }).join('\n') + return ` +
+ ` + } + + function getAudioHtml(audioData) { + let url = continueStr = volume = '' + + // short circuit to return an empty div if audioData is null or not an object + // this is useful for user to specify empty audio track to cause existing + // audio to pause + if (!audioData || !(typeof(audioData === 'object'))) { + return `
+ ` + } + + function makeEmbed(url) { + if (!url.endsWith('#embed')) { + return `${url}#embed` + } else { + return url + } + } + +})(); \ No newline at end of file