Mercurial > web-octave
annotate js/foundation/foundation.magellan.js @ 0:7abe02bf29ec
initial commit
author | Alex Krolick <whokilledtheelectricmonk@gmail.com> |
---|---|
date | Sat, 07 Nov 2015 18:04:42 -0800 |
parents | |
children |
rev | line source |
---|---|
0
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
1 ;(function ($, window, document, undefined) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
2 'use strict'; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
3 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
4 Foundation.libs['magellan-expedition'] = { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
5 name : 'magellan-expedition', |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
6 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
7 version : '5.5.3', |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
8 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
9 settings : { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
10 active_class : 'active', |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
11 threshold : 0, // pixels from the top of the expedition for it to become fixes |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
12 destination_threshold : 20, // pixels from the top of destination for it to be considered active |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
13 throttle_delay : 30, // calculation throttling to increase framerate |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
14 fixed_top : 0, // top distance in pixels assigend to the fixed element on scroll |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
15 offset_by_height : true, // whether to offset the destination by the expedition height. Usually you want this to be true, unless your expedition is on the side. |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
16 duration : 700, // animation duration time |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
17 easing : 'swing' // animation easing |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
18 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
19 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
20 init : function (scope, method, options) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
21 Foundation.inherit(this, 'throttle'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
22 this.bindings(method, options); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
23 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
24 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
25 events : function () { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
26 var self = this, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
27 S = self.S, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
28 settings = self.settings; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
29 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
30 // initialize expedition offset |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
31 self.set_expedition_position(); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
32 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
33 S(self.scope) |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
34 .off('.magellan') |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
35 .on('click.fndtn.magellan', '[' + self.add_namespace('data-magellan-arrival') + '] a[href*=#]', function (e) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
36 var sameHost = ((this.hostname === location.hostname) || !this.hostname), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
37 samePath = self.filterPathname(location.pathname) === self.filterPathname(this.pathname), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
38 testHash = this.hash.replace(/(:|\.|\/)/g, '\\$1'), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
39 anchor = this; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
40 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
41 if (sameHost && samePath && testHash) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
42 e.preventDefault(); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
43 var expedition = $(this).closest('[' + self.attr_name() + ']'), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
44 settings = expedition.data('magellan-expedition-init'), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
45 hash = this.hash.split('#').join(''), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
46 target = $('a[name="' + hash + '"]'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
47 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
48 if (target.length === 0) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
49 target = $('#' + hash); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
50 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
51 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
52 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
53 // Account for expedition height if fixed position |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
54 var scroll_top = target.offset().top - settings.destination_threshold + 1; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
55 if (settings.offset_by_height) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
56 scroll_top = scroll_top - expedition.outerHeight(); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
57 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
58 $('html, body').stop().animate({ |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
59 'scrollTop' : scroll_top |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
60 }, settings.duration, settings.easing, function () { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
61 if (history.pushState) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
62 history.pushState(null, null, anchor.pathname + anchor.search + '#' + hash); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
63 } else { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
64 location.hash = anchor.pathname + anchor.search + '#' + hash; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
65 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
66 }); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
67 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
68 }) |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
69 .on('scroll.fndtn.magellan', self.throttle(this.check_for_arrivals.bind(this), settings.throttle_delay)); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
70 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
71 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
72 check_for_arrivals : function () { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
73 var self = this; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
74 self.update_arrivals(); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
75 self.update_expedition_positions(); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
76 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
77 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
78 set_expedition_position : function () { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
79 var self = this; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
80 $('[' + this.attr_name() + '=fixed]', self.scope).each(function (idx, el) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
81 var expedition = $(this), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
82 settings = expedition.data('magellan-expedition-init'), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
83 styles = expedition.attr('styles'), // save styles |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
84 top_offset, fixed_top; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
85 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
86 expedition.attr('style', ''); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
87 top_offset = expedition.offset().top + settings.threshold; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
88 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
89 //set fixed-top by attribute |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
90 fixed_top = parseInt(expedition.data('magellan-fixed-top')); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
91 if (!isNaN(fixed_top)) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
92 self.settings.fixed_top = fixed_top; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
93 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
94 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
95 expedition.data(self.data_attr('magellan-top-offset'), top_offset); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
96 expedition.attr('style', styles); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
97 }); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
98 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
99 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
100 update_expedition_positions : function () { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
101 var self = this, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
102 window_top_offset = $(window).scrollTop(); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
103 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
104 $('[' + this.attr_name() + '=fixed]', self.scope).each(function () { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
105 var expedition = $(this), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
106 settings = expedition.data('magellan-expedition-init'), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
107 styles = expedition.attr('style'), // save styles |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
108 top_offset = expedition.data('magellan-top-offset'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
109 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
110 //scroll to the top distance |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
111 if (window_top_offset + self.settings.fixed_top >= top_offset) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
112 // Placeholder allows height calculations to be consistent even when |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
113 // appearing to switch between fixed/non-fixed placement |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
114 var placeholder = expedition.prev('[' + self.add_namespace('data-magellan-expedition-clone') + ']'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
115 if (placeholder.length === 0) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
116 placeholder = expedition.clone(); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
117 placeholder.removeAttr(self.attr_name()); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
118 placeholder.attr(self.add_namespace('data-magellan-expedition-clone'), ''); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
119 expedition.before(placeholder); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
120 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
121 expedition.css({position :'fixed', top : settings.fixed_top}).addClass('fixed'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
122 } else { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
123 expedition.prev('[' + self.add_namespace('data-magellan-expedition-clone') + ']').remove(); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
124 expedition.attr('style', styles).css('position', '').css('top', '').removeClass('fixed'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
125 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
126 }); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
127 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
128 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
129 update_arrivals : function () { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
130 var self = this, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
131 window_top_offset = $(window).scrollTop(); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
132 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
133 $('[' + this.attr_name() + ']', self.scope).each(function () { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
134 var expedition = $(this), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
135 settings = expedition.data(self.attr_name(true) + '-init'), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
136 offsets = self.offsets(expedition, window_top_offset), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
137 arrivals = expedition.find('[' + self.add_namespace('data-magellan-arrival') + ']'), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
138 active_item = false; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
139 offsets.each(function (idx, item) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
140 if (item.viewport_offset >= item.top_offset) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
141 var arrivals = expedition.find('[' + self.add_namespace('data-magellan-arrival') + ']'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
142 arrivals.not(item.arrival).removeClass(settings.active_class); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
143 item.arrival.addClass(settings.active_class); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
144 active_item = true; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
145 return true; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
146 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
147 }); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
148 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
149 if (!active_item) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
150 arrivals.removeClass(settings.active_class); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
151 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
152 }); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
153 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
154 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
155 offsets : function (expedition, window_offset) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
156 var self = this, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
157 settings = expedition.data(self.attr_name(true) + '-init'), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
158 viewport_offset = window_offset; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
159 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
160 return expedition.find('[' + self.add_namespace('data-magellan-arrival') + ']').map(function (idx, el) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
161 var name = $(this).data(self.data_attr('magellan-arrival')), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
162 dest = $('[' + self.add_namespace('data-magellan-destination') + '=' + name + ']'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
163 if (dest.length > 0) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
164 var top_offset = dest.offset().top - settings.destination_threshold; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
165 if (settings.offset_by_height) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
166 top_offset = top_offset - expedition.outerHeight(); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
167 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
168 top_offset = Math.floor(top_offset); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
169 return { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
170 destination : dest, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
171 arrival : $(this), |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
172 top_offset : top_offset, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
173 viewport_offset : viewport_offset |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
174 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
175 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
176 }).sort(function (a, b) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
177 if (a.top_offset < b.top_offset) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
178 return -1; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
179 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
180 if (a.top_offset > b.top_offset) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
181 return 1; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
182 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
183 return 0; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
184 }); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
185 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
186 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
187 data_attr : function (str) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
188 if (this.namespace.length > 0) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
189 return this.namespace + '-' + str; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
190 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
191 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
192 return str; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
193 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
194 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
195 off : function () { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
196 this.S(this.scope).off('.magellan'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
197 this.S(window).off('.magellan'); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
198 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
199 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
200 filterPathname : function (pathname) { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
201 pathname = pathname || ''; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
202 return pathname |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
203 .replace(/^\//,'') |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
204 .replace(/(?:index|default).[a-zA-Z]{3,4}$/,'') |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
205 .replace(/\/$/,''); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
206 }, |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
207 |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
208 reflow : function () { |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
209 var self = this; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
210 // remove placeholder expeditions used for height calculation purposes |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
211 $('[' + self.add_namespace('data-magellan-expedition-clone') + ']', self.scope).remove(); |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
212 } |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
213 }; |
7abe02bf29ec
initial commit
Alex Krolick <whokilledtheelectricmonk@gmail.com>
parents:
diff
changeset
|
214 }(jQuery, window, window.document)); |