Vulcan/lib/helpers.js

65 lines
2 KiB
JavaScript
Raw Normal View History

t=function(message){
var d=new Date();
console.log("### "+message+" rendered at "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds());
}
nl2br= function(str) {
var breakTag = '<br />';
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}
getSetting = function(setting){
var settings=Settings.find().fetch()[0];
if(settings){
return settings[setting];
}
return '';
}
2012-10-04 14:54:26 +09:00
trackEvent = function(event, properties){
console.log('trackevent: ', event, properties);
var properties= (typeof properties === 'undefined') ? {} : properties;
if(typeof mixpanel.track != 'undefined'){
mixpanel.track(event, properties);
}
}
2012-10-04 10:09:20 +09:00
sessionSetObject=function(name, value){
Session.set(name, JSON.stringify(value));
}
sessionGetObject=function(name){
return JSON.parse(Session.get(name));
}
2012-10-02 10:54:04 +09:00
getAuthorName = function(item){
// keep both variables for transition period
var id=item.userId || item.user_id;
// if item is linked to a user, get that user's display name. Else, return the author field.
return (id && (user=Meteor.users.findOne(id))) ? getDisplayName(user) : this.author;
}
scrollPageTo = function(selector){
$('body').scrollTop($(selector).offset().top);
}
2012-10-04 13:30:57 +09:00
// sortJsonArrayByProperty= function(objArray, prop, direction){
// // http://stackoverflow.com/questions/4222690/sorting-a-json-object-in-javascript
// var direct = arguments.length>2 ? arguments[2] : 1; //Default to ascending
// if (objArray && objArray.constructor===Array){
// var propPath = (prop.constructor===Array) ? prop : prop.split(".");
// objArray.sort(function(a,b){
// for (var p in propPath){
// if (a[propPath[p]] && b[propPath[p]]){
// a = a[propPath[p]];
// b = b[propPath[p]];
// }
// }
// // convert numeric strings to integers
// a = a.match(/^\d+$/) ? +a : a;
// b = b.match(/^\d+$/) ? +b : b;
// return ( (a < b) ? -1*direct : ((a > b) ? 1*direct : 0) );
// });
// }
// }