Merge remote branch 'kc/master' into new/enh/bug_5917
[koha.git] / koha-tt / opac-tmpl / prog / en / lib / greybox / GreyBox_v5_5 / greybox_source / auto_deco.js
1 var GB_SETS = {};
2 function decoGreyboxLinks() {
3     var as = AJS.$bytc('a');
4     AJS.map(as, function(a) {
5         if(a.getAttribute('href') && a.getAttribute('rel')) {
6             var rel = a.getAttribute('rel');
7             if(rel.indexOf('gb_') == 0) {
8                 var name = rel.match(/\w+/)[0];
9                 var attrs = rel.match(/\[(.*)\]/)[1];
10                 var index = 0;
11
12                 var item = {
13                     'caption': a.title || '',
14                     'url': a.href
15                 }
16
17                 //Set up GB_SETS
18                 if(name == 'gb_pageset' || name == 'gb_imageset') {
19                     if(!GB_SETS[attrs]) { GB_SETS[attrs] = []; }
20                     GB_SETS[attrs].push(item);
21                     index = GB_SETS[attrs].length;
22                 }
23
24                 //Append onclick
25                 if(name == 'gb_pageset') {
26                     a.onclick = function() {
27                         GB_showFullScreenSet(GB_SETS[attrs], index);
28                         return false;
29                     };
30                 }
31                 if(name == 'gb_imageset') {
32                     a.onclick = function() {
33                         GB_showImageSet(GB_SETS[attrs], index);
34                         return false;
35                     };
36                 }
37                 if(name == 'gb_image') {
38                     a.onclick = function() {
39                         GB_showImage(item.caption, item.url);
40                         return false;
41                     };
42                 }
43                 if(name == 'gb_page') {
44                     a.onclick = function() {
45                         var sp = attrs.split(/, ?/);
46                         GB_show(item.caption, item.url, parseInt(sp[1]), parseInt(sp[0]));
47                         return false;
48                     };
49                 }
50                 if(name == 'gb_page_fs') {
51                     a.onclick = function() {
52                         GB_showFullScreen(item.caption, item.url);
53                         return false;
54                     };
55                 }
56                 if(name == 'gb_page_center') {
57                     a.onclick = function() {
58                         var sp = attrs.split(/, ?/);
59                         GB_showCenter(item.caption, item.url, parseInt(sp[1]), parseInt(sp[0]));
60                         return false;
61                     };
62                 }
63             }
64         }});
65 }
66
67 AJS.AEV(window, 'load', decoGreyboxLinks);