@@ 1412-1619 (lines=208) @@ | ||
1409 | ||
1410 | })(UIkit2); |
|
1411 | ||
1412 | (function(UI) { |
|
1413 | ||
1414 | "use strict"; |
|
1415 | ||
1416 | var $win = UI.$win, |
|
1417 | $doc = UI.$doc, |
|
1418 | scrollspies = [], |
|
1419 | checkScrollSpy = function() { |
|
1420 | for(var i=0; i < scrollspies.length; i++) { |
|
1421 | window.requestAnimationFrame.apply(window, [scrollspies[i].check]); |
|
1422 | } |
|
1423 | }; |
|
1424 | ||
1425 | UI.component('scrollspy', { |
|
1426 | ||
1427 | defaults: { |
|
1428 | target : false, |
|
1429 | cls : 'uk-scrollspy-inview', |
|
1430 | initcls : 'uk-scrollspy-init-inview', |
|
1431 | topoffset : 0, |
|
1432 | leftoffset : 0, |
|
1433 | repeat : false, |
|
1434 | delay : 0 |
|
1435 | }, |
|
1436 | ||
1437 | boot: function() { |
|
1438 | ||
1439 | // listen to scroll and resize |
|
1440 | $doc.on('scrolling.uk.document', checkScrollSpy); |
|
1441 | $win.on('load resize orientationchange', UI.Utils.debounce(checkScrollSpy, 50)); |
|
1442 | ||
1443 | // init code |
|
1444 | UI.ready(function(context) { |
|
1445 | ||
1446 | UI.$('[data-uk-scrollspy]', context).each(function() { |
|
1447 | ||
1448 | var element = UI.$(this); |
|
1449 | ||
1450 | if (!element.data('scrollspy')) { |
|
1451 | var obj = UI.scrollspy(element, UI.Utils.options(element.attr('data-uk-scrollspy'))); |
|
1452 | } |
|
1453 | }); |
|
1454 | }); |
|
1455 | }, |
|
1456 | ||
1457 | init: function() { |
|
1458 | ||
1459 | var $this = this, inviewstate, initinview, togglecls = this.options.cls.split(/,/), fn = function(){ |
|
1460 | ||
1461 | var elements = $this.options.target ? $this.element.find($this.options.target) : $this.element, |
|
1462 | delayIdx = elements.length === 1 ? 1 : 0, |
|
1463 | toggleclsIdx = 0; |
|
1464 | ||
1465 | elements.each(function(idx){ |
|
1466 | ||
1467 | var element = UI.$(this), |
|
1468 | inviewstate = element.data('inviewstate'), |
|
1469 | inview = UI.Utils.isInView(element, $this.options), |
|
1470 | toggle = element.attr('data-uk-scrollspy-cls') || togglecls[toggleclsIdx].trim(); |
|
1471 | ||
1472 | if (inview && !inviewstate && !element.data('scrollspy-idle')) { |
|
1473 | ||
1474 | if (!initinview) { |
|
1475 | element.addClass($this.options.initcls); |
|
1476 | $this.offset = element.offset(); |
|
1477 | initinview = true; |
|
1478 | ||
1479 | element.trigger('init.uk.scrollspy'); |
|
1480 | } |
|
1481 | ||
1482 | element.data('scrollspy-idle', setTimeout(function(){ |
|
1483 | ||
1484 | element.addClass('uk-scrollspy-inview').toggleClass(toggle).width(); |
|
1485 | element.trigger('inview.uk.scrollspy'); |
|
1486 | ||
1487 | element.data('scrollspy-idle', false); |
|
1488 | element.data('inviewstate', true); |
|
1489 | ||
1490 | }, $this.options.delay * delayIdx)); |
|
1491 | ||
1492 | delayIdx++; |
|
1493 | } |
|
1494 | ||
1495 | if (!inview && inviewstate && $this.options.repeat) { |
|
1496 | ||
1497 | if (element.data('scrollspy-idle')) { |
|
1498 | clearTimeout(element.data('scrollspy-idle')); |
|
1499 | element.data('scrollspy-idle', false); |
|
1500 | } |
|
1501 | ||
1502 | element.removeClass('uk-scrollspy-inview').toggleClass(toggle); |
|
1503 | element.data('inviewstate', false); |
|
1504 | ||
1505 | element.trigger('outview.uk.scrollspy'); |
|
1506 | } |
|
1507 | ||
1508 | toggleclsIdx = togglecls[toggleclsIdx + 1] ? (toggleclsIdx + 1) : 0; |
|
1509 | ||
1510 | }); |
|
1511 | }; |
|
1512 | ||
1513 | fn(); |
|
1514 | ||
1515 | this.check = fn; |
|
1516 | ||
1517 | scrollspies.push(this); |
|
1518 | } |
|
1519 | }); |
|
1520 | ||
1521 | ||
1522 | var scrollspynavs = [], |
|
1523 | checkScrollSpyNavs = function() { |
|
1524 | for(var i=0; i < scrollspynavs.length; i++) { |
|
1525 | window.requestAnimationFrame.apply(window, [scrollspynavs[i].check]); |
|
1526 | } |
|
1527 | }; |
|
1528 | ||
1529 | UI.component('scrollspynav', { |
|
1530 | ||
1531 | defaults: { |
|
1532 | cls : 'uk-active', |
|
1533 | closest : false, |
|
1534 | topoffset : 0, |
|
1535 | leftoffset : 0, |
|
1536 | smoothscroll : false |
|
1537 | }, |
|
1538 | ||
1539 | boot: function() { |
|
1540 | ||
1541 | // listen to scroll and resize |
|
1542 | $doc.on('scrolling.uk.document', checkScrollSpyNavs); |
|
1543 | $win.on('resize orientationchange', UI.Utils.debounce(checkScrollSpyNavs, 50)); |
|
1544 | ||
1545 | // init code |
|
1546 | UI.ready(function(context) { |
|
1547 | ||
1548 | UI.$('[data-uk-scrollspy-nav]', context).each(function() { |
|
1549 | ||
1550 | var element = UI.$(this); |
|
1551 | ||
1552 | if (!element.data('scrollspynav')) { |
|
1553 | var obj = UI.scrollspynav(element, UI.Utils.options(element.attr('data-uk-scrollspy-nav'))); |
|
1554 | } |
|
1555 | }); |
|
1556 | }); |
|
1557 | }, |
|
1558 | ||
1559 | init: function() { |
|
1560 | ||
1561 | var ids = [], |
|
1562 | links = this.find("a[href^='#']").each(function(){ if(this.getAttribute('href').trim()!=='#') ids.push(this.getAttribute('href')); }), |
|
1563 | targets = UI.$(ids.join(",")), |
|
1564 | ||
1565 | clsActive = this.options.cls, |
|
1566 | clsClosest = this.options.closest || this.options.closest; |
|
1567 | ||
1568 | var $this = this, inviews, fn = function(){ |
|
1569 | ||
1570 | inviews = []; |
|
1571 | ||
1572 | for (var i=0 ; i < targets.length ; i++) { |
|
1573 | if (UI.Utils.isInView(targets.eq(i), $this.options)) { |
|
1574 | inviews.push(targets.eq(i)); |
|
1575 | } |
|
1576 | } |
|
1577 | ||
1578 | if (inviews.length) { |
|
1579 | ||
1580 | var navitems, |
|
1581 | scrollTop = $win.scrollTop(), |
|
1582 | target = (function(){ |
|
1583 | for(var i=0; i< inviews.length;i++){ |
|
1584 | if (inviews[i].offset().top - $this.options.topoffset >= scrollTop){ |
|
1585 | return inviews[i]; |
|
1586 | } |
|
1587 | } |
|
1588 | })(); |
|
1589 | ||
1590 | if (!target) return; |
|
1591 | ||
1592 | if ($this.options.closest) { |
|
1593 | links.blur().closest(clsClosest).removeClass(clsActive); |
|
1594 | navitems = links.filter("a[href='#"+target.attr('id')+"']").closest(clsClosest).addClass(clsActive); |
|
1595 | } else { |
|
1596 | navitems = links.removeClass(clsActive).filter("a[href='#"+target.attr("id")+"']").addClass(clsActive); |
|
1597 | } |
|
1598 | ||
1599 | $this.element.trigger('inview.uk.scrollspynav', [target, navitems]); |
|
1600 | } |
|
1601 | }; |
|
1602 | ||
1603 | if (this.options.smoothscroll && UI.smoothScroll) { |
|
1604 | links.each(function(){ |
|
1605 | UI.smoothScroll(this, $this.options.smoothscroll); |
|
1606 | }); |
|
1607 | } |
|
1608 | ||
1609 | fn(); |
|
1610 | ||
1611 | this.element.data('scrollspynav', this); |
|
1612 | ||
1613 | this.check = fn; |
|
1614 | scrollspynavs.push(this); |
|
1615 | ||
1616 | } |
|
1617 | }); |
|
1618 | ||
1619 | })(UIkit2); |
|
1620 | ||
1621 | (function(UI){ |
|
1622 |
@@ 2-209 (lines=208) @@ | ||
1 | /*! UIkit 2.27.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ |
|
2 | (function(UI) { |
|
3 | ||
4 | "use strict"; |
|
5 | ||
6 | var $win = UI.$win, |
|
7 | $doc = UI.$doc, |
|
8 | scrollspies = [], |
|
9 | checkScrollSpy = function() { |
|
10 | for(var i=0; i < scrollspies.length; i++) { |
|
11 | window.requestAnimationFrame.apply(window, [scrollspies[i].check]); |
|
12 | } |
|
13 | }; |
|
14 | ||
15 | UI.component('scrollspy', { |
|
16 | ||
17 | defaults: { |
|
18 | target : false, |
|
19 | cls : 'uk-scrollspy-inview', |
|
20 | initcls : 'uk-scrollspy-init-inview', |
|
21 | topoffset : 0, |
|
22 | leftoffset : 0, |
|
23 | repeat : false, |
|
24 | delay : 0 |
|
25 | }, |
|
26 | ||
27 | boot: function() { |
|
28 | ||
29 | // listen to scroll and resize |
|
30 | $doc.on('scrolling.uk.document', checkScrollSpy); |
|
31 | $win.on('load resize orientationchange', UI.Utils.debounce(checkScrollSpy, 50)); |
|
32 | ||
33 | // init code |
|
34 | UI.ready(function(context) { |
|
35 | ||
36 | UI.$('[data-uk-scrollspy]', context).each(function() { |
|
37 | ||
38 | var element = UI.$(this); |
|
39 | ||
40 | if (!element.data('scrollspy')) { |
|
41 | var obj = UI.scrollspy(element, UI.Utils.options(element.attr('data-uk-scrollspy'))); |
|
42 | } |
|
43 | }); |
|
44 | }); |
|
45 | }, |
|
46 | ||
47 | init: function() { |
|
48 | ||
49 | var $this = this, inviewstate, initinview, togglecls = this.options.cls.split(/,/), fn = function(){ |
|
50 | ||
51 | var elements = $this.options.target ? $this.element.find($this.options.target) : $this.element, |
|
52 | delayIdx = elements.length === 1 ? 1 : 0, |
|
53 | toggleclsIdx = 0; |
|
54 | ||
55 | elements.each(function(idx){ |
|
56 | ||
57 | var element = UI.$(this), |
|
58 | inviewstate = element.data('inviewstate'), |
|
59 | inview = UI.Utils.isInView(element, $this.options), |
|
60 | toggle = element.attr('data-uk-scrollspy-cls') || togglecls[toggleclsIdx].trim(); |
|
61 | ||
62 | if (inview && !inviewstate && !element.data('scrollspy-idle')) { |
|
63 | ||
64 | if (!initinview) { |
|
65 | element.addClass($this.options.initcls); |
|
66 | $this.offset = element.offset(); |
|
67 | initinview = true; |
|
68 | ||
69 | element.trigger('init.uk.scrollspy'); |
|
70 | } |
|
71 | ||
72 | element.data('scrollspy-idle', setTimeout(function(){ |
|
73 | ||
74 | element.addClass('uk-scrollspy-inview').toggleClass(toggle).width(); |
|
75 | element.trigger('inview.uk.scrollspy'); |
|
76 | ||
77 | element.data('scrollspy-idle', false); |
|
78 | element.data('inviewstate', true); |
|
79 | ||
80 | }, $this.options.delay * delayIdx)); |
|
81 | ||
82 | delayIdx++; |
|
83 | } |
|
84 | ||
85 | if (!inview && inviewstate && $this.options.repeat) { |
|
86 | ||
87 | if (element.data('scrollspy-idle')) { |
|
88 | clearTimeout(element.data('scrollspy-idle')); |
|
89 | element.data('scrollspy-idle', false); |
|
90 | } |
|
91 | ||
92 | element.removeClass('uk-scrollspy-inview').toggleClass(toggle); |
|
93 | element.data('inviewstate', false); |
|
94 | ||
95 | element.trigger('outview.uk.scrollspy'); |
|
96 | } |
|
97 | ||
98 | toggleclsIdx = togglecls[toggleclsIdx + 1] ? (toggleclsIdx + 1) : 0; |
|
99 | ||
100 | }); |
|
101 | }; |
|
102 | ||
103 | fn(); |
|
104 | ||
105 | this.check = fn; |
|
106 | ||
107 | scrollspies.push(this); |
|
108 | } |
|
109 | }); |
|
110 | ||
111 | ||
112 | var scrollspynavs = [], |
|
113 | checkScrollSpyNavs = function() { |
|
114 | for(var i=0; i < scrollspynavs.length; i++) { |
|
115 | window.requestAnimationFrame.apply(window, [scrollspynavs[i].check]); |
|
116 | } |
|
117 | }; |
|
118 | ||
119 | UI.component('scrollspynav', { |
|
120 | ||
121 | defaults: { |
|
122 | cls : 'uk-active', |
|
123 | closest : false, |
|
124 | topoffset : 0, |
|
125 | leftoffset : 0, |
|
126 | smoothscroll : false |
|
127 | }, |
|
128 | ||
129 | boot: function() { |
|
130 | ||
131 | // listen to scroll and resize |
|
132 | $doc.on('scrolling.uk.document', checkScrollSpyNavs); |
|
133 | $win.on('resize orientationchange', UI.Utils.debounce(checkScrollSpyNavs, 50)); |
|
134 | ||
135 | // init code |
|
136 | UI.ready(function(context) { |
|
137 | ||
138 | UI.$('[data-uk-scrollspy-nav]', context).each(function() { |
|
139 | ||
140 | var element = UI.$(this); |
|
141 | ||
142 | if (!element.data('scrollspynav')) { |
|
143 | var obj = UI.scrollspynav(element, UI.Utils.options(element.attr('data-uk-scrollspy-nav'))); |
|
144 | } |
|
145 | }); |
|
146 | }); |
|
147 | }, |
|
148 | ||
149 | init: function() { |
|
150 | ||
151 | var ids = [], |
|
152 | links = this.find("a[href^='#']").each(function(){ if(this.getAttribute('href').trim()!=='#') ids.push(this.getAttribute('href')); }), |
|
153 | targets = UI.$(ids.join(",")), |
|
154 | ||
155 | clsActive = this.options.cls, |
|
156 | clsClosest = this.options.closest || this.options.closest; |
|
157 | ||
158 | var $this = this, inviews, fn = function(){ |
|
159 | ||
160 | inviews = []; |
|
161 | ||
162 | for (var i=0 ; i < targets.length ; i++) { |
|
163 | if (UI.Utils.isInView(targets.eq(i), $this.options)) { |
|
164 | inviews.push(targets.eq(i)); |
|
165 | } |
|
166 | } |
|
167 | ||
168 | if (inviews.length) { |
|
169 | ||
170 | var navitems, |
|
171 | scrollTop = $win.scrollTop(), |
|
172 | target = (function(){ |
|
173 | for(var i=0; i< inviews.length;i++){ |
|
174 | if (inviews[i].offset().top - $this.options.topoffset >= scrollTop){ |
|
175 | return inviews[i]; |
|
176 | } |
|
177 | } |
|
178 | })(); |
|
179 | ||
180 | if (!target) return; |
|
181 | ||
182 | if ($this.options.closest) { |
|
183 | links.blur().closest(clsClosest).removeClass(clsActive); |
|
184 | navitems = links.filter("a[href='#"+target.attr('id')+"']").closest(clsClosest).addClass(clsActive); |
|
185 | } else { |
|
186 | navitems = links.removeClass(clsActive).filter("a[href='#"+target.attr("id")+"']").addClass(clsActive); |
|
187 | } |
|
188 | ||
189 | $this.element.trigger('inview.uk.scrollspynav', [target, navitems]); |
|
190 | } |
|
191 | }; |
|
192 | ||
193 | if (this.options.smoothscroll && UI.smoothScroll) { |
|
194 | links.each(function(){ |
|
195 | UI.smoothScroll(this, $this.options.smoothscroll); |
|
196 | }); |
|
197 | } |
|
198 | ||
199 | fn(); |
|
200 | ||
201 | this.element.data('scrollspynav', this); |
|
202 | ||
203 | this.check = fn; |
|
204 | scrollspynavs.push(this); |
|
205 | ||
206 | } |
|
207 | }); |
|
208 | ||
209 | })(UIkit2); |
|
210 |