49 _additionalInfoFields: [
50 "editBMPanel_descriptionRow",
51 "editBMPanel_loadInSidebarCheckbox",
52 "editBMPanel_keywordRow",
55 _initFolderTree:
function() {
57 this._places.place =
"place:excludeItems=1&expandQueries=0&folder=" + leftPaneRoot;
60 selectLeftPaneQuery:
function PO_selectLeftPaneQuery(aQueryName) {
62 this._places.selectItems([itemId]);
64 if (aQueryName ==
"AllBookmarks")
65 asContainer(this._places.selectedNode).containerOpen =
true;
68 init:
function PO_init() {
69 this._places = document.getElementById(
"placesList");
70 this._content = document.getElementById(
"placeContent");
71 this._initFolderTree();
73 var leftPaneSelection =
"AllBookmarks";
74 if (
"arguments" in
window &&
window.arguments.length > 0)
75 leftPaneSelection =
window.arguments[0];
77 this.selectLeftPaneQuery(leftPaneSelection);
79 this._backHistory.splice(0);
80 document.getElementById(
"OrganizerCommand:Back").setAttribute(
"disabled",
true);
82 var view = this._content.treeBoxObject.view;
83 if (view.rowCount > 0)
84 view.selection.select(0);
86 this._content.focus();
91 #ifdef PLACES_QUERY_BUILDER
96 window.addEventListener(
"AppCommand",
this,
true);
100 var findMenuItem = document.getElementById(
"menu_find");
101 findMenuItem.setAttribute(
"command",
"OrganizerCommand_find:all");
102 var findKey = document.getElementById(
"key_find");
103 findKey.setAttribute(
"command",
"OrganizerCommand_find:all");
106 var elements = [
"cmd_handleBackspace",
"cmd_handleShiftBackspace"];
107 for (var
i=0;
i < elements.length;
i++) {
108 document.getElementById(elements[
i]).setAttribute(
"disabled",
"true");
113 var historyMenuBack = document.getElementById(
"historyMenuBack");
114 historyMenuBack.removeAttribute(
"key");
115 var historyMenuForward = document.getElementById(
"historyMenuForward");
116 historyMenuForward.removeAttribute(
"key");
120 document.getElementById(
"placesContext")
121 .removeChild(document.getElementById(
"placesContext_show:info"));
125 if (aIID.equals(Components.interfaces.nsIDOMEventListener) ||
126 aIID.equals(Components.interfaces.nsISupports))
129 throw Components.results.NS_NOINTERFACE;
132 handleEvent:
function PO_handleEvent(aEvent) {
133 if (aEvent.type !=
"AppCommand")
136 aEvent.stopPropagation();
137 switch (aEvent.command) {
139 if (this._backHistory.length > 0)
143 if (this._forwardHistory.length > 0)
152 destroy:
function PO_destroy() {
157 return this._location;
160 set location(aLocation) {
161 if (!aLocation || this._location == aLocation)
165 this._backHistory.unshift(this.location);
166 this._forwardHistory.splice(0);
169 this._location = aLocation;
170 this._places.selectPlaceURI(aLocation);
172 if (!this._places.hasSelection) {
174 this._content.place = aLocation;
176 this.onContentTreeSelect();
179 if (this._backHistory.length == 0)
180 document.getElementById(
"OrganizerCommand:Back").setAttribute(
"disabled",
true);
182 document.getElementById(
"OrganizerCommand:Back").removeAttribute(
"disabled");
183 if (this._forwardHistory.length == 0)
184 document.getElementById(
"OrganizerCommand:Forward").setAttribute(
"disabled",
true);
186 document.getElementById(
"OrganizerCommand:Forward").removeAttribute(
"disabled");
194 back:
function PO_back() {
195 this._forwardHistory.unshift(this.location);
196 var historyEntry = this._backHistory.shift();
197 this._location =
null;
198 this.location = historyEntry;
200 forward:
function PO_forward() {
201 this._backHistory.unshift(this.location);
202 var historyEntry = this._forwardHistory.shift();
203 this._location =
null;
204 this.location = historyEntry;
217 _cachedLeftPaneSelectedURI:
null,
218 onPlaceSelected:
function PO_onPlaceSelected(resetSearchBox) {
220 if (!this._places.hasSelection)
223 var
node = this._places.selectedNode;
224 var queries =
asQuery(node).getQueries({});
227 var
options = node.queryOptions.clone();
228 options.excludeItems =
false;
229 var placeURI = PlacesUtils.history.queriesToQueryString(queries,
236 if (this._content.place != placeURI || !resetSearchBox) {
237 this._content.place = placeURI;
239 this.location = node.uri;
247 var folderButton = document.getElementById(
"scopeBarFolder");
248 var folderTitle = node.title || folderButton.getAttribute(
"emptytitle");
249 folderButton.setAttribute(
"label", folderTitle);
250 var cmd = document.getElementById(
"OrganizerCommand_find:current");
252 cmd.setAttribute(
"label", label);
262 if (node.uri ==
this._cachedLeftPaneSelectedURI)
264 this._cachedLeftPaneSelectedURI = node.uri;
270 this._setSearchScopeForNode(node);
271 if (this._places.treeBoxObject.focused)
272 this._fillDetailsPane([node]);
280 _setSearchScopeForNode:
function PO__setScopeForNode(aNode) {
281 var itemId = aNode.itemId;
282 if (PlacesUtils.nodeIsHistoryContainer(aNode) ||
291 var folderButton = document.getElementById(
"scopeBarFolder");
292 folderButton.hidden = !PlacesUtils.nodeIsFolder(aNode) ||
303 onTreeClick:
function PO_onTreeClick(aEvent) {
305 if (aEvent.target.localName !=
"treechildren")
308 var currentView = aEvent.currentTarget;
309 var selectedNode = currentView.selectedNode;
311 var doubleClickOnFlatList = (aEvent.button == 0 && aEvent.detail == 2 &&
312 aEvent.target.parentNode.flatList);
313 var middleClick = (aEvent.button == 1 && aEvent.detail == 1);
315 if (PlacesUtils.nodeIsURI(selectedNode) &&
316 (doubleClickOnFlatList || middleClick)) {
320 else if (middleClick &&
321 PlacesUtils.nodeIsContainer(selectedNode)) {
336 onTreeFocus:
function PO_onTreeFocus(aEvent) {
337 var currentView = aEvent.currentTarget;
338 var selectedNodes = currentView.selectedNode ? [currentView.selectedNode] :
339 this._content.getSelectionNodes();
340 this._fillDetailsPane(selectedNodes);
343 openFlatContainer:
function PO_openFlatContainerFlatContainer(aContainer) {
344 if (aContainer.itemId != -1)
345 this._places.selectItems([aContainer.itemId]);
346 else if (PlacesUtils.nodeIsQuery(aContainer))
347 this._places.selectPlaceURI(aContainer.uri);
350 openSelectedNode:
function PO_openSelectedNode(aEvent) {
351 PlacesUIUtils.openNodeWithEvent(this._content.selectedNode, aEvent);
358 getCurrentOptions:
function PO_getCurrentOptions() {
359 return asQuery(this._content.getResult().root).queryOptions;
366 getCurrentQueries:
function PO_getCurrentQueries() {
367 return asQuery(this._content.getResult().root).getQueries({});
373 importBookmarks:
function PO_import() {
375 var features =
"modal,centerscreen,chrome,resizable=no";
380 openDialog(
"chrome://browser/content/migration/migration.xul",
381 "migration", features,
"bookmarks");
383 this.importFromFile();
389 importFromFile:
function PO_importFromFile() {
390 var fp =
Cc[
"@mozilla.org/filepicker;1"].
393 Ci.nsIFilePicker.modeOpen);
394 fp.appendFilters(
Ci.nsIFilePicker.filterHTML);
395 if (fp.show() !=
Ci.nsIFilePicker.returnCancel) {
397 var
importer =
Cc[
"@mozilla.org/browser/places/import-export-service;1"].
399 var
file = fp.file.QueryInterface(
Ci.nsILocalFile);
400 importer.importHTMLFromFile(file,
false);
408 exportBookmarks:
function PO_exportBookmarks() {
409 var fp =
Cc[
"@mozilla.org/filepicker;1"].
412 Ci.nsIFilePicker.modeSave);
413 fp.appendFilters(
Ci.nsIFilePicker.filterHTML);
414 fp.defaultString =
"bookmarks.html";
415 if (fp.show() !=
Ci.nsIFilePicker.returnCancel) {
416 var exporter =
Cc[
"@mozilla.org/browser/places/import-export-service;1"].
418 exporter.exportHTMLToFile(fp.file);
425 populateRestoreMenu:
function PO_populateRestoreMenu() {
426 var restorePopup = document.getElementById(
"fileRestorePopup");
428 var dateSvc =
Cc[
"@mozilla.org/intl/scriptabledateformat;1"].
433 while (restorePopup.childNodes.length > 1)
434 restorePopup.removeChild(restorePopup.firstChild);
437 var localizedFilename = PlacesUtils.getString(
"bookmarksArchiveFilename");
438 var localizedFilenamePrefix = localizedFilename.substr(0, localizedFilename.indexOf(
"-"));
440 var files = this.bookmarksBackupDir.directoryEntries;
441 while (files.hasMoreElements()) {
442 var f = files.getNext().QueryInterface(
Ci.nsIFile);
443 var rx =
new RegExp(
"^(bookmarks|" + localizedFilenamePrefix +
444 ")-([0-9]{4}-[0-9]{2}-[0-9]{2})\.json$");
445 if (!f.isHidden() && f.leafName.match(rx)) {
446 var
date = f.leafName.match(rx)[2].replace(/-/g,
"/");
447 var dateObj =
new Date(date);
448 fileList.push({date: dateObj, filename: f.leafName});
452 fileList.sort(
function PO_fileList_compare(a, b) {
453 return b.date - a.date;
456 if (fileList.length == 0)
460 for (var
i = 0;
i < fileList.length;
i++) {
461 var m = restorePopup.insertBefore
462 (document.createElement(
"menuitem"),
463 document.getElementById(
"restoreFromFile"));
464 m.setAttribute(
"label",
465 dateSvc.FormatDate(
"",
466 Ci.nsIScriptableDateFormat.dateFormatLong,
467 fileList[
i].date.getFullYear(),
468 fileList[
i].date.getMonth() + 1,
469 fileList[
i].date.getDate()));
470 m.setAttribute(
"value", fileList[
i].filename);
471 m.setAttribute(
"oncommand",
472 "PlacesOrganizer.onRestoreMenuItemClick(this);");
474 restorePopup.insertBefore(document.createElement(
"menuseparator"),
475 document.getElementById(
"restoreFromFile"));
481 onRestoreMenuItemClick:
function PO_onRestoreMenuItemClick(
aMenuItem) {
482 var
dirSvc =
Cc[
"@mozilla.org/file/directory_service;1"].
484 var bookmarksFile = dirSvc.get(
"ProfD",
Ci.nsIFile);
485 bookmarksFile.append(
"bookmarkbackups");
486 bookmarksFile.append(
aMenuItem.getAttribute(
"value"));
487 if (!bookmarksFile.exists())
489 this.restoreBookmarksFromFile(bookmarksFile);
496 onRestoreBookmarksFromFile:
function PO_onRestoreBookmarksFromFile() {
497 var fp =
Cc[
"@mozilla.org/filepicker;1"].createInstance(
Ci.nsIFilePicker);
499 Ci.nsIFilePicker.modeOpen);
500 fp.appendFilter(
PlacesUIUtils.getString(
"bookmarksRestoreFilterName"),
502 fp.appendFilters(
Ci.nsIFilePicker.filterAll);
504 var
dirSvc =
Cc[
"@mozilla.org/file/directory_service;1"].
506 var backupsDir = dirSvc.get(
"Desk",
Ci.nsILocalFile);
507 fp.displayDirectory = backupsDir;
509 if (fp.show() !=
Ci.nsIFilePicker.returnCancel)
510 this.restoreBookmarksFromFile(fp.file);
516 restoreBookmarksFromFile:
function PO_restoreBookmarksFromFile(aFile) {
518 if (!aFile.leafName.match(/\.json$/)) {
519 this._showErrorAlert(
PlacesUIUtils.getString(
"bookmarksRestoreFormatError"));
524 var prompts =
Cc[
"@mozilla.org/embedcomp/prompt-service;1"].
526 if (!prompts.confirm(
null,
532 PlacesUtils.restoreBookmarksFromJSONFile(aFile);
535 this._showErrorAlert(
PlacesUIUtils.getString(
"bookmarksRestoreParseError"));
539 _showErrorAlert:
function PO__showErrorAlert(aMsg) {
540 var brandShortName = document.getElementById(
"brandStrings").
541 getString(
"brandShortName");
543 Cc[
"@mozilla.org/embedcomp/prompt-service;1"].
545 alert(
window, brandShortName, aMsg);
553 backupBookmarks:
function PO_backupBookmarks() {
554 var fp =
Cc[
"@mozilla.org/filepicker;1"].createInstance(
Ci.nsIFilePicker);
556 Ci.nsIFilePicker.modeSave);
557 fp.appendFilter(
PlacesUIUtils.getString(
"bookmarksRestoreFilterName"),
560 var
dirSvc =
Cc[
"@mozilla.org/file/directory_service;1"].
562 var backupsDir = dirSvc.get(
"Desk",
Ci.nsILocalFile);
563 fp.displayDirectory = backupsDir;
565 fp.defaultString = PlacesUtils.getBackupFilename();
567 if (fp.show() !=
Ci.nsIFilePicker.returnCancel) {
568 PlacesUtils.backupBookmarksToFile(fp.file);
571 var latestBackup = PlacesUtils.getMostRecentBackup();
572 if (!latestBackup || latestBackup != fp.file) {
573 latestBackup.remove(
false);
574 var
name = PlacesUtils.getBackupFilename();
575 fp.file.copyTo(this.bookmarksBackupDir, name);
580 get bookmarksBackupDir() {
581 delete this.bookmarksBackupDir;
582 var
dirSvc =
Cc[
"@mozilla.org/file/directory_service;1"].
584 var bookmarksBackupDir = dirSvc.get(
"ProfD",
Ci.nsIFile);
585 bookmarksBackupDir.append(
"bookmarkbackups");
586 if (!bookmarksBackupDir.exists())
587 bookmarksBackupDir.create(
Ci.nsIFile.DIRECTORY_TYPE, 0700);
588 return this.bookmarksBackupDir = bookmarksBackupDir;
591 _paneDisabled:
false,
592 _setDetailsFieldsDisabledState:
593 function PO__setDetailsFieldsDisabledState(aDisabled) {
595 document.getElementById(
"paneElementsBroadcaster")
596 .setAttribute(
"disabled",
"true");
599 document.getElementById(
"paneElementsBroadcaster")
600 .removeAttribute(
"disabled");
604 _detectAndSetDetailsPaneMinimalState:
605 function PO__detectAndSetDetailsPaneMinimalState(aNode) {
614 var infoBox = document.getElementById(
"infoBox");
615 var infoBoxExpander = document.getElementById(
"infoBoxExpander");
616 var infoBoxExpanderWrapper = document.getElementById(
"infoBoxExpanderWrapper");
617 var additionalInfoBroadcaster = document.getElementById(
"additionalInfoBroadcaster");
620 infoBoxExpanderWrapper.hidden =
true;
623 if (aNode.itemId != -1 &&
624 ((PlacesUtils.nodeIsFolder(aNode) &&
625 !PlacesUtils.nodeIsLivemarkContainer(aNode)) ||
626 PlacesUtils.nodeIsLivemarkItem(aNode))) {
627 if (infoBox.getAttribute(
"minimal") ==
"true")
628 infoBox.setAttribute(
"wasminimal",
"true");
629 infoBox.removeAttribute(
"minimal");
630 infoBoxExpanderWrapper.hidden =
true;
633 if (infoBox.getAttribute(
"wasminimal") ==
"true")
634 infoBox.setAttribute(
"minimal",
"true");
635 infoBox.removeAttribute(
"wasminimal");
636 infoBoxExpanderWrapper.hidden =
637 this._additionalInfoFields.every(
function (
id)
638 document.getElementById(
id).collapsed);
640 additionalInfoBroadcaster.hidden = infoBox.getAttribute(
"minimal") ==
"true";
644 updateThumbnailProportions:
function PO_updateThumbnailProportions() {
645 var previewBox = document.getElementById(
"previewBox");
646 var canvas = document.getElementById(
"itemThumbnail");
647 var
height = previewBox.boxObject.height;
648 var
width = height * (screen.width / screen.height);
649 canvas.width =
width;
653 onContentTreeSelect:
function PO_onContentTreeSelect() {
654 if (this._content.treeBoxObject.focused)
655 this._fillDetailsPane(this._content.getSelectionNodes());
658 _fillDetailsPane:
function PO__fillDetailsPane(aNodeList) {
659 var infoBox = document.getElementById(
"infoBox");
660 var detailsDeck = document.getElementById(
"detailsDeck");
664 infoBox.hidden =
false;
665 var aSelectedNode = aNodeList.length == 1 ? aNodeList[0] :
null;
669 var focusedElement = document.commandDispatcher.focusedElement;
670 if ((focusedElement instanceof HTMLInputElement ||
671 focusedElement instanceof HTMLTextAreaElement) &&
672 /^editBMPanel.*/.test(focusedElement.parentNode.parentNode.id))
673 focusedElement.blur();
678 var concreteId = PlacesUtils.getConcreteItemId(aSelectedNode);
683 if (nodeIsSame && detailsDeck.selectedIndex == 1 &&
692 if (aSelectedNode && !PlacesUtils.nodeIsSeparator(aSelectedNode)) {
693 detailsDeck.selectedIndex = 1;
698 var concreteId = PlacesUtils.getConcreteItemId(aSelectedNode);
699 var isRootItem = concreteId != -1 && PlacesUtils.isRootItem(concreteId);
700 var readOnly = isRootItem ||
701 aSelectedNode.parent.itemId ==
PlacesUIUtils.leftPaneFolderId;
702 var useConcreteId = isRootItem ||
703 PlacesUtils.nodeIsTagQuery(aSelectedNode);
705 if (concreteId != -1 && useConcreteId)
707 else if (aSelectedNode.itemId != -1)
708 itemId = aSelectedNode.itemId;
710 itemId = PlacesUtils._uri(aSelectedNode.uri);
713 forceReadOnly: readOnly });
720 if (aSelectedNode.itemId == -1 &&
721 (PlacesUtils.nodeIsDay(aSelectedNode) ||
722 PlacesUtils.nodeIsHost(aSelectedNode)))
725 this._detectAndSetDetailsPaneMinimalState(aSelectedNode);
727 else if (!aSelectedNode && aNodeList[0]) {
729 for (var
i = 0;
i < aNodeList.length;
i++) {
730 if (!PlacesUtils.nodeIsBookmark(aNodeList[
i]) &&
731 !PlacesUtils.nodeIsURI(aNodeList[i])) {
732 detailsDeck.selectedIndex = 0;
733 var selectItemDesc = document.getElementById(
"selectItemDescription");
734 var itemsCountLabel = document.getElementById(
"itemsCountText");
735 selectItemDesc.hidden =
false;
736 itemsCountLabel.value =
737 PlacesUIUtils.getFormattedString(
"detailsPane.multipleItems",
739 infoBox.hidden =
true;
742 itemIds[
i] = aNodeList[
i].itemId != -1 ? aNodeList[
i].itemId :
743 PlacesUtils._uri(aNodeList[i].
uri);
745 detailsDeck.selectedIndex = 1;
747 { hiddenRows: [
"folderPicker",
753 this._detectAndSetDetailsPaneMinimalState(aSelectedNode);
756 detailsDeck.selectedIndex = 0;
757 infoBox.hidden =
true;
758 var selectItemDesc = document.getElementById(
"selectItemDescription");
759 var itemsCountLabel = document.getElementById(
"itemsCountText");
760 var rowCount = this._content.treeBoxObject.view.rowCount;
762 selectItemDesc.hidden =
true;
763 itemsCountLabel.value =
PlacesUIUtils.getString(
"detailsPane.noItems");
766 selectItemDesc.hidden =
false;
768 itemsCountLabel.value =
PlacesUIUtils.getString(
"detailsPane.oneItem");
770 itemsCountLabel.value =
771 PlacesUIUtils.getFormattedString(
"detailsPane.multipleItems",
779 _updateThumbnail:
function PO__updateThumbnail() {
780 var bo = document.getElementById(
"previewBox").boxObject;
781 var
width = bo.width;
784 var canvas = document.getElementById(
"itemThumbnail");
785 var ctx = canvas.getContext(
'2d');
786 var notAvailableText = canvas.getAttribute(
"notavailabletext");
788 ctx.fillStyle =
"-moz-Dialog";
789 ctx.fillRect(0, 0, width, height);
790 ctx.translate(width/2, height/2);
792 ctx.fillStyle =
"GrayText";
793 ctx.mozTextStyle =
"12pt sans serif";
794 var len = ctx.mozMeasureText(notAvailableText);
795 ctx.translate(-len/2,0);
796 ctx.mozDrawText(notAvailableText);
800 toggleAdditionalInfoFields:
function PO_toggleAdditionalInfoFields() {
801 var infoBox = document.getElementById(
"infoBox");
802 var infoBoxExpander = document.getElementById(
"infoBoxExpander");
803 var infoBoxExpanderLabel = document.getElementById(
"infoBoxExpanderLabel");
804 var additionalInfoBroadcaster = document.getElementById(
"additionalInfoBroadcaster");
806 if (infoBox.getAttribute(
"minimal") ==
"true") {
807 infoBox.removeAttribute(
"minimal");
808 infoBoxExpanderLabel.value = infoBoxExpanderLabel.getAttribute(
"lesslabel");
809 infoBoxExpanderLabel.accessKey = infoBoxExpanderLabel.getAttribute(
"lessaccesskey");
810 infoBoxExpander.className =
"expander-up";
811 additionalInfoBroadcaster.removeAttribute(
"hidden");
814 infoBox.setAttribute(
"minimal",
"true");
815 infoBoxExpanderLabel.value = infoBoxExpanderLabel.getAttribute(
"morelabel");
816 infoBoxExpanderLabel.accessKey = infoBoxExpanderLabel.getAttribute(
"moreaccesskey");
817 infoBoxExpander.className =
"expander-down";
818 additionalInfoBroadcaster.setAttribute(
"hidden",
"true");
825 saveSearch:
function PO_saveSearch() {
828 var
options = this.getCurrentOptions();
830 #ifdef PLACES_QUERY_BUILDER
833 var queries = this.getCurrentQueries();
836 var placeSpec = PlacesUtils.history.queriesToQueryString(queries,
839 var placeURI =
Cc[
"@mozilla.org/network/io-service;1"].
847 var inputLabel =
PlacesUIUtils.getString(
"saveSearch.inputLabel");
848 var defaultText =
PlacesUIUtils.getString(
"saveSearch.inputDefaultText");
850 var prompts =
Cc[
"@mozilla.org/embedcomp/prompt-service;1"].
853 var input = {
value: defaultText};
854 var save = prompts.prompt(
null, title, inputLabel, input,
null, check);
857 if (!save || input.value ==
"")
862 PlacesUtils.bookmarksMenuFolderId,
863 PlacesUtils.bookmarks.DEFAULT_INDEX,
868 this._places.selectPlaceURI(placeSpec);
881 return document.getElementById(
"searchFilter");
889 if (this._folders.length == 0)
890 this._folders.push(PlacesUtils.bookmarksMenuFolderId,
891 PlacesUtils.unfiledBookmarksFolderId,
892 PlacesUtils.toolbarFolderId);
893 return this._folders;
895 set folders(aFolders) {
896 this._folders = aFolders;
907 search:
function PSB_search(filterString) {
913 if (filterString ==
"") {
914 PO.onPlaceSelected(
false);
918 var currentOptions = PO.getCurrentOptions();
919 var content = PO._content;
925 content.applyFilter(filterString, this.folders);
931 content.applyFilter(filterString, this.folders);
934 if (currentOptions.queryType !=
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY) {
935 var query = PlacesUtils.history.getNewQuery();
936 query.searchTerms = filterString;
937 var
options = currentOptions.clone();
939 options.resultType = currentOptions.RESULT_TYPE_URI;
940 options.queryType =
Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY;
941 content.load([query], options);
944 content.applyFilter(filterString);
947 throw "Invalid filterCollection on search";
960 findAll:
function PSB_findAll() {
968 findCurrent:
function PSB_findCurrent() {
978 updateCollectionTitle:
function PSB_updateCollectionTitle(title) {
980 this.searchFilter.emptyText =
981 PlacesUIUtils.getFormattedString(
"searchCurrentDefault", [title]);
983 this.searchFilter.emptyText = this.filterCollection ==
"history" ?
991 get filterCollection() {
992 return this.searchFilter.getAttribute(
"collection");
994 set filterCollection(collectionName) {
995 if (collectionName == this.filterCollection)
996 return collectionName;
998 this.searchFilter.setAttribute(
"collection", collectionName);
1000 var newGrayText =
null;
1001 if (collectionName ==
"collection") {
1003 document.getElementById(
"scopeBarFolder").
1006 this.updateCollectionTitle(newGrayText);
1007 return collectionName;
1013 focus:
function PSB_focus() {
1014 this.searchFilter.focus();
1020 init:
function PSB_init() {
1021 this.updateCollectionTitle();
1028 return this.searchFilter.value;
1031 return this.searchFilter.value =
value;
1034 showSearchUI:
function PSB_showSearchUI() {
1036 var searchModifiers = document.getElementById(
"searchModifiers");
1037 searchModifiers.hidden =
false;
1039 #ifdef PLACES_QUERY_BUILDER
1042 document.getElementById(
"OrganizerCommand_search:moreCriteria").doCommand();
1046 hideSearchUI:
function PSB_hideSearchUI() {
1047 var searchModifiers = document.getElementById(
"searchModifiers");
1048 searchModifiers.hidden =
true;
1060 #ifdef PLACES_QUERY_BUILDER
1069 advancedSearch_N_Subject:
"advancedSearch_N_SubjectKeyword",
1070 advancedSearch_N_LocationMenulist:
false,
1071 advancedSearch_N_TimeMenulist:
false,
1072 advancedSearch_N_Textbox:
"",
1073 advancedSearch_N_TimePicker:
false,
1074 advancedSearch_N_TimeMenulist2:
false
1077 advancedSearch_N_Subject:
"advancedSearch_N_SubjectLocation",
1078 advancedSearch_N_LocationMenulist:
"advancedSearch_N_LocationMenuSelected",
1079 advancedSearch_N_TimeMenulist:
false,
1080 advancedSearch_N_Textbox:
"",
1081 advancedSearch_N_TimePicker:
false,
1082 advancedSearch_N_TimeMenulist2:
false
1085 advancedSearch_N_Subject:
"advancedSearch_N_SubjectVisited",
1086 advancedSearch_N_LocationMenulist:
false,
1087 advancedSearch_N_TimeMenulist:
true,
1088 advancedSearch_N_Textbox:
false,
1089 advancedSearch_N_TimePicker:
"date",
1090 advancedSearch_N_TimeMenulist2:
false
1092 _timeInLastSearch: {
1093 advancedSearch_N_Subject:
"advancedSearch_N_SubjectVisited",
1094 advancedSearch_N_LocationMenulist:
false,
1095 advancedSearch_N_TimeMenulist:
true,
1096 advancedSearch_N_Textbox:
"7",
1097 advancedSearch_N_TimePicker:
false,
1098 advancedSearch_N_TimeMenulist2:
true
1101 _queryBuilders:
null,
1104 init:
function PQB_init() {
1106 this._nextSearch = {
1107 "keyword": this._timeSearch,
1108 "visited": this._locationSearch,
1112 this._queryBuilders = {
1113 "keyword": this.setKeywordQuery,
1114 "visited": this.setVisitedQuery,
1115 "location": this.setLocationQuery
1118 this._maxRows = this._queryBuilders.length;
1120 this._dateService =
Cc[
"@mozilla.org/intl/scriptabledateformat;1"].
1127 hide:
function PQB_hide() {
1128 var advancedSearch = document.getElementById(
"advancedSearch");
1130 advancedSearch.collapsed =
true;
1136 show:
function PQB_show() {
1137 var advancedSearch = document.getElementById(
"advancedSearch");
1138 advancedSearch.collapsed =
false;
1141 toggleVisibility:
function ABP_toggleVisibility() {
1142 var expander = document.getElementById(
"organizerScopeBarExpander");
1143 var advancedSearch = document.getElementById(
"advancedSearch");
1144 if (advancedSearch.collapsed) {
1145 advancedSearch.collapsed =
false;
1146 expander.className =
"expander-down";
1147 expander.setAttribute(
"tooltiptext",
1148 expander.getAttribute(
"tooltiptextdown"));
1151 advancedSearch.collapsed =
true;
1152 expander.className =
"expander-up"
1153 expander.setAttribute(
"tooltiptext",
1154 expander.getAttribute(
"tooltiptextup"));
1166 _setRowId:
function PQB__setRowId(
element, rowId) {
1168 element.id =
element.id.replace(
"advancedSearch0",
"advancedSearch" + rowId);
1169 if (
element.hasAttribute(
"rowid"))
1170 element.setAttribute(
"rowid", rowId);
1171 for (var
i = 0;
i <
element.childNodes.length; ++
i) {
1172 this._setRowId(
element.childNodes[
i], rowId);
1176 _updateUIForRowChange:
function PQB__updateUIForRowChange() {
1179 var command = document.getElementById(
"OrganizerCommand_search:moreCriteria");
1180 if (this.numRows >= this._maxRows)
1181 command.setAttribute(
"disabled",
"true");
1183 command.removeAttribute(
"disabled");
1190 addRow:
function PQB_addRow() {
1193 if (this.numRows >= this._maxRows)
1197 var gridRows = document.getElementById(
"advancedSearchRows");
1198 var newRow = gridRows.firstChild.cloneNode(
true);
1199 newRow.hidden =
false;
1205 var searchType = this._keywordSearch;
1206 var lastMenu = document.getElementById(
"advancedSearch" +
1209 if (this.numRows > 0 && lastMenu && lastMenu.selectedItem)
1210 searchType = this._nextSearch[lastMenu.selectedItem.value];
1217 gridRows.appendChild(newRow);
1218 this._setRowId(newRow, ++this.numRows);
1222 if (this.numRows == 1) {
1229 var searchTermsField = document.getElementById(
"advancedSearch1Textbox");
1230 if (searchTermsField)
1236 this.showSearch(this.numRows, searchType);
1237 this._updateUIForRowChange();
1246 removeRow:
function PQB_removeRow(row) {
1248 row = document.getElementById(
"advancedSearch" + this.numRows +
"Row");
1249 row.parentNode.removeChild(row);
1252 if (this.numRows < 1) {
1263 this._updateUIForRowChange();
1266 onDateTyped:
function PQB_onDateTyped(
event, row) {
1267 var textbox = document.getElementById(
"advancedSearch" + row +
"TimePicker");
1268 var dateString = textbox.value;
1269 var dateArr = dateString.split(
"-");
1278 if ((dateArr.length & 1) == 0) {
1279 var mid = dateArr.length / 2;
1280 var dateStr0 = dateArr[0];
1281 var dateStr1 = dateArr[mid];
1282 for (var
i = 1;
i < mid; ++
i) {
1283 dateStr0 +=
"-" + dateArr[
i];
1284 dateStr1 +=
"-" + dateArr[
i + mid];
1286 d0 =
new Date(dateStr0);
1287 d1 =
new Date(dateStr1);
1290 if (d0 ==
null || d0 ==
"Invalid Date") {
1291 d0 =
new Date(dateString);
1294 if (d0 !=
null && d0 !=
"Invalid Date") {
1296 var calendar = document.getElementById(
"advancedSearch" + row +
"Calendar");
1297 if (d0.getFullYear() < 2000)
1298 d0.setFullYear(2000 + (d0.getFullYear() % 100));
1299 if (d1 !=
null && d1 !=
"Invalid Date") {
1300 if (d1.getFullYear() < 2000)
1301 d1.setFullYear(2000 + (d1.getFullYear() % 100));
1302 calendar.updateSelection(d0, d1);
1305 calendar.updateSelection(d0, d0);
1313 onCalendarChanged:
function PQB_onCalendarChanged(
event, row) {
1314 var calendar = document.getElementById(
"advancedSearch" + row +
"Calendar");
1315 var begin = calendar.beginrange;
1316 var end = calendar.endrange;
1323 var textbox = document.getElementById(
"advancedSearch" + row +
"TimePicker");
1324 var beginDate = begin.getDate();
1325 var beginMonth = begin.getMonth() + 1;
1326 var beginYear = begin.getFullYear();
1328 var endMonth = end.getMonth() + 1;
1329 var endYear = end.getFullYear();
1330 if (beginDate == endDate && beginMonth == endMonth && beginYear == endYear) {
1332 textbox.value = this._dateService.FormatDate(
"",
1333 this._dateService.dateFormatShort,
1341 var beginStr = this._dateService.FormatDate(
"",
1342 this._dateService.dateFormatShort,
1346 var endStr = this._dateService.FormatDate(
"",
1347 this._dateService.dateFormatShort,
1351 textbox.value = beginStr +
" - " + endStr;
1360 handleTimePickerClick:
function PQB_handleTimePickerClick(
event, row) {
1361 var popup = document.getElementById(
"advancedSearch" + row +
"DatePopup");
1365 var textbox = document.getElementById(
"advancedSearch" + row +
"TimePicker");
1366 popup.showPopup(textbox, -1, -1,
"popup",
"bottomleft",
"topleft");
1370 showSearch:
function PQB_showSearch(row, values) {
1371 for (
val in values) {
1372 var
id =
val.replace(
"_N_", row);
1373 var
element = document.getElementById(
id);
1374 if (values[
val] || typeof(values[
val]) ==
"string") {
1375 if (typeof(values[val]) ==
"string") {
1376 if (values[val] ==
"date") {
1380 element.value = this._dateService.FormatDate(
"",
1381 this._dateService.dateFormatShort,
1385 var calendar = document.getElementById(
"advancedSearch" + row +
"Calendar");
1386 calendar.updateSelection(d, d);
1388 else if (element.nodeName ==
"textbox") {
1390 element.value = values[
val];
1393 var itemId = values[
val].replace(
"_N_", row);
1394 var item = document.getElementById(itemId);
1395 element.selectedItem = item;
1398 element.hidden =
false;
1401 element.hidden =
true;
1408 setKeywordQuery:
function PQB_setKeywordQuery(query, prefix) {
1409 query.searchTerms += document.getElementById(prefix +
"Textbox").value +
" ";
1412 setLocationQuery:
function PQB_setLocationQuery(query, prefix) {
1413 var type = document.getElementById(prefix +
"LocationMenulist").selectedItem.value;
1414 if (type ==
"onsite") {
1415 query.domain = document.getElementById(prefix +
"Textbox").value;
1418 query.uriIsPrefix = (type ==
"startswith");
1419 var spec = document.getElementById(prefix +
"Textbox").value;
1420 var
ios =
Cc[
"@mozilla.org/network/io-service;1"].
1423 query.uri = ios.newURI(spec,
null,
null);
1429 query.uri = ios.newURI(
"http://" + spec,
null,
null);
1439 setVisitedQuery:
function PQB_setVisitedQuery(query, prefix) {
1440 var searchType = document.getElementById(prefix +
"TimeMenulist").selectedItem.value;
1441 const DAY_MSEC = 86400000;
1442 switch (searchType) {
1444 var calendar = document.getElementById(prefix +
"Calendar");
1445 var begin = calendar.beginrange.getTime();
1446 var end = calendar.endrange.getTime();
1448 end = begin + DAY_MSEC;
1450 query.beginTime = begin * 1000;
1451 query.endTime = end * 1000;
1454 var calendar = document.getElementById(prefix +
"Calendar");
1455 var time = calendar.beginrange.getTime();
1456 query.endTime = time * 1000;
1459 var calendar = document.getElementById(prefix +
"Calendar");
1460 var time = calendar.endrange.getTime();
1461 query.beginTime = time * 1000;
1464 var textbox = document.getElementById(prefix +
"Textbox");
1465 var amount = parseInt(textbox.value);
1466 amount = amount * DAY_MSEC;
1467 var menulist = document.getElementById(prefix +
"TimeMenulist2");
1468 if (menulist.selectedItem.value ==
"weeks")
1469 amount = amount * 7;
1470 else if (menulist.selectedItem.value ==
"months")
1471 amount = amount * 30;
1472 var
now =
new Date();
1474 query.beginTime = now * 1000;
1479 doSearch:
function PQB_doSearch() {
1481 var queryType = document.getElementById(
"advancedSearchType").selectedItem.value;
1483 if (queryType ==
"and")
1484 this.queries.push(PlacesUtils.history.getNewQuery());
1486 for (var
i = 1; updated < this.numRows; ++
i) {
1487 var prefix =
"advancedSearch" +
i;
1492 var querySubjectElement = document.getElementById(prefix +
"Subject");
1493 if (querySubjectElement) {
1497 if (queryType ==
"and")
1498 query = this.queries[0];
1500 query = PlacesUtils.history.getNewQuery();
1502 var querySubject = querySubjectElement.value;
1503 this._queryBuilders[querySubject](query, prefix);
1505 if (queryType ==
"or")
1506 this.queries.push(query);
1529 onScopeSelected:
function PQB_onScopeSelected(aButton) {
1530 switch (aButton.id) {
1531 case "scopeBarHistory":
1532 this.setScope(
"history");
1534 case "scopeBarFolder":
1535 this.setScope(
"collection");
1538 this.setScope(
"bookmarks");
1541 throw "Invalid search scope button ID";
1554 setScope:
function PQB_setScope(aScope) {
1556 var filterCollection;
1561 filterCollection =
"history";
1562 scopeButtonId =
"scopeBarHistory";
1568 if (!document.getElementById(
"scopeBarFolder").hidden) {
1569 filterCollection =
"collection";
1570 scopeButtonId =
"scopeBarFolder";
1571 folders.push(PlacesUtils.getConcreteItemId(
1578 filterCollection =
"bookmarks";
1579 scopeButtonId =
"scopeBarAll";
1580 folders.push(PlacesUtils.bookmarksMenuFolderId,
1581 PlacesUtils.toolbarFolderId,
1582 PlacesUtils.unfiledBookmarksFolderId);
1585 throw "Invalid search scope";
1590 document.getElementById(scopeButtonId).checked =
true;
1625 _clean:
function VM__clean(popup, startID, endID) {
1627 NS_ASSERT(startID,
"meaningless to have valid endID and null startID");
1629 var startElement = document.getElementById(startID);
1631 popup,
"startElement is not in popup");
1633 "startID does not correspond to an existing element");
1634 var endElement =
null;
1636 endElement = document.getElementById(endID);
1637 NS_ASSERT(endElement.parentNode == popup,
1638 "endElement is not in popup");
1640 "endID does not correspond to an existing element");
1642 while (startElement.nextSibling != endElement)
1643 popup.removeChild(startElement.nextSibling);
1647 while(popup.hasChildNodes())
1648 popup.removeChild(popup.firstChild);
1674 fillWithColumns:
function VM_fillWithColumns(
event, startID, endID, type, propertyPrefix) {
1675 var popup =
event.target;
1676 var pivot = this._clean(popup, startID, endID);
1680 var isSorted =
false;
1681 var content = document.getElementById(
"placeContent");
1682 var
columns = content.columns;
1683 for (var
i = 0;
i < columns.count; ++
i) {
1684 var column = columns.getColumnAt(
i).element;
1685 var menuitem = document.createElement(
"menuitem");
1686 menuitem.id =
"menucol_" + column.id;
1687 menuitem.column = column;
1688 var
label = column.getAttribute(
"label");
1689 if (propertyPrefix) {
1690 var menuitemPrefix = propertyPrefix;
1693 var columnId = column.getAttribute(
"anonid");
1694 menuitemPrefix += columnId ==
"title" ?
"name" : columnId;
1696 var accesskey =
PlacesUIUtils.getString(menuitemPrefix +
".accesskey");
1697 menuitem.setAttribute(
"accesskey", accesskey);
1699 menuitem.setAttribute(
"label", label);
1700 if (type ==
"radio") {
1701 menuitem.setAttribute(
"type",
"radio");
1702 menuitem.setAttribute(
"name",
"columns");
1704 if (column.getAttribute(
"sortDirection") !=
"") {
1705 menuitem.setAttribute(
"checked",
"true");
1709 else if (type ==
"checkbox") {
1710 menuitem.setAttribute(
"type",
"checkbox");
1712 if (column.getAttribute(
"primary") ==
"true")
1713 menuitem.setAttribute(
"disabled",
"true");
1716 menuitem.setAttribute(
"checked",
"true");
1719 popup.insertBefore(menuitem, pivot);
1721 popup.appendChild(menuitem);
1723 event.stopPropagation();
1729 populateSortMenu:
function VM_populateSortMenu(
event) {
1730 this.fillWithColumns(
event,
"viewUnsorted",
"directionSeparator",
"radio",
"view.sortBy.");
1732 var sortColumn = this._getSortColumn();
1733 var viewSortAscending = document.getElementById(
"viewSortAscending");
1734 var viewSortDescending = document.getElementById(
"viewSortDescending");
1737 var viewUnsorted = document.getElementById(
"viewUnsorted");
1739 viewSortAscending.removeAttribute(
"checked");
1740 viewSortDescending.removeAttribute(
"checked");
1741 viewUnsorted.setAttribute(
"checked",
"true");
1743 else if (sortColumn.getAttribute(
"sortDirection") ==
"ascending") {
1744 viewSortAscending.setAttribute(
"checked",
"true");
1745 viewSortDescending.removeAttribute(
"checked");
1746 viewUnsorted.removeAttribute(
"checked");
1748 else if (sortColumn.getAttribute(
"sortDirection") ==
"descending") {
1749 viewSortDescending.setAttribute(
"checked",
"true");
1750 viewSortAscending.removeAttribute(
"checked");
1751 viewUnsorted.removeAttribute(
"checked");
1760 showHideColumn:
function VM_showHideColumn(
element) {
1763 var splitter = column.nextSibling;
1764 if (splitter && splitter.localName !=
"splitter")
1767 if (
element.getAttribute(
"checked") ==
"true") {
1768 column.setAttribute(
"hidden",
"false");
1770 splitter.removeAttribute(
"hidden");
1773 column.setAttribute(
"hidden",
"true");
1775 splitter.setAttribute(
"hidden",
"true");
1783 _getSortColumn:
function VM__getSortColumn() {
1784 var content = document.getElementById(
"placeContent");
1785 var cols = content.columns;
1786 for (var
i = 0;
i < cols.count; ++
i) {
1787 var column = cols.getColumnAt(
i).element;
1788 var sortDirection = column.getAttribute(
"sortDirection");
1789 if (sortDirection ==
"ascending" || sortDirection ==
"descending")
1806 setSortColumn:
function VM_setSortColumn(aColumn, aDirection) {
1807 var result = document.getElementById(
"placeContent").getResult();
1808 if (!aColumn && !aDirection) {
1809 result.sortingMode =
Ci.nsINavHistoryQueryOptions.SORT_BY_NONE;
1815 columnId = aColumn.getAttribute(
"anonid");
1817 var sortColumn = this._getSortColumn();
1819 aDirection = sortColumn.getAttribute(
"sortDirection");
1823 var sortColumn = this._getSortColumn();
1824 columnId = sortColumn ? sortColumn.getAttribute(
"anonid") :
"title";
1834 var colLookupTable = {
1835 title: {
key:
"TITLE",
dir:
"ascending" },
1836 tags: {
key:
"TAGS",
dir:
"ascending" },
1839 visitCount: {
key:
"VISITCOUNT",
dir:
"descending" },
1840 keyword: {
key:
"KEYWORD",
dir:
"ascending" },
1841 dateAdded: {
key:
"DATEADDED",
dir:
"descending" },
1842 lastModified: {
key:
"LASTMODIFIED",
dir:
"descending" },
1843 description: {
key:
"ANNOTATION",
1849 if (!colLookupTable.hasOwnProperty(columnId))
1850 throw(
"Invalid column");
1855 aDirection = (aDirection || colLookupTable[columnId].dir).toUpperCase();
1857 var sortConst =
"SORT_BY_" + colLookupTable[columnId].key +
"_" + aDirection;
1858 result.sortingAnnotation = colLookupTable[columnId].anno ||
"";
1859 result.sortingMode =
Ci.nsINavHistoryQueryOptions[sortConst];
sbOSDControlService prototype QueryInterface
getService(Ci.sbIFaceplateManager)
function addRow(name, type, url)
this _contentSandbox label
function search(aFolderId, aSearchStr, aExpectedScopeButtonId)
this _dialogInput val(dateText)
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
function newURI(aURLString)
function NS_ASSERT(cond, msg)
return aWindow document documentElement getAttribute(aAttribute)||dimension
_setDateDatepicker endDate
_setFaviconForWebReader aMenuItem
function doSearch(searchTerm, cmdLine)
let< body >< buttononblur="this.parentNode.removeChild(this);">< script > document body firstChild focus()
_getSelectedPageStyle s i
function asContainer(aNode)