_(data).forEach(function(activity) { // If activity is missing data, skip it if (!activity || !activity.user || (activity.type === 'newVolunteer' && !activity.task) || (activity.comment && typeof activity.comment.value === "undefined") ) return; // Render markdown if (activity.comment) { var value = activity.comment.value; value = marked(value, { sanitize: false }); //render comment in single line by stripping the markdown-generated paragraphs value = value.replace(/<\/?p>/gm, ''); value = value.replace(/<br>/gm, ''); value = value.trim(); activity.comment.value = value; } // Format timestamp activity.createdAtFormatted = $.timeago(activity.createdAt); var template = self.$('#' + activity.type).text(), content = _.template(template, { interpolate: /\{\{(.+?)\}\}/g })(activity); self.$('.activity-block .activity-feed').append(content); });
render: function(model) { var $cardContainer = $(this.cardTemplate); this.model = model; this.model.set('timeago', $.timeago(this.model.get('created_time'))); var headerTemplate = Handlebars.compile(this.headerTemplate); var photoTemplate = Handlebars.compile(this.photoTemplate); var locationTemplate = Handlebars.compile(this.locationTemplate); if (this.model.get('likes')) { this.model.set('numLikes', this.model.get('likes').data.length); } else { this.model.set('numLikes', 0); } if (this.model.get('comments')) { this.model.set('numComments', this.model.get('comments').data.length); } else { this.model.set('numComments', 0); } var appendTemplates = function(modelJSON) { $cardContainer.append(headerTemplate(modelJSON)); $cardContainer.append(photoTemplate(modelJSON)); $cardContainer.append(locationTemplate(modelJSON)); this.$el.append($cardContainer); }.bind(this); // get // user profile pic // photo // static maps // then render the card $.when(this.getProfilePicture(this.model.toJSON())).then(this.getPhotoSrc).done(appendTemplates); // todo // insert from newest to oldest, // inserting into dom as the models are added },
link: function (scope, element, attrs) { if ('undefined' !== typeof attrs.since && !attrs.duration) { var ival = since(attrs.since, element); $(element).tooltip({title: 'Started ' + new Date(attrs.since).toLocaleString()}); attrs.$observe('since', function () { $(element).tooltip({title: 'Started ' + new Date(attrs.since).toLocaleString()}); clearInterval(ival); ival = since(attrs.since, element); }); return scope.$on('$destroy', function () { clearInterval(ival); }); } var date; if ('undefined' !== typeof attrs.datetime) { date = new Date(attrs.datetime); $(element).tooltip({title: date.toLocaleString()}); } if ('undefined' !== typeof attrs.duration) { attrs.$observe('duration', function () { textDuration(attrs.duration, element); }); return textDuration(attrs.duration, element); } attrs.$observe('datetime', function () { date = new Date(attrs.datetime); $(element).tooltip({title: date.toLocaleString()}); $(element).text($.timeago(date)); }); // TODO: use moment.js $(element).text($.timeago(date)); setTimeout(function () { $(element).timeago(); }, 0); }
attrs.$observe('datetime', function () { date = new Date(attrs.datetime); $(element).tooltip({title: date.toLocaleString()}); $(element).text($.timeago(date)); });