[SPIP] +2.1.12
[velocampus/web/www.git] / www / prive / javascript / articles_tous_edite.js
1 function deplie_arbre(){
2 tree = jQuery('#articles_tous');
3 jQuery('ul:hidden',tree).siblings('img.expandImage').each(function(){jQuery(this).bascule()});
4 }
5 function plie_arbre(){
6 tree = jQuery('#articles_tous');
7 jQuery('#articles_tous ul').hide();
8 jQuery('img.expandImage', tree).attr('src',img_deplierhaut);
9 }
10 function annuler_deplacement(){
11 liste = jQuery("#deplacements").text();
12 tableau = liste.split("\n");
13 if (tableau.length>0){
14 action = tableau[tableau.length-1];
15 tab = action.split(":");
16 jQuery("#"+tab[2]).insertion(tab[0],jQuery("#"+tab[0]).parent().attr('id'));
17 tableau.pop();
18 jQuery("#deplacements").html(tableau.join("\n"));
19 if (tableau.length==0) jQuery("#cancel").hide();
20 if (tableau.length==0) jQuery("#apply").hide();
21 }
22 }
23
24 jQuery.fn.set_expandImage = function(){
25 jQuery('ul:hidden',jQuery(this)).parent().prepend('<img src="'+img_deplierhaut+'" class="expandImage" />');
26 jQuery('ul:visible',jQuery(this)).parent().prepend('<img src="'+img_deplierbas+'" class="expandImage" />');
27 jQuery('img.expandImage', jQuery(this)).click(function (){jQuery(this).bascule();});
28 return jQuery(this);
29 }
30
31 var recall;
32 jQuery.fn.deplie = function(){
33 jQuery(this).show();
34 jQuery(this).siblings('img.expandImage').eq(0).attr('src',img_deplierbas);
35 jQuery(this).children('li').children('a.ajax').each(function(){
36 jQuery(this).before("<div>"+ajax_image_searching+"</div>");
37 var id = jQuery(this).parent().parent().attr('id');
38 jQuery(this).parent().parent().load(jQuery(this).attr('href'),function(){jQuery("#"+id).set_expandImage().set_droppables();jQuery.recallDroppables();});
39 });
40 recall = true;
41 jQuery.recallDroppables();
42 return jQuery(this);
43 }
44
45 jQuery.fn.bascule = function() {
46 subbranch = jQuery(this).siblings('ul').eq(0);
47 if (subbranch.is(':hidden')) {
48 subbranch.show();
49 jQuery(this).attr('src',img_deplierbas);
50 subbranch.children('li').children('a.ajax').each(function(){
51 jQuery(this).before("<div>"+ajax_image_searching+"</div>");
52 var id = jQuery(this).parent().parent().attr('id');
53 jQuery(this).parent().parent().load(jQuery(this).attr('href'),function(){jQuery("#"+id).set_expandImage().set_droppables();});
54 });
55 } else {
56 subbranch.hide();
57 jQuery(this).attr('src',img_deplierhaut);
58 }
59 return jQuery(this);
60 }
61 jQuery.fn.insertion = function(dragged,oldParent){
62 subbranch = jQuery(this).children('ul').eq(0);
63 if (subbranch.size() == 0) {
64 jQuery(this).prepend('<img src="'+img_deplierbas+'" width="16" height="16" class="expandImage" />');
65 id = jQuery(this).attr('id');
66 id = id.split("-"); id=id[1]
67 jQuery(this).append("<ul id='ul"+id+"' ></ul>");
68 jQuery(this).children('img.expandImage').click(function (){jQuery(this).bascule();});
69 subbranch = jQuery(this).children('ul').eq(0);
70 }
71 if((dragged.is('li.art')) && (subbranch.children('li.rub').length>0)){
72 subbranch.end().children('li.rub').eq(0).before(dragged);
73 }
74 else
75 subbranch.end().append(dragged);
76
77 if (subbranch.is(':hidden')){
78 subbranch.deplie();
79 }
80
81 oldBranches = jQuery('li', oldParent);
82 if (oldBranches.size() == 0) {
83 oldParent.siblings('img.expandImage').remove();
84 oldParent.end().remove();
85 }
86 dragged.draggable( 'destroy' );
87 jQuery(this).set_droppables();
88 }
89
90 jQuery.fn.set_droppables = function(){
91 jQuery('span.holder',jQuery(this)).droppable(
92 {
93 accept : '.treeItem',
94 hoverClass : 'none',
95 activeClass : 'fakeClass',
96 tolerance : 'pointer',
97 over : function(event,ui)
98 {
99 jQuery(this).parent().addClass('selected');
100 if (!this.expanded) {
101 subbranch = jQuery(this).siblings('ul').eq(0);
102 if (subbranch.is(':hidden')){
103 subbranch.pause(1000).deplie();
104 this.expanded = true;
105 }
106 }
107 },
108 out : function(event,ui)
109 {
110 jQuery(this).parent().removeClass('selected');
111 if (this.expanded){
112 subbranch = jQuery(this).siblings('ul').eq(0);
113 subbranch.unpause();
114 if (recall){
115 recall=false;
116 }
117 }
118 this.expanded = false;
119 },
120 drop : function(event,ui)
121 {
122 jQuery(this).parent().removeClass('selected');
123 subbranch = jQuery(this).siblings('ul').eq(0);
124 if (this.expanded)
125 subbranch.unpause();
126 var target=jQuery(this).parent().attr('id');
127 var quoi=jQuery(ui.draggable).attr('id');
128 var source=jQuery(ui.draggable).parent().parent().attr('id'); // il faut stocker l'id du li car le ul peut avoir disparu au moment du cancel
129 action=quoi+":"+target+":"+source;
130 var dep = jQuery("#deplacements");
131 dep.html(dep.text()+"\n"+action);
132 jQuery("#apply").show();
133 jQuery("#cancel").show();
134 jQuery(this).parent().insertion(jQuery(ui.draggable),jQuery(ui.draggable).parent());
135 }
136 }
137 );
138 jQuery('li.treeItem',jQuery(this)).draggable(
139 {
140 revert : true/*,
141 ghosting : true,
142 autoSize : true*/
143 }
144 );
145 }
146
147 jQuery(
148 function()
149 {
150 jQuery('#articles_tous').set_expandImage();
151 jQuery('#articles_tous').set_droppables();
152 }
153 );