/* ChainHandler, py Peter van der Beken
-------------------------------------------------------- */
function chainHandler(obj, handlerName, handler) {
obj[handlerName] = (function(existingFunction) {
return function() {
handler.apply(this, arguments);
if (existingFunction)
existingFunction.apply(this, arguments);
};
})(handlerName in obj ? obj[handlerName] : null);
};
/* jQuery extensions
-------------------------------------------------------- */
jQuery.fn.check = function() {
return this.each(function() {
if (this.checked != undefined) { this.checked = true; }
});
};
jQuery.fn.unCheck = function() {
return this.each(function() {
if (this.checked != undefined) { this.checked = false; }
});
};
jQuery.fn.setChecked = function(status) {
return this.each(function() {
if (this.checked != undefined) { this.checked = status; }
});
};
jQuery.fn.toggleCheck = function() {
return this.each(function() {
if (this.checked != undefined) { this.checked = !this.checked; }
});
};
jQuery.fn.enableShiftClick = function() {
this.click(
function (event) {
if (event.shiftKey) {
if (dotclear.lastclicked != '') {
var range;
var trparent = $(this).parents('tr');
if (trparent.nextAll('#'+dotclear.lastclicked).length != 0)
range = trparent.nextUntil('#'+dotclear.lastclicked);
else
range = trparent.prevUntil('#'+dotclear.lastclicked);
range.find('input[type=checkbox]').setChecked(dotclear.lastclickedstatus);
this.checked = dotclear.lastclickedstatus;
}
} else {
dotclear.lastclicked = $(this).parents('tr')[0].id;
dotclear.lastclickedstatus = this.checked;
}
return true;
});
}
jQuery.fn.toggleWithLegend = function(target,s) {
var defaults = {
img_on_src: dotclear.img_plus_src,
img_on_alt: dotclear.img_plus_alt,
img_off_src: dotclear.img_minus_src,
img_off_alt: dotclear.img_minus_alt,
hide: true,
speed: 0,
legend_click: false,
fn: false, // A function called on first display,
cookie: false,
reverse_cookie: false // Reverse cookie behavior
};
var p = jQuery.extend(defaults,s);
if (!target) { return this; }
var set_cookie = p.hide ^ p.reverse_cookie;
if (p.cookie && jQuery.cookie(p.cookie)) {
p.hide = p.reverse_cookie;
}
var toggle = function(i,speed) {
speed = speed || 0;
if (p.hide) {
$(i).get(0).src = p.img_on_src;
$(i).get(0).alt = p.img_on_alt;
target.hide(speed);
} else {
$(i).get(0).src = p.img_off_src;
$(i).get(0).alt = p.img_off_alt;
target.show(speed);
if (p.fn) {
p.fn.apply(target);
p.fn = false;
}
}
if (p.cookie && set_cookie) {
if (p.hide ^ p.reverse_cookie) {
jQuery.cookie(p.cookie,'',{expires: -1});
} else {
jQuery.cookie(p.cookie,1,{expires: 30});
}
}
p.hide = !p.hide;
};
return this.each(function() {
var i = document.createElement('img');
i.src = p.img_off_src;
i.alt = p.img_off_alt;
var a = document.createElement('a');
a.href= '#';
$(a).append(i);
$(a).css({
border: 'none',
outline: 'none'
});
var ctarget = p.legend_click ? this : a;
$(ctarget).css('cursor','pointer');
if (p.legend_click) {
$(ctarget).find('label').css('cursor','pointer');
}
$(ctarget).click(function() {
toggle(i,p.speed);
return false;
});
toggle($(i).get(0));
$(this).prepend(' ').prepend(a);
});
};
jQuery.fn.helpViewer = function() {
if (this.length < 1) {
return this;
}
var p = {
img_on_src: dotclear.img_plus_src,
img_on_alt: dotclear.img_plus_alt,
img_off_src: dotclear.img_minus_src,
img_off_alt: dotclear.img_minus_alt
};
var This = this;
var toggle = function() {
$('#content').toggleClass('with-help');
if (document.all) {
if ($('#content').hasClass('with-help')) {
select = $('#content select:visible').hide();
} else {
select.show();
}
}
$('p#help-button span').text($('#content').hasClass('with-help') ? dotclear.msg.help_hide : dotclear.msg.help);
sizeBox();
return false;
};
var sizeBox = function() {
This.css('height','auto');
if ($('#main').height() > This.height()) {
This.css('height',$('#main').height() + 'px');
}
};
var textToggler = function(o) {
var i = $('');
o.css('cursor','pointer');
var hide = true;
o.prepend(' ').prepend(i);
o.click(function() {
$(this).nextAll().each(function() {
if ($(this).is('h3')) {
return false;
}
$(this).toggle();
sizeBox();
return true;
});
hide = !hide;
var img = $(this).find('img');
if (!hide) {
img.attr('src',p.img_off_src);
} else {
img.attr('src',p.img_on_src);
}
});
};
this.addClass('help-box');
this.find('>hr').remove();
this.find('h3').each(function() { textToggler($(this)); });
this.find('h3:first').nextAll('*:not(h3)').hide();
sizeBox();
var img = $('