aboutsummaryrefslogtreecommitdiffstats
path: root/assets/js
diff options
context:
space:
mode:
authorSam Potts <me@sampotts.me>2015-02-14 22:42:44 +1100
committerSam Potts <me@sampotts.me>2015-02-14 22:42:44 +1100
commit751d8db9d88d45b33792982103f8682e21ac876e (patch)
tree922222dd411b34a5d47d2e1453a167919dbdb417 /assets/js
downloadplyr-751d8db9d88d45b33792982103f8682e21ac876e.tar.lz
plyr-751d8db9d88d45b33792982103f8682e21ac876e.tar.xz
plyr-751d8db9d88d45b33792982103f8682e21ac876e.zip
WIP
Diffstat (limited to 'assets/js')
-rw-r--r--assets/js/docs.js19
-rw-r--r--assets/js/lib/hogan-3.0.2.mustache.js802
-rw-r--r--assets/js/simple-media.js627
3 files changed, 1448 insertions, 0 deletions
diff --git a/assets/js/docs.js b/assets/js/docs.js
new file mode 100644
index 00000000..c8a3bd44
--- /dev/null
+++ b/assets/js/docs.js
@@ -0,0 +1,19 @@
+// ==========================================================================
+// Docs example
+// ==========================================================================
+
+/*global InitPxVideo, Mustache, templates */
+
+// Initialize
+var video = new InitPxVideo({
+ "videoId": "myvid",
+ "captionsOnDefault": true,
+ "seekInterval": 20,
+ "videoTitle": "PayPal Austin promo",
+ "debug": true,
+ "html": templates.controls.render({
+
+ })
+});
+
+console.log(video); \ No newline at end of file
diff --git a/assets/js/lib/hogan-3.0.2.mustache.js b/assets/js/lib/hogan-3.0.2.mustache.js
new file mode 100644
index 00000000..f1300c46
--- /dev/null
+++ b/assets/js/lib/hogan-3.0.2.mustache.js
@@ -0,0 +1,802 @@
+/*!
+ * Copyright 2011 Twitter, Inc.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// A wrapper for compatibility with Mustache.js, quirks and all
+
+
+
+var Hogan = {};
+
+(function (Hogan) {
+ Hogan.Template = function (codeObj, text, compiler, options) {
+ codeObj = codeObj || {};
+ this.r = codeObj.code || this.r;
+ this.c = compiler;
+ this.options = options || {};
+ this.text = text || '';
+ this.partials = codeObj.partials || {};
+ this.subs = codeObj.subs || {};
+ this.buf = '';
+ }
+
+ Hogan.Template.prototype = {
+ // render: replaced by generated code.
+ r: function (context, partials, indent) { return ''; },
+
+ // variable escaping
+ v: hoganEscape,
+
+ // triple stache
+ t: coerceToString,
+
+ render: function render(context, partials, indent) {
+ return this.ri([context], partials || {}, indent);
+ },
+
+ // render internal -- a hook for overrides that catches partials too
+ ri: function (context, partials, indent) {
+ return this.r(context, partials, indent);
+ },
+
+ // ensurePartial
+ ep: function(symbol, partials) {
+ var partial = this.partials[symbol];
+
+ // check to see that if we've instantiated this partial before
+ var template = partials[partial.name];
+ if (partial.instance && partial.base == template) {
+ return partial.instance;
+ }
+
+ if (typeof template == 'string') {
+ if (!this.c) {
+ throw new Error("No compiler available.");
+ }
+ template = this.c.compile(template, this.options);
+ }
+
+ if (!template) {
+ return null;
+ }
+
+ // We use this to check whether the partials dictionary has changed
+ this.partials[symbol].base = template;
+
+ if (partial.subs) {
+ // Make sure we consider parent template now
+ if (!partials.stackText) partials.stackText = {};
+ for (key in partial.subs) {
+ if (!partials.stackText[key]) {
+ partials.stackText[key] = (this.activeSub !== undefined && partials.stackText[this.activeSub]) ? partials.stackText[this.activeSub] : this.text;
+ }
+ }
+ template = createSpecializedPartial(template, partial.subs, partial.partials,
+ this.stackSubs, this.stackPartials, partials.stackText);
+ }
+ this.partials[symbol].instance = template;
+
+ return template;
+ },
+
+ // tries to find a partial in the current scope and render it
+ rp: function(symbol, context, partials, indent) {
+ var partial = this.ep(symbol, partials);
+ if (!partial) {
+ return '';
+ }
+
+ return partial.ri(context, partials, indent);
+ },
+
+ // render a section
+ rs: function(context, partials, section) {
+ var tail = context[context.length - 1];
+
+ if (!isArray(tail)) {
+ section(context, partials, this);
+ return;
+ }
+
+ for (var i = 0; i < tail.length; i++) {
+ context.push(tail[i]);
+ section(context, partials, this);
+ context.pop();
+ }
+ },
+
+ // maybe start a section
+ s: function(val, ctx, partials, inverted, start, end, tags) {
+ var pass;
+
+ if (isArray(val) && val.length === 0) {
+ return false;
+ }
+
+ if (typeof val == 'function') {
+ val = this.ms(val, ctx, partials, inverted, start, end, tags);
+ }
+
+ pass = !!val;
+
+ if (!inverted && pass && ctx) {
+ ctx.push((typeof val == 'object') ? val : ctx[ctx.length - 1]);
+ }
+
+ return pass;
+ },
+
+ // find values with dotted names
+ d: function(key, ctx, partials, returnFound) {
+ var found,
+ names = key.split('.'),
+ val = this.f(names[0], ctx, partials, returnFound),
+ doModelGet = this.options.modelGet,
+ cx = null;
+
+ if (key === '.' && isArray(ctx[ctx.length - 2])) {
+ val = ctx[ctx.length - 1];
+ } else {
+ for (var i = 1; i < names.length; i++) {
+ found = findInScope(names[i], val, doModelGet);
+ if (found !== undefined) {
+ cx = val;
+ val = found;
+ } else {
+ val = '';
+ }
+ }
+ }
+
+ if (returnFound && !val) {
+ return false;
+ }
+
+ if (!returnFound && typeof val == 'function') {
+ ctx.push(cx);
+ val = this.mv(val, ctx, partials);
+ ctx.pop();
+ }
+
+ return val;
+ },
+
+ // find values with normal names
+ f: function(key, ctx, partials, returnFound) {
+ var val = false,
+ v = null,
+ found = false,
+ doModelGet = this.options.modelGet;
+
+ for (var i = ctx.length - 1; i >= 0; i--) {
+ v = ctx[i];
+ val = findInScope(key, v, doModelGet);
+ if (val !== undefined) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ return (returnFound) ? false : "";
+ }
+
+ if (!returnFound && typeof val == 'function') {
+ val = this.mv(val, ctx, partials);
+ }
+
+ return val;
+ },
+
+ // higher order templates
+ ls: function(func, cx, partials, text, tags) {
+ var oldTags = this.options.delimiters;
+
+ this.options.delimiters = tags;
+ this.b(this.ct(coerceToString(func.call(cx, text)), cx, partials));
+ this.options.delimiters = oldTags;
+
+ return false;
+ },
+
+ // compile text
+ ct: function(text, cx, partials) {
+ if (this.options.disableLambda) {
+ throw new Error('Lambda features disabled.');
+ }
+ return this.c.compile(text, this.options).render(cx, partials);
+ },
+
+ // template result buffering
+ b: function(s) { this.buf += s; },
+
+ fl: function() { var r = this.buf; this.buf = ''; return r; },
+
+ // method replace section
+ ms: function(func, ctx, partials, inverted, start, end, tags) {
+ var textSource,
+ cx = ctx[ctx.length - 1],
+ result = func.call(cx);
+
+ if (typeof result == 'function') {
+ if (inverted) {
+ return true;
+ } else {
+ textSource = (this.activeSub && this.subsText && this.subsText[this.activeSub]) ? this.subsText[this.activeSub] : this.text;
+ return this.ls(result, cx, partials, textSource.substring(start, end), tags);
+ }
+ }
+
+ return result;
+ },
+
+ // method replace variable
+ mv: function(func, ctx, partials) {
+ var cx = ctx[ctx.length - 1];
+ var result = func.call(cx);
+
+ if (typeof result == 'function') {
+ return this.ct(coerceToString(result.call(cx)), cx, partials);
+ }
+
+ return result;
+ },
+
+ sub: function(name, context, partials, indent) {
+ var f = this.subs[name];
+ if (f) {
+ this.activeSub = name;
+ f(context, partials, this, indent);
+ this.activeSub = false;
+ }
+ }
+
+ };
+
+ //Find a key in an object
+ function findInScope(key, scope, doModelGet) {
+ var val;
+
+ if (scope && typeof scope == 'object') {
+
+ if (scope[key] !== undefined) {
+ val = scope[key];
+
+ // try lookup with get for backbone or similar model data
+ } else if (doModelGet && scope.get && typeof scope.get == 'function') {
+ val = scope.get(key);
+ }
+ }
+
+ return val;
+ }
+
+ function createSpecializedPartial(instance, subs, partials, stackSubs, stackPartials, stackText) {
+ function PartialTemplate() {};
+ PartialTemplate.prototype = instance;
+ function Substitutions() {};
+ Substitutions.prototype = instance.subs;
+ var key;
+ var partial = new PartialTemplate();
+ partial.subs = new Substitutions();
+ partial.subsText = {}; //hehe. substext.
+ partial.buf = '';
+
+ stackSubs = stackSubs || {};
+ partial.stackSubs = stackSubs;
+ partial.subsText = stackText;
+ for (key in subs) {
+ if (!stackSubs[key]) stackSubs[key] = subs[key];
+ }
+ for (key in stackSubs) {
+ partial.subs[key] = stackSubs[key];
+ }
+
+ stackPartials = stackPartials || {};
+ partial.stackPartials = stackPartials;
+ for (key in partials) {
+ if (!stackPartials[key]) stackPartials[key] = partials[key];
+ }
+ for (key in stackPartials) {
+ partial.partials[key] = stackPartials[key];
+ }
+
+ return partial;
+ }
+
+ var rAmp = /&/g,
+ rLt = /</g,
+ rGt = />/g,
+ rApos = /\'/g,
+ rQuot = /\"/g,
+ hChars = /[&<>\"\']/;
+
+ function coerceToString(val) {
+ return String((val === null || val === undefined) ? '' : val);
+ }
+
+ function hoganEscape(str) {
+ str = coerceToString(str);
+ return hChars.test(str) ?
+ str
+ .replace(rAmp, '&amp;')
+ .replace(rLt, '&lt;')
+ .replace(rGt, '&gt;')
+ .replace(rApos, '&#39;')
+ .replace(rQuot, '&quot;') :
+ str;
+ }
+
+ var isArray = Array.isArray || function(a) {
+ return Object.prototype.toString.call(a) === '[object Array]';
+ };
+
+})(typeof exports !== 'undefined' ? exports : Hogan);
+
+
+
+(function (Hogan) {
+ // Setup regex assignments
+ // remove whitespace according to Mustache spec
+ var rIsWhitespace = /\S/,
+ rQuot = /\"/g,
+ rNewline = /\n/g,
+ rCr = /\r/g,
+ rSlash = /\\/g,
+ rLineSep = /\u2028/,
+ rParagraphSep = /\u2029/;
+
+ Hogan.tags = {
+ '#': 1, '^': 2, '<': 3, '$': 4,
+ '/': 5, '!': 6, '>': 7, '=': 8, '_v': 9,
+ '{': 10, '&': 11, '_t': 12
+ };
+
+ Hogan.scan = function scan(text, delimiters) {
+ var len = text.length,
+ IN_TEXT = 0,
+ IN_TAG_TYPE = 1,
+ IN_TAG = 2,
+ state = IN_TEXT,
+ tagType = null,
+ tag = null,
+ buf = '',
+ tokens = [],
+ seenTag = false,
+ i = 0,
+ lineStart = 0,
+ otag = '{{',
+ ctag = '}}';
+
+ function addBuf() {
+ if (buf.length > 0) {
+ tokens.push({tag: '_t', text: new String(buf)});
+ buf = '';
+ }
+ }
+
+ function lineIsWhitespace() {
+ var isAllWhitespace = true;
+ for (var j = lineStart; j < tokens.length; j++) {
+ isAllWhitespace =
+ (Hogan.tags[tokens[j].tag] < Hogan.tags['_v']) ||
+ (tokens[j].tag == '_t' && tokens[j].text.match(rIsWhitespace) === null);
+ if (!isAllWhitespace) {
+ return false;
+ }
+ }
+
+ return isAllWhitespace;
+ }
+
+ function filterLine(haveSeenTag, noNewLine) {
+ addBuf();
+
+ if (haveSeenTag && lineIsWhitespace()) {
+ for (var j = lineStart, next; j < tokens.length; j++) {
+ if (tokens[j].text) {
+ if ((next = tokens[j+1]) && next.tag == '>') {
+ // set indent to token value
+ next.indent = tokens[j].text.toString()
+ }
+ tokens.splice(j, 1);
+ }
+ }
+ } else if (!noNewLine) {
+ tokens.push({tag:'\n'});
+ }
+
+ seenTag = false;
+ lineStart = tokens.length;
+ }
+
+ function changeDelimiters(text, index) {
+ var close = '=' + ctag,
+ closeIndex = text.indexOf(close, index),
+ delimiters = trim(
+ text.substring(text.indexOf('=', index) + 1, closeIndex)
+ ).split(' ');
+
+ otag = delimiters[0];
+ ctag = delimiters[delimiters.length - 1];
+
+ return closeIndex + close.length - 1;
+ }
+
+ if (delimiters) {
+ delimiters = delimiters.split(' ');
+ otag = delimiters[0];
+ ctag = delimiters[1];
+ }
+
+ for (i = 0; i < len; i++) {
+ if (state == IN_TEXT) {
+ if (tagChange(otag, text, i)) {
+ --i;
+ addBuf();
+ state = IN_TAG_TYPE;
+ } else {
+ if (text.charAt(i) == '\n') {
+ filterLine(seenTag);
+ } else {
+ buf += text.charAt(i);
+ }
+ }
+ } else if (state == IN_TAG_TYPE) {
+ i += otag.length - 1;
+ tag = Hogan.tags[text.charAt(i + 1)];
+ tagType = tag ? text.charAt(i + 1) : '_v';
+ if (tagType == '=') {
+ i = changeDelimiters(text, i);
+ state = IN_TEXT;
+ } else {
+ if (tag) {
+ i++;
+ }
+ state = IN_TAG;
+ }
+ seenTag = i;
+ } else {
+ if (tagChange(ctag, text, i)) {
+ tokens.push({tag: tagType, n: trim(buf), otag: otag, ctag: ctag,
+ i: (tagType == '/') ? seenTag - otag.length : i + ctag.length});
+ buf = '';
+ i += ctag.length - 1;
+ state = IN_TEXT;
+ if (tagType == '{') {
+ if (ctag == '}}') {
+ i++;
+ } else {
+ cleanTripleStache(tokens[tokens.length - 1]);
+ }
+ }
+ } else {
+ buf += text.charAt(i);
+ }
+ }
+ }
+
+ filterLine(seenTag, true);
+
+ return tokens;
+ }
+
+ function cleanTripleStache(token) {
+ if (token.n.substr(token.n.length - 1) === '}') {
+ token.n = token.n.substring(0, token.n.length - 1);
+ }
+ }
+
+ function trim(s) {
+ if (s.trim) {
+ return s.trim();
+ }
+
+ return s.replace(/^\s*|\s*$/g, '');
+ }
+
+ function tagChange(tag, text, index) {
+ if (text.charAt(index) != tag.charAt(0)) {
+ return false;
+ }
+
+ for (var i = 1, l = tag.length; i < l; i++) {
+ if (text.charAt(index + i) != tag.charAt(i)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ // the tags allowed inside super templates
+ var allowedInSuper = {'_t': true, '\n': true, '$': true, '/': true};
+
+ function buildTree(tokens, kind, stack, customTags) {
+ var instructions = [],
+ opener = null,
+ tail = null,
+ token = null;
+
+ tail = stack[stack.length - 1];
+
+ while (tokens.length > 0) {
+ token = tokens.shift();
+
+ if (tail && tail.tag == '<' && !(token.tag in allowedInSuper)) {
+ throw new Error('Illegal content in < super tag.');
+ }
+
+ if (Hogan.tags[token.tag] <= Hogan.tags['$'] || isOpener(token, customTags)) {
+ stack.push(token);
+ token.nodes = buildTree(tokens, token.tag, stack, customTags);
+ } else if (token.tag == '/') {
+ if (stack.length === 0) {
+ throw new Error('Closing tag without opener: /' + token.n);
+ }
+ opener = stack.pop();
+ if (token.n != opener.n && !isCloser(token.n, opener.n, customTags)) {
+ throw new Error('Nesting error: ' + opener.n + ' vs. ' + token.n);
+ }
+ opener.end = token.i;
+ return instructions;
+ } else if (token.tag == '\n') {
+ token.last = (tokens.length == 0) || (tokens[0].tag == '\n');
+ }
+
+ instructions.push(token);
+ }
+
+ if (stack.length > 0) {
+ throw new Error('missing closing tag: ' + stack.pop().n);
+ }
+
+ return instructions;
+ }
+
+ function isOpener(token, tags) {
+ for (var i = 0, l = tags.length; i < l; i++) {
+ if (tags[i].o == token.n) {
+ token.tag = '#';
+ return true;
+ }
+ }
+ }
+
+ function isCloser(close, open, tags) {
+ for (var i = 0, l = tags.length; i < l; i++) {
+ if (tags[i].c == close && tags[i].o == open) {
+ return true;
+ }
+ }
+ }
+
+ function stringifySubstitutions(obj) {
+ var items = [];
+ for (var key in obj) {
+ items.push('"' + esc(key) + '": function(c,p,t,i) {' + obj[key] + '}');
+ }
+ return "{ " + items.join(",") + " }";
+ }
+
+ function stringifyPartials(codeObj) {
+ var partials = [];
+ for (var key in codeObj.partials) {
+ partials.push('"' + esc(key) + '":{name:"' + esc(codeObj.partials[key].name) + '", ' + stringifyPartials(codeObj.partials[key]) + "}");
+ }
+ return "partials: {" + partials.join(",") + "}, subs: " + stringifySubstitutions(codeObj.subs);
+ }
+
+ Hogan.stringify = function(codeObj, text, options) {
+ return "{code: function (c,p,i) { " + Hogan.wrapMain(codeObj.code) + " }," + stringifyPartials(codeObj) + "}";
+ }
+
+ var serialNo = 0;
+ Hogan.generate = function(tree, text, options) {
+ serialNo = 0;
+ var context = { code: '', subs: {}, partials: {} };
+ Hogan.walk(tree, context);
+
+ if (options.asString) {
+ return this.stringify(context, text, options);
+ }
+
+ return this.makeTemplate(context, text, options);
+ }
+
+ Hogan.wrapMain = function(code) {
+ return 'var t=this;t.b(i=i||"");' + code + 'return t.fl();';
+ }
+
+ Hogan.template = Hogan.Template;
+
+ Hogan.makeTemplate = function(codeObj, text, options) {
+ var template = this.makePartials(codeObj);
+ template.code = new Function('c', 'p', 'i', this.wrapMain(codeObj.code));
+ return new this.template(template, text, this, options);
+ }
+
+ Hogan.makePartials = function(codeObj) {
+ var key, template = {subs: {}, partials: codeObj.partials, name: codeObj.name};
+ for (key in template.partials) {
+ template.partials[key] = this.makePartials(template.partials[key]);
+ }
+ for (key in codeObj.subs) {
+ template.subs[key] = new Function('c', 'p', 't', 'i', codeObj.subs[key]);
+ }
+ return template;
+ }
+
+ function esc(s) {
+ return s.replace(rSlash, '\\\\')
+ .replace(rQuot, '\\\"')
+ .replace(rNewline, '\\n')
+ .replace(rCr, '\\r')
+ .replace(rLineSep, '\\u2028')
+ .replace(rParagraphSep, '\\u2029');
+ }
+
+ function chooseMethod(s) {
+ return (~s.indexOf('.')) ? 'd' : 'f';
+ }
+
+ function createPartial(node, context) {
+ var prefix = "<" + (context.prefix || "");
+ var sym = prefix + node.n + serialNo++;
+ context.partials[sym] = {name: node.n, partials: {}};
+ context.code += 't.b(t.rp("' + esc(sym) + '",c,p,"' + (node.indent || '') + '"));';
+ return sym;
+ }
+
+ Hogan.codegen = {
+ '#': function(node, context) {
+ context.code += 'if(t.s(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,1),' +
+ 'c,p,0,' + node.i + ',' + node.end + ',"' + node.otag + " " + node.ctag + '")){' +
+ 't.rs(c,p,' + 'function(c,p,t){';
+ Hogan.walk(node.nodes, context);
+ context.code += '});c.pop();}';
+ },
+
+ '^': function(node, context) {
+ context.code += 'if(!t.s(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,1),c,p,1,0,0,"")){';
+ Hogan.walk(node.nodes, context);
+ context.code += '};';
+ },
+
+ '>': createPartial,
+ '<': function(node, context) {
+ var ctx = {partials: {}, code: '', subs: {}, inPartial: true};
+ Hogan.walk(node.nodes, ctx);
+ var template = context.partials[createPartial(node, context)];
+ template.subs = ctx.subs;
+ template.partials = ctx.partials;
+ },
+
+ '$': function(node, context) {
+ var ctx = {subs: {}, code: '', partials: context.partials, prefix: node.n};
+ Hogan.walk(node.nodes, ctx);
+ context.subs[node.n] = ctx.code;
+ if (!context.inPartial) {
+ context.code += 't.sub("' + esc(node.n) + '",c,p,i);';
+ }
+ },
+
+ '\n': function(node, context) {
+ context.code += write('"\\n"' + (node.last ? '' : ' + i'));
+ },
+
+ '_v': function(node, context) {
+ context.code += 't.b(t.v(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,0)));';
+ },
+
+ '_t': function(node, context) {
+ context.code += write('"' + esc(node.text) + '"');
+ },
+
+ '{': tripleStache,
+
+ '&': tripleStache
+ }
+
+ function tripleStache(node, context) {
+ context.code += 't.b(t.t(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,0)));';
+ }
+
+ function write(s) {
+ return 't.b(' + s + ');';
+ }
+
+ Hogan.walk = function(nodelist, context) {
+ var func;
+ for (var i = 0, l = nodelist.length; i < l; i++) {
+ func = Hogan.codegen[nodelist[i].tag];
+ func && func(nodelist[i], context);
+ }
+ return context;
+ }
+
+ Hogan.parse = function(tokens, text, options) {
+ options = options || {};
+ return buildTree(tokens, '', [], options.sectionTags || []);
+ }
+
+ Hogan.cache = {};
+
+ Hogan.cacheKey = function(text, options) {
+ return [text, !!options.asString, !!options.disableLambda, options.delimiters, !!options.modelGet].join('||');
+ }
+
+ Hogan.compile = function(text, options) {
+ options = options || {};
+ var key = Hogan.cacheKey(text, options);
+ var template = this.cache[key];
+
+ if (template) {
+ var partials = template.partials;
+ for (var name in partials) {
+ delete partials[name].instance;
+ }
+ return template;
+ }
+
+ template = this.generate(this.parse(this.scan(text, options.delimiters), text, options), text, options);
+ return this.cache[key] = template;
+ }
+})(typeof exports !== 'undefined' ? exports : Hogan);
+
+
+var Mustache = (function (Hogan) {
+
+ // Mustache.js has non-spec partial context behavior
+ function mustachePartial(name, context, partials, indent) {
+ var partialScope = this.f(name, context, partials, 0);
+ var cx = context;
+ if (partialScope) {
+ cx = cx.concat(partialScope);
+ }
+
+ return Hogan.Template.prototype.rp.call(this, name, cx, partials, indent);
+ }
+
+ var HoganTemplateWrapper = function(renderFunc, text, compiler){
+ this.rp = mustachePartial;
+ Hogan.Template.call(this, renderFunc, text, compiler);
+ };
+ HoganTemplateWrapper.prototype = Hogan.Template.prototype;
+
+ // Add a wrapper for Hogan's generate method. Mustache and Hogan keep
+ // separate caches, and Mustache returns wrapped templates.
+ var wrapper;
+ var HoganWrapper = function(){
+ this.cache = {};
+ this.generate = function(code, text, options) {
+ return new HoganTemplateWrapper(new Function('c', 'p', 'i', code), text, wrapper);
+ }
+ };
+ HoganWrapper.prototype = Hogan;
+ wrapper = new HoganWrapper();
+
+ return {
+ to_html: function(text, data, partials, sendFun) {
+ var template = wrapper.compile(text);
+ var result = template.render(data, partials);
+ if (!sendFun) {
+ return result;
+ }
+
+ sendFun(result);
+ }
+ }
+
+})(Hogan);
diff --git a/assets/js/simple-media.js b/assets/js/simple-media.js
new file mode 100644
index 00000000..954cc9b2
--- /dev/null
+++ b/assets/js/simple-media.js
@@ -0,0 +1,627 @@
+function InitPxVideo(options) {
+
+ "use strict";
+
+ // Replace all
+ // ---------------------------------
+ if (!String.prototype.replaceAll) {
+ Object.defineProperty(String.prototype, "replaceAll", {
+ value: function(find, replace) {
+ return this.replace(new RegExp(find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"), "g"), replace);
+ }
+ });
+ }
+
+ // Utilities for caption time codes
+ function video_timecode_min(tc) {
+ var tcpair = [];
+ tcpair = tc.split(" --> ");
+ return videosub_tcsecs(tcpair[0]);
+ }
+
+ function video_timecode_max(tc) {
+ var tcpair = [];
+ tcpair = tc.split(" --> ");
+ return videosub_tcsecs(tcpair[1]);
+ }
+
+ function videosub_tcsecs(tc) {
+ if (tc === null || tc === undefined) {
+ return 0;
+ }
+ else {
+ var tc1 = [],
+ tc2 = [],
+ seconds;
+ tc1 = tc.split(",");
+ tc2 = tc1[0].split(":");
+ seconds = Math.floor(tc2[0]*60*60) + Math.floor(tc2[1]*60) + Math.floor(tc2[2]);
+ return seconds;
+ }
+ }
+
+ // For "manual" captions, adjust caption position when play time changed (via rewind, clicking progress bar, etc.)
+ function adjustManualCaptions(obj) {
+ obj.subcount = 0;
+ while (video_timecode_max(obj.captions[obj.subcount][0]) < obj.movie.currentTime.toFixed(1)) {
+ obj.subcount++;
+ if (obj.subcount > obj.captions.length-1) {
+ obj.subcount = obj.captions.length-1;
+ break;
+ }
+ }
+ }
+
+ // Display captions container and button (for initialization)
+ function showCaptionContainerAndButton(obj) {
+ //obj.captionsBtnContainer.className = "px-video-captions-btn-container show";
+ if (obj.isCaptionDefault) {
+ obj.captionsContainer.className = "px-video-captions show";
+ obj.captionsBtn.setAttribute("checked", "checked");
+ }
+ }
+
+ // Unfortunately, due to scattered support, browser sniffing is required
+ function browserSniff() {
+ var nAgt = navigator.userAgent,
+ browserName = navigator.appName,
+ fullVersion = ""+parseFloat(navigator.appVersion),
+ majorVersion = parseInt(navigator.appVersion,10),
+ nameOffset,
+ verOffset,
+ ix;
+
+ // MSIE 11
+ if ((navigator.appVersion.indexOf("Windows NT") !== -1) && (navigator.appVersion.indexOf("rv:11") !== -1)) {
+ browserName = "IE";
+ fullVersion = "11;";
+ }
+ // MSIE
+ else if ((verOffset=nAgt.indexOf("MSIE")) !== -1) {
+ browserName = "IE";
+ fullVersion = nAgt.substring(verOffset+5);
+ }
+ // Chrome
+ else if ((verOffset=nAgt.indexOf("Chrome")) !== -1) {
+ browserName = "Chrome";
+ fullVersion = nAgt.substring(verOffset+7);
+ }
+ // Safari
+ else if ((verOffset=nAgt.indexOf("Safari")) !== -1) {
+ browserName = "Safari";
+ fullVersion = nAgt.substring(verOffset+7);
+ if ((verOffset=nAgt.indexOf("Version")) !== -1) {
+ fullVersion = nAgt.substring(verOffset+8);
+ }
+ }
+ // Firefox
+ else if ((verOffset=nAgt.indexOf("Firefox")) !== -1) {
+ browserName = "Firefox";
+ fullVersion = nAgt.substring(verOffset+8);
+ }
+ // In most other browsers, "name/version" is at the end of userAgent
+ else if ( (nameOffset=nAgt.lastIndexOf(" ")+1) < (verOffset=nAgt.lastIndexOf("/")) ) {
+ browserName = nAgt.substring(nameOffset,verOffset);
+ fullVersion = nAgt.substring(verOffset+1);
+ if (browserName.toLowerCase()==browserName.toUpperCase()) {
+ browserName = navigator.appName;
+ }
+ }
+ // Trim the fullVersion string at semicolon/space if present
+ if ((ix=fullVersion.indexOf(";")) !== -1) {
+ fullVersion=fullVersion.substring(0,ix);
+ }
+ if ((ix=fullVersion.indexOf(" ")) !== -1) {
+ fullVersion=fullVersion.substring(0,ix);
+ }
+ // Get major version
+ majorVersion = parseInt(""+fullVersion,10);
+ if (isNaN(majorVersion)) {
+ fullVersion = ""+parseFloat(navigator.appVersion);
+ majorVersion = parseInt(navigator.appVersion,10);
+ }
+ // Return data
+ return [browserName, majorVersion];
+ }
+
+ // Global variable
+ var obj = {};
+
+ obj.arBrowserInfo = browserSniff();
+ obj.browserName = obj.arBrowserInfo[0];
+ obj.browserMajorVersion = obj.arBrowserInfo[1];
+
+ // If IE8, stop customization (use fallback)
+ // If IE9, stop customization (use native controls)
+ if (obj.browserName === "IE" && (obj.browserMajorVersion === 8 || obj.browserMajorVersion === 9) ) {
+ return false;
+ }
+
+ // If smartphone or tablet, stop customization as video (and captions in latest devices) are handled natively
+ obj.isSmartphoneOrTablet = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
+ if (obj.isSmartphoneOrTablet) {
+ return false;
+ }
+
+ // Set debug mode
+ if (typeof(options.debug)==="undefined") {
+ options.debug = false;
+ }
+ obj.debug = options.debug;
+
+ // Output browser info to log if debug on
+ if (options.debug) {
+ console.log(obj.browserName + " " + obj.browserMajorVersion);
+ }
+
+ // Set up aria-label for Play button with the videoTitle option
+ if ((typeof(options.videoTitle)==="undefined") || (options.videoTitle==="")) {
+ obj.playAriaLabel = "Play";
+ }
+ else {
+ obj.playAriaLabel = "Play video, " + options.videoTitle;
+ }
+
+ // Get the container, video element, and controls container
+ obj.container = document.getElementById(options.videoId);
+ obj.container.className = obj.container.className + " stopped";
+ obj.movie = obj.container.getElementsByTagName("video")[0];
+ obj.controls = obj.container.getElementsByClassName("px-video-controls")[0];
+
+ // Remove native video controls
+ obj.movie.removeAttribute("controls");
+
+ // Generate random number for ID/FOR attribute values for controls
+ obj.randomNum = Math.floor(Math.random() * (10000));
+
+ // Insert custom video controls
+ if (options.debug) {
+ console.log("Inserting custom video controls");
+ }
+ obj.controls.innerHTML = options.html
+ .replaceAll("{aria-label}", obj.playAriaLabel)
+ .replaceAll("{id}", obj.randomNum);
+
+ // Responsive ffs
+ // ----
+ // Adjust layout per width of video - container
+ //obj.movieWidth = obj.movie.width;
+ //if (obj.movieWidth < 360) {
+ // obj.movieWidth = 360;
+ //}
+ //obj.container.setAttribute("style", "width:" + obj.movieWidth + "px");
+
+ // Adjust layout per width of video - controls/mute offset
+ obj.labelMute = document.getElementById("labelMute" + obj.randomNum);
+ obj.labelMuteOffset = obj.movieWidth - 390;
+ if (obj.labelMuteOffset < 0) {
+ obj.labelMuteOffset = 0;
+ }
+ obj.labelMute.setAttribute("style", "margin-left:" + obj.labelMuteOffset + "px");
+
+ // Get URL of caption file if exists
+ var captionSrc = "",
+ kind,
+ children = obj.movie.childNodes;
+
+ for (var i = 0; i < children.length; i++) {
+ if (children[i].nodeName.toLowerCase() === "track") {
+ kind = children[i].getAttribute("kind");
+ if (kind === "captions") {
+ captionSrc = children[i].getAttribute("src");
+ }
+ }
+ }
+
+ // Record if caption file exists or not
+ obj.captionExists = true;
+ if (captionSrc === "") {
+ obj.captionExists = false;
+ if (options.debug) {
+ console.log("No caption track found.");
+ }
+ }
+ else {
+ if (options.debug) {
+ console.log("Caption track found; URI: " + captionSrc);
+ }
+ }
+
+ // Set captions on/off - on by default
+ if (typeof(options.captionsOnDefault) === "undefined") {
+ options.captionsOnDefault = true;
+ }
+ obj.isCaptionDefault = options.captionsOnDefault;
+
+ // Number of seconds for rewind and forward buttons
+ if (typeof(options.seekInterval) === "undefined") {
+ options.seekInterval = 10;
+ }
+ obj.seekInterval = options.seekInterval;
+
+ // Get the elements for the controls
+ obj.btnPlay = obj.container.getElementsByClassName("px-video-play")[0];
+ obj.btnPause = obj.container.getElementsByClassName("px-video-pause")[0];
+ obj.btnRestart = obj.container.getElementsByClassName("px-video-restart")[0];
+ obj.btnRewind = obj.container.getElementsByClassName("px-video-rewind")[0];
+ obj.btnForward = obj.container.getElementsByClassName("px-video-forward")[0];
+ obj.btnVolume = obj.container.getElementsByClassName("px-video-volume")[0];
+ obj.btnMute = obj.container.getElementsByClassName("px-video-mute")[0];
+ obj.progressBar = obj.container.getElementsByClassName("px-video-progress")[0];
+ obj.progressBarSpan = obj.progressBar.getElementsByTagName("span")[0];
+ obj.captionsContainer = obj.container.getElementsByClassName("px-video-captions")[0];
+ obj.captionsBtn = obj.container.getElementsByClassName("px-video-btnCaptions")[0];
+ obj.captionsBtnContainer = obj.container.getElementsByClassName("px-video-captions-btn-container")[0];
+ obj.duration = obj.container.getElementsByClassName("px-video-duration")[0];
+ obj.txtSeconds = obj.container.getElementsByClassName("px-seconds");
+
+ // Update number of seconds in rewind and fast forward buttons
+ obj.txtSeconds[0].innerHTML = obj.seekInterval;
+ obj.txtSeconds[1].innerHTML = obj.seekInterval;
+
+ // Determine if HTML5 textTracks is supported (for captions)
+ obj.isTextTracks = false;
+ if (obj.movie.textTracks) {
+ obj.isTextTracks = true;
+ }
+
+ // Play
+ obj.btnPlay.addEventListener("click", function() {
+ obj.movie.play();
+
+ obj.container.className = obj.container.className.replace("stopped", "playing");
+
+ obj.btnPlay.className = "px-video-play hide";
+ obj.btnPause.className = "px-video-pause px-video-show-inline";
+ obj.btnPause.focus();
+ }, false);
+
+ // Pause
+ obj.btnPause.addEventListener("click", function() {
+ obj.movie.pause();
+
+ obj.container.className = obj.container.className.replace("playing", "stopped");
+
+ obj.btnPlay.className = "px-video-play px-video-show-inline";
+ obj.btnPause.className = "px-video-pause hide";
+ obj.btnPlay.focus();
+ }, false);
+
+ // Restart
+ obj.btnRestart.addEventListener("click", function() {
+ // Move to beginning
+ obj.movie.currentTime = 0;
+
+ // Special handling for "manual" captions
+ if (!obj.isTextTracks) {
+ obj.subcount = 0;
+ }
+
+ // Play and ensure the play button is in correct state
+ obj.movie.play();
+ obj.btnPlay.className = "px-video-play hide";
+ obj.btnPause.className = "px-video-pause px-video-show-inline";
+
+ }, false);
+
+ // Rewind
+ obj.btnRewind.addEventListener("click", function() {
+ var targetTime = obj.movie.currentTime - obj.seekInterval;
+ if (targetTime < 0) {
+ obj.movie.currentTime = 0;
+ }
+ else {
+ obj.movie.currentTime = targetTime;
+ }
+ // Special handling for "manual" captions
+ if (!obj.isTextTracks) {
+ adjustManualCaptions(obj);
+ }
+ }, false);
+
+ // Fast forward
+ obj.btnForward.addEventListener("click", function() {
+ var targetTime = obj.movie.currentTime + obj.seekInterval;
+ if (targetTime > obj.movie.duration) {
+ obj.movie.currentTime = obj.movie.duration;
+ }
+ else {
+ obj.movie.currentTime = targetTime;
+ }
+ // Special handling for "manual" captions
+ if (!obj.isTextTracks) {
+ adjustManualCaptions(obj);
+ }
+ }, false);
+
+ // Get the HTML5 range input element and append audio volume adjustment on change
+ obj.btnVolume.addEventListener("change", function() {
+ obj.movie.volume = parseFloat(this.value / 10);
+ }, false);
+
+ // Mute
+ obj.btnMute.addEventListener("click", function() {
+ if (obj.movie.muted === true) {
+ obj.movie.muted = false;
+ }
+ else {
+ obj.movie.muted = true;
+ }
+ }, false);
+
+ // Duration
+ obj.movie.addEventListener("timeupdate", function() {
+ obj.secs = parseInt(obj.movie.currentTime % 60);
+ obj.mins = parseInt((obj.movie.currentTime / 60) % 60);
+
+ // Ensure it"s two digits. For example, 03 rather than 3.
+ obj.secs = ("0" + obj.secs).slice(-2);
+ obj.mins = ("0" + obj.mins).slice(-2);
+
+ // Render
+ obj.duration.innerHTML = obj.mins + ":" + obj.secs;
+ }, false);
+
+ // Progress bar
+ obj.movie.addEventListener("timeupdate", function() {
+ obj.percent = (100 / obj.movie.duration) * obj.movie.currentTime;
+ if (obj.percent > 0) {
+ obj.progressBar.value = obj.percent;
+ obj.progressBarSpan.innerHTML = obj.percent;
+ }
+ }, false);
+
+ // Skip when clicking progress bar
+ obj.progressBar.addEventListener("click", function(e) {
+ obj.pos = (e.pageX - this.offsetLeft) / this.offsetWidth;
+ obj.movie.currentTime = obj.pos * obj.movie.duration;
+
+ // Special handling for "manual" captions
+ if (!obj.isTextTracks) {
+ adjustManualCaptions(obj);
+ }
+ });
+
+ // Clear captions at end of video
+ obj.movie.addEventListener("ended", function() {
+ obj.captionsContainer.innerHTML = "";
+ });
+
+ // ***
+ // Captions
+ // ***
+
+ // Toggle display of captions via captions button
+ obj.captionsBtn.addEventListener("click", function() {
+ if (this.checked) {
+ obj.captionsContainer.className = "px-video-captions show";
+ } else {
+ obj.captionsContainer.className = "px-video-captions hide";
+ }
+ }, false);
+
+ // If no caption file exists, hide container for caption text
+ if (!obj.captionExists) {
+ obj.captionsContainer.className = "px-video-captions hide";
+ }
+
+ // If caption file exists, process captions
+ else {
+
+ // If IE 10/11 or Firefox 31+ or Safari 7+, don"t use native captioning (still doesn"t work although they claim it"s now supported)
+ if ((obj.browserName==="IE" && obj.browserMajorVersion===10) ||
+ (obj.browserName==="IE" && obj.browserMajorVersion===11) ||
+ (obj.browserName==="Firefox" && obj.browserMajorVersion>=31) ||
+ (obj.browserName==="Safari" && obj.browserMajorVersion>=7)) {
+ if (options.debug) {
+ console.log("Detected IE 10/11 or Firefox 31+ or Safari 7+");
+ }
+ // set to false so skips to "manual" captioning
+ obj.isTextTracks = false;
+
+ // turn off native caption rendering to avoid double captions [doesn"t work in Safari 7; see patch below]
+ var track = {};
+ var tracks = obj.movie.textTracks;
+ for (var j=0; j < tracks.length; j++) {
+ track = obj.movie.textTracks[j];
+ track.mode = "hidden";
+ }
+ }
+
+ // Rendering caption tracks - native support required - http://caniuse.com/webvtt
+ if (obj.isTextTracks) {
+ if (options.debug) {
+ console.log("textTracks supported");
+ }
+ showCaptionContainerAndButton(obj);
+
+ var track = {};
+ var tracks = obj.movie.textTracks;
+ for (var j=0; j < tracks.length; j++) {
+ track = obj.movie.textTracks[j];
+ track.mode = "hidden";
+ if (track.kind === "captions") {
+ track.addEventListener("cuechange",function() {
+ if (this.activeCues[0]) {
+ if (this.activeCues[0].hasOwnProperty("text")) {
+ obj.captionsContainer.innerHTML = this.activeCues[0].text;
+ }
+ }
+ },false);
+ }
+ }
+ }
+ // Caption tracks not natively supported
+ else {
+ if (options.debug) {
+ console.log("textTracks not supported so rendering captions manually");
+ }
+ showCaptionContainerAndButton(obj);
+
+ // Render captions from array at appropriate time
+ obj.currentCaption = "";
+ obj.subcount = 0;
+ obj.captions = [];
+
+ obj.movie.addEventListener("timeupdate", function() {
+ // Check if the next caption is in the current time range
+ if (obj.movie.currentTime.toFixed(1) > video_timecode_min(obj.captions[obj.subcount][0]) &&
+ obj.movie.currentTime.toFixed(1) < video_timecode_max(obj.captions[obj.subcount][0])) {
+ obj.currentCaption = obj.captions[obj.subcount][1];
+ }
+ // Is there a next timecode?
+ if (obj.movie.currentTime.toFixed(1) > video_timecode_max(obj.captions[obj.subcount][0]) &&
+ obj.subcount < (obj.captions.length-1)) {
+ obj.subcount++;
+ }
+ // Render the caption
+ obj.captionsContainer.innerHTML = obj.currentCaption;
+ }, false);
+
+ if (captionSrc !== "") {
+ // Create XMLHttpRequest object
+ var xhr;
+ if (window.XMLHttpRequest) {
+ xhr = new XMLHttpRequest();
+ } else if (window.ActiveXObject) { // IE8
+ xhr = new ActiveXObject("Microsoft.XMLHTTP");
+ }
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState === 4) {
+ if (xhr.status === 200) {
+ if (options.debug) {
+ console.log("xhr = 200");
+ }
+
+ obj.captions = [];
+ var records = [],
+ record,
+ req = xhr.responseText;
+ records = req.split("\n\n");
+ for (var r=0; r < records.length; r++) {
+ record = records[r];
+ obj.captions[r] = [];
+ obj.captions[r] = record.split("\n");
+ }
+ // Remove first element ("VTT")
+ obj.captions.shift();
+
+ if (options.debug) {
+ console.log("Successfully loaded the caption file via ajax.");
+ }
+ } else {
+ if (options.debug) {
+ console.log("There was a problem loading the caption file via ajax.");
+ }
+ }
+ }
+ }
+ xhr.open("get", captionSrc, true);
+ xhr.send();
+ }
+ }
+
+ // If Safari 7, removing track from DOM [see "turn off native caption rendering" above]
+ if (obj.browserName === "Safari" && obj.browserMajorVersion === 7) {
+ console.log("Safari 7 detected; removing track from DOM");
+ var tracks = obj.movie.getElementsByTagName("track");
+ obj.movie.removeChild(tracks[0]);
+ }
+
+ }
+};
+
+
+
+/*$(function() {
+ $("video").simplePlayer();
+});*/
+
+// Simple player plugin
+// ---------------------------------
+/*;(function($) {
+ $.fn.simplePlayer = function (settings) {
+ // Config defaults
+ var config = {
+ wrapperClass: "media", // Class name added to replaced selects
+ shownClass: "in",
+ autoplay: false,
+ templates: {
+ controls: "<div class="media-controls js-media-controls"> \
+ <button type="button" class="play button-toggle-play js-button-toggle-play"> \
+ <span class="icon-play"></span> \
+ </button> \
+ <div class="progress progress-play js-progress-play" role="progress-bar"> \
+ <div class="progress-buffered js-progress-buffered"></div> \
+ <div class="progress-played js-progress-played"></div> \
+ </div> \
+ <div class="time js-time"> \
+ <span class="time-elapsed js-time-elapsed">88:88</span> \
+ <span class="time-seperator js-time-seperator">/</span> \
+ <span class="time-total js-time-total">88:88</span> \
+ </div> \
+ <div class="volume has-popover js-volume"> \
+ <button type="button" class="button-toggle-mute js-button-toggle-mute"> \
+ <span class="icon-volume-up"></span> \
+ </button> \
+ <div class="popover popover-volume js-popover-volume"> \
+ <div class="progress vertical-progress progress-audio-volume js-progress-audio-volume"> \
+ <div class="progress-volume js-progress-volume" style="height: 80%"></div> \
+ </div> \
+ <div class="volume-label js-volume-label">100%</div> \
+ </div> \
+ </div> \
+ <button type="button" class="fullscreen button-fullscreen js-button-fullscreen"> \
+ <span class="icon-resize-full"></span> \
+ </button> \
+ </div>",
+ overlay: "<div class="overlay overlay-play"><span><i class="icon-play"></i></span></div>"
+ }
+ };
+
+ // Extend settings if they"re passed
+ if (settings) {
+ $.extend(config, settings);
+ }
+
+ this.each(function() {
+ var player = this,
+ status = {},
+ $player = $(this).wrap("<div class="" + config.wrapperClass + (config.autoplay ? " playing" : " stopped") + "" />"),
+ $wrapper = $player.parents("." + config.wrapperClass),
+ supportMP4 = (function (v) { return (v.canPlayType && v.canPlayType("video/mp4")); }(document.createElement("video")));
+
+ console.log($wrapper);
+
+ // Inject the controls
+ $(config.templates.controls).insertAfter($player);
+ $(config.templates.overlay).insertAfter($player);
+
+ // Select controls
+ var $playbackToggle = $(".js-button-toggle-play"),
+ $muteToggle = $(".js-button-toggle-mute");
+
+ function togglePlayback() {
+ if(status.playing && status.playing == true) {
+ player.pause();
+ status.playing = false;
+ $wrapper.removeClass("playing").addClass("paused");
+ } else {
+ player.play();
+ status.playing = true;
+ $wrapper.removeClass("paused stopped").addClass("playing");
+ }
+ $("span", this).attr("class", "icon-" + (status.playing ? "pause" : "play"));
+ };
+
+ function toggleMute() {
+ player.muted = !status.muted;
+ status.muted = player.muted;
+ $("span", this).attr("class", "icon-" + (status.muted ? "mute" : "volume-up"));
+ };
+
+ $playbackToggle.on("click", togglePlayback);
+ $muteToggle.on("click", toggleMute);
+ });
+ };
+})(jQuery);*/ \ No newline at end of file