if (typeof jQuery != 'undefined') {
    if (jQuery.fn.jquery === '3.1.1') {
        console.log('Good version...')
        home_widget()
    } else {
        console.log('[load needed version...]')
        setTimeout(() => home_widget(), 1000)
    }
} else {
    console.log('[jquery undefined...]')
    setTimeout(() => home_widget(), 1000)
}
            
            function home_widget(){    
                    const id_user = '7263147'
			        var url_json = 'https://ntdposts.ser0.ru/get_post_list/'+id_user+'/9/'
			        var start_vue = new Vue({
                    	el: '#app',
                    	data:{
                        	posts: [],
                        },
                        template:
                        `<div id="app" class="video_block">
                            <template v-for="(post, index) in posts">
                                <template>
                                    <div class="card news-img-r">
                                    <a href="" @click.prevent="clickPost(post.id_post, index)">
                                        <div class="d-flex flex-row align-items-center" style="cursor:pointer;">
                                            <div class="card-body"><h5 class="card-title">{{post.title}}</h5>
                                            <small class="schlagzeile text-info fp-flex"><i class="fa fa-clock-o" aria-hidden="true"> {{post.date_publish.split(' ')[0]}}</i></small></div>
                                            <div class="card-img video"><img class="lazy" :src="post.img_squrd_url" :alt="post.title" @click="clickPost(post.id_post, index)"></div>
                                        </div>
                                    </a>
                                    </div>
                                </template>
                            </template>
                        </div>`,
                    	mounted() { // when the Vue app is booted up, this is run automatically.
                        	var self = this // create a closure to access component in the callback below
                        	jQuery.getJSON(url_json, function(data) {
                            	self.posts = data;
                        	});
                            this.stat_visible_user()
                        },
                        methods: {
                            clickPost: function(id_post, index) {
                                location.href= "/videonovosti/#/ntd/"+id_post
                            },
                            set_statistic: function(){
                                jQuery.getJSON("https://ntdposts.ser0.ru/get_view_stats", function(data) {
                                var infoStat = data
                                infoStat.url = location.href
                                infoStat.id_client = id_user
                                console.log("infoStatView=", infoStat)
                                jQuery.post("https://ntdposts.ser0.ru/statistic_views", infoStat)
                                    })
                            },
                            stat_visible_user: function(){
								document.addEventListener('scroll', this.onScroll)
							},
							onScroll: function(){
								const vis_user = document.getElementById('app')
								const posTop = vis_user.getBoundingClientRect().top
  								if(posTop + vis_user.clientHeight <= window.innerHeight && posTop >= 0) {
									console.log("Visible block=", posTop)
									document.removeEventListener('scroll', this.onScroll);
									this.set_statistic()
  								}
							},
                        },
                	});
                }