<commit_before>import g from './globals';
import {Matreshka as MK, balalaika as $} from '../matreshka';

export default class Article extends MK.Object {
	constructor(data) {
		super(data)
			.set('commentsShown', false)
			.events()
			.links()
	}

	events() {
		return this
			.on({
				'click::menuItem(.expand)': evt => {
					this.expanded = !this.expanded;
					evt.preventDefault();
				},
				'change:isActive': evt => {
					var node = this.bound('menuItem');
					while (node = node.parentNode) {
						$('.submenu-wrapper').filter(function(wrapper) {
							return wrapper.contains(node);
						}).map(function(wrapper) {
							return wrapper.previousElementSibling;
						}).map(function(menuItem) {
							return menuItem.querySelector('.hidden-active-child');
						}).forEach(function(menuItem) {
							menuItem.innerHTML = this.isActive ? this.name : ''
						}, this);
						break;
					}
				},
				'click::comment': evt => {
					var url = document.location.origin + document.location.pathname + '#' + this.id,
						commentsContainer = this.bound('commentsContainer');

					if (this.commentsShown = !this.commentsShown) {
						commentsContainer.classList.add('muut');
						g.app.muut();
					}
				},
				'click::(.share-facebook)': evt => {
					let url = `http://www.facebook.com/dialog/feed?app_id=901572946532005&link=${encodeURIComponent(location.href)}&name=${this.name}&description=${this.summary}&redirect_uri=${encodeURIComponent('http://matreshka.io/popupclose.html')}&display=popup&picture=${encodeURIComponent('http://matreshka.io/img/mk_logo.png')}`;

					window.open(url, 'Facebook', 'height=600,width=700');
				}, //
				'click::(.share-twitter)': evt => {
					let url = `https://twitter.com/intent/tweet?text=${encodeURIComponent('#matreshkajs ' + this.name +': ' + this.summary.substr(0, 60) + '...')}&url=${location.href}`;
					window.open(url, 'Twitter', 'height=600,width=700');
				}
			})
			.on('render change:expanded', function() {
				var submenu = this.bound('submenu');
				if (submenu) {
					if (!this.expanded) {
						submenu.style.marginTop = -44 * this.selectAll(':bound(submenu) li').length + 'px';
					} else {
						submenu.style.marginTop = 0;
						submenu.style.display = 'block';
					}
				}
			}, true);
	}

	links() {
		return this
			.linkProps('ieVersion', [g.app, 'ieVersion'])
			.linkProps('newVersions', [g.app, 'newVersions'])
			.linkProps('_previous', [
				this, 'previous',
				g.app, 'unstableVersion',
				g.app, 'version',
				g.app, 'articles',
				g.app, 'importanceLevel'
			], (previous, unstableVersion, version, articles, importanceLevel) => {
				if (!previous || !previous.importance || version == 'unstable' || !articles) {
					return previous;
				} else {
					do {
						if (previous.since != unstableVersion && previous.importance <= importanceLevel) { 
							return previous;
						}
					} while (previous = previous.previous)
				}
			})
			.linkProps('_next', [
				this, 'next',
				g.app, 'unstableVersion',
				g.app, 'version',
				g.app, 'articles',
				g.app, 'importanceLevel'
			], (next, unstableVersion, version, articles, importanceLevel) => {
				if (!next || !next.importance || version == 'unstable' || !articles) {
					return next;
				} else {
					do {
						if (next.since != unstableVersion && next.importance <= importanceLevel) {
							return next;
						}
					} while (next = next.next)
				}
			})
			.linkProps('previousId', '_previous', function(previous) {
				return previous ? previous.id : '';
			})
			.linkProps('nextId', '_next', function(next) {
				return next ? next.id : '';
			})
			.linkProps('previousHeader', '_previous', function(previous) {
				return previous ? previous.name : '';
			})
			.linkProps('nextHeader', '_next', function(next) {
				return next ? next.name : '';
			});
	}

	onRender() {
		var paginationHTML = g.app.select('#pagination-template').innerHTML;
		this.bindNode('id', ':sandbox', MK.binders.property('id'));

		if(!this.id) {
			return;
		}

		return this
			.bindNode({
				menuItem: 'nav a[href="#' + this.id + '"]',
				since: [':sandbox', MK.binders.dataset('since')],
				isActive: [':bound(menuItem)', MK.binders.className('active')],
				expanded: [':bound(menuItem)', MK.binders.className('expanded')],
				newVersions: [':sandbox', {
					setValue(v) {
						this.classList.toggle('new', ~v.indexOf(this.getAttribute('data-since')));
					}
				}]
			})
			.bindOptionalNode({
				commentsContainer: ':sandbox .comments-container',
				submenu: 'nav ul[data-submenu="' + this.id + '"]',
				comment: ':sandbox .comments',
				commentsShown: [':bound(commentsContainer)', MK.binders.visibility()],
				ieVersion: [':sandbox .comments', MK.binders.className('hide')],
				header: [':sandbox h2', {
					getValue: function() {
						return this.innerHTML.replace(/<wbr>/g, '');
					}
				}],
				summary: [':sandbox .summary p', MK.binders.innerText()],
				importance: [':sandbox', {
					getValue() {
						return +this.getAttribute('data-importance');
					}
				}]
			})
			.bindNode('pagination', [
				this.sandbox.insertBefore($(paginationHTML)[0], this.sandbox.firstChild),
				this.sandbox.appendChild($(paginationHTML)[0])
			])<commit_msg>added hashpart to share text; fix in all summaries<commit_after>import g from './globals';
import {Matreshka as MK, balalaika as $} from '../matreshka';

export default class Article extends MK.Object {
	constructor(data) {
		super(data)
			.set('commentsShown', false)
			.events()
			.links()
	}

	events() {
		return this
			.on({
				'click::menuItem(.expand)': evt => {
					this.expanded = !this.expanded;
					evt.preventDefault();
				},
				'change:isActive': evt => {
					var node = this.bound('menuItem');
					while (node = node.parentNode) {
						$('.submenu-wrapper').filter(function(wrapper) {
							return wrapper.contains(node);
						}).map(function(wrapper) {
							return wrapper.previousElementSibling;
						}).map(function(menuItem) {
							return menuItem.querySelector('.hidden-active-child');
						}).forEach(function(menuItem) {
							menuItem.innerHTML = this.isActive ? this.name : ''
						}, this);
						break;
					}
				},
				'click::comment': evt => {
					var url = document.location.origin + document.location.pathname + '#' + this.id,
						commentsContainer = this.bound('commentsContainer');

					if (this.commentsShown = !this.commentsShown) {
						commentsContainer.classList.add('muut');
						g.app.muut();
					}
				},
				'click::(.share-facebook)': evt => {
					let url = `http://www.facebook.com/dialog/feed?app_id=901572946532005&link=${encodeURIComponent(location.href)}&name=${this.name}&description=${this.summary}&redirect_uri=${encodeURIComponent('http://matreshka.io/popupclose.html')}&display=popup&picture=${encodeURIComponent('http://matreshka.io/img/mk_logo.png')}`;

					window.open(url, 'Facebook', 'height=600,width=700');
				}, //
				'click::(.share-twitter)': evt => {
					let url = `https://twitter.com/intent/tweet?text=${encodeURIComponent('#matreshkajs ' + this.name +': ' + this.summary.substr(0, 60) + '...')}&url=${encodeURIComponent(location.href)}`;
					window.open(url, 'Twitter', 'height=600,width=700');
				}
			})
			.on('render change:expanded', function() {
				var submenu = this.bound('submenu');
				if (submenu) {
					if (!this.expanded) {
						submenu.style.marginTop = -44 * this.selectAll(':bound(submenu) li').length + 'px';
					} else {
						submenu.style.marginTop = 0;
						submenu.style.display = 'block';
					}
				}
			}, true);
	}

	links() {
		return this
			.linkProps('ieVersion', [g.app, 'ieVersion'])
			.linkProps('newVersions', [g.app, 'newVersions'])
			.linkProps('_previous', [
				this, 'previous',
				g.app, 'unstableVersion',
				g.app, 'version',
				g.app, 'articles',
				g.app, 'importanceLevel'
			], (previous, unstableVersion, version, articles, importanceLevel) => {
				if (!previous || !previous.importance || version == 'unstable' || !articles) {
					return previous;
				} else {
					do {
						if (previous.since != unstableVersion && previous.importance <= importanceLevel) {
							return previous;
						}
					} while (previous = previous.previous)
				}
			})
			.linkProps('_next', [
				this, 'next',
				g.app, 'unstableVersion',
				g.app, 'version',
				g.app, 'articles',
				g.app, 'importanceLevel'
			], (next, unstableVersion, version, articles, importanceLevel) => {
				if (!next || !next.importance || version == 'unstable' || !articles) {
					return next;
				} else {
					do {
						if (next.since != unstableVersion && next.importance <= importanceLevel) {
							return next;
						}
					} while (next = next.next)
				}
			})
			.linkProps('previousId', '_previous', function(previous) {
				return previous ? previous.id : '';
			})
			.linkProps('nextId', '_next', function(next) {
				return next ? next.id : '';
			})
			.linkProps('previousHeader', '_previous', function(previous) {
				return previous ? previous.name : '';
			})
			.linkProps('nextHeader', '_next', function(next) {
				return next ? next.name : '';
			});
	}

	onRender() {
		var paginationHTML = g.app.select('#pagination-template').innerHTML;
		this.bindNode('id', ':sandbox', MK.binders.property('id'));

		if(!this.id) {
			return;
		}

		return this
			.bindNode({
				menuItem: 'nav a[href="#' + this.id + '"]',
				since: [':sandbox', MK.binders.dataset('since')],
				isActive: [':bound(menuItem)', MK.binders.className('active')],
				expanded: [':bound(menuItem)', MK.binders.className('expanded')],
				newVersions: [':sandbox', {
					setValue(v) {
						this.classList.toggle('new', ~v.indexOf(this.getAttribute('data-since')));
					}
				}]
			})
			.bindOptionalNode({
				commentsContainer: ':sandbox .comments-container',
				submenu: 'nav ul[data-submenu="' + this.id + '"]',
				comment: ':sandbox .comments',
				commentsShown: [':bound(commentsContainer)', MK.binders.visibility()],
				ieVersion: [':sandbox .comments', MK.binders.className('hide')],
				header: [':sandbox h2', {
					getValue: function() {
						return this.innerHTML.replace(/<wbr>/g, '');
					}
				}],
				summary: [':sandbox .summary p', {
					getValue() {
						return this.textContent;
					}
				}],
				importance: [':sandbox', {
					getValue() {
						return +this.getAttribute('data-importance');
					}
				}]
			})
			.bindNode('pagination', [
				this.sandbox.insertBefore($(paginationHTML)[0], this.sandbox.firstChild),
				this.sandbox.appendChild($(paginationHTML)[0])
			])
{'fraction_non_alphanumeric': 0.1868672532879175, 'fraction_numerical': 0.006812375816065853, 'mean_word_length': 3.2296918767507004, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5909354', 'n_tokens_mistral': 4451, 'n_tokens_neox': 3426, 'n_words': 580}