Welcome to mirror list, hosted at ThFree Co, Russian Federation.

main.js « js « assets - github.com/kc0bfv/autophugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 123996a0214c5a34f5d88dd48cfcb5c1d0166492 (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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
(function($) {

    $(function() {

        var $window = $(window),
            $body = $('body'),
            $wrapper = $('#wrapper');

        // Add (and later, on load, remove) "loading" class.
            $body.addClass('loading');
            if( document.readyState != 'loading' ) {
                window.setTimeout(function() {
                    $body.removeClass('loading');
                }, 100);
            } else {
                $window.on('load', function() {
                    window.setTimeout(function() {
                        $body.removeClass('loading');
                    }, 100);
                });
            }

        // Prevent transitions/animations on resize.
            var resizeTimeout;

            $window.on('resize', function() {

                window.clearTimeout(resizeTimeout);

                $body.addClass('resizing');

                resizeTimeout = window.setTimeout(function() {
                    $body.removeClass('resizing');
                }, 100);

            });

        // Scroll back to top.
            $window.scrollTop(0);

        // Fix: Placeholder polyfill.
            $('form').placeholder();

        // Panels.
            var $panels = $('.panel');

            $panels.each(function() {

                var $this = $(this),
                    $toggles = $('[href="#' + $this.attr('id') + '"]'),
                    $closer = $('<div class="closer" />').appendTo($this);

                // Closer.
                    $closer
                        .on('click', function(event) {
                            $this.trigger('---hide');
                        });

                // Events.
                    $this
                        .on('click', function(event) {
                            event.stopPropagation();
                        })
                        .on('---toggle', function() {

                            if ($this.hasClass('active'))
                                $this.triggerHandler('---hide');
                            else
                                $this.triggerHandler('---show');

                        })
                        .on('---show', function() {

                            // Hide other content.
                                if ($body.hasClass('content-active'))
                                    $panels.trigger('---hide');

                            // Activate content, toggles.
                                $this.addClass('active');
                                $toggles.addClass('active');

                            // Activate body.
                                $body.addClass('content-active');

                        })
                        .on('---hide', function() {

                            // Deactivate content, toggles.
                                $this.removeClass('active');
                                $toggles.removeClass('active');

                            // Deactivate body.
                                $body.removeClass('content-active');

                        });

                // Toggles.
                    $toggles
                        .removeAttr('href')
                        .css('cursor', 'pointer')
                        .on('click', function(event) {

                            event.preventDefault();
                            event.stopPropagation();

                            $this.trigger('---toggle');

                        });

            });

            // Global events.
                $body
                    .on('click', function(event) {

                        if ($body.hasClass('content-active')) {

                            event.preventDefault();
                            event.stopPropagation();

                            $panels.trigger('---hide');

                        }

                    });

                $window
                    .on('keyup', function(event) {

                        if (event.keyCode == 27
                        &&  $body.hasClass('content-active')) {

                            event.preventDefault();
                            event.stopPropagation();

                            $panels.trigger('---hide');

                        }

                    });

        // Footer.
            var $footer = $('#footer');

        // Main.
            var $main = $('#main');

            // Thumbs.
                $main.children('.thumb').each(function() {

                    var $this = $(this),
                        $image = $this.find('.image'), $image_img = $image.children('img'),
                        x;

                    // No image? Bail.
                        if ($image.length == 0)
                            return;

                    // Image.
                    // This sets the background of the "image" <span> to the image pointed to by its child
                    // <img> (which is then hidden). Gives us way more flexibility.

                        // Set background.
                            $image.css('background-image', 'url(' + $image_img.attr('src') + ')');

                        // Set background position.
                            if (x = $image_img.data('position'))
                                $image.css('background-position', x);

                        // Hide original img.
                            $image_img.hide();

                });

            // Thumbs Index.
                $main.children('.thumb').each(function() {

                    var $this = $(this),
                        $link = $this.find('.link'), $link_img = $link.children('img'),
                        x;

                    // No link? Bail.
                        if ($link.length == 0)
                            return;

                    // link.
                    // This sets the background of the "link" <span> to the link pointed to by its child
                    // <img> (which is then hidden). Gives us way more flexibility.

                        // Set background.
                            $link.css('background-image', 'url(' + $link_img.attr('src') + ')');

                        // Set background position.
                            if (x = $link_img.data('position'))
                                $link.css('background-position', x);

                        // Hide original img.
                            $link_img.hide();
                });

                var gallery_items = $(".gallery-item").sort(
                        function(item_a, item_b){
                            return item_a.getAttribute("gallery_index") - 
                                    item_b.getAttribute("gallery_index");
                            }
                    );
                gallery_items.magnificPopup({
                    type: "image",
                    image: {
                        titleSrc: function(item) {
                            let caption = '';
                            if(item.el.attr("downloadable") == "true"){
                                caption += '<div title="Download" ' +
                                    'class="download-button"><a href="' +
                                    item.el.attr("download_file") + '" download="' +
                                    item.el.attr("orig_name") +
                                    '"><i class="fa fa-download"></i></a></div>';
                            }
                            caption += '<div class="caption-surround">';
                            if( item.el.attr("phototitle") != "" ) {
                                caption += "<h2>" + item.el.attr("phototitle") + "</h2>";
                            }
                            if( item.el.attr("description") != "" ) {
                                caption += '<div class="description">' +
                                    item.el.attr("description") + "</div>";
                            }
                            let tax_elem = item.el.parent().find(".caption_tax");
                            if( tax_elem.length > 0 ) {
                                caption += tax_elem[0].outerHTML;
                            }
                            caption += "</div>";
                            return caption;
                        },
                    },
                    gallery:{
                        enabled:true,
                        arrowMarkup: '<button title="%title%" class="nav-%dir%"></button>',
                    },
                    callbacks: {
                        change: function() {
                            window.location.hash = this.currItem.el.attr("id");
                        },
                        close: function() {
                            window.location.hash = "";
                        },
                    },
                    fixedContentPos: true,
                });

                // If there's a fragment id, see if it's an image index
                // If it is, and it's really a gallery_item then click on it
                let click_hash = function () {
                    let fid = $(window.location.hash);
                    if( fid.length == 1 &&
                        (
                            fid[0].classList.contains("gallery-item") ||
                            fid[0].classList.contains("gallery-item-marker")
                        )
                    ) {
                        let curr_item = $.magnificPopup.instance.currItem;
                        if( curr_item &&
                            curr_item.el.attr("id") == fid[0].id )
                        {
                            // Nothing needs to happen in this case...
                            return false;
                        } else
                        {
                            // Otherwise we need to update the popup, so click it
                            fid.click();
                            return false;
                        }
                    } else {
                        // Some other hash was present, let the browser handle it
                        $.magnificPopup.close();
                        return true;
                    }
                    return true;
                }

                // Check the fragment id at load
                if( window.location.hash != "" ) {
                    click_hash();
                }

                // Check the fragment id on hashchange
                $(window).on("hashchange", click_hash);
    });

})(jQuery);