1 <!DOCTYPE HTML> 2 <html i18n-values="dir:textdirection;"> 3 <head> 4 <meta charset="utf-8"> 5 <title i18n-content="title"></title> 6 <link rel="icon" href="../../app/theme/downloads_favicon.png"> 7 <style type="text/css"> 8 div.header { 9 border-bottom: 1px solid #7289E2; 10 padding: 8px; 11 margin: 0; 12 width: 100%; 13 left: 0; 14 top: 0; 15 height: 32px; 16 position: absolute; 17 box-sizing: border-box; 18 background-image: -webkit-linear-gradient(#D0DAF8, #A6BAF7); 19 border-bottom-color: #999; 20 border-bottom-width: 1px; 21 border-left-color: #999; 22 border-left-width: 1px; 23 border-right-color: #999; 24 border-right-width: 1px; 25 color: black; 26 } 27 28 *:-khtml-drag { 29 background-color: rgba(238,238,238, 0.5); 30 } 31 32 *[draggable] { 33 -khtml-user-drag: element; 34 cursor: move; 35 } 36 37 .rowlink { 38 height: 100%; 39 width: 90%; 40 cursor: pointer; 41 } 42 43 .status { 44 position: absolute; 45 display: none; 46 bottom: 0; 47 left: 0; 48 right: 0; 49 height: 24px; 50 border-top-color: #999; 51 border-top-width: 1px; 52 padding-top: 6px; 53 padding-left: 10px; 54 background-image: -webkit-linear-gradient(#D0DAF8, #A6BAF7); 55 } 56 .deleteYesNoContainer { 57 display: -webkit-box; 58 -webkit-box-align: center; 59 -webkit-box-pack: center; 60 } 61 .deleteYes { 62 margin: 4px; 63 text-decoration: underline; 64 color: blue; 65 } 66 67 .deleteNo { 68 margin: 4px; 69 text-decoration: underline; 70 color: blue; 71 } 72 73 .confirmdelete { 74 text-align: center; 75 border: 1px solid rgba(0, 0, 0, 0.25); 76 border-radius: 2px; 77 min-height: 36px; 78 padding: 4px; 79 } 80 81 .link { 82 color: blue; 83 text-decoration: underline; 84 float: left; 85 margin-left: 5px; 86 margin-right: 5px; 87 } 88 89 .prompt { 90 float: left; 91 text-decoration: none; 92 color: black; 93 margin-left: 5px; 94 margin-right: 5px; 95 cursor: default; 96 } 97 98 a.iconlink { 99 display: block; 100 font-weight: bold; 101 font-size: 11px; 102 color: white; 103 text-decoration: none; 104 } 105 106 a.iconlink img { 107 margin-bottom: 5px; 108 } 109 110 ul.filebrowselist { 111 list-style-type: none; 112 margin: 0; 113 padding: 0; 114 position: relative; 115 } 116 117 .playbackelement { 118 width: 600px; 119 height: 600px; 120 position: fixed; 121 right: 0; 122 top: 0; 123 z-index: 99999; 124 background: black; 125 } 126 127 .fullscreenplayback { 128 width: 100%; 129 height: 100%; 130 position: fixed; 131 left: 0; 132 top: 0; 133 z-index: 99999; 134 background: black; 135 } 136 137 .downloading { 138 background: white; 139 } 140 141 .imagepreview { 142 width: 600px; 143 position: fixed; 144 right: 0; 145 top: 0; 146 z-index: 99999; 147 background: black; 148 } 149 150 .fullscreentoggle { 151 top: 0; 152 right: 0; 153 width: 50px; 154 height: 50px; 155 z-index: 999999; 156 cursor: pointer; 157 background: url('shared/images/filebrowse_fullscreen.png'); 158 position: absolute; 159 background-repeat: no-repeat; 160 } 161 162 li.filebrowserow div.icon { 163 float: left; 164 margin-left: -44px; 165 margin-top: -3px; 166 display: inline 167 position: relative; 168 width: 21px; 169 height: 17px; 170 background-repeat: no-repeat; 171 } 172 173 .rightarrow { 174 opacity: 0.5; 175 position: absolute; 176 right: 22px; 177 top: 8px; 178 } 179 180 .menuicon { 181 position: absolute; 182 right: 4px; 183 top: 5px; 184 height: 100%; 185 width: 15px; 186 margin-left: 0; 187 background: url('shared/images/filebrowse_menu.png'); 188 margin-top: 5px; 189 background-repeat: no-repeat; 190 cursor: pointer; 191 opacity: 0.3; 192 -webkit-transition: opacity 0.2s ease-out ; 193 } 194 195 .spinicon { 196 position: absolute; 197 right: 4px; 198 top: 5px; 199 height: 100%; 200 width: 15px; 201 margin-left: 0; 202 margin-top: 5px; 203 background-repeat: no-repeat; 204 } 205 206 li.filebrowserow:hover .menuicon { 207 opacity: 0.75; 208 -webkit-transition: opacity 0.0s ease-out ; 209 } 210 211 li.filebrowserow:hover .menuicon:hover { 212 opacity: 1.0; 213 -webkit-transition: opacity 0.0s ease-out ; 214 } 215 216 .uploadcomplete { 217 height: 100%; 218 position: absolute; 219 right: 0; 220 top: 5px; 221 height: 100%; 222 width: 70px; 223 margin-left: 5px; 224 margin-top: 5px; 225 } 226 227 .uploadprogress { 228 position: absolute; 229 right: 0; 230 top: 5px; 231 height: 100%; 232 width: 12px; 233 margin-left: 5px; 234 margin-top: 5px; 235 background-repeat: no-repeat; 236 } 237 238 li.filebrowserow { 239 border-bottom: 1px solid #f7f7f7; 240 padding: 8px 5px 5px 54px; 241 font-size: .8em; 242 position: relative; 243 background: #fff; 244 } 245 246 .downloadstatus { 247 width: 100%; 248 font-size: .6em; 249 height: 20px; 250 } 251 252 .downloadpause { 253 right: 0; 254 bottom: 0; 255 height: 15px; 256 cursor: pointer; 257 color: blue; 258 text-align: center; 259 position: absolute; 260 } 261 262 li.filebrowserow:hover { 263 background: #ebeff9; 264 cursor: pointer; 265 } 266 267 li.filebrowserow span.name { 268 margin-top: 10px; 269 margin-left: -22px; 270 position: relative; 271 } 272 273 li.filebrowserow input.name { 274 margin-top: 0; 275 margin-left: -22px; 276 position: relative; 277 } 278 279 li.filebrowserow span.namelink { 280 margin-left: -22px; 281 position: relative; 282 display: block; 283 overflow: hidden; 284 white-space: nowrap; 285 text-overflow: ellipsis; 286 color:#0D0052; 287 -webkit-transition: color 1.0s ease-out ; 288 } 289 290 li.filebrowserow:hover span.namelink { 291 text-decoration: underline; 292 color: #20c; 293 -webkit-transition: color 0.0s ease-out ; 294 } 295 296 li.selected { 297 background-color: #b1c8f2 !important; 298 } 299 300 div.title { 301 text-align: right; 302 position: relative; 303 font-size: .8em; 304 font-weight: bold; 305 padding-top: 2px; 306 } 307 308 div.controlbutton { 309 width: 16px; 310 height: 15px; 311 display: inline; 312 position: relative; 313 z-index: 999; 314 border: 1px solid #859EE8; 315 cursor: pointer; 316 padding: 4px; 317 padding-bottom: 0; 318 background: -webkit-linear-gradient(#F4F6FB, #CCD7F8); 319 } 320 321 div.controlbutton:hover { 322 323 background: -webkit-linear-gradient(#FFF, #D9E0F6); 324 } 325 326 div.column { 327 width: 250px; 328 height: 100%; 329 float: left; 330 position: relative; 331 } 332 333 div.columnlistadv { 334 width: 100%; 335 bottom: 0; 336 top: 32px; 337 position: absolute; 338 overflow-y: scroll; 339 overflow-x: hidden; 340 } 341 342 div.columnlist { 343 width: 100%; 344 bottom: 0; 345 top: 0; 346 position: absolute; 347 overflow-y: scroll; 348 overflow-x: hidden; 349 } 350 351 div.iconmedia { 352 background: url('shared/images/icon_media.png'); 353 } 354 355 div.iconfolder { 356 background: url('shared/images/icon_folder.png'); 357 } 358 359 div.iconfile { 360 background: url('shared/images/icon_file.png'); 361 } 362 363 div.iconphoto { 364 background: url('shared/images/icon_photo.png'); 365 } 366 367 div.iconmusic { 368 background: url('shared/images/icon_media.png'); 369 } 370 371 div.backbutton { 372 border-radius: 4px; 373 left: 0; 374 top: 0; 375 } 376 377 div.playbackcontainer { 378 top: 0; 379 left: 0; 380 position: absolute; 381 width: 100%; 382 height: 100%; 383 background: black; 384 } 385 386 div.scanningcontainer { 387 top: 0; 388 left: 0; 389 position: absolute; 390 width: 100%; 391 height: 100%; 392 } 393 394 .filenameprompt { 395 top: 8px; 396 left: 13px; 397 font-size: .8em; 398 position: absolute; 399 } 400 401 .filename { 402 left: 90px; 403 top: 3px; 404 border-radius: 4px; 405 right: 10px; 406 font-size: .8em; 407 position: absolute; 408 } 409 410 div.buttonscontainer { 411 display: -webkit-box; 412 bottom: 0; 413 right: 10px; 414 position: absolute; 415 } 416 417 div.openbutton { 418 min-width: 50px; 419 margin: 3px; 420 } 421 422 div.cancelbutton { 423 min-width: 50px; 424 margin: 3px; 425 } 426 427 #newfolderbutton { 428 bottom: 3px; 429 left: 10px; 430 position: absolute; 431 } 432 433 div.disabled { 434 color: gray; 435 cursor: default; 436 } 437 438 div.opencontainer { 439 width: 100%; 440 bottom: 0; 441 left: 0; 442 height: 30px; 443 position: absolute; 444 background-image: -webkit-linear-gradient(#fcfcfc, #eff1f2 90%); 445 } 446 447 div.savecontainer { 448 width: 100%; 449 bottom: 0; 450 left: 0; 451 height: 60px; 452 position: absolute; 453 background-image: -webkit-linear-gradient(#fcfcfc, #eff1f2 90%); 454 } 455 456 div.container { 457 top: 0; 458 position: absolute; 459 width: 100%; 460 left: 0; 461 bottom: 0; 462 } 463 464 div.containerwithopenbuttons { 465 top: 0; 466 position: absolute; 467 right: 0; 468 border: 1px solid #C2C2C2; 469 margin: 4px; 470 left: 0; 471 bottom: 30px; 472 } 473 474 div.containerwithsavebuttons { 475 top: 0; 476 position: absolute; 477 right: 0; 478 margin: 4px; 479 border: 1px solid #C2C2C2; 480 left: 0; 481 bottom: 60px; 482 } 483 484 div.fullcontainer { 485 top: 0px; 486 position: absolute; 487 left: 0; 488 bottom: 0; 489 right: 600px; 490 overflow-y: hidden; 491 overflow-x: scroll; 492 } 493 494 .popout { 495 right: 10px; 496 top: 10px; 497 width: 15px; 498 text-align: center; 499 height: 10px; 500 font-size: .4em; 501 background: rgb(239, 242, 249); 502 cursor: pointer; 503 z-index: 99999; 504 padding-top: 1px; 505 border: 1px solid #999; 506 position: absolute; 507 border-radius: 5px; 508 } 509 510 .mediacontainer { 511 top: 0; 512 left: 0; 513 position: absolute; 514 width: 100%; 515 height: 100%; 516 } 517 518 .menu { 519 top: 14px; 520 right: 2px; 521 width: 180px; 522 -webkit-box-shadow: rgba(0, 0, 0, 0.3) 0px 3px 3px; 523 border-bottom-left-radius: 4px 4px; 524 border-bottom-right-radius: 4px 4px; 525 border-top-left-radius: 4px 4px; 526 border-top-right-radius: 0px 0px; 527 position: absolute; 528 display: none; 529 z-index: 999; 530 background: white; 531 border-top-left-radius: 4px; 532 border: 1px solid rgba(0, 0, 0, 0.6); 533 padding: 5px; 534 } 535 536 .menuitem { 537 width: 100%; 538 height: 20px; 539 text-align: left; 540 cursor: pointer; 541 left: 0; 542 color: #0D0052; 543 -webkit-transition: color 1.0s ease-out ; 544 } 545 546 .menuitem:hover { 547 text-decoration: underline; 548 color: #20c; 549 background: #ebeff9; 550 -webkit-transition: color 0.0s ease-out ; 551 } 552 553 .menuitemdisabled { 554 width: 100%; 555 height: 20px; 556 text-align: left; 557 color: gray; 558 left: 0; 559 } 560 561 .downloading[dangerous] > * > .icon { 562 background: url('../../app/theme/alert_small.png'); 563 } 564 565 input.error { 566 background-color: #ff6666; 567 } 568 569 </style> 570 <script src="shared/js/local_strings.js"></script> 571 <script src="shared/js/media_common.js"></script> 572 <script> 573 574 function $(o) { 575 return document.getElementById(o); 576 } 577 578 /** 579 * Partial function application. 580 * 581 * Usage: 582 * var g = partial(f, arg1, arg2); 583 * g(arg3, arg4); 584 * 585 * @param {!Function} fn A function to partially apply. 586 * @param {...*} var_args Additional arguments that are partially 587 * applied to fn. 588 * @return {!Function} A partially-applied form of the function partial() was 589 * called with. 590 */ 591 function partial(fn, var_args) { 592 var args = Array.prototype.slice.call(arguments, 1); 593 return function(e) { 594 if (e.stopPropagation) { 595 e.stopPropagation(); 596 } 597 // Prepend the bound arguments to the current arguments. 598 var newArgs = Array.prototype.slice.call(arguments); 599 newArgs.unshift.apply(newArgs, args); 600 return fn.apply(this, newArgs); 601 }; 602 } 603 604 function supportsPdf() { 605 return 'application/pdf' in navigator.mimeTypes; 606 } 607 608 var currentSavedPath = ''; 609 var currentNode = -1; 610 var menus = []; 611 var currentImageMenu = ''; 612 var inFullMode = false; 613 var inSelectMode = false; 614 var videoPlaybackElement = null; 615 var photoPreviewElement = null; 616 var numColumns = 0; 617 var divArray = []; 618 var rootsDiv = null; 619 var currentlySelectedItems = []; 620 var currentlySelectedPaths = []; 621 var multiSelect = false; 622 var selectFolder = false; 623 var inSaveMode = false; 624 var currentMenu = null; 625 var mainColumn = null; 626 var localStrings; 627 var downloadList = []; 628 var advancedEnabled = false; 629 var mediaPlayerEnabled = false; 630 // strings 631 var kPauseDownload; 632 var kResumeDownload; 633 634 function enabledResult(info) { 635 advancedEnabled = info.enabled; 636 mediaPlayerEnabled = info.mpEnabled; 637 mainColumn = $('main'); 638 if (!advancedEnabled) { 639 $('header').style.display = 'none'; 640 } 641 if (document.documentElement.clientWidth <= 600) { 642 inFullMode = false; 643 if (chrome.dialogArguments) { 644 var args = JSON.parse(chrome.dialogArguments); 645 if (args.type == 'open') { 646 multiSelect = false; 647 selectFolder = false; 648 } else if (args.type == 'save') { 649 inSaveMode = true; 650 selectFolder = false; 651 } else if (args.type == 'open_multiple') { 652 multiSelect = true; 653 selectFolder = false; 654 } else if (args.type == 'folder') { 655 multiSelect = false; 656 selectFolder = true; 657 } else { 658 alert('got unknown type' + args.type); 659 } 660 inSelectMode = true; 661 if (inSaveMode) { 662 var main = mainColumn; 663 main.className = 'containerwithsavebuttons'; 664 var savemenu = document.createElement('div'); 665 savemenu.className = 'savecontainer'; 666 667 // The container is used for placing buttons horizontally. 668 var buttonsContainer = document.createElement('div'); 669 buttonsContainer.className = 'buttonscontainer'; 670 savemenu.appendChild(buttonsContainer); 671 672 var savebutton = document.createElement('button'); 673 savebutton.id = 'savebutton'; 674 savebutton.className = 'openbutton disabled'; 675 savebutton.onclick = dialogSaveClick; 676 savebutton.textContent = localStrings.getString('save'); 677 buttonsContainer.appendChild(savebutton); 678 679 var cancelbutton = document.createElement('button'); 680 cancelbutton.className = 'cancelbutton'; 681 cancelbutton.textContent = localStrings.getString('confirmcancel'); 682 cancelbutton.onclick = dialogCancelClick; 683 buttonsContainer.appendChild(cancelbutton); 684 685 var filenameprompt = document.createElement('div'); 686 filenameprompt.className = 'filenameprompt'; 687 filenameprompt.textContent = localStrings.getString('filenameprompt'); 688 savemenu.appendChild(filenameprompt); 689 690 var backbutton = $('back'); 691 if (backbutton) { 692 backbutton.style.top = '5px'; 693 } 694 695 var filename = document.createElement('input'); 696 filename.className = 'filename'; 697 filename.id = 'filename'; 698 filename.value = args.current_file; 699 savemenu.appendChild(filename); 700 701 if (advancedEnabled) { 702 var newfolderbutton = document.createElement('button'); 703 newfolderbutton.id = 'newfolderbutton'; 704 newfolderbutton.className = 'newfolderbutton disabled'; 705 newfolderbutton.textContent = localStrings.getString('newfolder'); 706 newfolderbutton.onclick = dialogNewFolderClick; 707 savemenu.appendChild(newfolderbutton); 708 } 709 710 document.body.appendChild(savemenu); 711 // Give focus to the save button. This has to be done after the 712 // parent node is added to document.body. 713 savebutton.focus(); 714 715 } else { 716 var main = mainColumn; 717 main.className = 'containerwithopenbuttons'; 718 var openmenu = document.createElement('div'); 719 openmenu.className = 'opencontainer'; 720 var openbutton = document.createElement('button'); 721 openbutton.id = 'openbutton'; 722 openbutton.className = 'openbutton disabled'; 723 var cancelbutton = document.createElement('button'); 724 cancelbutton.className = 'cancelbutton'; 725 openmenu.appendChild(openbutton); 726 openbutton.onclick = dialogOkClick; 727 openmenu.appendChild(cancelbutton); 728 cancelbutton.onclick = dialogCancelClick; 729 openbutton.textContent = localStrings.getString('open'); 730 cancelbutton.textContent = localStrings.getString('confirmcancel'); 731 document.body.appendChild(openmenu); 732 var backbutton = $('back'); 733 if (backbutton) { 734 backbutton.style.top = '5px'; 735 } 736 } 737 } 738 } else { 739 var main = mainColumn; 740 main.className = 'fullcontainer'; 741 var innerContainer = document.createElement('div'); 742 innerContainer.className = 'container'; 743 innerContainer.id = 'inner'; 744 main.appendChild(innerContainer); 745 inFullMode = true; 746 $('back').style.display = 'none'; 747 } 748 749 if (document.location.href.indexOf('#') != -1) { 750 var currentpathArray = document.location.href.split('#'); 751 var path = currentpathArray[1]; 752 if (path == 'scanningdevice') { 753 setUpForScanning(); 754 } else { 755 currentNode++; 756 currentSavedPath = path; 757 getDataForPath(path); 758 } 759 } else { 760 currentNode++; 761 if (advancedEnabled) { 762 currentSavedPath = 'roots'; 763 getDataForPath('roots'); 764 } else { 765 currentSavedPath = localStrings.getString('downloadpath'); 766 getDataForPath(currentSavedPath); 767 } 768 } 769 chrome.send('getDownloads', []); 770 } 771 772 function isPathUnderRoot(path, includeRoot) { 773 var downloadpath = localStrings.getString('downloadpath'); 774 return (!includeRoot || path !== downloadpath) 775 && path.search(downloadpath) === 0; 776 } 777 778 function goBackInList() { 779 currentNode--; 780 if (isPathUnderRoot(currentSavedPath, true)) { 781 var c = currentSavedPath.split('/'); 782 c.pop(); 783 currentSavedPath = c.join('/'); 784 } else { 785 currentSavedPath = 'roots'; 786 } 787 getDataForPath(currentSavedPath); 788 } 789 790 function toggleFullscreen() { 791 if (videoPlaybackElement != null) { 792 if (videoPlaybackElement.className == 'fullscreenplayback') { 793 videoPlaybackElement.className = 'playbackelement'; 794 } else { 795 videoPlaybackElement.className = 'fullscreenplayback'; 796 } 797 } 798 } 799 800 var lastScrollLeft = 0; 801 function animateScrollRight() { 802 803 var main = mainColumn; 804 main.scrollLeft += 20; 805 // since if its larger than a size, we know we reached the leftmost part when 806 // it stops growing, so clear it out and no more timeouts. 807 if (lastScrollLeft != main.scrollLeft) { 808 lastScrollLeft = main.scrollLeft; 809 setTimeout('animateScrollRight()', 15); 810 } else { 811 lastScrollLeft = 0; 812 } 813 814 } 815 816 function getCurrentContainer() { 817 if (inFullMode) { 818 var newContainer = document.createElement('div'); 819 var main = $('inner'); 820 numColumns++; 821 main.style.width = (numColumns * 250) + 'px'; 822 newContainer.className = 'column'; 823 main.appendChild(newContainer); 824 animateScrollRight(); 825 return newContainer; 826 } else { 827 return mainColumn; 828 } 829 } 830 831 function clearList(list) { 832 if (list.hasChildNodes()) { 833 while (list.childNodes.length >= 1) { 834 list.removeChild(list.firstChild); 835 } 836 } 837 } 838 839 function rootsChanged() { 840 if (inFullMode) { 841 chrome.send('getRoots', []); 842 } 843 } 844 845 function browseFileResult(info, results) { 846 var lastDirArray = info.path.split('/'); 847 var lastDir = lastDirArray[lastDirArray.length - 1]; 848 if (info.functionCall == 'getRoots') { 849 if (rootsDiv) { 850 clearList(rootsDiv); 851 createNewList(lastDir, results, rootsDiv, info.path); 852 } else { 853 var main = getCurrentContainer(); 854 rootsDiv = main; 855 divArray.push(main); 856 createNewList(lastDir, results, main, info.path); 857 } 858 } else if (info.functionCall == 'getChildren') { 859 var main = getCurrentContainer(); 860 main.addEventListener('dragover', function(e) { 861 if (e.preventDefault) e.preventDefault(); 862 e.dataTransfer.dropEffect = 'copy'; 863 return false; 864 }, false); 865 main.addEventListener('drop', function(e) { 866 if (e.stopPropagation) e.stopPropagation(); 867 var src = e.dataTransfer.getData('Text'); 868 var path = getPathAndFilenameForPath(src); 869 var dest = currentSavedPath + '/' + path[2]; 870 var dirId = $('list/dir/' + currentSavedPath); 871 if (dirId) { 872 var element = $(dest); 873 if (!element) { 874 // TODO(dhg): We probably should do some checking for 875 // existance. 876 element = createNewFakeItem(path[2], dest, false, true); 877 } 878 dirId.appendChild(element); 879 element.scrollIntoView(); 880 } 881 chrome.send('copyFile', [src, dest]); 882 return false; 883 }, false); 884 main.id = 'dir/' + info.path; 885 divArray.push(main); 886 document.location.hash = info.path; 887 createNewList(lastDir, results, main, info.path); 888 } else if (info.functionCall == 'refresh') { 889 var main = $('dir/' + info.path); 890 if (main) { 891 clearList(main); 892 createNewList(lastDir, results, main, info.path); 893 } else { 894 // not currently displayed, so just return. 895 return; 896 } 897 } 898 chrome.send('getDownloads', []); 899 } 900 901 function moveScrollLeft() { 902 var main = mainColumn; 903 main.scrollLeft += 10; 904 } 905 906 function getClassForPath(path, isDirectory) { 907 if (isDirectory) { 908 return 'icon iconfolder'; 909 } else if (pathIsImageFile(path)) { 910 return 'icon iconphoto'; 911 } else if (pathIsVideoFile(path)) { 912 return 'icon iconmedia'; 913 } else if (pathIsAudioFile(path)) { 914 return 'icon iconmusic'; 915 } 916 return 'icon iconfile'; 917 } 918 919 function getDataForPath(path) { 920 var newfolderbutton = $('newfolderbutton'); 921 if (newfolderbutton && advancedEnabled) { 922 // Enable newfolder button for paths under downloadpath 923 if (inSaveMode && isPathUnderRoot(path, false)) { 924 newfolderbutton.className = 'newfolderbutton'; 925 } else { 926 newfolderbutton.className = 'newfolderbutton disabled'; 927 } 928 } 929 930 if (path == 'roots') { 931 if (inSaveMode) { 932 var savebutton = $('savebutton'); 933 savebutton.className = 'openbutton disabled'; 934 } else if (inSelectMode) { 935 var openbutton = $('openbutton'); 936 openbutton.className = 'openbutton disabled'; 937 } 938 chrome.send('getRoots', []); 939 } else { 940 if (inSaveMode) { 941 var savebutton = $('savebutton'); 942 savebutton.className = 'openbutton'; 943 } else if (inSelectMode) { 944 var openbutton = $('openbutton'); 945 openbutton.className = 'openbutton'; 946 } 947 chrome.send('getChildren', [path]); 948 } 949 } 950 951 function setUpForScanning() { 952 var header = $('header'); 953 document.body.removeChild(header); 954 var main = mainColumn; 955 main.className = 'scanningcontainer'; 956 main.textContent = localStrings.getString('scanning'); 957 } 958 959 function dialogOkClick() { 960 if (currentlySelectedPaths.length == 0) { 961 return; 962 } 963 if (!multiSelect) { 964 chrome.send('DialogClose', 965 [JSON.stringify({'path' : currentlySelectedPaths[0]})]); 966 } else { 967 chrome.send('DialogClose', 968 [JSON.stringify({'path' : currentlySelectedPaths})]); 969 } 970 } 971 972 function dialogCancelClick() { 973 chrome.send('DialogClose', ['']); 974 } 975 976 function dialogSaveClick() { 977 var filenameInput = $('filename'); 978 var filename = filenameInput.value; 979 var currentPath = currentSavedPath; 980 if (currentPath == 'roots') { 981 return; 982 } 983 currentPath += '/'; 984 currentPath += filename; 985 chrome.send('validateSavePath', [currentPath]); 986 987 filenameInput.disabled = true; 988 $('savebutton').disabled = true; 989 } 990 991 function onValidatedSavePath(valid, savePath) { 992 var filenameInput = $('filename'); 993 994 filenameInput.disabled = false; 995 $('savebutton').disabled = false; 996 997 if (valid) { 998 filenameInput.classList.remove('error'); 999 chrome.send('DialogClose', [JSON.stringify({'path' : savePath})]); 1000 } else { 1001 filenameInput.classList.add('error'); 1002 } 1003 } 1004 1005 function createNewFormItem( 1006 initialName, isDirectory, id, blurcallback, keypresscallback) { 1007 var element = document.createElement('li'); 1008 element.className = 'filebrowserow'; 1009 element.id = 'listItem' + elementIdCounter; 1010 elementIdCounter++; 1011 1012 var link; 1013 link = document.createElement('div'); 1014 link.className = 'rowlink'; 1015 1016 var icon = document.createElement('div'); 1017 icon.className = getClassForPath('', isDirectory); 1018 link.appendChild(icon); 1019 var input = document.createElement('input'); 1020 input.className = 'name'; 1021 input.id = 'newfoldername'; 1022 input.onblur = blurcallback; 1023 input.onkeypress = keypresscallback; 1024 1025 input.value = initialName; 1026 link.appendChild(input); 1027 1028 element.appendChild(link); 1029 1030 return element; 1031 } 1032 1033 function createFolder(elementId) { 1034 var currentPath = currentSavedPath; 1035 var element = $('newfoldername'); 1036 if (!element) { 1037 return false; 1038 } 1039 element.id = ''; 1040 var filename = element.value; 1041 currentPath += '/'; 1042 currentPath += filename; 1043 var existingfolder = $(currentPath); 1044 var counter = 1; 1045 while (existingfolder) { 1046 var testfilepath = currentPath; 1047 testfilepath = testfilepath + counter; 1048 existingfolder = $(testfilepath); 1049 if (!existingfolder) { 1050 currentPath = testfilepath; 1051 filename = filename + counter; 1052 break; 1053 } 1054 counter++; 1055 } 1056 1057 // Disallow / in folder name. 1058 if (filename.match(/^[^\/]+$/) === null) { 1059 return false; 1060 } 1061 1062 var parent = element.parentNode; 1063 parent.removeChild(element); 1064 listitem = parent.parentNode; 1065 1066 parent.onclick = getFunctionForItem(currentPath, listitem.id, true); 1067 1068 var span = document.createElement('span'); 1069 if (inSelectMode) { 1070 span.className = 'name'; 1071 } else { 1072 span.className = 'namelink'; 1073 } 1074 span.textContent = filename; 1075 parent.appendChild(span); 1076 1077 var rightArrow = document.createElement('span'); 1078 rightArrow.textContent = ''; 1079 rightArrow.className = 'rightarrow'; 1080 parent.appendChild(rightArrow); 1081 1082 chrome.send('createNewFolder', [currentPath]); 1083 } 1084 1085 function deleteFile(path) { 1086 chrome.send('deleteFile', [path]); 1087 } 1088 1089 function removeDeleteConfirm(path) { 1090 var element = menus[path]; 1091 element.firstChild.removeChild(element.firstChild.lastChild); 1092 } 1093 1094 function deleteFileConfirm(path) { 1095 var element = menus[path]; 1096 if (!element || element.querySelector('.confirmdelete')) { 1097 return; 1098 } 1099 var askingDiv = document.createElement('div'); 1100 askingDiv.className = 'confirmdelete'; 1101 askingDiv.textContent = localStrings.getString('confirmdelete'); 1102 yesNoDiv = document.createElement('div'); 1103 yesNoDiv.className = 'deleteYesNoContainer'; 1104 var yes = document.createElement('div'); 1105 yes.className = 'deleteYes'; 1106 yes.textContent = localStrings.getString('confirmyes'); 1107 yes.onclick = partial(deleteFile, path); 1108 var no = document.createElement('div'); 1109 no.onclick = partial(removeDeleteConfirm, path); 1110 no.textContent = localStrings.getString('confirmcancel'); 1111 no.className = 'deleteNo'; 1112 yesNoDiv.appendChild(yes); 1113 yesNoDiv.appendChild(no); 1114 askingDiv.appendChild(yesNoDiv); 1115 element.firstChild.appendChild(askingDiv); 1116 askingDiv.scrollIntoView(); 1117 window.event.stopPropagation(); 1118 } 1119 1120 function createFolderTyping(elementId) { 1121 if (window.event.keyCode == 13) { 1122 createFolder(elementId); 1123 } 1124 } 1125 1126 function getDirectoryForPath(path) { 1127 var index = path.lastIndexOf('/'); 1128 if (index == -1) { 1129 return path; 1130 } 1131 return path.substr(path, index); 1132 } 1133 1134 function pauseToggleDownload(id) { 1135 var element = $('downloaditem' + id); 1136 if (element.textContent == kPauseDownload) { 1137 element.textContent = kResumeDownload; 1138 } else { 1139 element.textContent = kPauseDownload; 1140 } 1141 // Have to convert to a string, the system wasn't accepting ints 1142 chrome.send('pauseToggleDownload', ['' + id]); 1143 } 1144 1145 function allowDownload(id, path) { 1146 var element = $(path); 1147 element.removeAttribute('dangerous'); 1148 var pauseDiv = $('downloaditem' + id); 1149 if (pauseDiv) { 1150 if (pauseDiv.firstChild) { 1151 pauseDiv.removeChild(pauseDiv.firstChild); 1152 } 1153 pauseDiv.onclick = partial(pauseToggleDownload, id); 1154 pauseDiv.textContent = kPauseDownload; 1155 } 1156 chrome.send('allowDownload', ['' + id]); 1157 } 1158 1159 function cancelDownload(id, path) { 1160 var element = $(path); 1161 element.removeAttribute('dangerous'); 1162 chrome.send('cancelDownload', ['' + id]); 1163 } 1164 1165 function getPathAndFilenameForPath(path) { 1166 return path.match(/(.*)[\/\\]([^\/\\]+\.\w+)$/); 1167 } 1168 1169 function newDownload(results) { 1170 var x; 1171 for (x = 0; x < results.length; x++) { 1172 var element = $(results[x].file_path); 1173 if (!element && 1174 results[x].state != 'CANCELLED' && 1175 results[x].state != 'INTERRUPTED') { 1176 var extracted = getPathAndFilenameForPath(results[x].file_path); 1177 var dirId = $('list/dir/' + extracted[1]); 1178 if (dirId) { 1179 element = 1180 createNewItem(results[x].file_name, results[x].file_path, false); 1181 downloadList.push(element); 1182 if (dirId.firstChild) { 1183 dirId.insertBefore(element, dirId.firstChild); 1184 } else { 1185 dirId.appendChild(element); 1186 } 1187 element.scrollIntoView(); 1188 } 1189 } 1190 } 1191 } 1192 1193 function removeDownload(element, dirId) { 1194 var status = undefined; 1195 var pause = undefined; 1196 for (var x = 0; x < element.children.length; x++) { 1197 if (element.children[x].className == 'downloadstatus') { 1198 var child = element.children[x]; 1199 status = child; 1200 } else if (element.children[x].className == 'downloadpause') { 1201 var child = element.children[x]; 1202 pause = child; 1203 } 1204 } 1205 if (status) { 1206 element.removeChild(status); 1207 } 1208 if (pause) { 1209 element.removeChild(pause); 1210 } 1211 element.className = 'filebrowserow'; 1212 var elementList = []; 1213 for (var x = 0; x < downloadList.length; x++) { 1214 if (element != downloadList[x]) { 1215 elementList.push(downloadList[x]); 1216 } 1217 } 1218 downloadList = elementList; 1219 if (dirId) { 1220 dirId.removeChild(element); 1221 } 1222 } 1223 1224 function downloadsList(results) { 1225 var removeDownloads = []; 1226 removeDownloads.pushUnique = function(element) { 1227 if (this.indexOf(element) === -1) { 1228 this.push(element); 1229 } 1230 }; 1231 for (var y = 0; y < downloadList.length; y++) { 1232 var found = false; 1233 for (var x = 0; x < results.length; x++) { 1234 var element = $(results[x].file_path); 1235 if (downloadList[y] == element) { 1236 found = true; 1237 break; 1238 } 1239 } 1240 if (!found) { 1241 removeDownloads.pushUnique(downloadList[y]); 1242 } 1243 } 1244 1245 for (var i = 0; i < results.length; ++i) { 1246 downloadUpdated(results[i]); 1247 } 1248 1249 for (var x = 0; x < removeDownloads.length; x++) { 1250 var element = removeDownloads[x]; 1251 var extracted = getPathAndFilenameForPath(element.id); 1252 var dirId = $('list/dir/' + extracted[1]); 1253 removeDownload(element, dirId); 1254 } 1255 } 1256 1257 function downloadUpdated(result) { 1258 var element = $(result.file_path); 1259 var extracted = getPathAndFilenameForPath(result.file_path); 1260 var dirId = $('list/dir/' + extracted[1]); 1261 if (!element && 1262 result.state != 'CANCELLED' && 1263 result.state != 'INTERRUPTED') { 1264 if (dirId) { 1265 element = createNewItem(result.file_name, result.file_path, false); 1266 if (dirId.firstChild) { 1267 dirId.insertBefore(element, dirId.firstChild); 1268 } else { 1269 dirId.appendChild(element); 1270 } 1271 element.scrollIntoView(); 1272 } 1273 } 1274 if (element) { 1275 if (result.state == 'CANCELLED' || 1276 result.state == 'INTERRUPTED') { 1277 element.parentNode.removeChild(element); 1278 return; 1279 } 1280 if (result.percent < 100 || result.state == 'DANGEROUS') { 1281 var progressDiv = null; 1282 for (var y = 0; y < element.children.length; y++) { 1283 if (element.children[y].className == 'downloadstatus') { 1284 progressDiv = element.children[y]; 1285 } 1286 } 1287 if (progressDiv == null) { 1288 downloadList.push(element); 1289 element.className = 'filebrowserow downloading'; 1290 fixTitleForItem(element, result); 1291 var progressDiv = document.createElement('div'); 1292 progressDiv.className = 'downloadstatus'; 1293 element.appendChild(progressDiv); 1294 var pauseDiv = document.createElement('div'); 1295 pauseDiv.onclick = partial(pauseToggleDownload, result.id); 1296 pauseDiv.className = 'downloadpause'; 1297 if (result.state == 'DANGEROUS') { 1298 element.setAttribute('dangerous', 'true'); 1299 pauseDiv.onClick = undefined; 1300 var prompt = document.createElement('div'); 1301 prompt.textContent = localStrings.getString('allowdownload'); 1302 prompt.className = 'prompt'; 1303 pauseDiv.appendChild(prompt); 1304 var yes = document.createElement('div'); 1305 yes.className = 'link'; 1306 yes.textContent = localStrings.getString('confirmyes'); 1307 yes.onclick = partial(allowDownload, 1308 result.id, 1309 result.file_path); 1310 var no = document.createElement('div'); 1311 no.onclick = partial(cancelDownload, 1312 result.id, 1313 result.file_path); 1314 no.textContent = localStrings.getString('confirmcancel'); 1315 no.className = 'link'; 1316 pauseDiv.onclick = undefined; 1317 pauseDiv.appendChild(yes); 1318 pauseDiv.appendChild(no); 1319 progressDiv.textContent = ''; 1320 } 1321 pauseDiv.id = 'downloaditem' + result.id; 1322 element.appendChild(pauseDiv); 1323 } 1324 var pauseDiv = $('downloaditem' + result.id); 1325 if (pauseDiv && 1326 result.state == 'PAUSED' && 1327 pauseDiv.textContent != kResumeDownload) { 1328 pauseDiv.textContent = kResumeDownload; 1329 } else if (pauseDiv && 1330 result.state == 'IN_PROGRESS' && 1331 pauseDiv.textContent != kPauseDownload) { 1332 pauseDiv.textContent = kPauseDownload; 1333 } 1334 if (result.percent < 100 && 1335 result.state != 'DANGEROUS') { 1336 progressDiv.textContent = result.progress_status_text; 1337 } 1338 1339 } else { 1340 removeDownloadIfDone(element, dirId); 1341 } 1342 } 1343 } 1344 1345 function removeDownloadIfDone(element, dirId) { 1346 var len = downloadList.length; 1347 while (len--) { 1348 if (element.title === downloadList[len].title) { 1349 if (element.id !== downloadList[len].id) { 1350 // Dangerous download. 1351 removeDownload(downloadList[len], dirId); 1352 } else { 1353 removeDownload(downloadList[len]); 1354 } 1355 break; 1356 } 1357 } 1358 } 1359 1360 function dialogNewFolderClick() { 1361 var newfolderbutton = $('newfolderbutton'); 1362 if (newfolderbutton.className.indexOf('disabled') != -1) { 1363 return; 1364 } 1365 1366 var main = divArray[divArray.length - 1]; 1367 var list; 1368 for (var x = 0; x < main.childNodes.length; x++) { 1369 if (main.childNodes[x].className == 'columnlist' || 1370 main.childNodes[x].className == 'columnlistadv') { 1371 list = main.childNodes[x].firstChild; 1372 break; 1373 } 1374 } 1375 var id = 'listItem' + elementIdCounter; 1376 elementIdCounter++; 1377 var element = createNewFormItem('', 1378 true, 1379 id, 1380 partial(createFolder, id), 1381 partial(createFolderTyping, id)); 1382 list.appendChild(element); 1383 element.scrollIntoView(); 1384 var inputelement = $('newfoldername'); 1385 inputelement.focus(); 1386 } 1387 1388 /////////////////////////////////////////////////////////////////////////////// 1389 // Document Functions: 1390 /** 1391 * Window onload handler, sets up the page. 1392 */ 1393 function load() { 1394 localStrings = new LocalStrings(); 1395 kPauseDownload = localStrings.getString('pause'); 1396 kResumeDownload = localStrings.getString('resume'); 1397 chrome.send('isAdvancedEnabled', ['']); 1398 } 1399 1400 function jumpToNode(nodeNumber) { 1401 if (currentNode == nodeNumber) { 1402 return; 1403 } 1404 if (inFullMode) { 1405 var main = $('inner'); 1406 for (var x = (nodeNumber + 1); x < divArray.length; x++) { 1407 main.removeChild(divArray[x]); 1408 numColumns--; 1409 } 1410 divArray = divArray.slice(0, nodeNumber + 1); 1411 } 1412 currentNode = nodeNumber; 1413 } 1414 1415 function descend(path, nodeNumber) { 1416 jumpToNode(nodeNumber); 1417 currentNode++; 1418 if (selectFolder) { 1419 currentlySelectedPaths = []; 1420 currentlySelectedPaths.push(path); 1421 } 1422 currentSavedPath = path; 1423 getDataForPath(path); 1424 } 1425 1426 function clearPreviewPane() { 1427 if (videoPlaybackElement != null) { 1428 document.body.removeChild($('fullscreentoggle')); 1429 document.body.removeChild(videoPlaybackElement); 1430 videoPlaybackElement = null; 1431 } 1432 if (photoPreviewElement != null) { 1433 document.body.removeChild(photoPreviewElement); 1434 photoPreviewElement = null; 1435 } 1436 } 1437 1438 function playMediaFile(path) { 1439 var newPath = 'file://' + path; 1440 chrome.send('playMediaFile', [newPath]); 1441 } 1442 1443 function enqueueMediaFile(path) { 1444 var newPath = 'file://' + path; 1445 chrome.send('enqueueMediaFile', [newPath]); 1446 } 1447 1448 function showImage(path) { 1449 if (inFullMode) { 1450 if (photoPreviewElement == null) { 1451 photoPreviewElement = document.createElement('img'); 1452 photoPreviewElement.className = 'imagepreview'; 1453 photoPreviewElement.src = 'file://' + path; 1454 document.body.appendChild(photoPreviewElement); 1455 } else { 1456 photoPreviewElement.src = 'file://' + path; 1457 } 1458 } else { 1459 chrome.send('openNewFullWindow', ['chrome://slideshow#' + path]); 1460 } 1461 } 1462 1463 function showPath(path) { 1464 chrome.send('openNewFullWindow', ['file://' + path]); 1465 } 1466 1467 function clearMenus() { 1468 if (currentMenu) { 1469 currentMenu.firstChild.style.display = 'none'; 1470 currentMenu.style.opacity = ''; 1471 currentMenu = null; 1472 } 1473 } 1474 1475 function uploadImage(path) { 1476 var status = $('status'); 1477 status.style.display = 'block'; 1478 var extracted = getPathAndFilenameForPath(path); 1479 var main = $('dir/' + extracted[1]); 1480 main.style.bottom = '30px'; 1481 status.textContent = 'Uploading'; 1482 chrome.send('uploadToPicasaweb', [path]); 1483 } 1484 1485 function showMenu(path) { 1486 var element = menus[path]; 1487 if (element.firstChild.style.display == 'block') { 1488 // Second click should clear the menu. 1489 clearMenus(); 1490 } else { 1491 clearMenus(); 1492 element.firstChild.style.display = 'block'; 1493 element.style.opacity = '1'; 1494 currentMenu = element; 1495 currentMenu.scrollIntoView(); 1496 } 1497 window.event.stopPropagation(); 1498 } 1499 1500 function uploadComplete(result) { 1501 var element = $('status'); 1502 if (result.status_code == 201) { 1503 element.textContent = ''; 1504 var a = document.createElement('a'); 1505 a.href = result.url; 1506 a.target = '_blank'; 1507 //TODO(altimofeev): Should really be localStrings.getString(...) 1508 a.textContent = 'Uploaded'; 1509 element.appendChild(a); 1510 } else { 1511 element.textContent = 'Error'; 1512 } 1513 } 1514 1515 function findInArray(arr, element) { 1516 for (var x = 0; x < arr.length; x++) { 1517 if (arr[x] == element) { 1518 return x; 1519 } 1520 } 1521 return -1; 1522 } 1523 1524 function selectItem(elementid, path) { 1525 var element = $(elementid); 1526 if (element.className == 'filebrowserow downloading') { 1527 return; 1528 } 1529 var index; 1530 if ((index = findInArray(currentlySelectedItems, element)) != -1) { 1531 // the user must want to toggle 1532 currentlySelectedItems.splice(index, 1); 1533 element.classname = 'filebrowserow'; 1534 index = findInArray(currentlySelectedPaths, path); 1535 currentlySelectedPaths.splice(index, 1); 1536 } else { 1537 if (!multiSelect) { 1538 // clear out previous selected elements 1539 for (var x = 0; x < currentlySelectedItems.length; x++) { 1540 currentlySelectedItems[x].className = 'filebrowserow'; 1541 } 1542 currentlySelectedItems = []; 1543 currentlySelectedPaths = []; 1544 } 1545 element.className = 'selected filebrowserow'; 1546 currentlySelectedItems.push(element); 1547 currentlySelectedPaths.push(path); 1548 if (inSaveMode) { 1549 var extracted = getPathAndFilenameForPath(path); 1550 var file = $('filename'); 1551 file.value = extracted[2]; 1552 } 1553 } 1554 } 1555 1556 function setItemInfoText(element, text) { 1557 var span; 1558 if (element.childNodes.length == 2) { 1559 span = document.createElement('span'); 1560 span.className = 'name'; 1561 span.textContent = text; 1562 element.appendChild(span); 1563 element.childNodes.item(1).style.display = 'none'; 1564 } else { 1565 span = element.childNodes.item(2); 1566 span.textContent = text; 1567 } 1568 } 1569 1570 function getUnknownFileTypeHandler() { 1571 return function() { 1572 var element = event.currentTarget; 1573 setItemInfoText(element, 1574 localStrings.getStringF('error_unknown_file_type', 1575 element.childNodes.item(1).textContent)); 1576 }; 1577 } 1578 1579 function getFunctionForItem(path, id, isDirectory) { 1580 if (isDirectory) { 1581 return function() { 1582 selectItem(id, path); 1583 descend(path, currentNode); 1584 }; 1585 } 1586 if (inSelectMode) { 1587 return function() { 1588 selectItem(id, path); 1589 }; 1590 } 1591 if (pathIsAudioFile(path)) { 1592 return function() { 1593 playMediaFile(path); 1594 }; 1595 } 1596 if (pathIsVideoFile(path)) { 1597 return function() { 1598 playMediaFile(path); 1599 }; 1600 } 1601 if (pathIsImageFile(path)) { 1602 return function() { 1603 showImage(path); 1604 } 1605 } 1606 if (pathIsHtmlFile(path)) { 1607 return function() { 1608 showPath(path); 1609 } 1610 } 1611 if (pathIsPdfFile(path) && supportsPdf()) { 1612 return function() { 1613 showPath(path); 1614 } 1615 } 1616 1617 return getUnknownFileTypeHandler(); 1618 } 1619 1620 /** 1621 * Double click handler for items. 1622 * 1623 * @param {string} path The file path of the item. 1624 * @param {string} id The id for this item. 1625 * @param {boolean} isDirectory Whether this item is a directory. 1626 * @return {Function} The function to handle the double click. 1627 */ 1628 function getDoubleClickForItem(path, id, isDirectory) { 1629 if (isDirectory) { 1630 return function() {}; 1631 } 1632 if (inSelectMode) { 1633 return function() { 1634 selectItem(id, path); 1635 dialogOkClick(); 1636 }; 1637 } 1638 return function() {}; 1639 } 1640 1641 var elementIdCounter = 0; 1642 1643 function createNewFakeItem(title, path, isDirectory, hasspinner) { 1644 var element = document.createElement('li'); 1645 1646 element.className = 'filebrowserow'; 1647 element.id = path; 1648 elementIdCounter++; 1649 var link; 1650 link = document.createElement('div'); 1651 link.className = 'rowlink'; 1652 1653 var icon = document.createElement('div'); 1654 icon.className = getClassForPath(path, isDirectory); 1655 link.appendChild(icon); 1656 1657 var span = document.createElement('span'); 1658 span.className = 'name'; 1659 span.textContent = title; 1660 link.appendChild(span); 1661 1662 element.appendChild(link); 1663 1664 // Setup Menu 1665 var currentPath = currentSavedPath; 1666 if (hasspinner) { 1667 var spinicon = document.createElement('div'); 1668 spinicon.align = 'right'; 1669 spinicon.className = 'spinicon'; 1670 element.appendChild(spinicon); 1671 } 1672 return element; 1673 } 1674 1675 function createNewItem(title, path, isDirectory) { 1676 var element = document.createElement('li'); 1677 element.setAttribute('draggable', 'true'); 1678 1679 element.addEventListener('dragstart', function(e) { 1680 e.dataTransfer.effectAllowed = 'copy'; 1681 e.dataTransfer.setData('Text', this.id); 1682 }, false); 1683 1684 element.className = 'filebrowserow'; 1685 element.title = title; 1686 /*element.id = 'listItem' + elementIdCounter;*/ 1687 element.id = path; 1688 elementIdCounter++; 1689 var link; 1690 link = document.createElement('div'); 1691 link.onclick = getFunctionForItem(path, element.id, isDirectory); 1692 link.ondblclick = getDoubleClickForItem(path, element.id, isDirectory); 1693 link.className = 'rowlink'; 1694 1695 var icon = document.createElement('div'); 1696 icon.className = getClassForPath(path, isDirectory); 1697 link.appendChild(icon); 1698 1699 var span = document.createElement('span'); 1700 if (inSelectMode) { 1701 span.className = 'name'; 1702 } else { 1703 span.className = 'namelink'; 1704 } 1705 span.textContent = title; 1706 link.appendChild(span); 1707 1708 element.appendChild(link); 1709 1710 // Setup Menu 1711 var currentPath = currentSavedPath; 1712 if (currentPath != 'roots') { 1713 var menuicon = document.createElement('div'); 1714 var menu = document.createElement('div'); 1715 menu.className = 'menu'; 1716 if ((pathIsVideoFile(path) || pathIsAudioFile(path)) && 1717 mediaPlayerEnabled) { 1718 var enqueueitem = document.createElement('div'); 1719 enqueueitem.textContent = localStrings.getString('enqueue'); 1720 enqueueitem.className = 'menuitem'; 1721 enqueueitem.onclick = partial(enqueueMediaFile, path); 1722 menu.appendChild(enqueueitem); 1723 } 1724 var deleteitem = document.createElement('div'); 1725 deleteitem.textContent = localStrings.getString('delete'); 1726 deleteitem.className = 'menuitem'; 1727 deleteitem.onclick = partial(deleteFileConfirm, path); 1728 menu.appendChild(deleteitem); 1729 menuicon.align = 'right'; 1730 menuicon.className = 'menuicon'; 1731 menuicon.onclick = partial(showMenu, path); 1732 menuicon.appendChild(menu); 1733 element.appendChild(menuicon); 1734 menus[path] = menuicon; 1735 } 1736 if (isDirectory) { 1737 var rightarrow = document.createElement('span'); 1738 rightarrow.innerHTML = ' »'; 1739 rightarrow.className = 'rightarrow'; 1740 link.appendChild(rightarrow); 1741 } 1742 return element; 1743 } 1744 1745 function fixTitleForItem(element, result) { 1746 element.title = result.file_name; 1747 // This is a bit fragile. 1748 element.getElementsByTagName('span')[0].textContent = result.file_name; 1749 } 1750 1751 function clearChildren(element) { 1752 element.innerHTML = ''; 1753 } 1754 1755 function popout(path) { 1756 var newPath = 'chrome://filebrowse#' + path; 1757 chrome.send('openNewPopupWindow', [newPath]); 1758 } 1759 1760 function createNewList(title, results, main, path) { 1761 downloadList = []; 1762 clearChildren(main); 1763 1764 var mainList = document.createElement('div'); 1765 if (advancedEnabled) { 1766 mainList.className = 'columnlistadv'; 1767 } else { 1768 mainList.className = 'columnlist'; 1769 } 1770 1771 var list = document.createElement('ul'); 1772 list.className = 'filebrowselist'; 1773 list.id = 'list/dir/' + path; 1774 // Use the translated title for the Downloads directory. 1775 if (path == localStrings.getString('downloadpath')) { 1776 document.title = (localStrings.getString('downloadtitle') || title); 1777 } else { 1778 document.title = title; 1779 } 1780 if (advancedEnabled) { 1781 var header = document.createElement('div'); 1782 header.className = 'header'; 1783 var divTitle = document.createElement('div'); 1784 divTitle.className = 'title'; 1785 if (inFullMode) { 1786 divTitle.style['text-align'] = 'center'; 1787 } 1788 divTitle.innerText = title; 1789 if (inFullMode && (path.length != 0)) { 1790 var popOutButton = document.createElement('div'); 1791 popOutButton.innerHTML = '∏'; 1792 popOutButton.className = 'popout'; 1793 popOutButton.onclick = partial(popout, path); 1794 header.appendChild(popOutButton); 1795 } 1796 header.appendChild(divTitle); 1797 main.appendChild(header); 1798 } 1799 main.appendChild(mainList); 1800 for (var x = 0; x < results.length; x++) { 1801 var element = createNewItem(results[x].title, 1802 results[x].path, 1803 results[x].isDirectory); 1804 list.appendChild(element); 1805 } 1806 mainList.appendChild(list); 1807 } 1808 1809 </script> 1810 <body onload='load();' onclick='clearMenus()' onselectstart='return false' 1811 i18n-values=".style.fontFamily:fontfamily"> 1812 <div id='header' class=''> 1813 <div id='back' class='backbutton controlbutton' onclick='goBackInList();return false;'> 1814 <img src="shared/images/filebrowse_back.png"> 1815 </div> 1816 <div id='currenttitle' class=''></div> 1817 </div><br> 1818 <div id='main' class='container'></div> 1819 <div id='status' class='status'></div> 1820 </body> 1821 </html> 1822