1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-02-18 11:44:12 +01:00

Merge pull request #103 from anonfagola/patch-14

Added id highlighting
This commit is contained in:
Fredrick Brennan 2014-09-27 15:59:36 -04:00
commit b219b20deb
4 changed files with 79 additions and 0 deletions

View File

@ -121,6 +121,7 @@
$config['additional_javascript'][] = 'js/toggle-locked-threads.js';
$config['additional_javascript'][] = 'js/toggle-images.js';
$config['additional_javascript'][] = 'js/mobile-style.js';
$config['additional_javascript'][] = 'js/id_highlighter.js'
$config['font_awesome_css'] = '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css';

34
js/id_colors.js Normal file
View File

@ -0,0 +1,34 @@
$.hash = function(str) {
var i, j, msg = 0;
for (i = 0, j = str.length; i < j; ++i) {
msg = ((msg << 5) - msg) + str.charCodeAt(i);
}
return msg;
};
function stringToRGB(str){
var rgb, hash;
rgb = [];
hash = $.hash(str);
rgb[0] = (hash >> 24) & 0xFF;
rgb[1] = (hash >> 16) & 0xFF;
rgb[2] = (hash >> 8) & 0xFF;
return rgb;
}
$(".poster_id").each(function(){
var rgb = stringToRGB($(this).text());
$(this).css({
"background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")",
"padding": "3px 5px",
"border-radius": "8px",
"color": "white"
});
});

40
js/id_highlighter.js Normal file
View File

@ -0,0 +1,40 @@
Array.prototype.remove = function(v) { this.splice(this.indexOf(v) == -1 ? this.length : this.indexOf(v), 1); }
var idshighlighted = [];
function getPostsById(id){
return $(".poster_id").filter(function(i){
return $(this).text() == id;
});
}
function getMasterPosts(parents){
if(!parents.hasClass("post")) return;
var toRet = [];
$(parents).each(function(){
if($(this).hasClass("post"))
toRet.push($(this));
});
return toRet;
}
$(".poster_id").click(function(){
var id = $(this).text();
if($.inArray(id, idshighlighted) !== -1){
idshighlighted.remove(id);
$(getMasterPosts(getPostsById(id).parents())).each(function(i){
$(this).removeClass("highlighted");
});
}else{
idshighlighted.push(id);
$(getMasterPosts(getPostsById(id).parents())).each(function(i){
$(this).addClass("highlighted");
});
}
});

View File

@ -905,6 +905,10 @@ div.thread:hover {
word-wrap: break-word;
}
.poster_id{
cursor: pointer;
}
code > pre {
/* Better code tags */
background:black;