1'use strict'; 2 3var Templater = require('./templater.js'); 4var Ajax = require('./ajax.js'); 5var Utils = require('./utils.js'); 6var ProgressBar = require('./progressBar.js'); 7var qs = window.location.href.split('?')[1] || ''; 8 9var $list = $('#list'); 10var offset = $list.find('.short-item:visible').length; 11var cntRows = $list.data('max'); 12 13var clearList = false; 14 15var options = {}; 16 17var publicNotFound = $('.public-posts-not-found'); 18var allNotFound = $('.all-posts-not-found'); 19 20function init(url, template, callback, id) { 21 if (id) { 22 $list = $('#' + id); 23 offset = $list.find('.short-item:visible').length; 24 cntRows = $list.data('max'); 25 } 26 27 options.url = url; 28 options.template = template; 29 options.callback = callback || null; 30 31 $('#show-more').click(function(e) { 32 e.preventDefault(); 33 loadPosts(); 34 }); 35 36 window.filterChange = function () { 37 38 qs = window.location.href.split('?')[1] || '' 39 offset = 0; 40 clearList = true; 41 42 $list.addClass('list-loader'); 43 44 loadPosts(); 45 } 46} 47 48function loadPosts() { 49 50 var $showMore = $('#show-more').hide(); 51 52 var _id = ProgressBar.show(); 53 var path = location.pathname; 54 if (path[path.length - 1] === '/') { 55 path = path.substr(0, path.length - 1); 56 } 57 58 if (qs && qs[0] !== '&') { 59 qs = '&' + qs; 60 } 61 62 Ajax.getJSON(options.url + (options.url && options.url.indexOf('?') == -1 ? '?' : '&') + 'offset=' + offset + qs, function (result) { 63 ProgressBar.hide(_id); 64 $showMore.show(); 65 66 if (result.response) { 67 var posts = result.response.rows; 68 var _like = result.response._like; 69 var isNotify = result.response.users; 70 var html = []; 71 72 cntRows = result.response.rows; 73 74 if (publicNotFound) { 75 if (result.response.rows_count === 0 && qs.indexOf('review=1') !== -1) { 76 publicNotFound.show() 77 } else { 78 publicNotFound.hide() 79 } 80 } 81 if (allNotFound) { 82 if (result.response.rows_count === 0 && qs.indexOf('review=1') === -1) { 83 allNotFound.show() 84 } else { 85 allNotFound.hide() 86 } 87 } 88 89 _.each(posts, function (v, i) { 90 if (v._available && _like) { 91 v.show_like = true; 92 } 93 94 v.isAuth = _like; 95 v.origin = window.location.origin; 96 97 if (v.level_id && i > 0 && !posts[i - 1].level_id && (qs.indexOf('review=1') > -1)) { 98 v.show_next = $list.data('next'); 99 } 100 101 if (!isNotify) { 102 html.push(Templater.render(options.template, v, undefined, true)); 103 } else { 104 html.push(Templater.render(options.template, {notify: v, items: result.response}, undefined, true)); 105 } 106 }); 107 108 if (clearList) { 109 $list.html(html.join('')); 110 } else { 111 $list.append(html.join('')); 112 } 113 $list.removeClass('list-loader'); 114 115 offset += posts.length; 116 117 if (isNotify) { 118 Utils.setStatusNotify('user'); 119 } 120 121 cntRows = result.response.rows_count; 122 if (offset >= cntRows) { 123 $showMore.hide(); 124 } else { 125 $showMore.show(); 126 } 127 128 if (typeof options.callback === 'function') { 129 options.callback(); 130 } 131 } 132 }); 133} 134 135module.exports = init;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.