es6 standard class declaration
use for projects to do ajax, social sharing, tracking, and using animations.
Usage: import Globals from 'path/to/globals.js';
/*
* @class Globals
* ------------------------------------------
* Declare global variables and methods here
* ------------------------------------------
*/
export default class Globals {
constructor(){
this.animation_object = {
duration: 300,
easing: 'ease'
}
this.break_points = {
xs_width: 320,
sm_width: 480,
md_width: 768,
lg_width: 992,
xl_width: 1024,
xxl_width: 1200
}
this.ajax_config = function(endpoint, method) {
var type = typeof method === 'undefined' ? 'GET' : method;
return {
type: type,
url: $('#app').data('base') + endpoint
};
}
this.track = function(category, action, label){
return ga('send', 'event', category.toLowerCase(), action.toLowerCase(), label.toLowerCase());
}
this.facebook = function(name, link, picture, caption, description) {
return FB.ui({
method: 'feed',
name: name,
link: link,
caption: caption,
description: description
});
}
this.tweet = function(text, hashtags, link) {
text = encodeURI(text);
link = encodeURI(link);
return window.open('https://twitter.com/intent/tweet?text=' + text + '&hashtags=' + hashtags + '&url=' + link,'','width=600,height=600');
}
this.short_url = function(url,username,key) {
return $.getJSON("https://api-ssl.bitly.com/v3/shorten?access_token="+key+"&longUrl="+url+"&login="+username+"&format=json");
}
}
}