-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
355 lines (355 loc) · 16.1 KB
/
index.html
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Scalar Auto-navigate Plugin</title>
<meta name="author" content="craigdietrich.com">
<meta name="description" content="Auto-navigate Scalar projects. Also works with Omeka and Omeka S. See documentation at https://github.com/craigdietrich/scalar-auto-navigate.">
<style>
body {color:#e3e3e3; font-size:1rem; font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif !important;}
#site {position:absolute; left:0px; top:0px; width:100%; height:100%; z-index:7; border:0; background-color:#000000;}
.custom_msg {
position:fixed; left:10%; right:10%; top:15px; z-index:8; background-color:#000000; color:#bbbbbb; border-radius:10px;
text-align:center; padding:6px 10px 7px 10px; overflow:hidden; font-size:smaller; display:none;
}
#countdown {position:absolute; background-color:#333333; right:0px; top:0px; padding:5px 10px 3px 10px; font-size:smaller; z-index:9; opacity:0.5;}
</style>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script>
var platform = null;
var is_scrolling = false;
var prev_urls = [];
var max_clicks = 20;
var global_stop_timer = false;
$(document).ready(function() {
var $iframe = $('#site');
// Determine the platform
if (-1 != document.location.href.indexOf('book=') && -1 != document.location.href.indexOf('system/application/plugins')) {
platform = 'scalar';
} else if (-1 != document.location.href.indexOf('plugins/AutoNavigate')) {
platform = 'omeka';
} else if (-1 != document.location.href.indexOf('modules/AutoNavigate')) {
platform = 'omeka-s';
} else if (-1 != document.location.href.indexOf('wp-content/plugins/auto-navigate')) {
platform = 'wordpress';
} else {
alert('Couldn\'t determine the platform (Scalar, Omeka, Omeka S, Wordpress)');
return;
}
console.log('Platform: '+platform);
// Messages from parent
window.addEventListener("message", function (event) {
switch (event.data) {
case 'autonavigate_reset_timer':
reset_timer();
break;
case 'autonavigate_stop_timer':
stop_timer();
break;
case 'autonavigate_kill_timer':
global_stop_timer = true;
stop_timer();
$('#countdown').fadeOut();
break;
case 'autonavigate_birth_timer':
global_stop_timer = false;
reset_timer();
$('#countdown').fadeIn();
break;
}
}, false);
// Get the current book or site, load it, and start the timer
if ('scalar' == platform) {
var system = document.location.href.substr(0, document.location.href.indexOf('system/application/plugins'));
var slug = document.location.href.substr(document.location.href.indexOf('book=')+5);
if (-1 != slug.indexOf('&')) slug = slug.substr(0, slug.indexOf('&'));
var url = system + slug;
$iframe.on('load', function() {
reset_timer();
$iframe[0].contentWindow.$($iframe[0].contentWindow.document).bind("click mousemove scroll", function() {
if (!is_scrolling) reset_timer();
});
$iframe[0].contentWindow.$($iframe[0].contentWindow.document).bind("click mousemove", function() {
window.parent.postMessage('autonavigate_user_interaction','*');
$('.custom_msg').fadeOut('slow', function() {
$(this).remove();
});
});
$iframe[0].contentWindow.postMessage('css_no_zooming', '*');
});
} else if ('omeka' == platform) {
var url = document.location.href.substr(0, document.location.href.indexOf('plugins/AutoNavigate'));
$iframe.on('load', function() {
reset_timer();
$($iframe.contents()).bind("click mousemove scroll", function() {
if (!is_scrolling) reset_timer();
});
$iframe[0].contentWindow.$($iframe[0].contentWindow.document).bind("click mousemove", function() {
window.parent.postMessage('autonavigate_user_interaction','*');
$('.custom_msg').fadeOut('slow', function() {
$(this).remove();
});
});
});
} else if ('omeka-s' == platform) {
var url = decodeURIComponent(document.location.href.substr(document.location.href.indexOf('site=')+5));
$iframe.on('load', function() {
reset_timer();
$($iframe.contents()).bind("click mousemove scroll", function() {
if (!is_scrolling) reset_timer();
});
$iframe[0].contentWindow.$($iframe[0].contentWindow.document).bind("click mousemove", function() {
window.parent.postMessage('autonavigate_user_interaction','*');
$('.custom_msg').fadeOut('slow', function() {
$(this).remove();
});
});
});
} else if ('wordpress' == platform) {
var url = document.location.href.substr(0, document.location.href.indexOf('wp-content/plugins/auto-navigate'));
$iframe.on('load', function() {
reset_timer();
$($iframe.contents()).bind("click mousemove scroll", function() {
if (!is_scrolling) reset_timer();
});
$iframe[0].contentWindow.$($iframe[0].contentWindow.document).bind("click mousemove", function() {
window.parent.postMessage('autonavigate_user_interaction','*');
$('.custom_msg').fadeOut('slow', function() {
$(this).remove();
});
});
});
};
$iframe.attr('src', url);
});
function reset_timer(start) {
if (global_stop_timer) return;
if ('undefined'==typeof(start)) start = 20;
$('#countdown').text(start + ' sec');
stop_timer();
interval = setInterval(function() {
start--;
$('#countdown').text(start + ' sec');
if (!start) {
clearInterval(interval);
interval = null;
if (!do_scroll()) do_click();
return;
};
}, 1000);
};
function stop_timer() {
if ('undefined'!=typeof(interval) && null!=interval) {
clearInterval(interval);
interval = null;
};
}
function do_scroll() {
$iframe = $("#site");
var buffer = parseInt($iframe.height()) * 0.4;
var amount = parseInt($iframe.height()) * 0.8;
var duration = 4000;
if ( $iframe.contents().scrollTop() + $iframe.height() >= $iframe.contents().height() - buffer ) {
return false;
};
var scroll_to = parseInt($iframe.contents().scrollTop()) + amount;
if (scroll_to + parseInt($iframe.height()) > parseInt($iframe.contents().height())) scroll_to = parseInt($iframe.contents().height()) - parseInt($iframe.height());
if (window.navigator.userAgent.indexOf("Edge") > -1) { // Things work a little differently in Edge within the Universal Windows Platform
if ('scalar' == platform) {
var el = $iframe.contents().find('article').eq(0);
} else if ('omeka' == platform) {
var el = $iframe.contents().find('#wrap').eq(0);
} else if ('omeka-s' == platform) {
var el = $iframe.contents().find('#content').eq(0);
} else if ('wordpress' == platform) {
var el = $iframe.contents().find('div:first').eq(0);
};
if ('undefined'==typeof(el)) return false;
var scroller = el.closest(":scrollable(vertical)"); // The area that can actually scroll (probably the body tag)
if (scroller.length <= 0) return false;
scroller = scroller.eq(0);
if (scroller[0].nodeName.toLowerCase() == 'html') scroller = $iframe.contents().find('body').eq(0);
is_scrolling = true;
scroller.animate({
scrollTop: scroll_to
}, {
duration: duration,
always: function() {
is_scrolling = false;
reset_timer(5);
}
});
var $custom = $('<div class="custom_msg"></div>').insertAfter($iframe);
$custom.html('<b>'+$iframe.contents().find('a.book-title, header h1 > span').html()+'</b>');
$custom.delay(duration + 200).fadeIn('slow');
} else {
is_scrolling = true;
$iframe.contents().children().animate({
scrollTop: scroll_to + "px"
}, {
duration: duration,
always: function() {
is_scrolling = false;
reset_timer(5);
}
});
var $custom = $('<div class="custom_msg"></div>').insertAfter($iframe);
$custom.html('<b>'+$iframe.contents().find('a.book-title, header h1 > span').html()+'</b>');
$custom.delay(duration + 200).fadeIn('slow');
};
return true;
};
function do_click() {
var url = get_url();
if (prev_urls.indexOf(url) != -1) {
window.parent.postMessage('autonavigate_finished','*');
return;
}
prev_urls.push(url);
if (prev_urls.length > max_clicks) {
window.parent.postMessage('autonavigate_finished','*');
return;
}
console.log('Clicking: '+url);
if (!url) {
window.parent.postMessage('autonavigate_finished','*');
return;
}
var $link = $('#site').contents().find('article [href="'+url+'"]');
if ($link.length && !$link.closest('.visual_path').length && !$link.closest('#gallery_content').length) $link.focus();
$('#site').attr('src', url);
$('.custom_msg').fadeOut('slow', function() {
$(this).remove();
});
window.parent.postMessage('autonavigate_click','*');
};
function get_url() {
if ('scalar' == platform) {
return scalar_get_url();
} else if ('omeka' == platform) {
return omeka_get_url();
} else if ('omeka-s' == platform) {
return omeka_s_get_url();
} else if ('wordpress' == platform) {
return wordpress_get_url();
};
return null;
};
function scalar_get_url() {
var selectors = [
// TODO: close citations panel
'article header a.path_begin:first', // "Begin path" on splash pages
'article.visual_path .nav_btn:first', // Visual Path
'#gallery_content .content_block:first a:first', // Structured Media Gallery
'article .relationships a.path_begin:first', // "Begin path" on pages
'article .relationships a.continue_btn:first', // "Continue path" e.g. pages on paths
'article .relationships a.nav_btn:not(.bordered):first', // Move to a different path
'article a.nav_btn:last' // Visual Path layout
];
var $iframe = $('#site');
var selector = '';
for (var j = 0; j < selectors.length; j++) {
var $el = $iframe.contents().find(selectors[j]);
if ($el.length && 'undefined'!=typeof($el.attr('href'))) {
console.log("Selector: " + selectors[j]);
return $el.attr('href');
}
};
// Selectors didn't match, try to find an internal hyperlink
var slug = document.location.href.substr(document.location.href.indexOf('?book=')+6);
if (slug.indexOf('/') != -1) slug = slug.substr(0, slug.indexOf('/'));
var url = null;
$iframe.contents().find("*:not(iframe, object, embed, canvas, svg)").each(function() {
var $this = $(this);
if (!$this.is('a')) return;
if (!$this.closest('span[property="sioc:content"]').length) return;
if ('undefined' == typeof($this.attr('href')) || !$this.attr('href').length) return;
if ($this.attr('href').indexOf(slug) <= 0) return;
if ($this.attr('href').indexOf('media/') >= 0) return;
if (null==url) url = $this.attr('href');
});
if (null!=url) return url;
/// Couldn't find anything
return null;
};
function omeka_get_url() {
var selectors = [
'#featured-collection .collection:first a:first', // Featured collection
'#collection-items .item:first a:first', // Item in collection
'.item-pagination #next-item a:first', // Next item in collection
'.collection h2:first a:first', // Collection in Browse collections tab
'.nav-menu .nav-item:nth-child(2) a:first' // Browse collections
];
var $iframe = $('#site');
var selector = '';
for (var j = 0; j < selectors.length; j++) {
var $el = $iframe.contents().find(selectors[j]);
if ($el.length && 'undefined'!=typeof($el.attr('href'))) return $el.attr('href');
};
return null;
};
function omeka_s_get_url() {
var $iframe = $('#site');
var $active = $iframe.contents().find('header .navigation > li.active');
if ($active.next().length) {
var $el = $active.next();
} else {
var $el = $iframe.contents().find('header .navigation > li:first');
};
if ($el.length) return $el.children('a').eq(0).attr('href');
return null;
};
function wordpress_get_url() {
var $iframe = $('#site');
var $active_a = $iframe.contents().find('nav a.active');
var $active_li_a = $iframe.contents().find('nav li.active a');
var $current_page_item_a = $iframe.contents().find('.current_page_item a');
if ($active_a.length) {
if ($active_a.closest('li').next().find('a').length) {
var $el = $active_a.closest('li').next().find('a');
} else {
var $el = $iframe.contents().find('nav a:first');
};
};
if ('undefined' == typeof($el)) {
if ($active_li_a.length) {
if ($active_li_a.closest('li').next().find('a').length) {
var $el = $active_li_a.closest('li').next().find('a');
} else {
var $el = $iframe.contents().find('nav li.active a');
};
};
};
if ('undefined' == typeof($el)) {
if ($current_page_item_a.length) {
if ($current_page_item_a.closest('li').next().find('a').length) {
var $el = $current_page_item_a.closest('li').next().find('a');
} else {
var $el = $iframe.contents().find('.current_page_item a')
};
};
};
if ('undefined' != typeof($el) && $el.length) {
if ($el.is('a')) return $el.eq(0).attr('href');
}
return null;
};
/*!
* jQuery scrollintoview() plugin and :scrollable selector filter
*
* Version 1.8 (14 Jul 2011)
* Requires jQuery 1.4 or newer
*
* Copyright (c) 2011 Robert Koritnik
* Licensed under the terms of the MIT license
* http://www.opensource.org/licenses/mit-license.php
*/
// Needed for the :scrollable selector used in the Edge scroller ~Craig
!function(t){var e={vertical:{x:!1,y:!0},horizontal:{x:!0,y:!1},both:{x:!0,y:!0},x:{x:!0,y:!1},y:{x:!1,y:!0}},o={duration:"fast",direction:"both"},r=/^(?:html)$/i,l=function(e){var o,l=t(window),i=r.test(e[0].nodeName);return{border:i?{top:0,left:0,bottom:0,right:0}:function(e,o){o=o||(document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(e,null):e.currentStyle);var r=!(!document.defaultView||!document.defaultView.getComputedStyle),l={top:parseFloat(r?o.borderTopWidth:t.css(e,"borderTopWidth"))||0,left:parseFloat(r?o.borderLeftWidth:t.css(e,"borderLeftWidth"))||0,bottom:parseFloat(r?o.borderBottomWidth:t.css(e,"borderBottomWidth"))||0,right:parseFloat(r?o.borderRightWidth:t.css(e,"borderRightWidth"))||0};return{top:l.top,left:l.left,bottom:l.bottom,right:l.right,vertical:l.top+l.bottom,horizontal:l.left+l.right}}(e[0]),scroll:{top:(i?l:e).scrollTop(),left:(i?l:e).scrollLeft()},scrollbar:{right:i?0:e.innerWidth()-e[0].clientWidth,bottom:i?0:e.innerHeight()-e[0].clientHeight},rect:(o=e[0].getBoundingClientRect(),{top:i?0:o.top,left:i?0:o.left,bottom:i?e[0].clientHeight:o.bottom,right:i?e[0].clientWidth:o.right})}};t.fn.extend({scrollintoview:function(i){(i=t.extend({},o,i)).direction=e["string"==typeof i.direction&&i.direction.toLowerCase()]||e.both;var c="";!0===i.direction.x&&(c="horizontal"),!0===i.direction.y&&(c=c?"both":"vertical");var n=this.eq(0),d=n.closest(":scrollable("+c+")");if(d.length>0){d=d.eq(0);var s=l(n),h=l(d),a={top:s.rect.top-(h.rect.top+h.border.top),bottom:h.rect.bottom-h.border.bottom-h.scrollbar.bottom-s.rect.bottom,left:s.rect.left-(h.rect.left+h.border.left),right:h.rect.right-h.border.right-h.scrollbar.right-s.rect.right},u={};!0===i.direction.y&&(a.top<0?u.scrollTop=h.scroll.top+a.top:a.top>0&&a.bottom<0&&(u.scrollTop=h.scroll.top+Math.min(a.top,-a.bottom))),!0===i.direction.x&&(a.left<0?u.scrollLeft=h.scroll.left+a.left:a.left>0&&a.right<0&&(u.scrollLeft=h.scroll.left+Math.min(a.left,-a.right))),t.isEmptyObject(u)?t.isFunction(i.complete)&&i.complete.call(d[0]):(r.test(d[0].nodeName)&&(d=t("html,body")),d.animate(u,i.duration).eq(0).queue(function(e){t.isFunction(i.complete)&&i.complete.call(d[0]),e()}))}return this}});var i={auto:!0,scroll:!0,visible:!1,hidden:!1};t.extend(t.expr[":"],{scrollable:function(t,o,l,c){var n=e["string"==typeof l[3]&&l[3].toLowerCase()]||e.both,d=document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(t,null):t.currentStyle,s={x:i[d.overflowX.toLowerCase()]||!1,y:i[d.overflowY.toLowerCase()]||!1,isRoot:r.test(t.nodeName)};if(!s.x&&!s.y&&!s.isRoot)return!1;var h={height:{scroll:t.scrollHeight,client:t.clientHeight},width:{scroll:t.scrollWidth,client:t.clientWidth},scrollableX:function(){return(s.x||s.isRoot)&&this.width.scroll>this.width.client},scrollableY:function(){return(s.y||s.isRoot)&&this.height.scroll>this.height.client}};return n.y&&h.scrollableY()||n.x&&h.scrollableX()}})}(jQuery);
</script>
</head>
<body>
<div id="countdown"></div>
<iframe id="site" src=""></iframe>
</body>
</html>