12 var navComponentLinks;
20 var initialize = function () {
25 bod = $(document.body)
26 iphone = iphone || $('.iphone');
27 noticeBanner = $('.notice-banner');
28 navComponentLinks = $('.nav-components-link');
29 componentsList = $('.components-list');
30 componentLinks = $('.component-example a');
31 contentSection = $('.component');
32 topCache = contentSection.map(function () { return $(this).offset().top })
33 windowHeight = $(window).height() / 3
34 pageHeight = $(document).height();
35 contentPadding = parseInt($('.docs-content').css('padding-bottom'));
36 footerHeight = $('.docs-footer').outerHeight(false);
38 iphone.initialLeft = iphone.offset().left;
39 iphone.initialTop = iphone.initialTop || iphone.offset().top;
40 iphone.dockingOffset = ($(window).height() + 20 + $('.docs-masthead').height() - iphone.height())/2;
41 checkDesktopContent();
44 if (!eventListeners) addEventListeners();
47 var addEventListeners = function () {
48 eventListeners = true;
50 noticeBanner.on('click', function () {
54 iphone.on('click', function (e) {
58 navComponentLinks.click(function(e) {
61 componentsList.toggleClass('active');
64 doc.on('click', function () {
65 componentsList.removeClass('active');
68 win.on('scroll', calculateScroll);
71 var checkDesktopContent = function () {
72 windowWidth = $(window).width();
73 if (windowWidth <= 768) {
74 var content = $('.content')
75 if (content.length > 1) {
76 $(content[0]).remove()
81 var calculateScroll = function() {
82 // if small screen don't worry about this
83 if (windowWidth <= 768) return
85 // Save scrollTop value
86 var contentSectionItem;
87 var currentTop = win.scrollTop();
89 // If page is scrolled to bottom near footers
90 if(pageHeight - currentTop < footerHeight + contentPadding + 1400) {
91 iphone[0].className = "iphone iphone-bottom";
92 iphone[0].setAttribute('style','')
93 } else if((iphone.initialTop - currentTop) <= iphone.dockingOffset) {
94 iphone[0].className = "iphone iphone-fixed";
95 iphone.css({top: iphone.dockingOffset})
97 iphone[0].className = "iphone"
98 iphone[0].setAttribute('style','')
101 // Injection of components into phone
102 for (var l = contentSection.length; l--;) {
103 if ((topCache[l] - currentTop) < windowHeight) {
104 if (currentActive == l) return;
106 bod.find('.component.active').removeClass('active');
107 contentSectionItem = $(contentSection[l])
108 contentSectionItem.addClass('active')
109 if(contentSectionItem.attr('id')) {
110 iphone.attr("id", contentSectionItem.attr('id') + "InPhone");
112 iphone.attr("id", "")
114 if (!contentSectionItem.hasClass('informational')) {
115 updateContent(contentSectionItem.find('.prettyprint').not('.js').text())
121 function updateContent(content) {
122 $('#iwindow').html(content);
126 $(window).on('load resize', initialize);
127 $(window).on('load', function () { new FingerBlast('.iphone-content'); });