making embedly thumbnail width and height configurable

This commit is contained in:
Sacha Greif 2014-11-30 11:31:07 +09:00
parent aa25a75dc8
commit 69b3ec2352
7 changed files with 57 additions and 11 deletions

View file

@ -1,9 +1,9 @@
<template name="settings">
<div class="grid-small grid-module dialog settings">
{{#if this.hasSettings}}
{{> quickForm collection="Settings" id="updateSettingsForm" type="update" doc=this.settings label-class="control-label" input-col-class="controls" template="settings"}}
{{> quickForm collection="Settings" id="updateSettingsForm" type="update" doc=this.settings label-class="control-label" input-col-class="controls" template="telescope"}}
{{else}}
{{> quickForm collection="Settings" id="updateSettingsForm" type="insert" template="settings" label-class="control-label" input-col-class="controls"}}
{{> quickForm collection="Settings" id="updateSettingsForm" type="insert" template="telescope" label-class="control-label" input-col-class="controls"}}
{{/if}}
</div>
</template>

View file

@ -2,7 +2,9 @@
{{#autoForm qfAutoFormContext}}
<div class='no-fieldset'>
{{> 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}}
</div>
{{#each afFieldsets}}

View file

@ -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;
},

View file

@ -1,4 +1,7 @@
<template name="afPostThumbnail">
<img src="{{this.value}}" class="post-thumbnail-preview" />
<div class="post-thumbnail-container">
<img src="{{this.value}}" class="post-thumbnail-preview" style="{{style}}"/>
<div class="post-thumbnail-loading">Loading…</div>
</div>
<input type="hidden" value="{{this.value}}" {{this.atts}}/>
</template>

View file

@ -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');
}
});
}

View file

@ -41,4 +41,28 @@ var embedlyKeyProperty = {
}
}
}
addToSettingsSchema.push(embedlyKeyProperty);
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);

View file

@ -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'
}
});