Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Make tree-view expansions and contractions persist on a "Back" in Chrome and IE. (Works without the extra javascript on Firefox and Safari.) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: | ab00f2b007d5229da6868718bad9ce12 |
User & Date: | drh 2014-01-15 02:54:03 |
Context
2014-01-15
| ||
11:43 | Avoid unnecessary no-op write transactions on the server during a pull. check-in: b4dffdac user: drh tags: trunk | |
02:54 | Make tree-view expansions and contractions persist on a "Back" in Chrome and IE. (Works without the extra javascript on Firefox and Safari.) check-in: ab00f2b0 user: drh tags: trunk | |
01:55 | Add missing "var". Closed-Leaf check-in: cdd441f8 user: joel tags: tree-view-enhancements | |
01:29 | Improve a comment. check-in: 5e368e91 user: mistachkin tags: trunk | |
Changes
Changes to src/browse.c.
416 417 418 419 420 421 422 423 424 425 426 427 428 429 ... 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 ... 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
char *zREx = ""; /* Extra parameters for path hyperlinks */ ReCompiled *pRE = 0; /* Compiled regular expression */ FileTreeNode *p; /* One line of the tree */ FileTree sTree; /* The complete tree of files */ HQuery sURI; /* Hyperlink */ int startExpanded; /* True to start out with the tree expanded */ int showDirOnly; /* Show directories only. Omit files */ char *zProjectName = db_get("project-name", 0); if( strcmp(PD("type",""),"flat")==0 ){ page_dir(); return; } memset(&sTree, 0, sizeof(sTree)); login_check_credentials(); if( !g.perm.Read ){ login_needed(); return; } while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; } ................................................................................ if( nD ){ @ <li class="dir"> }else{ @ <li class="dir subdir"> } @ %z(href("%s",url_render(&sURI,"name",0,0,0)))%h(zProjectName)</a> @ <ul> for(p=sTree.pFirst; p; p=p->pNext){ if( p->isDir ){ if( p->nFullName==nD-1 ){ @ <li class="dir subdir"> }else{ @ <li class="dir"> } @ %z(href("%s",url_render(&sURI,"name",p->zFullName,0,0)))%h(p->zName)</a> if( startExpanded || p->nFullName<=nD ){ @ <ul> }else{ @ <ul style='display:none;'> } }else if( !showDirOnly ){ char *zLink; if( zCI ){ zLink = href("%R/artifact/%S",p->zUuid); }else{ zLink = href("%R/finfo?name=%T",p->zFullName); } ................................................................................ @ </ul> } } } @ </ul> @ </ul></div> @ <script>(function(){ @ function style(elem, prop){ @ return window.getComputedStyle(elem).getPropertyValue(prop); @ } @ @ function toggleAll(tree){ @ var lists = tree.querySelectorAll('.subdir > ul > li ul'); @ var display = 'block'; /* Default action: make all sublists visible */ @ for( var i=0; lists[i]; i++ ){ @ if( style(lists[i], 'display')!='none'){ @ display = 'none'; /* Any already visible - make them all hidden */ @ break; @ } @ } @ for( var i=0; lists[i]; i++ ){ @ lists[i].style.display = display; @ } @ } @ @ var outer_ul = document.querySelector('.filetree > ul'); @ var subdir = outer_ul.querySelector('.subdir'); @ outer_ul.onclick = function( e ){ @ var a = e.target; @ if( a.nodeName!='A' ) return true; @ if( a.parentNode==subdir ){ @ toggleAll(outer_ul); @ return false; @ } @ if( !subdir.contains(a) ) return true; @ var ul = a.nextSibling; @ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling; @ if( !ul ) return true; /* This is a file link, not a directory */ @ ul.style.display = style(ul, 'display')=='none' ? 'block' : 'none'; @ return false; @ } @ }())</script> style_footer(); /* We could free memory used by sTree here if we needed to. But ** the process is about to exit, so doing so would not really accomplish |
> | | | > | | > > > > > > > > > | > | | < > | > | > > > | > > > > > > > > > > > > | | |
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 ... 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 ... 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 |
char *zREx = ""; /* Extra parameters for path hyperlinks */ ReCompiled *pRE = 0; /* Compiled regular expression */ FileTreeNode *p; /* One line of the tree */ FileTree sTree; /* The complete tree of files */ HQuery sURI; /* Hyperlink */ int startExpanded; /* True to start out with the tree expanded */ int showDirOnly; /* Show directories only. Omit files */ int nDir = 0; /* Number of directories. Used for ID attributes */ char *zProjectName = db_get("project-name", 0); if( strcmp(PD("type",""),"flat")==0 ){ page_dir(); return; } memset(&sTree, 0, sizeof(sTree)); login_check_credentials(); if( !g.perm.Read ){ login_needed(); return; } while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; } ................................................................................ if( nD ){ @ <li class="dir"> }else{ @ <li class="dir subdir"> } @ %z(href("%s",url_render(&sURI,"name",0,0,0)))%h(zProjectName)</a> @ <ul> for(p=sTree.pFirst, nDir=0; p; p=p->pNext){ if( p->isDir ){ if( p->nFullName==nD-1 ){ @ <li class="dir subdir"> }else{ @ <li class="dir"> } @ %z(href("%s",url_render(&sURI,"name",p->zFullName,0,0)))%h(p->zName)</a> if( startExpanded || p->nFullName<=nD ){ @ <ul id="dir%d(nDir)"> }else{ @ <ul id="dir%d(nDir)" style='display:none;'> } nDir++; }else if( !showDirOnly ){ char *zLink; if( zCI ){ zLink = href("%R/artifact/%S",p->zUuid); }else{ zLink = href("%R/finfo?name=%T",p->zFullName); } ................................................................................ @ </ul> } } } @ </ul> @ </ul></div> @ <script>(function(){ @ function isExpanded(ul){ @ var display = window.getComputedStyle(ul).getPropertyValue('display'); @ return display!='none'; @ } @ @ function toggleDir(ul, useInitValue){ @ if( !useInitValue ){ @ expandMap[ul.id] = !isExpanded(ul); @ history.replaceState(expandMap, ''); @ } @ ul.style.display = expandMap[ul.id] ? 'block' : 'none'; @ } @ @ function toggleAll(tree, useInitValue){ @ var lists = tree.querySelectorAll('.subdir > ul > li ul'); @ if( !useInitValue ){ @ var expand = true; /* Default action: make all sublists visible */ @ for( var i=0; lists[i]; i++ ){ @ if( isExpanded(lists[i]) ){ @ expand = false; /* Any already visible - make them all hidden */ @ break; @ } @ } @ expandMap = {'*': expand}; @ history.replaceState(expandMap, ''); @ } @ var display = expandMap['*'] ? 'block' : 'none'; @ for( var i=0; lists[i]; i++ ){ @ lists[i].style.display = display; @ } @ } @ @ function checkState(){ @ expandMap = history.state || {}; @ if( expandMap['*'] ) toggleAll(outer_ul, true); @ for( var id in expandMap ){ @ if( id!=='*' ) toggleDir(gebi(id), true); @ } @ } @ @ /* No-op shim for IE9 */ @ if( !history.replaceState ) history.replaceState = function(){}; @ var outer_ul = document.querySelector('.filetree > ul'); @ var subdir = outer_ul.querySelector('.subdir'); @ var expandMap = {}; @ checkState(); @ outer_ul.onclick = function(e){ @ var a = e.target; @ if( a.nodeName!='A' ) return true; @ if( a.parentNode==subdir ){ @ toggleAll(outer_ul); @ return false; @ } @ if( !subdir.contains(a) ) return true; @ var ul = a.nextSibling; @ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling; @ if( !ul ) return true; /* This is a file link, not a directory */ @ toggleDir(ul); @ return false; @ } @ }())</script> style_footer(); /* We could free memory used by sTree here if we needed to. But ** the process is about to exit, so doing so would not really accomplish |