summaryrefslogtreecommitdiff
path: root/media/js/slideshow.js
blob: 378412f16c1dd82c5c5b540211eedaee31ba85ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//Utility functions for map info window
function mapit(latlontitle) {
    lat = parseFloat(latlontitle.split(',')[0]);
    lon = parseFloat(latlontitle.split(',')[1]);
    title= latlontitle.split(',')[2];
    centerCoord = new google.maps.LatLng(lat, lon);
    var mapitinit;
    if (mapitinit == true) {
        mapPanTo();
    } else {
        mapInit();
    }
    
    function mapInit()  {
        var mapOptions = {
            zoom: 8,
            center: centerCoord,
            disableDefaultUI: true,
            navigationControl: true,
            mapTypeId: google.maps.MapTypeId.TERRAIN,
            navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}
        };
        map = new google.maps.Map(document.getElementById("map-wrapper"), mapOptions);
        var marker = new google.maps.Marker({
            position: centerCoord, 
            map: map, 
            title: title
        });   
        mapitinit = true;
    }
    function mapPanTo(){
        var marker = new google.maps.Marker({
            position: centerCoord, 
            map: map, 
            title: title
        });  
        map.panTo(centerCoord);
    }
}  

// utility functions to create/remove map container
function create_map(obj) {
    //create container divs
    $(obj).parent().parent().parent().append('<div id="map-container">');
    $('#map-container').append('<div id="map-wrapper">');
    //deal with the variable height of div.legend
    $('#map-container').css({
      bottom: function(index, value) {
        return parseFloat($(obj).parent().parent().height())-2;
      }
     });
    
    mapit(obj.title);
}
function remove_map() {
    $('#map-container').remove();
}
// utility functions to create/remove camera info container
function get_exif(obj,id) {
    $(obj).parents().eq(2).append('<div id="exif-container">');
    $(obj).parents().eq(2).children('.meta').clone().appendTo('#exif-container').css('display', 'block');
    //deal with the variable height of div.legend
    $('#exif-container').css({
        bottom: function(index, value) {
            return parseFloat($(obj).parent().parent().height())-14;
        }
     });
}
function remove_exif() {
    $("#exif-container").remove();
}


//
$(document).ready(function(){ 
    
    
    //Add navigation
    $('#breadcrumbs').after('<div id="slideshow-controls"><ul><li><a id="prev" title="you can also use the arrow keys to navigate" href="#"> &larr; Older</a></li><li><a id="play" title="Pause Slideshow" href="#">▐▐</a></li><li><a id="next" title="you can also use the arrow keys to navigate" href="#">Newer &rarr;</a></li></ul></div>');
    
    
    //activate pause button
    //state var
    var show_state = 'playing';
    $('#play').click(function() {
        if (show_state == 'playing') {
            $('#slides').cycle('pause');
            $(this).html('▶');
            $(this).attr('title','Play slideshow');
            show_state = 'paused';
        } else {
            $('#slides').cycle('resume', true);
            $(this).html('▐▐');
            $(this).attr('title','Pause slideshow');
            show_state= 'playing';
        }
        return false;
    });



    //set up click events for map button
    $('.map-link').click( function() {
        if ($("#exif-container").is(":visible")){
                remove_exif();
        }
        if ($('#map-container').is(":visible")) {
            remove_map();  
        } else {
            create_map(this);
        }
        return false;
    
    });
    
    //set up click events camera info button
    $('.exif-link').click( function() {
        if ($('#map-container').is(":visible")){
            remove_map();
        }
        if ($('#exif-container').is(":visible")) {
            remove_exif();
        } else {
            get_exif(this);
        }
        return false;
    });

    
    // create and hide nav buttons (needed for keyboard shortcuts
    $('#slides').append('<div class="slidenav"><a id="prev">< Prev&nbsp;</a><a id="next">&nbsp;Next ></a></div>');
    $('.slidenav').css("display","none");
    
    var is_permalink = false;
    //find out if we should display a specific slide
    var index = 0, hash = window.location.hash;
    if (hash) {
        index = /\d+/.exec(hash)[0];
        index = (parseInt(index) || 1) - 1; // slides are zero-based
        //if this is a permalink, then don't autoplay:
        is_permalink = true;
    }
    // initialize the cycle slideshow
    $('#slides .bigimg').wrapAll('<div class="bigimgs">').parents('#slides').append('<ul class="menu" id="feature_gallery_pager">').cycle({ 
        fx: 'fade',
        startingSlide: index,
        prev: $(this).find('#prev'),
        next: $(this).find('#next'),
        before:  onBefore,
        after: onAfter,
        slideExpr: '.bigimg', 
        pager:      '#feature_gallery_pager', 
        pagerAnchorBuilder: function(idx, slide) { 
            return '<li><a href="#"><img src="'+slide.id+'" class="thumb"><span></span></a></li>';  
        }
    });
    
    //if this is a permalink, then pause:
    if(is_permalink == true) {
        $('#play').click()
    }
    //callback to delete map and camera info windows if they exist
    function onBefore() { 
        $('#map-container').remove(); 
        $('#exif-container').remove(); 
    } 
    
    //callback to change url for permalinks and scroll jcarousel
    function onAfter(curr,next,opts) { 
        if (opts.currSlide % 10 == 0) {
            if (opts.currSlide != 0) {
                $('#slides').trigger('image-loaded',[opts.currSlide+1]);
            } else {
                $('#slides').trigger('image-loaded',[1]);
            }
        }  
        window.location.hash = 'image'+(opts.currSlide + 1);
    } 
    
    //callback for jcarousel
    function initCallbackFunction(carousel) {
        // bind "image-loaded" event to the #slides container (trigger in onAfter function)
        $('#slides').bind('image-loaded', function(event, num) {
            // scroll carousel
            carousel.scroll(num);
            return false;
        });
    };
    
    //initialize the jcarousel plugin
    $(function() {
        $('#feature_gallery_pager').jcarousel({
            scroll:10,
            initCallback: initCallbackFunction
        });
    });
    
    //enable keyboard shortcuts:
    $(document.documentElement).keyup(function(event) {
        var direction = null;
        if (event.keyCode == 37) {
            direction = 'prev';
        } else if (event.keyCode == 39) {
            direction = 'next';
        }
        if (direction != null) {
            $('#slides').each(function(index) {
                $('#prev,#next', this)[direction]().click();
            });
        }
    });
    
     
  
});