Threads view initial
This commit is contained in:
parent
5234c5f9f9
commit
20567e68a8
|
@ -6,6 +6,8 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=0.7">
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
|
||||
<script src="js/helpers.js"></script>
|
||||
<script src="js/threads.js"></script>
|
||||
<script src="js/script.js"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
</head>
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
|
||||
<!-- <script src="js/jquery-1.8.min.js"></script> -->
|
||||
<script src="js/multiple-select.js"></script>
|
||||
<script src="js/js.cookie.js"></script>
|
||||
<script src="js/helpers.js"></script>
|
||||
<script src="js/threads.js"></script>
|
||||
<script src="js/script.js"></script>
|
||||
<script src="js/autolink.js"></Script>
|
||||
|
@ -24,7 +26,7 @@
|
|||
<!-- <div class="logo"><a href="/" style="text-decoration: none; color: #c9c9c9;">dynamic | less</a></div> -->
|
||||
<input type="search" id="searchInput" placeholder="Example: python">
|
||||
<div id="selector">
|
||||
<form><a href="/" style="text-decoration: none; color: #c9c9c9;"><i id="siteIcon" class="fa fa-sitemap" ></i> </a> <select id="echoSelector" multiple size="5"></select></form>
|
||||
<form><a href="/" style="text-decoration: none; color: #c9c9c9;"><i id="siteIcon" class="fa fa-sitemap" ></i> </a> <select id="echoSelector" multiple size="5"></select><a href="javascript:void(0)" onclick="toggleViewMode()">Mode</a></form>
|
||||
</div>
|
||||
<a id="menu" href="javascript:void(0)" onclick="showMenu()"><i class="fa fa-bars"></i></a>
|
||||
<div id="dropdown-content">
|
||||
|
|
24
js/helpers.js
Normal file
24
js/helpers.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
function bake_cookie(name, value) {
|
||||
var echo = read_cookie("echo");
|
||||
var threads = read_cookie("threads");
|
||||
if (name != "echo") {
|
||||
var cookie = ["echo=", echo, ';', "threads", '=', value, '; domain=.', window.location.host.toString(), '; path=/;'].join('');
|
||||
document.cookie = cookie;
|
||||
} else if (threads) {
|
||||
var cookie = ["echo=", value, ';', "threads", '=', threads, '; domain=.', window.location.host.toString(), '; path=/;'].join('');
|
||||
document.cookie = cookie;
|
||||
} else {
|
||||
console.log("Setting echoes " + value);
|
||||
var cookie = ["echo=", value, ';', 'domain=.', window.location.host.toString(), '; path=/;'].join('');
|
||||
document.cookie = cookie;
|
||||
}
|
||||
console.log("Cookie: " + document.cookie);
|
||||
}
|
||||
|
||||
function read_cookie(name) {
|
||||
var result = document.cookie.match(new RegExp(name + '=([^;]+)'));
|
||||
if (result) {
|
||||
result = result[1];
|
||||
}
|
||||
return result;
|
||||
}
|
165
js/js.cookie.js
Normal file
165
js/js.cookie.js
Normal file
|
@ -0,0 +1,165 @@
|
|||
/*!
|
||||
* JavaScript Cookie v2.2.0
|
||||
* https://github.com/js-cookie/js-cookie
|
||||
*
|
||||
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
|
||||
* Released under the MIT license
|
||||
*/
|
||||
;(function (factory) {
|
||||
var registeredInModuleLoader = false;
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(factory);
|
||||
registeredInModuleLoader = true;
|
||||
}
|
||||
if (typeof exports === 'object') {
|
||||
module.exports = factory();
|
||||
registeredInModuleLoader = true;
|
||||
}
|
||||
if (!registeredInModuleLoader) {
|
||||
var OldCookies = window.Cookies;
|
||||
var api = window.Cookies = factory();
|
||||
api.noConflict = function () {
|
||||
window.Cookies = OldCookies;
|
||||
return api;
|
||||
};
|
||||
}
|
||||
}(function () {
|
||||
function extend () {
|
||||
var i = 0;
|
||||
var result = {};
|
||||
for (; i < arguments.length; i++) {
|
||||
var attributes = arguments[ i ];
|
||||
for (var key in attributes) {
|
||||
result[key] = attributes[key];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function init (converter) {
|
||||
function api (key, value, attributes) {
|
||||
var result;
|
||||
if (typeof document === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Write
|
||||
|
||||
if (arguments.length > 1) {
|
||||
attributes = extend({
|
||||
path: '/'
|
||||
}, api.defaults, attributes);
|
||||
|
||||
if (typeof attributes.expires === 'number') {
|
||||
var expires = new Date();
|
||||
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
|
||||
attributes.expires = expires;
|
||||
}
|
||||
|
||||
// We're using "expires" because "max-age" is not supported by IE
|
||||
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
|
||||
|
||||
try {
|
||||
result = JSON.stringify(value);
|
||||
if (/^[\{\[]/.test(result)) {
|
||||
value = result;
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
if (!converter.write) {
|
||||
value = encodeURIComponent(String(value))
|
||||
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
|
||||
} else {
|
||||
value = converter.write(value, key);
|
||||
}
|
||||
|
||||
key = encodeURIComponent(String(key));
|
||||
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
|
||||
key = key.replace(/[\(\)]/g, escape);
|
||||
|
||||
var stringifiedAttributes = '';
|
||||
|
||||
for (var attributeName in attributes) {
|
||||
if (!attributes[attributeName]) {
|
||||
continue;
|
||||
}
|
||||
stringifiedAttributes += '; ' + attributeName;
|
||||
if (attributes[attributeName] === true) {
|
||||
continue;
|
||||
}
|
||||
stringifiedAttributes += '=' + attributes[attributeName];
|
||||
}
|
||||
return (document.cookie = key + '=' + value + stringifiedAttributes);
|
||||
}
|
||||
|
||||
// Read
|
||||
|
||||
if (!key) {
|
||||
result = {};
|
||||
}
|
||||
|
||||
// To prevent the for loop in the first place assign an empty array
|
||||
// in case there are no cookies at all. Also prevents odd result when
|
||||
// calling "get()"
|
||||
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
||||
var rdecode = /(%[0-9A-Z]{2})+/g;
|
||||
var i = 0;
|
||||
|
||||
for (; i < cookies.length; i++) {
|
||||
var parts = cookies[i].split('=');
|
||||
var cookie = parts.slice(1).join('=');
|
||||
|
||||
if (!this.json && cookie.charAt(0) === '"') {
|
||||
cookie = cookie.slice(1, -1);
|
||||
}
|
||||
|
||||
try {
|
||||
var name = parts[0].replace(rdecode, decodeURIComponent);
|
||||
cookie = converter.read ?
|
||||
converter.read(cookie, name) : converter(cookie, name) ||
|
||||
cookie.replace(rdecode, decodeURIComponent);
|
||||
|
||||
if (this.json) {
|
||||
try {
|
||||
cookie = JSON.parse(cookie);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
if (key === name) {
|
||||
result = cookie;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!key) {
|
||||
result[name] = cookie;
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
api.set = api;
|
||||
api.get = function (key) {
|
||||
return api.call(api, key);
|
||||
};
|
||||
api.getJSON = function () {
|
||||
return api.apply({
|
||||
json: true
|
||||
}, [].slice.call(arguments));
|
||||
};
|
||||
api.defaults = {};
|
||||
|
||||
api.remove = function (key, attributes) {
|
||||
api(key, '', extend(attributes, {
|
||||
expires: -1
|
||||
}));
|
||||
};
|
||||
|
||||
api.withConverter = init;
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
return init(function () {});
|
||||
}));
|
12
js/script.js
12
js/script.js
|
@ -14,7 +14,8 @@ var thread = '';
|
|||
//var date = new Date(new Date().getTime() + 60 * 1000);
|
||||
var date = new Date;
|
||||
date.setDate(date.getDate() + 7);
|
||||
var echo = document.cookie;
|
||||
var echo = Cookies.get('echo');
|
||||
console.log(echo);
|
||||
|
||||
hash = parseLocationHash();
|
||||
if (hash.matched) {
|
||||
|
@ -70,7 +71,7 @@ $(function() {
|
|||
}
|
||||
}
|
||||
|
||||
$('#echoSelected').html("Выбранные эхи: " + document.cookie);
|
||||
$('#echoSelected').html("Выбранные эхи: " + Cookies.get("echo"));
|
||||
$('#echoSelector').html(options);
|
||||
$('#echoCheckBox').html(checks);
|
||||
// $('#echoSelect').html(select);
|
||||
|
@ -90,7 +91,7 @@ $(function() {
|
|||
echo = '';
|
||||
for (var i=0; i<$("input[type=checkbox]:checked").length; i++) {
|
||||
echo += $("input[type=checkbox]:checked")[i]["defaultValue"] + " ";}
|
||||
document.cookie = echo +"; path=/; expires=" + date.toUTCString();
|
||||
Cookies.set("echo", echo, {expires: 7});
|
||||
$('#echoSelected').html("Выбранные эхи: " + echo);
|
||||
});
|
||||
|
||||
|
@ -102,7 +103,7 @@ $(function() {
|
|||
echo += $(this).val()[i] + " ";
|
||||
console.log($(this).val()[i]);
|
||||
}
|
||||
document.cookie = echo +"; path=/; expires=" + date.toUTCString();
|
||||
Cookies.set("echo", echo, {expires: 7});
|
||||
requestEcho();
|
||||
$('#echoSelected').html("Выбранные эхи: " + echo)
|
||||
|
||||
|
@ -396,7 +397,8 @@ function requestBuildThread(msg, init) {
|
|||
}
|
||||
|
||||
function clearFilter() {
|
||||
document.cookie = "";
|
||||
Cookies.remove('echo');
|
||||
Cookies.remove('threads');
|
||||
}
|
||||
|
||||
function showMenu() {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
var thread_html = "";
|
||||
var top_id = "";
|
||||
var view_mode = false;
|
||||
|
||||
$(function() {
|
||||
var jumpLocation = parseLocation();
|
||||
|
||||
// Cleanup content
|
||||
if (jumpLocation['matched']) {
|
||||
// Cleanup content
|
||||
|
@ -69,14 +71,12 @@ function proccessThreadRequest(data, msgid) {
|
|||
function proccessThread(msgid, callback) {
|
||||
data = '{"sort": [ { "date": { "order": "asc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["repto"], "query" :"' + msgid + '"}}, "size": 100 }';
|
||||
if (callback) {
|
||||
console.log(callback);
|
||||
for (hit in callback["hits"]["hits"]) {
|
||||
msg = callback["hits"]["hits"][hit]["_source"];
|
||||
thread_html += makeMessageHTML(callback["hits"]["hits"][0]["_source"]);
|
||||
proccessThread(msg["msgid"], false);
|
||||
}
|
||||
} else {
|
||||
console.log(data);
|
||||
proccessThreadRequest(data, msgid);
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,35 @@ function parseLocation() {
|
|||
}
|
||||
}
|
||||
|
||||
// Set cookie with v=threads
|
||||
function toggleViewModeOn() {
|
||||
Cookies.set("threads", "on");
|
||||
}
|
||||
|
||||
// Remove cookie with v=threads
|
||||
function toggleViewModeOff() {
|
||||
Cookies.set("threads", "off");
|
||||
}
|
||||
|
||||
function toggleViewMode() {
|
||||
if (checkViewMode()) {
|
||||
toggleViewModeOff();
|
||||
} else {
|
||||
toggleViewModeOn();
|
||||
}
|
||||
}
|
||||
|
||||
// Check view mode
|
||||
function checkViewMode() {
|
||||
if (Cookies.get("threads") && Cookies.get("threads") == "on") {
|
||||
console.log('THREADS ON');
|
||||
return true
|
||||
} else {
|
||||
console.log('NORMAL');
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Make message HTML
|
||||
function makeMessageHTML(msgItem) {
|
||||
var t = new Date(msgItem['date'] * 1000);
|
||||
|
|
Loading…
Reference in New Issue
Block a user