diff options
author | Dimitri van Heesch <dimitri@stack.nl> | 2016-05-01 08:05:39 (GMT) |
---|---|---|
committer | Dimitri van Heesch <dimitri@stack.nl> | 2016-05-05 19:40:39 (GMT) |
commit | 8480d35beef57ed08139b58972bfb83a3b37422c (patch) | |
tree | 13d486ed244ee6382a88d5d3312f0ea01b5131be /templates/html/resize.js | |
parent | 33915cdce6b66af7e0f8d3e98d741df6e9cc5e32 (diff) | |
download | Doxygen-8480d35beef57ed08139b58972bfb83a3b37422c.zip Doxygen-8480d35beef57ed08139b58972bfb83a3b37422c.tar.gz Doxygen-8480d35beef57ed08139b58972bfb83a3b37422c.tar.bz2 |
Applied responsive design to menu bar using smartmenus
Diffstat (limited to 'templates/html/resize.js')
-rw-r--r-- | templates/html/resize.js | 141 |
1 files changed, 86 insertions, 55 deletions
diff --git a/templates/html/resize.js b/templates/html/resize.js index 76c1a6b..2066667 100644 --- a/templates/html/resize.js +++ b/templates/html/resize.js @@ -1,84 +1,114 @@ -var cookie_namespace = 'doxygen'; -var sidenav,navtree,content,header; - -function readCookie(cookie) +function initResizable() { - var myCookie = cookie_namespace+"_"+cookie+"="; - if (document.cookie) + var cookie_namespace = 'doxygen'; + var sidenav,navtree,content,header,collapsed,collapsedWidth=0,barWidth=6,desktop_vp=768,titleHeight; + + function readCookie(cookie) { - var index = document.cookie.indexOf(myCookie); - if (index != -1) - { - var valStart = index + myCookie.length; - var valEnd = document.cookie.indexOf(";", valStart); - if (valEnd == -1) - { - valEnd = document.cookie.length; + var myCookie = cookie_namespace+"_"+cookie+"="; + if (document.cookie) { + var index = document.cookie.indexOf(myCookie); + if (index != -1) { + var valStart = index + myCookie.length; + var valEnd = document.cookie.indexOf(";", valStart); + if (valEnd == -1) { + valEnd = document.cookie.length; + } + var val = document.cookie.substring(valStart, valEnd); + return val; } - var val = document.cookie.substring(valStart, valEnd); - return val; } + return 0; } - return 0; -} -function writeCookie(cookie, val, expiration) -{ - if (val==undefined) return; - if (expiration == null) + function writeCookie(cookie, val, expiration) { - var date = new Date(); - date.setTime(date.getTime()+(10*365*24*60*60*1000)); // default expiration is one week - expiration = date.toGMTString(); + if (val==undefined) return; + if (expiration == null) { + var date = new Date(); + date.setTime(date.getTime()+(10*365*24*60*60*1000)); // default expiration is one week + expiration = date.toGMTString(); + } + document.cookie = cookie_namespace + "_" + cookie + "=" + val + "; expires=" + expiration+"; path=/"; } - document.cookie = cookie_namespace + "_" + cookie + "=" + val + "; expires=" + expiration+"; path=/"; -} - -function resizeWidth() -{ - var windowWidth = $(window).width() + "px"; - var sidenavWidth = $(sidenav).outerWidth(); - content.css({marginLeft:parseInt(sidenavWidth)+"px"}); - writeCookie('width',sidenavWidth, null); -} -function restoreWidth(navWidth) -{ - var windowWidth = $(window).width() + "px"; - content.css({marginLeft:parseInt(navWidth)+6+"px"}); - sidenav.css({width:navWidth + "px"}); -} + function resizeWidth() + { + var windowWidth = $(window).width() + "px"; + var sidenavWidth = $(sidenav).outerWidth(); + content.css({marginLeft:parseInt(sidenavWidth)+"px"}); + writeCookie('width',sidenavWidth-barWidth, null); + } -function resizeHeight() -{ - var headerHeight = header.outerHeight(); - var footerHeight = footer.outerHeight(); - var windowHeight = $(window).height() - headerHeight - footerHeight; - content.css({height:windowHeight + "px"}); - navtree.css({height:windowHeight + "px"}); - sidenav.css({height:windowHeight + "px"}); -} + function restoreWidth(navWidth) + { + var windowWidth = $(window).width() + "px"; + content.css({marginLeft:parseInt(navWidth)+barWidth+"px"}); + sidenav.css({width:navWidth + "px"}); + } + + function resizeHeight() + { + var headerHeight = header.outerHeight(); + var footerHeight = footer.outerHeight(); + var windowHeight = $(window).height() - headerHeight - footerHeight; + content.css({height:windowHeight + "px"}); + navtree.css({height:windowHeight + "px"}); + sidenav.css({height:windowHeight + "px"}); + var width=$(window).width(); + if (width!=collapsedWidth) { + if (width<desktop_vp && collapsedWidth>=desktop_vp) { + if (!collapsed) { + collapseExpand(); + } + } else if (width>desktop_vp && collapsedWidth<desktop_vp) { + if (collapsed) { + collapseExpand(); + } + } + collapsedWidth=width; + } + } + + function collapseExpand() + { + if (sidenav.width()>0) { + restoreWidth(0); + collapsed=true; + } + else { + var width = readCookie('width'); + if (width>200 && width<$(window).width()) { restoreWidth(width); } else { restoreWidth(200); } + collapsed=false; + } + } -function initResizable() -{ header = $("#top"); sidenav = $("#side-nav"); content = $("#doc-content"); navtree = $("#nav-tree"); footer = $("#nav-path"); $(".side-nav-resizable").resizable({resize: function(e, ui) { resizeWidth(); } }); + $(sidenav).resizable({ minWidth: 0 }); $(window).resize(function() { resizeHeight(); }); + var device = navigator.userAgent.toLowerCase(); + var ios_or_android = device.match(/(iphone|ipod|ipad|android)/); + if (ios_or_android) { /* wider split bar for touch only devices */ + $(sidenav).css({ paddingRight:'20px' }); + $('.ui-resizable-e').css({ width:'20px' }); + console.log('ui='+$('.ui-resizable-e').width()); + $('#nav-sync').css({ right:'34px' }); + barWidth=20; + } var width = readCookie('width'); if (width) { restoreWidth(width); } else { resizeWidth(); } - resizeHeight(); var url = location.href; var i=url.indexOf("#"); if (i>=0) window.location.hash=url.substr(i); var _preventDefault = function(evt) { evt.preventDefault(); }; $("#splitbar").bind("dragstart", _preventDefault).bind("selectstart", _preventDefault); + $(".ui-resizable-handle").dblclick(collapseExpand); $(document).bind('touchmove',function(e){ - var device = navigator.userAgent.toLowerCase(); - var ios_or_android = device.match(/(iphone|ipod|ipad|android)/); if (ios_or_android) { try { var target = e.target; @@ -92,6 +122,7 @@ function initResizable() } } }); + $(window).load(resizeHeight); } |