From 587c9f7d3f4ac9efbd8851dad1c2f62b9e7e6e61 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 9 Apr 2015 01:07:37 -0400 Subject: stub in video field --- app/node_modules/okschema/index.js | 5 + examples/db.json | 4 +- themes/okadmin/public/css/main.css | 4 + themes/okadmin/public/js/app.js | 16 +- themes/okadmin/public/js/parser.js | 282 ++++++++++++++++++++++++ themes/okadmin/templates/partials/inputs.liquid | 14 +- themes/okadmin/templates/partials/tail.liquid | 1 + 7 files changed, 321 insertions(+), 5 deletions(-) create mode 100644 themes/okadmin/public/js/parser.js diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js index 4e8ea73..6c7cf96 100644 --- a/app/node_modules/okschema/index.js +++ b/app/node_modules/okschema/index.js @@ -21,6 +21,11 @@ var types = { // Let parent handle validation assertValid: function(spec, value) {} }, + 'video': { + parent: {type: 'string'}, + // Let parent handle validation + assertValid: function(spec, value) {} + }, 'enum': { parent: {type: 'string'}, assertValid: function(spec, value) { diff --git a/examples/db.json b/examples/db.json index b2cdf4a..f7936d5 100644 --- a/examples/db.json +++ b/examples/db.json @@ -4,9 +4,9 @@ { "type": "pretzel", "description": "really a very tasty bread! yup yes", - "color": "blue", + "color": "green", "id": "pretzel", - "title": "" + "title": "Pretzel Chips" }, { "type": "bagel", diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index c5694eb..aff28fd 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -160,6 +160,10 @@ label { font-size: 1.0em; } +.disabled { + display: none; +} + .clear { clear: both; } diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index b850466..3abc347 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -1,11 +1,23 @@ var OKAdmin = function(){ - OKUpload.bind() OKUpload.add = function(data){ console.log(data) } + $(".video .url").change(function(){ + var $el = $(this) + var url = $el.val() + Parser.parse( url, function(media){ + $el.next(".video-type").val( media.type ) + $el.next(".video-token").val( media.token ) + $el.next(".video-title").val( media.title ) + $el.next(".video-thumb").val( media.thumbnail ) + }) + }) + } -window.app = new OKAdmin () +$(function(){ + window.app = new OKAdmin () +}) diff --git a/themes/okadmin/public/js/parser.js b/themes/okadmin/public/js/parser.js new file mode 100644 index 0000000..411f425 --- /dev/null +++ b/themes/okadmin/public/js/parser.js @@ -0,0 +1,282 @@ +var Parser = { + integrations: [{ + type: 'image', + regex: /\.(jpeg|jpg|gif|png|svg)(\?.*)?$/i, + fetch: function(url, done) { + var img = new Image () + img.onload = function(){ + if (!img) return + var width = img.naturalWidth, height = img.naturalHeight + img = null + done({ + url: url, + type: "image", + token: "", + thumbnail: "", + title: "", + width: width, + height: height, + }) + } + img.src = url + if (img.complete) { + img.onload() + } + }, + tag: function (media) { + return ''; + } + }, { + type: 'video', + regex: /\.(mp4|webm)(\?.*)?$/i, + fetch: function(url, done) { + var video = document.createElement("video") + video.addEventListener("loadedmetadata", function(){ + var width = video.videoWidth, height = video.videoHeight + video = null + done({ + url: url, + type: "video", + token: "", + thumbnail: "", + title: "", + width: width, + height: height, + }) + }) + video.src = url + video.load() + }, + tag: function (media) { + return '