(function($){
	$(window).on('load', function() {
		// Get current page/post ID
		var postId = 0;
		var classList = $('body').attr('class').split(/\s+/);
		$.each( classList, function ( index, item ) {
			if ( item.indexOf('page-id') >= 0 || item.indexOf('postid') >= 0 ) {
				var item_arr = item.split('-');
				postId = item_arr[item_arr.length - 1];
				return false;
			}
		});
		
		// Get the current views for this post 
		if ( postId !== 0 ) {
			$.ajax({
				url: "/wp-json/drah/v1/post-views-abbr/" + postId,
				method: "GET",
				dataType: "json",
				success: function( response ) {
					var updateValue = response;
					var viewsCount = $( '.drah-post-views .views-count' );
					viewsCount.text( updateValue );
				},
				error: function(error) {
					console.log(error);
				}
			});
				
			$.ajax({
				url: "/wp-json/drah/v1/post-views-ajax/" + postId,
				method: "GET",
				dataType: "json",
				success: function( response ) {
					var updateValue = response;
					var viewsCount = $( '.drah-post-views .views-count' );
					viewsCount.attr( 'title', updateValue );				
				},
				error: function(error) {
					console.log(error);
				}
			});
		}
	});
})(jQuery);