dbea64c89df266f65a041429ddc4a6ac3c1a6192
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;
17 this.form
= undefined;
18 var parent
= this.grid
.parentNode
;
20 parent
= parent
.parentNode
;
21 if (parent
.tagName
=== 'FORM') {
25 else if (parent
.tagName
=== 'BODY') {
30 addListener(this.grid
, 'click', function(evt
){thisLightbox
.mouseClickHandler(evt
);});
32 var fm
= new FormManager(this.form
);
33 fm
.onBeforeSubmit = function(fm_
, evt
) {return thisLightbox
.onBeforeSubmit(fm_
, evt
);};
34 fm
.onResponseLoad = function(req
) {return thisLightbox
.onResponseLoad(req
);};
38 Lightbox
.prototype.mouseClickHandler = function(evt
) {
39 var target
= getTargetedObject(evt
);
40 if (target
.tagName
=== 'IMG') {
42 var link
= target
.parentNode
;
43 var button
= link
.parentNode
;
44 var slide
= button
.parentNode
;
46 if (link
.tagName
=== 'A') {
47 switch(link
.getAttribute('name')) {
48 case 'add_to_selection':
51 req
= new XMLHttpRequest();
53 req
.open("POST", url
, true);
54 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
57 slide
.className
= 'selected';
59 link
.setAttribute('name', 'remove_to_selection');
60 link
.href
= url
.replace(/(.*\/)add_to_selection$/, '$1remove_to_selection');
61 link
.title
= img
.alt
= 'Retirer de la sélection';
62 button
.className
= "button slide-deselect";
65 case 'remove_to_selection':
68 req
= new XMLHttpRequest();
70 req
.open("POST", url
, true);
71 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
73 slide
.className
= null;
74 link
.setAttribute('name', 'add_to_selection');
75 link
.href
= url
.replace(/(.*\/)remove_to_selection$/, '$1add_to_selection');
76 link
.title
= img
.alt
= 'Ajouter à la sélection';
77 button
.className
= "button slide-select";
82 slide
.widget
= new CartWidget(slide
, link
.href
);
85 case 'hide_for_anonymous':
88 req
= new XMLHttpRequest();
90 req
.open("POST", url
, true);
91 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
93 slide
.className
= 'hidden-slide';
94 link
.setAttribute('name', 'show_for_anonymous');
95 link
.href
= url
.replace(/(.*\/)hideForAnonymous$/, '$1resetHide');
96 link
.title
= img
.alt
= 'Montrer au anonymes';
97 button
.className
= "button slide-show";
100 case 'show_for_anonymous':
103 req
= new XMLHttpRequest();
105 req
.open("POST", url
, true);
106 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
108 slide
.className
= null;
109 link
.setAttribute('name', 'hide_for_anonymous');
110 link
.href
= url
.replace(/(.*\/)resetHide$/, '$1hideForAnonymous');
111 link
.title
= img
.alt
= 'Masquer pour les anonymes';
112 button
.className
= "button slide-hide";
116 } else if(target
.tagName
=== 'INPUT' && target
.type
=== 'checkbox') {
119 cb
.setAttribute('checked', 'checked');
122 cb
.removeAttribute('checked');
124 this.selectCBRange(evt
);
128 Lightbox
.prototype.onBeforeSubmit = function(fm
, evt
) {
129 switch(fm
.submitButton
.name
) {
131 this.hideSelection();
136 Lightbox
.prototype.onResponseLoad = function(req
) {
137 switch(req
.responseXML
.documentElement
.nodeName
) {
139 this.deleteSelection();
142 this.showSelection();
147 Lightbox
.prototype.hideSelection = function() {
149 for (i
=0 ; i
<this.form
.elements
.length
; i
++) {
150 e
= this.form
.elements
[i
];
151 if (e
.type
=== 'checkbox' && e
.checked
) {
152 slide
= e
.parentNode
.parentNode
;
153 slide
.classList
.add('zero_opacity');
158 Lightbox
.prototype.showSelection = function() {
160 for (i
=0 ; i
<this.form
.elements
.length
; i
++) {
161 e
= this.form
.elements
[i
];
162 if (e
.type
=== 'checkbox' && e
.checked
) {
163 slide
= e
.parentNode
.parentNode
;
164 slide
.classList
.remove('zero_opacity');
169 Lightbox
.prototype.deleteSelection = function() {
171 for (i
=0 ; i
<this.form
.elements
.length
; i
++) {
172 e
= this.form
.elements
[i
];
173 if (e
.type
=== 'checkbox' && e
.checked
) {
174 slide
= e
.parentNode
.parentNode
;
175 slide
.classList
.add('zero_width');
179 // if you change this, delay you should also change this css rule :
180 // .lightbox span { transition: width 1s
181 setTimeout(function(){self
._removeSelection();}, 1000);
184 Lightbox
.prototype._removeSelection = function() {
187 for (i
=0 ; i
<this.form
.elements
.length
; i
++) {
188 e
= this.form
.elements
[i
];
189 if (e
.type
=== 'checkbox' && e
.checked
) {
190 toRemove
.push(e
.parentNode
.parentNode
);
193 for (i
=0 ; i
<toRemove
.length
; i
++) {
195 slide
.parentNode
.removeChild(slide
);
197 this.cbIndex
= undefined;
200 Lightbox
.prototype.getCBIndex = function(cb
) {
202 // build checkbox index
205 var nodes
= this.grid
.childNodes
;
206 for (i
=0 ; i
<nodes
.length
; i
++) {
208 if (node
.nodeName
=== 'SPAN') {
209 c
= node
.getElementsByTagName('input')[0];
210 c
.index
= this.cbIndex
.length
;
211 this.cbIndex
[this.cbIndex
.length
] = c
;
218 Lightbox
.prototype.selectCBRange = function(evt
) {
219 var target
= getTargetedObject(evt
);
220 evt
= getEventObject(evt
);
221 var shift
= evt
.shiftKey
;
222 if (shift
&& this.lastCBChecked
) {
223 var from = this.getCBIndex(this.lastCBChecked
);
224 var to
= this.getCBIndex(target
);
225 var start
= Math
.min(from, to
);
226 var stop
= Math
.max(from, to
);
228 for (i
=start
; i
<stop
; i
++ ) {
229 this.cbIndex
[i
].setAttribute('checked', 'checked');
232 else if (target
.checked
) {
233 this.lastCBChecked
= target
;
236 this.lastCBChecked
= undefined;
241 var _outlineSelectedSlide
;
242 if (browser
.isGecko
) {
243 _outlineSelectedSlide = function(slide
) {
244 slide
.className
= 'selected';
248 _outlineSelectedSlide = function(slide
) {
249 if (slide
.className
&&
250 !reSelected
.test(slide
.className
)) {
251 slide
.className
= slide
.className
+ ' selected';