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