2 * 2008-2014 Benoit Pin - MINES ParisTech
4 * Licence Creative Commons http://creativecommons.org/licenses/by-nc/2.0/
12 var reSelected
= /.*selected.*/;
14 Lightbox = function(grid
) {
16 this.lastCBChecked
= undefined;
18 addListener(this.grid
, 'click', function(evt
){thisLightbox
.mouseClickHandler(evt
);});
19 if (!browser
.isGecko
){
20 addListener(this.grid
, 'mouseover', function(evt
){thisLightbox
.mouseOverHandler(evt
);});
21 addListener(this.grid
, 'mouseout', function(evt
){thisLightbox
.mouseOutHandler(evt
);});
25 Lightbox
.prototype.mouseClickHandler = function(evt
) {
26 var target
= getTargetedObject(evt
);
27 if (target
.tagName
=== 'IMG') {
29 var link
= target
.parentNode
;
30 var button
= link
.parentNode
;
31 var slide
= button
.parentNode
;
33 if (link
.tagName
=== 'A') {
34 switch(link
.getAttribute('name')) {
35 case 'add_to_selection':
38 req
= new XMLHttpRequest();
40 req
.open("POST", url
, true);
41 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
44 slide
.className
= 'selected';
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";
52 case 'remove_to_selection':
55 req
= new XMLHttpRequest();
57 req
.open("POST", url
, true);
58 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
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";
69 slide
.widget
= new CartWidget(slide
, link
.href
);
72 case 'hide_for_anonymous':
75 req
= new XMLHttpRequest();
77 req
.open("POST", url
, true);
78 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
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";
87 case 'show_for_anonymous':
90 req
= new XMLHttpRequest();
92 req
.open("POST", url
, true);
93 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
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";
103 } else if(target
.tagName
=== 'INPUT' && target
.type
=== 'checkbox') {
106 cb
.setAttribute('checked', 'checked');
109 cb
.removeAttribute('checked');
111 this.selectCBRange(evt
);
115 Lightbox
.prototype.mouseOverHandler = function(evt
) {
116 var target
= getTargetedObject(evt
);
117 if (target
.tagName
==='AREA') {
118 var slide
= target
.parentNode
.parentNode
;
119 if(reSelected
.test(slide
.className
)) {
120 slide
.className
= 'slide_over_selected';}
122 slide
.className
= 'slide_over';}
126 Lightbox
.prototype.mouseOutHandler = function(evt
) {
127 var target
= getTargetedObject(evt
);
128 if (target
.tagName
==='AREA') {
129 var slide
= target
.parentNode
.parentNode
;
130 if(reSelected
.test(slide
.className
)) {
131 slide
.className
= 'selected';}
133 slide
.className
= undefined;}
137 Lightbox
.prototype.getCBIndex = function(cb
) {
139 // build checkbox index
142 var nodes
= this.grid
.childNodes
;
143 for (i
=0 ; i
<nodes
.length
; i
++) {
145 if (node
.nodeName
=== 'SPAN') {
146 c
= node
.getElementsByTagName('input')[0];
147 c
.index
= this.cbIndex
.length
;
148 this.cbIndex
[this.cbIndex
.length
] = c
;
155 Lightbox
.prototype.selectCBRange = function(evt
) {
156 var target
= getTargetedObject(evt
);
157 evt
= getEventObject(evt
);
158 var shift
= evt
.shiftKey
;
159 if (shift
&& this.lastCBChecked
) {
160 var from = this.getCBIndex(this.lastCBChecked
);
161 var to
= this.getCBIndex(target
);
162 var start
= Math
.min(from, to
);
163 var stop
= Math
.max(from, to
);
165 for (i
=start
; i
<stop
; i
++ ) {
166 this.cbIndex
[i
].setAttribute('checked', 'checked');
169 else if (target
.checked
) {
170 this.lastCBChecked
= target
;
173 this.lastCBChecked
= undefined;
178 var _outlineSelectedSlide
;
179 if (browser
.isGecko
) {
180 _outlineSelectedSlide = function(slide
) {
181 slide
.className
= 'selected';
185 _outlineSelectedSlide = function(slide
) {
186 if (slide
.className
&&
187 !reSelected
.test(slide
.className
)) {
188 slide
.className
= slide
.className
+ ' selected';