source: trunk/spip/2.1/extensions/magusine-portage2.1/javascript/manip_menu.js @ 756

Last change on this file since 756 was 756, checked in by guillermoacedo@…, 14 years ago

se agrego la correccion de magusine para 2.1 basica

  • Property svn:executable set to *
File size: 4.7 KB
Line 
1$(document).ready(function(){
2
3  $('.ajouter').each(function(){
4    $(this).click(function(){
5      titre = $(this).siblings("span").text();
6      regex = /(id_rubrique|id_article|id_groupe|id_mot)=([0-9]+)/;
7      matches = regex.exec(this.getAttribute('href'));
8      if (matches.length > 2) {
9        if (matches[1] == "id_rubrique" && !isNaN(matches[2] && !$('#r'+matches[2]).length)) {
10          $("#selection").append('<li id="r'+matches[2]+'" class="sortable">'+titre+" <span class='url_petit'>("+traductions['rubrique']+")</span> <a href=\"javascript:supprimer('#r"+matches[2]+"')\">x</a></li>");
11        } else if (matches[1] == "id_article" && !isNaN(matches[2]) && !$('#a'+matches[2]).length) {
12          $("#selection").append('<li id="a'+matches[2]+'" class="sortable">'+titre+" <span class='url_petit'>("+traductions['article']+")</span> <a href=\"javascript:supprimer('#a"+matches[2]+"')\">x</a></li>");
13        } else if (matches[1] == "id_groupe" && !isNaN(matches[2]) && !$('#g'+matches[2]).length) {
14          $("#selection").append('<li id="g'+matches[2]+'" class="sortable">'+titre+" <span class='url_petit'>("+traductions['groupe']+")</span> <a href=\"javascript:supprimer('#g"+matches[2]+"')\">x</a></li>");
15        } else if (matches[1] == "id_mot" && !isNaN(matches[2]) && !$('#m'+matches[2]).length) {
16          $("#selection").append('<li id="m'+matches[2]+'" class="sortable">'+titre+" <span class='url_petit'>("+traductions['mot']+")</span> <a href=\"javascript:supprimer('#m"+matches[2]+"')\">x</a></li>");
17        }
18      }
19     
20      $('#bloc_sauver').css({background: "red"});
21     
22      makesortable();
23      return false;
24    });
25  });
26});
27
28function makesortable() {
29  if (type_sortable == "flat") {
30
31  $('#selection').Sortable(
32  {
33        accept: 'sortable',
34        helperclass: 'sortHelper',
35        activeclass :   'sortableactive',
36        hoverclass :    'sortablehover',
37        //handle: 'div.itemHeader',
38        tolerance: 'pointer',
39        opacity: 0.5,
40        onChange : function(ser)
41        {
42        },
43        onStart : function()
44        {
45                $.iAutoscroller.start(this, document.getElementsByTagName('body'));
46        },
47        onStop : function()
48        {
49                $.iAutoscroller.stop();
50      $('#bloc_sauver').css({background: "red"});
51
52    }
53  }
54  );
55 
56  } else if (type_sortable = "nested") {
57
58  $('#selection').NestedSortable(
59  {
60        accept: 'sortable',
61        helperclass: 'sortHelper',
62        activeclass :   'sortableactive',
63        hoverclass :    'sortablehover',
64        //handle: 'div.itemHeader',
65        tolerance: 'pointer',
66        opacity: 0.5,
67        onChange : function(ser)
68        {
69        },
70        onStart : function()
71        {
72                $.iAutoscroller.start(this, document.getElementsByTagName('body'));
73        },
74        onStop : function()
75        {
76                $.iAutoscroller.stop();
77      $('#bloc_sauver').css({background: "red"});
78
79    }
80  }
81  ); 
82 
83  }
84}
85
86function ajouter_lien() {
87  nom = $('#nom_lien').attr('value');
88  lurl = $('#url_lien').attr('value');
89  if(!nom || !lurl) { return; }
90 
91  afficheurl = lurl;
92  affichenom = nom;
93  nom = nom.replace(/\|/g, "");
94  lurl = lurl.replace(/\|/g, "");
95 
96  // correctif pour le sortable.hash qui merde
97  id = htmlentities('|' + nom+'|'+ lurl);
98 
99  // trouver un id factice superieur à 90000
100  base=90000;
101  unique=0;
102 
103  while(unique==0){
104        if ($("#selection li[@id^=l"+ base+"]").length > 0){
105        base++;
106        } else {
107                unique=1;
108        }
109  }
110 
111  id="l" + base + id;
112    $("#selection").append('<li id="'+id+'" class="sortable">'+affichenom+" <span class='url_petit'>("+ afficheurl+")</span> <a href='javascript:supprimer_lien(\""+id+"\")'>x</a></li>");
113  $('#bloc_sauver').css({background: "red"});
114  makesortable();
115}
116
117function sauver(langue){
118                $('#search').css({visibility: 'visible'});
119
120  if (type_sortable == "nested") {
121    serial = $.iNestedSortable.serialize('selection');
122  } else {
123    serial = $.SortSerialize();
124  }
125        $.post("?exec=menu&mode=sauver&langue_menu=" + langue + "&niveaux=" + type_sortable, serial.hash, function (reponse) {
126                //console.log(reponse);
127                $('#search').css({visibility: 'hidden'});
128    $('#bloc_sauver').css({background: "green"});
129        });
130}
131
132function supprimer(elem) {
133 jQuery(elem).remove();
134       $('#bloc_sauver').css({background: "red"});
135
136}
137function supprimer_lien(elem) {
138elem = document.getElementById(elem);
139 jQuery(elem).remove();
140       $('#bloc_sauver').css({background: "red"});
141
142}
143
144function htmlentities(str) {
145    var i,output="",len;
146    len = str.length;
147    for(i=0;i<len;i++){
148        char = str[i].charCodeAt(0);
149       if(char == 34) { output+="ggguiii"; }
150       else if(char ==39) { output +="aaapooo"; }
151       else if(char==45){ output +="tttirrr"; }
152        else { output += str[i]; }
153    }
154    return output;
155}
Note: See TracBrowser for help on using the repository browser.