2014-06-22 12:58:41 +09:00
|
|
|
cl = function(something){
|
|
|
|
console.log(l);
|
|
|
|
}
|
2013-04-26 17:28:09 +09:00
|
|
|
getSetting = function(setting, defaultValue){
|
2013-04-14 14:51:37 +09:00
|
|
|
var settings=Settings.find().fetch()[0];
|
|
|
|
if(settings){
|
|
|
|
return settings[setting];
|
|
|
|
}
|
2013-04-26 17:28:09 +09:00
|
|
|
return typeof defaultValue === 'undefined' ? '' : defaultValue;
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-10-14 12:14:12 +09:00
|
|
|
getCurrentTemplate = function() {
|
2014-05-08 15:35:47 +09:00
|
|
|
return Router.current().lookupTemplate();
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-11-16 14:01:00 +09:00
|
|
|
getCurrentRoute = function() {
|
|
|
|
return Router._currentController.path;
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2012-09-25 09:20:49 +09:00
|
|
|
t=function(message){
|
2012-11-26 17:11:21 +09:00
|
|
|
var d=new Date();
|
|
|
|
console.log("### "+message+" rendered at "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds());
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2012-09-25 09:20:49 +09:00
|
|
|
nl2br= function(str) {
|
|
|
|
var breakTag = '<br />';
|
|
|
|
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2012-10-02 10:54:04 +09:00
|
|
|
getAuthorName = function(item){
|
2013-10-21 18:56:22 +08:00
|
|
|
// since we are not publishing the user collection except for admins, just display the normalized author field
|
|
|
|
return item.author;
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2012-10-02 13:49:38 +09:00
|
|
|
scrollPageTo = function(selector){
|
2012-11-26 17:11:21 +09:00
|
|
|
$('body').scrollTop($(selector).offset().top);
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2012-10-10 13:54:48 +09:00
|
|
|
getDigestURL = function(moment){
|
2014-05-06 20:15:48 -07:00
|
|
|
return '/digest/'+moment.year()+'/'+(moment.month()+1)+'/'+moment.date();
|
|
|
|
};
|
2012-10-10 13:54:48 +09:00
|
|
|
getDateRange= function(pageNumber){
|
|
|
|
var now = moment(new Date());
|
|
|
|
var dayToDisplay=now.subtract('days', pageNumber-1);
|
|
|
|
var range={};
|
|
|
|
range.start = dayToDisplay.startOf('day').valueOf();
|
|
|
|
range.end = dayToDisplay.endOf('day').valueOf();
|
|
|
|
// console.log("after: ", dayToDisplay.startOf('day').format("dddd, MMMM Do YYYY, h:mm:ss a"));
|
|
|
|
// console.log("before: ", dayToDisplay.endOf('day').format("dddd, MMMM Do YYYY, h:mm:ss a"));
|
|
|
|
return range;
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-02-18 13:38:15 +09:00
|
|
|
// getPostCategories = function(post){
|
|
|
|
// var postCategories = _.map(post.categories, function(categoryId){
|
|
|
|
// return Categories.findOne(categoryId);
|
|
|
|
// });
|
|
|
|
// // put resulting array through a filter to remove empty values in case
|
|
|
|
// // some of the post's categories weren't found in the database
|
|
|
|
// return _.filter(postCategories, function(e){return e});
|
|
|
|
// }
|
2013-02-04 13:14:32 +09:00
|
|
|
// ---------------------------------- URL Helper Functions ----------------------------------- //
|
2013-10-06 09:17:37 +09:00
|
|
|
goTo = function(url){
|
|
|
|
Router.go(url);
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-02-04 13:14:32 +09:00
|
|
|
getPostUrl = function(id){
|
2013-02-16 16:56:02 +09:00
|
|
|
return Meteor.absoluteUrl()+'posts/'+id;
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-10-06 09:17:37 +09:00
|
|
|
getPostEditUrl = function(id){
|
|
|
|
return Meteor.absoluteUrl()+'posts/'+id+'/edit';
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-02-04 13:14:32 +09:00
|
|
|
getCommentUrl = function(id){
|
2013-02-16 16:56:02 +09:00
|
|
|
return Meteor.absoluteUrl()+'comments/'+id;
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-02-04 13:14:32 +09:00
|
|
|
getPostCommentUrl = function(postId, commentId){
|
|
|
|
// get link to a comment on a post page
|
2013-02-16 16:56:02 +09:00
|
|
|
return Meteor.absoluteUrl()+'posts/'+postId+'/comment/'+commentId;
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-02-18 12:13:27 +09:00
|
|
|
getCategoryUrl = function(slug){
|
2013-10-24 21:02:42 +09:00
|
|
|
return Meteor.absoluteUrl()+'category/'+slug;
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-02-18 12:13:27 +09:00
|
|
|
slugify = function(text) {
|
2013-11-18 11:30:58 +09:00
|
|
|
if(text){
|
|
|
|
text = text.replace(/[^-a-zA-Z0-9,&\s]+/ig, '');
|
|
|
|
text = text.replace(/-/gi, "_");
|
|
|
|
text = text.replace(/\s/gi, "-");
|
|
|
|
text = text.toLowerCase();
|
|
|
|
}
|
2013-02-18 12:13:27 +09:00
|
|
|
return text;
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-07-04 12:09:31 +09:00
|
|
|
getShortUrl = function(post){
|
|
|
|
return post.shortUrl ? post.shortUrl : post.url;
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-07-19 12:17:49 +09:00
|
|
|
getDomain = function(url){
|
|
|
|
urlObject = Npm.require('url');
|
|
|
|
return urlObject.parse(url).hostname;
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-10-23 19:43:42 +09:00
|
|
|
invitesEnabled = function () {
|
|
|
|
return getSetting("requireViewInvite") || getSetting("requirePostInvite");
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2014-01-18 16:52:12 +09:00
|
|
|
getOutgoingUrl = function(url){
|
2014-02-24 18:41:59 +09:00
|
|
|
return Meteor.absoluteUrl() + 'out?url=' + encodeURIComponent(url);
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-02-04 13:14:32 +09:00
|
|
|
// ---------------------------------- String Helper Functions ----------------------------------- //
|
2012-12-13 10:58:17 +09:00
|
|
|
cleanUp = function(s){
|
|
|
|
return stripHTML(s);
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2012-12-13 10:58:17 +09:00
|
|
|
stripHTML = function(s){
|
|
|
|
return s.replace(/<(?:.|\n)*?>/gm, '');
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-02-04 13:14:32 +09:00
|
|
|
stripMarkdown = function(s){
|
|
|
|
var converter = new Markdown.Converter();
|
|
|
|
var html_body = converter.makeHtml(s);
|
|
|
|
return stripHTML(html_body);
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-02-04 13:14:32 +09:00
|
|
|
trimWords = function(s, numWords) {
|
|
|
|
expString = s.split(/\s+/,numWords);
|
|
|
|
if(expString.length >= numWords)
|
|
|
|
return expString.join(" ")+"…";
|
|
|
|
return s;
|
2014-05-06 20:15:48 -07:00
|
|
|
};
|
2013-11-07 09:57:57 +09:00
|
|
|
|
|
|
|
// http://stackoverflow.com/questions/2631001/javascript-test-for-existence-of-nested-object-key
|
|
|
|
checkNested = function(obj /*, level1, level2, ... levelN*/) {
|
|
|
|
var args = Array.prototype.slice.call(arguments),
|
|
|
|
obj = args.shift();
|
|
|
|
|
|
|
|
for (var i = 0; i < args.length; i++) {
|
|
|
|
if (!obj.hasOwnProperty(args[i])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
obj = obj[args[i]];
|
|
|
|
}
|
|
|
|
return true;
|
2014-05-08 15:30:36 +09:00
|
|
|
};
|