<commit_before>requirejs.config({
	baseUrl: 'js/lib',
	paths: {
		app: '../app',
		jquery: 'jquery-3.1.0.min',
		vue: 'vue.min',
		css: 'css.min',
		cssroot: '../../css'
	},
})
require(['jquery', 'vue', 'app/page', 'app/sidenav', 'app/navbar',
		'app/bookmark'
	],
	function($, Vue, page, sidenav, navbar, bookmark) {
		Vue.component('enovelhub-page', page)
		Vue.component('enovelhub-sidenav', sidenav)
		Vue.component('enovelhub-navbar', navbar)

		var app = new Vue({
			el: '#app',
			ready: function() {
				var self = this
				var book = bookmark.loadLastRead()
				if (book) {
					self.loadBookPages(book, bookmark.getLastRead().index)
				} else {
					$.get('testdata.json', function(book) {
						self.loadBookPages(book, 0)
					})
				}

			},
			data: {
				appName: 'enovelhub',
				book: {
					author: "author",
					title: "book title",
					content: [{
						title: 'chapter title',
						content: ['content 0', 'line 1', 'line 2']
					}],
				},
				css: {
					author: {
						float: 'right',
						fontSize: 'small',
						marginRight: '2rem',
						textAlign: 'center',
					},
					index: {
						float: 'left',
						marginLeft: '2rem',
						textAlign: 'center',
					},
					title: {
						float: 'right',
						textAlign: 'center',
						marginRight: '2rem',
					}
				},
			},
			computed: {
				titles: function() {
					var titles = new Array()
					for (i = 0; i < this.book.content.length; i++) {
						titles[i] = this.book.content[i].title
					}
					return titles
				},
			},
			methods: {
				loadBookPages: function(book, lastReadIndex) {
					var self = this
					bookmark.save(book)
					bookmark.setLastRead(book.author, book.title, 0)

					self.book.author = book.author
					self.book.title = book.title
					self.book.content = new Array(book.content.length)
					var updateContent = function(index, length) {
						if (index == length) {
							self.$broadcast('navbar-progress', 100)
							self.$emit('select-page', lastReadIndex)
							self.autoUpdatePageIndex()
							return
						}

						self.book.content.$set(index, book.content[index])
						Vue.nextTick(function() {
							self.$broadcast('navbar-progress', index / length * 100)
							setTimeout(function() {
								updateContent(index + 1, length)
							}, 0)
						})
					}
					updateContent(0, book.content.length)
				},
				autoUpdatePageIndex: function() {
					var self = this
					var updateIndex = function(index) {
						self.$broadcast('sidenav-index', index)
					}
					var autoUpdatePageIndex = function() {
						var docScrollTop = $(document).scrollTop()
						var min = Number.MAX_SAFE_INTEGER;
						var id = ""

						var pages = $('.{appName}-page'
							.replace(/{appName}/g, self.$root.appName)
						).each(function() {
							var v = $(this).offset().top + $(this).height() - docScrollTop
							if (v > 0 && Math.abs(v) < min) {
								min = v
								id = $(this).attr('id')
							}
						})

						index = id.replace(/.*-page-/g, "") - 0
						updateIndex(index)
						bookmark.setLastRead(bookmark.getLastRead().author,
							bookmark.getLastRead().name, index)

						setTimeout(function() {
							autoUpdatePageIndex()
						}, 500)
					}

					autoUpdatePageIndex()
				}
			},
			events: {
				'select-page': function(index) {
					var selector = '#{appName}-page-{index}'
						.replace(/{appName}/g, this.$root.appName)
						.replace(/{index}/g, index)
					$('html,body').animate({
						scrollTop: $(selector).offset().top - 100
					}, 500)
					this.$broadcast('navbar-progress', 100)
					this.$broadcast('hide-sidenav')
				},
				'show-sidenav': function() {
					this.$broadcast('show-sidenav')
				}
			},
			template: `
		<enovelhub-navbar>
			<slot>
				<span :style="css.index" @click="this.$emit('show-sidenav')">Index</span>
				<span :style="css.author">by.{{ book.author }}</span>
				<span :style="css.title">{{ book.title }}</span>
			</slot><commit_msg>click book name to clear book cache<commit_after>requirejs.config({
	baseUrl: 'js/lib',
	paths: {
		app: '../app',
		jquery: 'jquery-3.1.0.min',
		vue: 'vue.min',
		css: 'css.min',
		cssroot: '../../css'
	},
})
require(['jquery', 'vue', 'app/page', 'app/sidenav', 'app/navbar',
		'app/bookmark'
	],
	function($, Vue, page, sidenav, navbar, bookmark) {
		Vue.component('enovelhub-page', page)
		Vue.component('enovelhub-sidenav', sidenav)
		Vue.component('enovelhub-navbar', navbar)

		var app = new Vue({
			el: '#app',
			ready: function() {
				var self = this
				var book = bookmark.loadLastRead()
				if (book) {
					self.loadBookPages(book, bookmark.getLastRead().index)
				} else {
					$.get('testdata.json', function(book) {
						self.loadBookPages(book, 0)
					})
				}

			},
			data: {
				appName: 'enovelhub',
				book: {
					author: "author",
					title: "book title",
					content: [{
						title: 'chapter title',
						content: ['content 0', 'line 1', 'line 2']
					}],
				},
				css: {
					author: {
						float: 'right',
						fontSize: 'small',
						marginRight: '2rem',
						textAlign: 'center',
					},
					index: {
						float: 'left',
						marginLeft: '2rem',
						textAlign: 'center',
					},
					title: {
						float: 'right',
						textAlign: 'center',
						marginRight: '2rem',
					}
				},
			},
			computed: {
				titles: function() {
					var titles = new Array()
					for (i = 0; i < this.book.content.length; i++) {
						titles[i] = this.book.content[i].title
					}
					return titles
				},
			},
			methods: {
				loadBookPages: function(book, lastReadIndex) {
					var self = this
					bookmark.save(book)
					bookmark.setLastRead(book.author, book.title, 0)

					self.book.author = book.author
					self.book.title = book.title
					self.book.content = new Array(book.content.length)
					var updateContent = function(index, length) {
						if (index == length) {
							self.$broadcast('navbar-progress', 100)
							self.$emit('select-page', lastReadIndex)
							self.autoUpdatePageIndex()
							return
						}

						self.book.content.$set(index, book.content[index])
						Vue.nextTick(function() {
							self.$broadcast('navbar-progress', index / length * 100)
							setTimeout(function() {
								updateContent(index + 1, length)
							}, 0)
						})
					}
					updateContent(0, book.content.length)
				},
				clearCache: function() {
					bookmark.clear()
				},
				autoUpdatePageIndex: function() {
					var self = this
					var updateIndex = function(index) {
						self.$broadcast('sidenav-index', index)
					}
					var autoUpdatePageIndex = function() {
						var docScrollTop = $(document).scrollTop()
						var min = Number.MAX_SAFE_INTEGER;
						var id = ""

						var pages = $('.{appName}-page'
							.replace(/{appName}/g, self.$root.appName)
						).each(function() {
							var v = $(this).offset().top + $(this).height() - docScrollTop
							if (v > 0 && Math.abs(v) < min) {
								min = v
								id = $(this).attr('id')
							}
						})

						index = id.replace(/.*-page-/g, "") - 0
						updateIndex(index)
						bookmark.setLastRead(bookmark.getLastRead().author,
							bookmark.getLastRead().name, index)

						setTimeout(function() {
							autoUpdatePageIndex()
						}, 500)
					}

					autoUpdatePageIndex()
				}
			},
			events: {
				'select-page': function(index) {
					var selector = '#{appName}-page-{index}'
						.replace(/{appName}/g, this.$root.appName)
						.replace(/{index}/g, index)
					$('html,body').animate({
						scrollTop: $(selector).offset().top - 100
					}, 500)
					this.$broadcast('navbar-progress', 100)
					this.$broadcast('hide-sidenav')
				},
				'show-sidenav': function() {
					this.$broadcast('show-sidenav')
				}
			},
			template: `
		<enovelhub-navbar>
			<slot>
				<span :style="css.index" @click="this.$emit('show-sidenav')">Index</span>
				<span :style="css.author">by.{{ book.author }}</span>
				<span :style="css.title" @click="clearCache()">{{ book.title }}</span>
			</slot>
{'fraction_non_alphanumeric': 0.17582831325301204, 'fraction_numerical': 0.008785140562248996, 'mean_word_length': 2.389621437686091, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, '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': '1288540', 'n_tokens_mistral': 3855, 'n_tokens_neox': 2693, 'n_words': 507}