Accueil/js/jquery.links.js

80 lines
2.9 KiB
JavaScript

$(document).ready(function(){
// Réglage des options
$('body').append('<img src="images/interface/link_edit.png" id="links-menu" />');
$('body').append('<img src="images/interface/link_add.png" id="links-add-menu" />');
$('#menu-bar').prepend($('#links-menu'));
$('#menu-bar').prepend($('#links-add-menu'));
$('#links-add-fancy').append('<form action="addLink.php" enctype="multipart/form-data" method="POST"><label for="urlField">URL : </label><input type="text" name="urlField" id="urlField"/><br/><label for="popupField">popup ? </label><input type="checkbox" name="popupField" id="popupField" checked="checked" value="1" /><br/><label for="imgField">Icône : </label><input type="file" name="imgField" id="imgField"/><br/><label for="titreField">Titre : </label><input type="text" name="titreField" id="titreField"/><br/><input type="submit" class="green-button" id="links-add-submit" value="Envoyer"/></form>');
// Apparition du menu d'ajout de lien
$('#links-add-menu').live('click', function(){
$.fancybox(
$('#links-add-fancy').html()
);
});
// Apparition de la reserve de liens
$('#links-menu').live('click', function(){
$.get('ajax/loadReserve.php', function(html){
$.fancybox(
html,
{
'autoDimensions' : false,
'width' : 400,
'height' : 'auto',
'showNavArrows' : false,
'transitionIn' : 'elastic'
}
);
});
});
// Passage Reserve => Liste
$('#reserveiconlist .iconitem').live('click', function(e){
e.preventDefault();
$.post("ajax/reserveToList.php", {reserve: $(this).attr('id')});
$('.iconlist').last().append('<li class="iconitem" id="'+$(this).attr('id')+'">'+$(this).html()+'</li>');
$.fancybox.close();
});
//Passage Liste => Reserve
$('.iconitem').mouseover(function(){
$(this).children('.deleteLink').show();
});
$('.iconitem').mouseout(function(){
$(this).children('.deleteLink').hide();
});
$('.deleteLink').click(function(){
$.post("ajax/listToReserve.php", {reserve: $(this).parent().attr('id')});
$(this).parent().fadeOut();
});
// Mouvement des liens avec enregistrement
$(".iconlist").sortable(
{
connectWith: '.iconlist',
update: function(event,ui){
var linkOrder = $(this).sortable('toArray').toString();
var label = $(ui.item).parent()[0].id;
var itemMoved = $(ui.item)[0].id;
$.post("ajax/update-links-order.php", {order: linkOrder, label : label, itemMoved: itemMoved});
},
start: function(e) {
// have to remvoe click handler off item so drop doesn't click
$("a.popup").unbind("click");
}
}
).disableSelection().mouseout(function(){
// reattach the item click handler
$('a.popup').unbind("click").bind("click", function(e){
e.preventDefault();
var url = $(this).attr('href');
spawnURL(url);
});
});
});