From 69b3ec2352058e8340410b86203a6788c959a73d Mon Sep 17 00:00:00 2001 From: Sacha Greif Date: Sun, 30 Nov 2014 11:31:07 +0900 Subject: [PATCH] making embedly thumbnail width and height configurable --- client/views/admin/settings.html | 4 +-- client/views/forms/quickFormTelescope.html | 4 ++- client/views/forms/quickFormTelescope.js | 11 +++++--- .../lib/client/autoform-postthumbnail.html | 5 +++- .../lib/client/autoform-postthumbnail.js | 10 +++++++ .../telescope-module-embedly/lib/embedly.js | 26 ++++++++++++++++++- .../lib/server/get_embedly_data.js | 8 +++--- 7 files changed, 57 insertions(+), 11 deletions(-) diff --git a/client/views/admin/settings.html b/client/views/admin/settings.html index ea06b88f5..cb3fedd48 100644 --- a/client/views/admin/settings.html +++ b/client/views/admin/settings.html @@ -1,9 +1,9 @@ \ No newline at end of file diff --git a/client/views/forms/quickFormTelescope.html b/client/views/forms/quickFormTelescope.html index b641e1977..6bed71c9f 100644 --- a/client/views/forms/quickFormTelescope.html +++ b/client/views/forms/quickFormTelescope.html @@ -2,7 +2,9 @@ {{#autoForm qfAutoFormContext}}
- {{> afQuickFields fields=fieldsWithNoFieldset omitFields=../atts.omitFields template="telescope" input-col-class=inputClass label-class=labelClass}} + {{#each fieldsWithNoFieldset}} + {{> afQuickField name=this template="telescope" input-col-class=inputClass label-class=labelClass}} + {{/each}}
{{#each afFieldsets}} diff --git a/client/views/forms/quickFormTelescope.js b/client/views/forms/quickFormTelescope.js index 7a1139a10..f9928f4cc 100644 --- a/client/views/forms/quickFormTelescope.js +++ b/client/views/forms/quickFormTelescope.js @@ -25,10 +25,15 @@ var canEditField = function (field) { Template[getTemplate('quickForm_telescope')].helpers({ fieldsWithNoFieldset: function () { - // get names of fields who don't have an autoform attribute or don't have a group + // get names of fields who don't have an autoform attribute or don't have a group, but are not omitted var fields = _.pluck(_.filter(getSchema(), function (field, key) { - // filter out fields with "$" in their name - return (field.name.indexOf('$') === -1) && (!field.autoform || !field.autoform.group); // TODO: find cleaner solution + if (field.name.indexOf('$') !== -1) // filter out fields with "$" in their name + return false + if (field.autoform && field.autoform.omit) // filter out fields with omit = true + return false + if (field.autoform && field.autoform.group) // filter out fields with a group + return false + return true // return remaining fields }), 'name'); return fields; }, diff --git a/packages/telescope-module-embedly/lib/client/autoform-postthumbnail.html b/packages/telescope-module-embedly/lib/client/autoform-postthumbnail.html index aa2c8c5e4..355daeaea 100644 --- a/packages/telescope-module-embedly/lib/client/autoform-postthumbnail.html +++ b/packages/telescope-module-embedly/lib/client/autoform-postthumbnail.html @@ -1,4 +1,7 @@ \ No newline at end of file diff --git a/packages/telescope-module-embedly/lib/client/autoform-postthumbnail.js b/packages/telescope-module-embedly/lib/client/autoform-postthumbnail.js index 0750fd380..8cd11b7d4 100644 --- a/packages/telescope-module-embedly/lib/client/autoform-postthumbnail.js +++ b/packages/telescope-module-embedly/lib/client/autoform-postthumbnail.js @@ -8,6 +8,11 @@ Template.afPostThumbnail.helpers({ // Add bootstrap class atts = AutoForm.Utility.addClass(atts, "form-control"); return atts; + }, + style: function () { + var thumbnailWidth = getSetting('thumbnailWidth', 200); + var thumbnailHeight = getSetting('thumbnailHeight', 125); + return "width: "+thumbnailWidth+"px; height: "+thumbnailHeight+"px;" } }); @@ -20,16 +25,21 @@ Template.afPostThumbnail.rendered = function () { var $urlField = $('[name="url"]'); var $titleField = $('[name="title"]'); var $bodyField = $('[name="body"]'); + var $thumbnailContainer = $('.post-thumbnail-container'); + $urlField.change(function (e) { var url = $urlField.val(); if (!!url) { + $thumbnailContainer.addClass('loading'); + console.log('getting embedly data for '+url); Meteor.call('getEmbedlyData', url, function (error, data) { if (data) { $img.attr('src', data.thumbnailUrl); $thumbnailUrlField.val(data.thumbnailUrl); $titleField.val(data.title); $bodyField.val(data.description); + $thumbnailContainer.removeClass('loading'); } }); } diff --git a/packages/telescope-module-embedly/lib/embedly.js b/packages/telescope-module-embedly/lib/embedly.js index b21995614..f48a34e52 100644 --- a/packages/telescope-module-embedly/lib/embedly.js +++ b/packages/telescope-module-embedly/lib/embedly.js @@ -41,4 +41,28 @@ var embedlyKeyProperty = { } } } -addToSettingsSchema.push(embedlyKeyProperty); \ No newline at end of file +addToSettingsSchema.push(embedlyKeyProperty); + +var thumbnailWidthProperty = { + propertyName: 'thumbnailWidth', + propertySchema: { + type: Number, + optional: true, + autoform: { + group: 'embedly' + } + } +} +addToSettingsSchema.push(thumbnailWidthProperty); + +var thumbnailHeightProperty = { + propertyName: 'thumbnailHeight', + propertySchema: { + type: Number, + optional: true, + autoform: { + group: 'embedly' + } + } +} +addToSettingsSchema.push(thumbnailHeightProperty); \ No newline at end of file diff --git a/packages/telescope-module-embedly/lib/server/get_embedly_data.js b/packages/telescope-module-embedly/lib/server/get_embedly_data.js index 30ce45fbe..4a0aa63a4 100644 --- a/packages/telescope-module-embedly/lib/server/get_embedly_data.js +++ b/packages/telescope-module-embedly/lib/server/get_embedly_data.js @@ -2,7 +2,9 @@ getEmbedlyData = function (url) { var data = {} var extractBase = 'http://api.embed.ly/1/extract'; var embedlyKey = getSetting('embedlyKey'); - + var thumbnailWidth = getSetting('thumbnailWidth', 200); + var thumbnailHeight = getSetting('thumbnailHeight', 125); + try { if(!embedlyKey) @@ -12,8 +14,8 @@ getEmbedlyData = function (url) { params: { key: embedlyKey, url: url, - image_width: 200, - image_height: 150, + image_width: thumbnailWidth, + image_height: thumbnailHeight, image_method: 'crop' } });