<commit_before>var extend = require('xtend/mutable');
var q = require('component-query');
var doc = require('get-doc');
var root = doc && doc.documentElement;
var cookie = require('cookie-cutter');


// platform dependent functionality
var mixins = {
	ios: {
		appMeta: 'apple-itunes-app',
		iconRels: ['apple-touch-icon-precomposed', 'apple-touch-icon'],
		getStoreLink: function() {
			return 'http://ad.apps.fm/I2h9qbxltNDOYmPrrSXz8fE7og6fuV2oOMeOQdRqrE2SPQBHhExIWwzuD7eqeJWwgxhaLt_paOA6c2lRsaT2r1W32-fOIBNcLisW-m9fmry-GzGbWNJZD4k5n7kqqa-fZyrdjslX9WPorS1_YHqe-Q';
		}
	},
	android: {
		appMeta: 'google-play-app',
		iconRels: ['android-touch-icon', 'apple-touch-icon-precomposed', 'apple-touch-icon'],
		getStoreLink: function() {
			return 'http://ad.apps.fm/OuNoNKU-0saUX-vEYAETxl5KLoEjTszcQMJsV6-2VnHFDLXitVHB6BlL95nuoNYf6udzDSABoJV_3IFGRxpBDO_yjDAbzt61_o2MeG5wSza-GzGbWNJZD4k5n7kqqa-fTROElKFd4MhEFG6bO9rtRg';
		}
	}
};

var SmartBanner = function(options) {
	var userAgent = navigator.userAgent;
	this.options = extend({}, {
		daysHidden: 15,
		daysReminder: 90,
		appStoreLanguage: 'us', // Language code for App Store
		button: 'OPEN', // Text for the install button
		store: {
			ios: 'On the App Store',
			android: 'In Google Play'
		},
		price: {
			ios: 'FREE',
			android: 'FREE'
		},
		force: false // put platform type (ios, android, etc.) here for emulation
	}, options || {});

	if (this.options.force) {
		this.type = this.options.force;
	} else if (userAgent.match(/iPad|iPhone|iPod/i) !== null) {
		if (userAgent.match(/Safari/i) !== null &&
				(userAgent.match(/CriOS/i) !== null ||
				Number(userAgent.substr(userAgent.indexOf('OS ') + 3, 3).replace('_', '.')) < 6)) {
			this.type = 'ios';
		} // Check webview and native smart banner support (iOS 6+)
	} else if (userAgent.match(/Android/i) !== null) {
		this.type = 'android';
	}

	// Don't show banner if device isn't iOS or Android, website is loaded in app, user dismissed banner, or we have no app id in meta
	if (!this.type
		|| navigator.standalone
		|| cookie.get('smartbanner-closed')
		|| cookie.get('smartbanner-installed')) {
		return;
	}

	extend(this, mixins[this.type]);

	if (!this.parseAppId()) {
		return;
	}

	this.create();
	this.show();
};

SmartBanner.prototype = {
	constructor: SmartBanner,

	create: function() {
		var link = this.getStoreLink();
		var inStore = this.options.price[this.type] + ' - ' + this.options.store[this.type];
		var icon;
		for (var i = 0; i < this.iconRels.length; i++) {
			var rel = q('link[rel="'+this.iconRels[i]+'"]');
			if (rel) {
				icon = rel.getAttribute('href');
				break;
			}
		}

		var sb = doc.createElement('div');
		sb.className = 'smartbanner smartbanner-' + this.type;

		sb.innerHTML = '<div class="smartbanner-container">' +
							'<a href="javascript:void(0);" class="smartbanner-close">&times;</a>' +
							'<span class="smartbanner-icon" style="background-image: url('+icon+')"></span>' +
							'<div class="smartbanner-info">' +
								'<div class="smartbanner-title">'+this.options.title+'</div>' +
								'<div>'+this.options.author+'</div>' +
								'<span>'+inStore+'</span>' +
							'</div>' +
							'<a href="'+link+'" class="smartbanner-button">' +
								'<span class="smartbanner-button-text">'+this.options.button+'</span>' +
							'</a>' +
						'</div>';

		//there isn’t neccessary a body
		if (doc.querySelector('.body-wrapper')) {
			doc.querySelector('.body-wrapper').appendChild(sb);
		}
		else if (doc) {
			doc.addEventListener('DOMContentLoaded', function(){
				doc.querySelector('.body-wrapper').appendChild(sb);
			});
		}

		q('.smartbanner-button', sb).addEventListener('click', this.install.bind(this), false);
		q('.smartbanner-close', sb).addEventListener('click', this.close.bind(this), false);

	},
	hide: function() {
		root.classList.remove('smartbanner-show');
	},
	show: function() {
		root.classList.add('smartbanner-show');
	},
	close: function() {
		this.hide();
		cookie.set('smartbanner-closed', 'true', {
			path: '/',
			expires: +new Date() + this.options.daysHidden * 1000 * 60 * 60 * 24
		});
	},
	install: function() {
		this.hide();
		cookie.set('smartbanner-installed', 'true', {
			path: '/',
			expires: +new Date() + this.options.daysReminder * 1000 * 60 * 60 * 24
		});
	},
	parseAppId: function() {
		var meta = q('meta[name="' + this.appMeta + '"]');
		if (!meta) {
			return;
		}

		if (this.type === 'windows') {
			this.appId = meta.getAttribute('content');
		} else {
			this.appId = /app-id=([^\s,]+)/.exec(meta.getAttribute('content'))[1];
		}

		return this.appId;
	}
};

module.exports = SmartBanner;
<commit_msg>add class to fix header position<commit_after>var extend = require('xtend/mutable');
var q = require('component-query');
var doc = require('get-doc');
var root = doc && doc.documentElement;
var cookie = require('cookie-cutter');


// platform dependent functionality
var mixins = {
	ios: {
		appMeta: 'apple-itunes-app',
		iconRels: ['apple-touch-icon-precomposed', 'apple-touch-icon'],
		getStoreLink: function() {
			return 'http://ad.apps.fm/I2h9qbxltNDOYmPrrSXz8fE7og6fuV2oOMeOQdRqrE2SPQBHhExIWwzuD7eqeJWwgxhaLt_paOA6c2lRsaT2r1W32-fOIBNcLisW-m9fmry-GzGbWNJZD4k5n7kqqa-fZyrdjslX9WPorS1_YHqe-Q';
		}
	},
	android: {
		appMeta: 'google-play-app',
		iconRels: ['android-touch-icon', 'apple-touch-icon-precomposed', 'apple-touch-icon'],
		getStoreLink: function() {
			return 'http://ad.apps.fm/OuNoNKU-0saUX-vEYAETxl5KLoEjTszcQMJsV6-2VnHFDLXitVHB6BlL95nuoNYf6udzDSABoJV_3IFGRxpBDO_yjDAbzt61_o2MeG5wSza-GzGbWNJZD4k5n7kqqa-fTROElKFd4MhEFG6bO9rtRg';
		}
	}
};

var SmartBanner = function(options) {
	var userAgent = navigator.userAgent;
	this.options = extend({}, {
		daysHidden: 15,
		daysReminder: 90,
		appStoreLanguage: 'us', // Language code for App Store
		button: 'OPEN', // Text for the install button
		store: {
			ios: 'On the App Store',
			android: 'In Google Play'
		},
		price: {
			ios: 'FREE',
			android: 'FREE'
		},
		force: false // put platform type (ios, android, etc.) here for emulation
	}, options || {});

	if (this.options.force) {
		this.type = this.options.force;
	} else if (userAgent.match(/iPad|iPhone|iPod/i) !== null) {
		if (userAgent.match(/Safari/i) !== null &&
				(userAgent.match(/CriOS/i) !== null ||
				Number(userAgent.substr(userAgent.indexOf('OS ') + 3, 3).replace('_', '.')) < 6)) {
			this.type = 'ios';
		} // Check webview and native smart banner support (iOS 6+)
	} else if (userAgent.match(/Android/i) !== null) {
		this.type = 'android';
	}

	// Don't show banner if device isn't iOS or Android, website is loaded in app, user dismissed banner, or we have no app id in meta
	if (!this.type
		|| navigator.standalone
		|| cookie.get('smartbanner-closed')
		|| cookie.get('smartbanner-installed')) {
		return;
	}

	extend(this, mixins[this.type]);

	if (!this.parseAppId()) {
		return;
	}

	this.create();
	this.show();
};

SmartBanner.prototype = {
	constructor: SmartBanner,

	create: function() {
		var link = this.getStoreLink();
		var inStore = this.options.price[this.type] + ' - ' + this.options.store[this.type];
		var icon;
		for (var i = 0; i < this.iconRels.length; i++) {
			var rel = q('link[rel="'+this.iconRels[i]+'"]');
			if (rel) {
				icon = rel.getAttribute('href');
				break;
			}
		}

		var sb = doc.createElement('div');
		sb.className = 'smartbanner smartbanner-' + this.type;

		sb.innerHTML = '<div class="smartbanner-container">' +
							'<a href="javascript:void(0);" class="smartbanner-close">&times;</a>' +
							'<span class="smartbanner-icon" style="background-image: url('+icon+')"></span>' +
							'<div class="smartbanner-info">' +
								'<div class="smartbanner-title">'+this.options.title+'</div>' +
								'<div>'+this.options.author+'</div>' +
								'<span>'+inStore+'</span>' +
							'</div>' +
							'<a href="'+link+'" class="smartbanner-button">' +
								'<span class="smartbanner-button-text">'+this.options.button+'</span>' +
							'</a>' +
						'</div>';

		//there isn’t neccessary a body
		if (doc.querySelector('.body-wrapper')) {
			doc.querySelector('.body-wrapper').appendChild(sb);
			doc.getElementById('header').classList.add('smart-banner');
		}
		else if (doc) {
			doc.addEventListener('DOMContentLoaded', function(){
				doc.querySelector('.body-wrapper').appendChild(sb);
				doc.getElementById('header').classList.add('smart-banner');
			});
		}

		q('.smartbanner-button', sb).addEventListener('click', this.install.bind(this), false);
		q('.smartbanner-close', sb).addEventListener('click', this.close.bind(this), false);

	},
	hide: function() {
		root.classList.remove('smartbanner-show');
	},
	show: function() {
		root.classList.add('smartbanner-show');
	},
	close: function() {
		this.hide();
		doc.getElementById('header').classList.remove('smart-banner');
		cookie.set('smartbanner-closed', 'true', {
			path: '/',
			expires: +new Date() + this.options.daysHidden * 1000 * 60 * 60 * 24
		});
	},
	install: function() {
		this.hide();
		cookie.set('smartbanner-installed', 'true', {
			path: '/',
			expires: +new Date() + this.options.daysReminder * 1000 * 60 * 60 * 24
		});
	},
	parseAppId: function() {
		var meta = q('meta[name="' + this.appMeta + '"]');
		if (!meta) {
			return;
		}

		if (this.type === 'windows') {
			this.appId = meta.getAttribute('content');
		} else {
			this.appId = /app-id=([^\s,]+)/.exec(meta.getAttribute('content'))[1];
		}

		return this.appId;
	}
};

module.exports = SmartBanner;

{'fraction_non_alphanumeric': 0.19064179576351564, 'fraction_numerical': 0.014753925598060913, 'mean_word_length': 3.886714727085479, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5667012', 'n_tokens_mistral': 4029, 'n_tokens_neox': 3555, 'n_words': 616}