From d8e9b4d5334db049feec81b0083c3adcedaf7e12 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 28 Mar 2016 19:10:26 -0400 Subject: allow generic urls in media field --- examples/db.json | 15 +++++++++ examples/index.js | 6 ++++ themes/okadmin/public/js/app.js | 38 ++++++++++++++++------- themes/okadmin/public/js/parser.js | 4 +-- themes/okadmin/templates/partials/inputs.liquid | 41 ++++++++++++++++++++----- 5 files changed, 83 insertions(+), 21 deletions(-) diff --git a/examples/db.json b/examples/db.json index 9ab7233..b9de44b 100644 --- a/examples/db.json +++ b/examples/db.json @@ -124,5 +124,20 @@ ], "dateCreated": "" } + ], + "test": [ + { + "id": "test", + "title": "tEst", + "media": [ + { + "uri": "http://asdf.us/", + "caption": "ASDF", + "type": "link" + } + ], + "__index": "0", + "dateCreated": "Mon, 28 Mar 2016 23:02:45 GMT" + } ] } \ No newline at end of file diff --git a/examples/index.js b/examples/index.js index bf51dfc..4bf385f 100644 --- a/examples/index.js +++ b/examples/index.js @@ -21,12 +21,18 @@ var app = okcms.createApp({ video: {type: 'video'}, images: {type: 'captioned-image-list'} }, + test: { + id: {type: 'string', hidden: true}, + title: {type: 'string'}, + media: {type: 'media-list'}, + } }, resources: [ { type: 'page', static: {id: 'about'}}, { type: 'page', static: {id: 'contact'}}, { type: 'bread' }, + { type: 'test' }, ], services: { diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index da398eb..61fc8c8 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -47,17 +47,33 @@ var OKAdmin = function(){ $("ol", parent).prepend($el) } uploader.addVideo = function(media){ - console.log(media) - var videoTemplate = $(".video-template", parent).html() - var $el = $(videoTemplate) - $el.addClass("loaded") - $el.find(".video-type").val( media.type ) - $el.find(".video-token").val( media.token ) - $el.find(".video-title").val( media.title ) - $el.find(".video-thumb").val( media.thumbnail ) - $el.find("img").attr("src", media.thumbnail ) - $("ol", parent).prepend($el) - } + switch (media.type) { + case 'youtube': + case 'vimeo': + case 'video': + var videoTemplate = $(".video-template", parent).html() + var $el = $(videoTemplate) + $el.addClass("loaded") + $el.find(".video-type").val( media.type ) + $el.find(".video-token").val( media.token ) + $el.find(".video-title").val( media.title ) + $el.find(".video-thumb").val( media.thumbnail ) + $el.find(".video-width").val( media.width ) + $el.find(".video-height").val( media.height ) + $el.find("img").attr("src", media.thumbnail ) + $("ol", parent).prepend($el) + break + case 'link': + var linkTemplate = $(".link-template", parent).html() + var $el = $(linkTemplate) + $el.addClass("loaded") + $el.find(".uri").val( media.url ) + $("ol", parent).prepend($el) + break + default: + alert("Unsupported link type!") + } + } }) // delete image from gallery $(document).on("mousedown", ".media-list .remove", function(){ diff --git a/themes/okadmin/public/js/parser.js b/themes/okadmin/public/js/parser.js index 411f425..95b391c 100644 --- a/themes/okadmin/public/js/parser.js +++ b/themes/okadmin/public/js/parser.js @@ -145,7 +145,6 @@ var Parser = { '&color=ff6600&auto_play=false&show_artwork=true">' } }, - /* { type: 'link', regex: /^http.+/i, @@ -163,8 +162,7 @@ var Parser = { tag: function (media) { return '' + media.url + '' } - } - */ + }, ], tumblr: function(url, cb){ diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index 4acb435..77ee7a4 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -29,6 +29,8 @@ + + @@ -143,11 +145,12 @@ - + + +
    {% for image in spec.value %} - {% if image.token %} + {% if image.type and (image.type == "vimeo" or image.type == "youtube" or image.type == "video") %}
  1. + + @@ -185,11 +201,22 @@
  2. + {% elsif image.type and image.type == "link" %} + {% else %}
  3. + - {{image.caption}} + + {{image.caption | strip_html}}
  4. {% endif %} @@ -210,7 +237,7 @@
  5. - {{image.caption}} +
  6. @@ -220,7 +247,7 @@
  7. - {{image.caption}} + {{image.caption | strip_html}}
  8. {% endfor %} @@ -238,7 +265,7 @@