Skip to content

Commit

Permalink
Add image function
Browse files Browse the repository at this point in the history
  • Loading branch information
danallison committed Nov 3, 2017
1 parent aa1c575 commit f183ec3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
calculist.register('createComputationContextObject', ['_','ss','evalculist','isItem','keyToVarName','getItemByGuid'], function (_, ss, evalculist, isItem, keyToVarName, getItemByGuid) {
calculist.register('createComputationContextObject', ['_','ss','evalculist','isItem','keyToVarName','getItemByGuid','urlFinder'], function (_, ss, evalculist, isItem, keyToVarName, getItemByGuid, urlFinder) {

'use strict';

Expand Down Expand Up @@ -375,6 +375,20 @@ calculist.register('createComputationContextObject', ['_','ss','evalculist','isI
}
});

var imageToString = _.constant('[Image]');
proto.image = function (url, width, height) {
if (!urlFinder.isUrl(url)) return NaN;
var html = '<img src="' + url + '"';
if (_.isNumber(+width)) html += ' width="' + (+width) + '"';
if (_.isNumber(+height)) html += ' height="' + (+height) + '"';
html += '/>';
return {
mediaType: 'image',
toString: imageToString,
toHTML: _.constant(html),
};
};

proto.uniq = proto.unique = itemsFirst(function (items) {
items = _.map(items, proto.valueOf);
return _.uniq(items);
Expand Down
7 changes: 6 additions & 1 deletion app/assets/javascripts/shared/Item/item.getComputed.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ calculist.require(['Item','removeHTML','_'], function (Item, removeHTML, _) {
this.valueOf();
val = this.val;
if (val != null) {
val = "<span class='value'>" + (this.formatVal(val)) + "</span>";
if (_.isPlainObject(val) && val.toHTML) {
val = val.toHTML();
} else {
val = this.formatVal(val);
}
val = "<span class='value'>" + val + "</span>";
if (this.key) {
return "<span class='key'>" + (this.formatKey(this.key)) + "</span>: " + val;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ calculist.require(['Item','itemOfFocus'], function (Item, itemOfFocus) {
this.valueOf();
val = this.val;
if (this.valIsComputed && this.hasVal) {
val = this.formatVal(val);
val = (_.isPlainObject(val) && val.toHTML) ? val.toString() : this.formatVal(val);
$cd = this.$("#computed-display" + this.id);
$cd.text("" + val).css({
'margin-left': -$cd.width()
Expand Down

0 comments on commit f183ec3

Please sign in to comment.