1function getView() { 2 var cookie = getCookie('deviceView'), 3 isMobile; 4 5 if (cookie) { 6 isMobile = cookie == 'mobile'; 7 } else { 8 isMobile = isMobileDevice(); 9 } 10 11 return isMobile ? 'mobile' : 'desktop'; 12} 13 14function toggleDeviceView() { 15 if (getView() == 'mobile') { 16 setCookie('deviceView', 'desktop', 365, true); 17 } else { 18 setCookie('deviceView', 'mobile', 365, true); 19 } 20 21 location.reload(); 22} 23 24function isMobileDevice() { 25 var isMobile = false, 26 htmlTagClasses = css_browser_selector(navigator.userAgent), 27 resolution, 28 mobileResolution = 640; //iPhone 29 30 if (htmlTagClasses.indexOf('mobile') > -1) { 31 isMobile = true; 32 } 33 34 // Set opera mobile as mobile device. 35 if (htmlTagClasses.indexOf('opera') > -1 && htmlTagClasses.indexOf('linux') > -1) { 36 isMobile = true; 37 } 38 39 if (window.screen) { 40 resolution = Math.min(window.screen.width, window.screen.height); 41 42 // Set large devices as desktop. 43 if (isMobile && resolution > mobileResolution) { 44 isMobile = false; 45 } 46 } 47 48 return isMobile; 49} 50 51function showMobileView($) { 52 var meta, 53 html = $('html'), emptyClass = 'container-empty', 54 contentNode, firstNavigationWidget, headerContainer; 55 56 // Add viewport meta tag for mobile browsers 57 if (!$('meta[name="viewport"]').length) { 58 meta = document.createElement('meta'); 59 meta.name = 'viewport'; 60 meta.content = 'width=device-width, initial-scale=1, user-scalable=1'; 61 document.getElementsByTagName('head')[0].appendChild(meta); 62 } 63 64 html.addClass('mobile-view'); 65 66 // set content before sidebars 67 contentNode = document.getElementById('content'); 68 contentNode.parentNode.insertBefore(contentNode, contentNode.parentNode.firstChild); 69 70 // Attach mobile navigation to content 71 $('ul.navigation a:not([href*="#"])').each(function() { 72 var $this = $(this), 73 linkPath = $this.attr('href'); 74 $this.attr('href', linkPath + '#content-content-inner'); 75 }); 76 77 //Move the first navigation widget to the top if it isn't there 78 firstNavigationWidget = $('.widget-navigation').first(); 79 firstNavigationWidget.addClass('navigation-first'); 80 firstNavigationWidget.parent().show(); 81 if (firstNavigationWidget[0] != $('.widget').first()[0]) { 82 firstNavigationWidget.prependTo('#header-content-inner'); 83 84 headerContainer = $('.container.header').first(); 85 if (headerContainer.hasClass(emptyClass)) { 86 headerContainer.removeClass(emptyClass); 87 } 88 } 89 90 // Some mobile browsers don't handle anchor links. We should force scrolling. 91 if (window.location.hash) { 92 html.animate({ 93 scrollTop: $(window.location.hash).offset().top 94 }, 750); 95 } 96 97 $('.mobile-view-switcher').html(window.mobileSwitcherText); 98} 99 100function showDesktopView($) { 101 $('html').removeClass('mobile-view'); 102 $('.mobile-view-switcher').html(window.desktopSwitcherText); 103} 104 105function showMobileSwitcher($) { 106 $('.mobile-view-switcher') 107 .show() 108 .click(function (e) { 109 e.preventDefault(); 110 toggleDeviceView(); 111 }); 112} 113 114(function($) { 115 $(function() { 116 if (getView() == 'mobile') { 117 showMobileView($); 118 } else { 119 showDesktopView($); 120 } 121 122 if (isMobileDevice()) { 123 showMobileSwitcher($); 124 } 125 }); 126})(siteBuilderJs);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.