Gazelle/static/functions/collage.js

133 lines
3.1 KiB
JavaScript
Raw Normal View History

2011-03-28 14:21:28 +00:00
function Add(input) {
2013-05-04 08:00:48 +00:00
if (input.checked == false) {
2011-03-28 14:21:28 +00:00
Cancel();
} else {
2013-05-16 16:15:57 +00:00
if (document.getElementById("choices").raw().value == "") {
2011-03-28 14:21:28 +00:00
document.getElementById("choices").raw().value += input.name;
} else {
document.getElementById("choices").raw().value += "|" + input.name;
}
}
}
function Cancel() {
var e=document.getElementsByTagName("input");
2013-05-04 08:00:48 +00:00
for (i = 0; i < e.length; i++) {
if (e[i].type == "checkbox") {
2011-03-28 14:21:28 +00:00
e[i].checked=false;
}
}
document.getElementById("choices").raw().value = "";
}
function CollageSubscribe(collageid) {
ajax.get("userhistory.php?action=collage_subscribe&collageid=" + collageid + "&auth=" + authkey, function() {
var subscribeLink = $("#subscribelink" + collageid).raw();
2013-05-04 08:00:48 +00:00
if (subscribeLink) {
2013-02-06 08:00:17 +00:00
subscribeLink.firstChild.nodeValue = subscribeLink.firstChild.nodeValue.charAt(0) == 'U'
? "Subscribe"
: "Unsubscribe";
}
});
2011-11-20 08:00:18 +00:00
}
var collageShow = {
pg:0,
pages:false,
wrap:false,
2013-05-04 08:00:48 +00:00
init:function(collagePages) {
2011-11-20 08:00:18 +00:00
this.wrap = document.getElementById('coverart');
this.pages = collagePages;
2013-05-04 08:00:48 +00:00
this.max = this.pages.length - 1;
2011-11-20 08:00:18 +00:00
},
2013-05-04 08:00:48 +00:00
selected:function() {
2011-11-20 08:00:18 +00:00
return $('.linkbox .selected').raw();
},
2013-05-04 08:00:48 +00:00
createUL:function(data) {
2011-11-20 08:00:18 +00:00
var ul = document.createElement('ul');
$(ul).add_class('collage_images');
ul.id = 'collage_page'+this.pg;
$(ul).html(data);
this.wrap.appendChild(ul);
return ul;
},
2013-05-04 08:00:48 +00:00
page:function(num,el) {
2011-11-20 08:00:18 +00:00
var ul = $('#collage_page'+num).raw(), s = this.selected(), covers, lists, i;
this.pg = num;
2013-02-22 08:00:24 +00:00
2013-05-04 08:00:48 +00:00
if (!ul) {
2011-11-20 08:00:18 +00:00
covers = this.pages[num];
2013-05-04 08:00:48 +00:00
if (covers) {
2011-11-20 08:00:18 +00:00
ul = this.createUL(covers);
}
}
2013-02-22 08:00:24 +00:00
2013-06-27 08:01:06 +00:00
$('.collage_images').ghide();
2013-02-22 08:00:24 +00:00
2013-06-17 08:01:02 +00:00
$(ul).gshow();
2013-05-04 08:00:48 +00:00
if (s) {
$(s).remove_class('selected');
}
if (el) {
$(el.parentNode).add_class('selected');
}
2013-02-22 08:00:24 +00:00
2011-11-20 08:00:18 +00:00
// Toggle the page number links
first = Math.max(0, this.pg - 2);
if (this.max - this.pg < 2) {
first = Math.max(this.max - 4, 0);
}
last = Math.min(first + 4, this.max);
for (i = 0; i < first; i++) {
2013-06-17 08:01:02 +00:00
$('#pagelink' + i).ghide();
2011-11-20 08:00:18 +00:00
}
for (i = first; i <= last; i++) {
2013-06-17 08:01:02 +00:00
$('#pagelink' + i).gshow();
2011-11-20 08:00:18 +00:00
}
for (i = last + 1; i <= this.max; i++) {
2013-06-17 08:01:02 +00:00
$('#pagelink' + i).ghide();
2011-11-20 08:00:18 +00:00
}
2013-02-22 08:00:24 +00:00
2011-11-20 08:00:18 +00:00
// Toggle the first, prev, next, and last links
if (this.pg > 0) {
$('#prevpage').remove_class('invisible');
} else {
$('#prevpage').add_class('invisible');
}
if (this.pg > 1) {
$('#firstpage').remove_class('invisible');
} else {
$('#firstpage').add_class('invisible');
}
if (this.pg < this.max) {
$('#nextpage').remove_class('invisible');
} else {
$('#nextpage').add_class('invisible');
}
if (this.pg < this.max - 1) {
$('#lastpage').remove_class('invisible');
} else {
$('#lastpage').add_class('invisible');
}
2013-02-22 08:00:24 +00:00
2011-11-20 08:00:18 +00:00
// Toggle the bar
if ((last == this.max) && (this.pg != this.max)) {
2013-06-17 08:01:02 +00:00
$('#nextbar').gshow();
2011-11-20 08:00:18 +00:00
} else {
2013-06-17 08:01:02 +00:00
$('#nextbar').ghide();
2011-11-20 08:00:18 +00:00
}
},
2013-05-04 08:00:48 +00:00
nextPage:function() {
this.pg = this.pg < this.max ? this.pg + 1 : this.pg;
2011-11-20 08:00:18 +00:00
this.pager();
},
2013-05-04 08:00:48 +00:00
prevPage:function() {
this.pg = this.pg > 0 ? this.pg - 1 : this.pg;
2011-11-20 08:00:18 +00:00
this.pager();
},
2013-05-04 08:00:48 +00:00
pager:function() {
2011-11-20 08:00:18 +00:00
this.page(this.pg,$('#pagelink'+this.pg).raw().firstChild);
}
2013-05-04 08:00:48 +00:00
};