This repository has been archived by the owner on Mar 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
225 lines (180 loc) · 7.02 KB
/
script.js
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
$(document).ready(function() {
// run test on initial page load
checkSize();
// run test on resize of the window
$(window).resize(checkSize);
var activeClasses = $('.s-lg-tabs-side li.active').length;
var contentHeight = $('.s-lg-tab-content').height();
var navHeight = $('.s-lg-tabs-side').height();
if(contentHeight > navHeight) {
$('#s-lg-tabs-container .nav-stacked').affix({
offset: {
top: 205
, bottom: function () {
return (this.bottom = $('.footer').outerHeight(true))
}
}
})
}
if(activeClasses > 1) {
$('.s-lg-tabs-side ul li').removeClass('active');
$('.s-lg-tabs-side ul li:first').addClass('active');
}
$('#s-lib-bc-customer a').text('Harvard Library');
$('#s-lib-bc-site a').text('Research Guides');
$( "#s-lg-guide-desc-container" ).on( "click", ".s-lg-tabs-side-toggle", function() {
$('.s-lg-tabs-side').slideToggle();
});
$('.s-lib-profile-container').closest('.s-lib-box-container').parent().remove();
$('body').windowspy({ target: '.s-lg-tabs-side' });
$('#s-lib-bc').prependTo('#s-lib-footer-public');
//var prettyUrl = $('#s-lg-guide-header-url .s-lg-text-greyout').text();
//$('<p><a href="' + prettyUrl + '">' + prettyUrl + '</a></p>').prependTo('#s-lg-guide-description').addClass('s-lg-text-greyout');
var updated_on = $('meta[name="DC.Date.Modified"]').attr("content");
var creator = $('meta[name="DC.Creator"]').attr("content");
profileBox(creator);
var additionalCreator = $('meta[name="DC.Additional.Creator"]').attr("content");
profileBox(additionalCreator)
function profileBox(creator) {
$.getJSON( config.apiUrl, function( data ) {
$.each( data, function( key, val ) {
if((val.first_name + ' ' + val.last_name) === creator) {
if(val.profile.image) {
var image_path = config.imageBase + val.profile.account_id + '/profiles/' + val.profile.id + '/' + val.profile.image.file;
}
else {
var image_path = config.imageBackground;
}
var email = val.email;
var profile = val.profile.url;
$('#s-lg-guide-desc-container').append('<div class="s-lg-guide-footer-byline"><a href="' + profile + '"><img src="' + image_path + '"></a><p><span class="s-lg-guide-byline-updated">Last updated ' + updated_on + '</span><a href="' + profile + '">' + creator + '</a> | <a href="mailto:' + email + '"><i class="fa fa-envelope" title="Email"></i> Email</a></p></div>');
}
});
});
}
// Replace search box
//$('#s-lg-guide-search-form').attr('action', 'https://cse.google.com/cse/publicurl');
//$( "input[name='guide_id']").attr('name', 'cx').attr('value', '005262195415746452776:ekldow64xay');
//$('#s-lg-guide-search-terms').attr('placeholder', 'Search Research Guides');
});
//Function to the css rule
function checkSize(){
if ($(".s-lg-tabs-side").css("display") == "none" ){
$('.s-lg-tabs-side > ul > li').clone().prependTo('.guide-menu-container');
$('.guide-menu-container li').removeClass('active');
}
}
+function ($) {
'use strict';
// SCROLLSPY CLASS DEFINITION
// ==========================
function WindowSpy(element, options) {
var href
var process = $.proxy(this.process, this)
this.$element = $(element).is('body') ? $(window) : $(element)
this.$body = $('body')
this.$scrollElement = this.$element.on('scroll.bs.windowspy', process)
this.options = $.extend({}, WindowSpy.DEFAULTS, options)
this.selector = (this.options.target
|| ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
|| '') + ' .nav li > a'
this.offsets = $([])
this.targets = $([])
this.activeTarget = null
this.refresh()
this.process()
}
WindowSpy.DEFAULTS = {
offset: 10
}
WindowSpy.prototype.refresh = function () {
var offsetMethod = this.$element[0] == window ? 'offset' : 'position'
this.offsets = $([])
this.targets = $([])
var self = this
this.$body
.find(this.selector)
.map(function () {
var $el = $(this)
var href = $el.data('target') || $el.attr('href')
var hrefsplit = href.split('#')
href = '#' + hrefsplit[1]
var $href = /^#./.test(href) && $(href)
return ($href
&& $href.length
&& $href.is(':visible')
&& [[ $href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null
})
.sort(function (a, b) { return a[0] - b[0] })
.each(function () {
self.offsets.push(this[0])
self.targets.push(this[1])
})
}
WindowSpy.prototype.process = function () {
var scrollTop = this.$scrollElement.scrollTop() + this.options.offset
var scrollHeight = this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight)
var maxScroll = scrollHeight - this.$scrollElement.height()
var offsets = this.offsets
var targets = this.targets
var activeTarget = this.activeTarget
var i
if (scrollTop >= maxScroll) {
return activeTarget != (i = targets.last()[0]) && this.activate(i)
}
if (activeTarget && scrollTop <= offsets[0]) {
return activeTarget != (i = targets[0]) && this.activate(i)
}
for (i = offsets.length; i--;) {
activeTarget != targets[i]
&& scrollTop >= offsets[i]
&& (!offsets[i + 1] || scrollTop <= offsets[i + 1])
&& this.activate( targets[i] )
}
}
WindowSpy.prototype.activate = function (target) {
this.activeTarget = target
$(this.selector)
.parentsUntil(this.options.target, '.active')
.removeClass('active')
var selector = this.selector +
'[data-target="' + target + '"],' +
this.selector + '[href$="' + target + '"]'
var active = $(selector)
.parents('li')
.addClass('active')
if (active.parent('.dropdown-menu').length) {
active = active
.closest('li.dropdown')
.addClass('active')
}
active.trigger('activate.bs.windowspy')
}
// SCROLLSPY PLUGIN DEFINITION
// ===========================
var old = $.fn.windowspy
$.fn.windowspy = function (option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.windowspy')
var options = typeof option == 'object' && option
if (!data) $this.data('bs.windowspy', (data = new WindowSpy(this, options)))
if (typeof option == 'string') data[option]()
})
}
$.fn.windowspy.Constructor = WindowSpy
// SCROLLSPY NO CONFLICT
// =====================
$.fn.windowspy.noConflict = function () {
$.fn.windowspy = old
return this
}
// SCROLLSPY DATA-API
// ==================
$(window).on('load.bs.windowspy.data-api', function () {
$('[data-spy="scroll"]').each(function () {
var $spy = $(this)
$spy.windowspy($spy.data())
})
})
}(jQuery);