replace lots of javascript with a little jquery

This commit is contained in:
Shish 2012-03-02 23:57:27 +00:00
parent 74f0d38c04
commit 15fdd2e0b7
12 changed files with 42 additions and 445 deletions

View file

@ -41,17 +41,6 @@ $(document).ready(function() {
$("TABLE.sortable").tablesorter();
var sections=get_sections();
for(var i=0;i<sections.length;i++) toggle(sections[i]);
if(document.location.hash.length > 3) {
query = document.location.hash.substring(1);
a = document.getElementById("prevlink");
a.href = a.href + '?' + query;
a = document.getElementById("nextlink");
a.href = a.href + '?' + query;
}
$(".comment_link").each(function(idx, elm) {
var target_id = $(elm).text().match(/#c?(\d+)/);
if(target_id && $("#c"+target_id[1])) {
@ -62,6 +51,38 @@ $(document).ready(function() {
}
}
});
var sidebar_hidden = ($.cookie("sidebar-hidden") || "").split("|");
for(var i in sidebar_hidden) {
$("#"+sidebar_hidden[i]).hide();
};
$(".shm-toggler").each(function(idx, elm) {
var tid = $(elm).data("toggle-id");
var tob = $("#"+tid);
$(elm).click(function(e) {
tob.slideToggle("slow");
if(sidebar_hidden.indexOf(tid) == -1) {
sidebar_hidden.push(tid);
}
else {
console.log("unhiding", tid);
for (var i in sidebar_hidden) {
if (sidebar_hidden[i] === tid) {
sidebar_hidden.splice(i, 1);
}
}
}
$.cookie("sidebar-hidden", sidebar_hidden.join("|"), {path: '/'});
})
});
if(document.location.hash.length > 3) {
query = document.location.hash.substring(1);
a = document.getElementById("prevlink");
a.href = a.href + '?' + query;
a = document.getElementById("nextlink");
a.href = a.href + '?' + query;
}
});

View file

@ -13,7 +13,7 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Danbooru Theme - Notes (Bzchan)
Files: default.php, sidebar.js, style.css
Files: default.php, style.css
How to use a theme
- Copy the danbooru folder with all its contained files into the "themes"
@ -197,7 +197,6 @@ class Layout {
<head>
<title>{$page->title}</title>
$header_html
<script src='$data_href/themes/$theme_name/sidebar.js' type='text/javascript'></script>
<script src='$data_href/themes/$theme_name/script.js' type='text/javascript'></script>
</head>
@ -241,13 +240,13 @@ EOD;
$html = "";
if($hidable) {
$i = str_replace(' ', '_', $h.$s);
if(!is_null($h)) $html .= "\n<h3 id='$i-toggle' onclick=\"toggle('$i')\">$h</h3>\n";
if(!is_null($h)) $html .= "\n<h3 class='shm-toggler' data-toggle-id='$i'>$h</h3>\n";
if(!is_null($b)) $html .= "<div id='$i'>$b</div>\n";
}
else {
$i = str_replace(' ', '_', $h.$s);
if(!is_null($h)) $html .= "\n<h3>$h</h3>\n";
if(!is_null($b)) $html .= "<div id='$i'>$b</div>\n";
if(!is_null($b)) $html .= "<div>$b</div>\n";
}
return $html;
}

View file

@ -1,83 +0,0 @@
/*
* This script shamelessly stolen from wakachan.org d(^_^)b
*/
var cookie_name="shimmie_sidebar";
var default_sections=[];
function toggle(id)
{
var e=document.getElementById(id);
if(!e) return;
if(e.style.display)
{
remove_section(id);
e.style.display="";
var e2 = document.getElementById(id+"-toggle");
if(e2) {
e2.style.color = "#000";
}
}
else
{
add_section(id);
e.style.display="none";
var e2 = document.getElementById(id+"-toggle");
if(e2) {
e2.style.color = "#AAA";
}
}
}
function add_section(id)
{
var sections=get_sections();
for(var i=0;i<sections.length;i++) if(sections[i]==id) return;
sections.push(id);
set_sections(sections);
}
function remove_section(id)
{
var sections=get_sections();
var new_sections=new Array();
for(var i=0;i<sections.length;i++) if(sections[i]!=id) new_sections.push(sections[i]);
set_sections(new_sections);
}
function get_sections()
{
var cookie=get_cookie(cookie_name);
if(cookie) return cookie.split(/,/);
else return default_sections;
}
function set_sections(sections) { set_cookie(cookie_name,sections.join(","),365); }
function get_cookie(name)
{
with(document.cookie)
{
var index=indexOf(name+"=");
if(index==-1) return '';
index=indexOf("=",index)+1;
var endstr=indexOf(";",index);
if(endstr==-1) endstr=length;
return unescape(substring(index,endstr));
}
};
function set_cookie(name,value,days)
{
if(days)
{
var date=new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires="; expires="+date.toGMTString();
}
else expires="";
document.cookie=name+"="+value+expires+"; path=/";
}

View file

@ -54,7 +54,6 @@ class Layout {
<html>
<head>
<title>{$page->title}</title>
<script src='$data_href/themes/$theme_name/sidebar.js' type='text/javascript'></script>
$header_html
</head>
@ -89,27 +88,8 @@ EOD;
$b = $block->body;
$html = "";
$i = str_replace(' ', '_', $h) . $salt;
if($hidable) $html .= "
<script type='text/javascript'><!--
$(document).ready(function() {
$(\"#$i-toggle\").click(function() {
$(\"#$i\").slideToggle(\"slow\", function() {
if($(\"#$i\").is(\":hidden\")) {
$.cookie(\"$i-hidden\", 'true', {path: '/'});
}
else {
$.cookie(\"$i-hidden\", 'false', {path: '/'});
}
});
});
if($.cookie(\"$i-hidden\") == 'true') {
$(\"#$i\").hide();
}
});
//--></script>
";
if(!is_null($h)) $html .= "
<h3 id='$i-toggle' class='hrr'>$h</h3>
<h3 data-toggle-id='$i' class='hrr shm-toggler'>$h</h3>
";
if(!is_null($b)) {
if(strpos($b, "<!-- cancel border -->") === FALSE) {

View file

@ -1,83 +0,0 @@
/*
* This script shamelessly stolen from wakachan.org d(^_^)b
*/
var cookie_name="shimmie_sidebar";
var default_sections=["upload", "edit_tags"];
function toggle(id)
{
var e=document.getElementById(id);
if(!e) return;
if(e.style.display)
{
remove_section(id);
e.style.display="";
var e2 = document.getElementById(id+"-toggle");
if(e2) {
e2.style.color = "#000";
}
}
else
{
add_section(id);
e.style.display="none";
var e2 = document.getElementById(id+"-toggle");
if(e2) {
e2.style.color = "#AAA";
}
}
}
function add_section(id)
{
var sections=get_sections();
for(var i=0;i<sections.length;i++) if(sections[i]==id) return;
sections.push(id);
set_sections(sections);
}
function remove_section(id)
{
var sections=get_sections();
var new_sections=new Array();
for(var i=0;i<sections.length;i++) if(sections[i]!=id) new_sections.push(sections[i]);
set_sections(new_sections);
}
function get_sections()
{
var cookie=get_cookie(cookie_name);
if(cookie) return cookie.split(/,/);
else return default_sections;
}
function set_sections(sections) { set_cookie(cookie_name,sections.join(","),365); }
function get_cookie(name)
{
with(document.cookie)
{
var index=indexOf(name+"=");
if(index==-1) return '';
index=indexOf("=",index)+1;
var endstr=indexOf(";",index);
if(endstr==-1) endstr=length;
return unescape(substring(index,endstr));
}
};
function set_cookie(name,value,days)
{
if(days)
{
var date=new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires="; expires="+date.toGMTString();
}
else expires="";
document.cookie=name+"="+value+expires+"; path=/";
}

View file

@ -89,27 +89,8 @@ EOD;
$b = $block->body;
$html = "";
$i = str_replace(' ', '_', $h) . $salt;
if($hidable) $html .= "
<script type='text/javascript'><!--
$(document).ready(function() {
$(\"#$i-toggle\").click(function() {
$(\"#$i\").slideToggle(\"slow\", function() {
if($(\"#$i\").is(\":hidden\")) {
$.cookie(\"$i-hidden\", 'true', {path: '/'});
}
else {
$.cookie(\"$i-hidden\", 'false', {path: '/'});
}
});
});
if($.cookie(\"$i-hidden\") == 'true') {
$(\"#$i\").hide();
}
});
//--></script>
";
if(!is_null($h)) $html .= "
<div class='hrr' id='$i-toggle'>
<div class='hrr shm-toggler' data-toggle-id='$i'>
<div class='hrrtop'><div></div></div>
<div class='hrrcontent'><h3>$h</h3></div>
<div class='hrrbot'><div></div></div>

View file

@ -61,7 +61,6 @@ class Layout {
<head>
<title>{$page->title}</title>
$header_html
<script src='$data_href/themes/$theme_name/sidebar.js' type='text/javascript'></script>
<script src='$data_href/themes/$theme_name/script.js' type='text/javascript'></script>
</head>
@ -95,13 +94,7 @@ EOD;
$b = $block->body;
$html = "";
$i = str_replace(' ', '_', $h) . $salt;
if($hidable) {
$toggle = " onclick=\"toggle('$i')\"";
}
else {
$toggle = "";
}
if(!is_null($h)) $html .= "\n<h3 id='$i-toggle'$toggle>$h</h3>\n";
if(!is_null($h)) $html .= "\n<h3 data-toggle-id='$i' class='shm-toggler'>$h</h3>\n";
if(!is_null($b)) $html .= "<div id='$i'>$b</div>\n";
return $html;
}

View file

@ -1,83 +0,0 @@
/*
* This script shamelessly stolen from wakachan.org d(^_^)b
*/
var cookie_name="shimmie_sidebar";
var default_sections=["upload", "edit_tags"];
function toggle(id)
{
var e=document.getElementById(id);
if(!e) return;
if(e.style.display)
{
remove_section(id);
e.style.display="";
var e2 = document.getElementById(id+"-toggle");
if(e2) {
e2.style.color = "#000";
}
}
else
{
add_section(id);
e.style.display="none";
var e2 = document.getElementById(id+"-toggle");
if(e2) {
e2.style.color = "#AAA";
}
}
}
function add_section(id)
{
var sections=get_sections();
for(var i=0;i<sections.length;i++) if(sections[i]==id) return;
sections.push(id);
set_sections(sections);
}
function remove_section(id)
{
var sections=get_sections();
var new_sections=new Array();
for(var i=0;i<sections.length;i++) if(sections[i]!=id) new_sections.push(sections[i]);
set_sections(new_sections);
}
function get_sections()
{
var cookie=get_cookie(cookie_name);
if(cookie) return cookie.split(/,/);
else return default_sections;
}
function set_sections(sections) { set_cookie(cookie_name,sections.join(","),365); }
function get_cookie(name)
{
with(document.cookie)
{
var index=indexOf(name+"=");
if(index==-1) return '';
index=indexOf("=",index)+1;
var endstr=indexOf(";",index);
if(endstr==-1) endstr=length;
return unescape(substring(index,endstr));
}
};
function set_cookie(name,value,days)
{
if(days)
{
var date=new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires="; expires="+date.toGMTString();
}
else expires="";
document.cookie=name+"="+value+expires+"; path=/";
}

View file

@ -202,30 +202,11 @@ EOD;
$b = $block->body;
$html = "";
$i = str_replace(' ', '_', $h) . $salt;
if($hidable) $html .= "
<script type='text/javascript'><!--
$(document).ready(function() {
$(\"#$i-toggle\").click(function() {
$(\"#$i\").slideToggle(\"slow\", function() {
if($(\"#$i\").is(\":hidden\")) {
$.cookie(\"$i-hidden\", 'true', {path: '/'});
}
else {
$.cookie(\"$i-hidden\", 'false', {path: '/'});
}
});
});
if($.cookie(\"$i-hidden\") == 'true') {
$(\"#$i\").hide();
}
});
//--></script>
";
if(!is_null($h)) {
if($salt == "main") {
$html .= "<div class='maintop navside tab' id='$i-toggle'>$h</div>";
$html .= "<div class='maintop navside tab shm-toggler' data-toggle-id='$i'>$h</div>";
} else {
$html .= "<div class='navtop navside tab' id='$i-toggle'>$h</div>";
$html .= "<div class='navtop navside tab shm-toggler' data-toggle-id='$i'>$h</div>";
}
}
if(!is_null($b)) {

View file

@ -51,7 +51,6 @@ class Layout {
<head>
<title>{$page->title}</title>
$header_html
<script src='$data_href/themes/$theme_name/sidebar.js' type='text/javascript'></script>
<script src='$data_href/themes/$theme_name/script.js' type='text/javascript'></script>
</head>
@ -84,13 +83,7 @@ EOD;
$b = $block->body;
$html = "";
$i = str_replace(' ', '_', $h) . $salt;
if($hidable) {
$toggle = " onclick=\"toggle('$i')\"";
}
else {
$toggle = "";
}
if(!is_null($h)) $html .= "\n<h3 id='$i-toggle'$toggle>$h</h3>\n";
if(!is_null($h)) $html .= "\n<h3 data-toggle-id='$i' class='shm-toggler'>$h</h3>\n";
if(!is_null($b)) $html .= "<div id='$i'>$b</div>\n";
return $html;
}

View file

@ -1,83 +0,0 @@
/*
* This script shamelessly stolen from wakachan.org d(^_^)b
*/
var cookie_name="shimmie_sidebar";
var default_sections=["upload", "edit_tags"];
function toggle(id)
{
var e=document.getElementById(id);
if(!e) return;
if(e.style.display)
{
remove_section(id);
e.style.display="";
var e2 = document.getElementById(id+"-toggle");
if(e2) {
e2.style.color = "#000";
}
}
else
{
add_section(id);
e.style.display="none";
var e2 = document.getElementById(id+"-toggle");
if(e2) {
e2.style.color = "#AAA";
}
}
}
function add_section(id)
{
var sections=get_sections();
for(var i=0;i<sections.length;i++) if(sections[i]==id) return;
sections.push(id);
set_sections(sections);
}
function remove_section(id)
{
var sections=get_sections();
var new_sections=new Array();
for(var i=0;i<sections.length;i++) if(sections[i]!=id) new_sections.push(sections[i]);
set_sections(new_sections);
}
function get_sections()
{
var cookie=get_cookie(cookie_name);
if(cookie) return cookie.split(/,/);
else return default_sections;
}
function set_sections(sections) { set_cookie(cookie_name,sections.join(","),365); }
function get_cookie(name)
{
with(document.cookie)
{
var index=indexOf(name+"=");
if(index==-1) return '';
index=indexOf("=",index)+1;
var endstr=indexOf(";",index);
if(endstr==-1) endstr=length;
return unescape(substring(index,endstr));
}
};
function set_cookie(name,value,days)
{
if(days)
{
var date=new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires="; expires="+date.toGMTString();
}
else expires="";
document.cookie=name+"="+value+expires+"; path=/";
}

View file

@ -103,27 +103,8 @@ EOD;
$b = $block->body;
$html = "";
$i = str_replace(' ', '_', $h) . $salt;
if($hidable) $html .= "
<script type='text/javascript'><!--
$(document).ready(function() {
$(\"#$i-toggle\").click(function() {
$(\"#$i\").slideToggle(\"slow\", function() {
if($(\"#$i\").is(\":hidden\")) {
$.cookie(\"$i-hidden\", 'true', {path: '/'});
}
else {
$.cookie(\"$i-hidden\", 'false', {path: '/'});
}
});
});
if($.cookie(\"$i-hidden\") == 'true') {
$(\"#$i\").hide();
}
});
//--></script>
";
if(!is_null($h)) $html .= "
<div class='hrr' id='$i-toggle'>
<div class='hrr' data-toggle-id='$i' class='shm-toggler'>
<div class='hrrtop'><div></div></div>
<div class='hrrcontent'><h3>$h</h3></div>
<div class='hrrbot'><div></div></div>