Giter VIP home page Giter VIP logo

cabana.share's Introduction

Cabana.Share

Cabana A/S Sharing-module. This sharing module is privacy-embracing, cookie-avoiding and ultra-light.

Installing

Either you grap one of the build files from /build ... or you use bower install cabana-share

To make sure you always have the latest version use: <script src="https://rawgit.com/Cabana/cabana.Share/master/build/cabana.Share.min.js" type="text/javascript"></script>

Usage

/**
* Summary of Cabana.Share
* Share current page to external media
* @param Url (optional) - Url to share - will default to window.location.href
* @param Type - Media to share through
* @return boolean
*/
Cabana.Share(Url, Type);

/*
* Minimal version
*/
Cabana.Share(Type);

Types are:

  • facebook
  • twitter
  • email
  • print
  • linkedin
  • google

Configuration

Configuration is not yet possible, but will be in the future. Configuration can be made, by defining window.CabanaShareSettings

window.CabanaShareSettings = {
	'twitter': {
		user: null,
		/* Twitter-handle for user associated with site, will be added to tweet. Defaults to null */
		text: null,
		/* Standard text for tweet before url. Defaults to window.location.href */
		hashtags: null,
		/* Comma-seperated list of hashtags to add to tweet. Defaults to null */
	},
	'email': {
		text: null,
		/* Standard body for email. Every [URL] will be replaced by window.location.href. Defaults to window.location.href */
		subject: null,
		/* Mail-subject. Defaults to document.title */
	},
	'linkedin': {
		text: null,
		/* Standard text for sharing. Defaults to meta[name='description'] content-attribute */
		title: null
		/* Title for sharing. Defaults to document.title */
	}
}

###On-share configuration If you have multiple share actions on one page and want various configurations for those, use the built in on-share configuration. Instead of passing a string for URL, you pass an object looking like this:

var config = {
	'url': 'http://notMyWindowLocationHref.com',
	'options': {
		'user': 'leoorsnes'
	}
};
Cabana.Share(config, 'twitter');

Here the options object within the config depends on type of sharing as seen above. Fx. you can use 'user' for Twitter but not for linkedin etc.

##Tracking & listeners

###Google Tag Manager If Google Tag Manager's dataLayer is found any share-event will be pushed to the object with following parameters:

dataLayer.push({
	'event': 'Share.event',
	/* Fx. Share.facebook if Facebook, Share.twitter if Twitter etc. */
	'title': document.title,
	/* The current sites title will be parsed through here */
	'url': location.href
	/* Current url is parsed as well */
})

###Event listeners

####Built-in If you are used to using jQuery event-namespaces, the built-in event listeners will suit you quite well. Setting a listener:

Cabana.Share().on('twitter', function() {
	alert('My cool callback');
});

Setting a global listener:

Cabana.Share().on('share', function(type) {
	alert('You shared through '+type);
});

Removing a listener:

Cabana.Share().off('twitter');

Setting namespaced listener:

Cabana.Share().on('twitter.myCoolNameSpace', callback);

Removing a namespaced listener:

Cabana.Share().off('twitter.myCoolNameSpace');

Output all current listeners:

Cabana.Share().listeners

####Good ol' listeners If you are not using Google Tag Manager, you can fetch all the event by listening on the document for 'Share.event'. If you want to listen for any Facebook sharing-clicks you could do it as follows:

document.addEventListener('Share.facebook', function() {
	/* Custom tracking-actions */
});

AddThis replacement

This module is made as an ultra-light and slimmer alternative for AddThis. This means that the module can work instead of AddThis or "on top" of AddThis - "on top" meaning that it will override all AddThis listeners and functions, all though AddThis will initially run, before it's overridden. This module will override (or create) both addthis.update() and addthis_sendto().

Status

This module is still in alpha release

cabana.share's People

Contributors

donlion avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.