Support de la supression d'un portfolio.
[Portfolio.git] / skins / photo_lightbox_viewer.js
1 /*
2 * © 2008 Benoît Pin – Centre de recherche en informatique – École des mines de Paris
3 * http://plinn.org
4 * Licence Creative Commons http://creativecommons.org/licenses/by-nc/2.0/
5 * $Id: photo_lightbox_viewer.js 1006 2009-05-16 16:20:20Z pin $
6 * $URL: http://svn.luxia.fr/svn/labo/projects/zope/Portfolio/trunk/skins/photo_lightbox_viewer.js $
7 */
8
9
10 var Lightbox;
11
12 (function(){
13
14 var reSelected = /.*selected.*/;
15
16 Lightbox = function(grid) {
17 this.grid = grid;
18 thisLightbox = this;
19 addListener(this.grid, 'click', function(evt){thisLightbox.mouseClickHandler(evt);});
20 if (!browser.isGecko){
21 addListener(this.grid, 'mouseover', function(evt){thisLightbox.mouseOverHandler(evt);});
22 addListener(this.grid, 'mouseout', function(evt){thisLightbox.mouseOutHandler(evt);});
23 }
24 }
25
26 Lightbox.prototype.mouseClickHandler = function(evt) {
27 var target = getTargetedObject(evt);
28 if (target.tagName == 'IMG') {
29 var img = target;
30 var link = target.parentNode;
31 var button = link.parentNode;
32 var slide = button.parentNode;
33 if (link.tagName == 'A') {
34 switch(link.getAttribute('name')) {
35 case 'add_to_selection':
36 disableDefault(evt);
37 link.blur();
38 var req = new XMLHttpRequest();
39 var url = link.href;
40 req.open("POST", url, true);
41 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
42 req.send("ajax=1");
43
44 slide.className = 'selected';
45
46 link.setAttribute('name', 'remove_to_selection');
47 link.href = url.replace(/(.*\/)add_to_selection$/, '$1remove_to_selection');
48 link.title = img.alt = 'Retirer de la sélection';
49 button.className = "button slide-deselect";
50 break;
51
52 case 'remove_to_selection':
53 disableDefault(evt);
54 link.blur();
55 var req = new XMLHttpRequest();
56 var url = link.href;
57 req.open("POST", url, true);
58 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
59 req.send("ajax=1");
60 slide.className = null;
61 link.setAttribute('name', 'add_to_selection');
62 link.href = url.replace(/(.*\/)remove_to_selection$/, '$1add_to_selection');
63 link.title = img.alt = 'Ajouter à la sélection';
64 button.className = "button slide-select";
65 break;
66
67 case 'add_to_cart' :
68 disableDefault(evt);
69 slide.widget = new CartWidget(slide, link.href);
70 break;
71
72 case 'hide_for_anonymous':
73 disableDefault(evt);
74 link.blur();
75 var req = new XMLHttpRequest();
76 var url = link.href;
77 req.open("POST", url, true);
78 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
79 req.send(null);
80 slide.className = 'hidden-slide';
81 link.setAttribute('name', 'show_for_anonymous');
82 link.href = url.replace(/(.*\/)hideForAnonymous$/, '$1resetHide');
83 link.title = img.alt = 'Montrer au anonymes';
84 button.className = "button slide-show";
85 break;
86
87 case 'show_for_anonymous':
88 disableDefault(evt);
89 link.blur();
90 var req = new XMLHttpRequest();
91 var url = link.href;
92 req.open("POST", url, true);
93 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
94 req.send(null);
95 slide.className = null;
96 link.setAttribute('name', 'hide_for_anonymous');
97 link.href = url.replace(/(.*\/)resetHide$/, '$1hideForAnonymous');
98 link.title = img.alt = 'Masquer pour les anonymes';
99 button.className = "button slide-hide";
100 break;
101 }
102 }
103 }
104 };
105
106 Lightbox.prototype.mouseOverHandler = function(evt) {
107 var target = getTargetedObject(evt);
108 if (target.tagName=='AREA') {
109 var slide = target.parentNode.parentNode;
110 if(reSelected.test(slide.className))
111 slide.className = 'slide_over_selected';
112 else
113 slide.className = 'slide_over';
114 }
115 };
116
117 Lightbox.prototype.mouseOutHandler = function(evt) {
118 var target = getTargetedObject(evt);
119 if (target.tagName=='AREA') {
120 var slide = target.parentNode.parentNode;
121 if(reSelected.test(slide.className))
122 slide.className = 'selected';
123 else
124 slide.className = undefined;
125 }
126 };
127
128 var _outlineSelectedSlide;
129 if (browser.isGecko) {
130 _outlineSelectedSlide = function(slide) {
131 slide.className = 'selected';
132 }
133 }
134 else {
135 _outlineSelectedSlide = function(slide) {
136 if (slide.className)
137 if (!reSelected.test(slide.className))
138 slide.className = slide.className + ' selected';
139 }
140 }
141
142 })();