function openSidebar(url) { var id = sidebarId++; var window = browserWindows.activeWindow; var view = core.viewFor(window); // btoa in addition, since simple uri encoding creates an invalid url according to older firefox sidebar. var wrappedUrl = self.data.url('sidebar.html?id=' + id + '&url=' + encodeURIComponent(view.btoa(url))); if(!window.dictccSidebar) { window.dictccSidebar = ui.Sidebar({ id: 'dictcc-sidebar-' + id, title: _('sidebar_title'), url: wrappedUrl }); } else { window.dictccSidebar.url = wrappedUrl; } window.dictccSidebar.show(view); }
"use strict"; var panel = require("sdk/panel"); var ui = require('sdk/ui'); var tabs = require("sdk/tabs"); var self = require('sdk/self'); var sidebar = ui.Sidebar({ id: 'my-sidebar', title: 'My sidebar', url: './sidebar.html' }); sidebar.show();
var self = require("sdk/self"); var tabs = require('sdk/tabs'); var ui = require("sdk/ui"); var buttons = require('sdk/ui/button/action'); var button = buttons.ActionButton({ id: "click-sample-bootstrap", label: "Open Sample Bootstrap Sidebar", icon: { "16": "./icons/bootstrap-16.png", "32": "./icons/bootstrap-32.png", }, onClick: handleClick, }); function handleClick(state) { // Open sidebar to work with sidebar.show(); } var sidebar = ui.Sidebar({ id: 'sample-bootstrap-sidebar', title: 'Get bootstrap?', url: self.data.url("sidebar.html"), });
/** * This function creates the sidebar. */ function initializeSidebar() { sidebar = ui.Sidebar({ id: 'taskstodo-sidebar', title: 'TasksTodo.org', url: data.url("goals.html"), onAttach: function (worker) { // Add sidebar worker to the workers array workers.push(worker); worker.on("detach", function() { var index = workers.indexOf(worker); if (index >= 0) workers.splice(index, 1); }); ///////////////////////////////////////////////////////////////////////////// // TASKSTODO EVENT TRACKING // ///////////////////////////////////////////////////////////////////////////// /** * Redirects to a certain page. */ worker.port.on("TrackEvent", function(eventType, eventId) { if (eventType && eventId) { console.log("LOG: Triggered event " + eventType + " on " + eventId); addLogEntry({ "action": "user_event", "parameters": [ { "key": "type", "value": eventType }, { "key": "target", "value": eventId } ] }); } }); ///////////////////////////////////////////////////////////////////////////// // NAVIGATION // ///////////////////////////////////////////////////////////////////////////// /** * Redirects to a certain page. */ worker.port.on("Redirect", function(page) { sidebar.url = data.url(page); }); ///////////////////////////////////////////////////////////////////////////// // GOALS // ///////////////////////////////////////////////////////////////////////////// /** * Loads all goals. */ worker.port.on("LoadGoals", function() { services.loadGoals(worker); }); /** * Load a specific goal. */ worker.port.on("LoadGoal", function(goalId) { services.loadGoal(worker, goalId); }); /** * Adds a new goal. */ worker.port.on("AddGoal", function(goal) { services.addGoal(worker, goal); }); /** * Saves changes to an existing goal. */ worker.port.on("UpdateGoal", function(goal) { services.updateGoal(worker, goal); }); /** * Deletes an existing goal. */ worker.port.on("DeleteGoal", function(goal) { services.deleteGoal(worker, goal._id); }); /** * Sets active goal. */ worker.port.on("SetActiveGoal", function(goal) { if (goal != null) { var msg = "The goal '" + goal.title + "' has been selected!"; console.log(msg); notify("Goal selected", msg); addLogEntry({ "action": "goal_selected", "parameters": [ { "key": "goalId", "value": goal._id } ] }); } else { var msg = "The goal '" + activeGoal.title + "' has been deselected!"; console.log(msg); notify("Goal deselected", msg); addLogEntry({ "action": "goal_deselected", "parameters": [ { "key": "goalId", "value": activeGoal._id } ] }); } // Set active goal activeGoal = goal; activeTask = null; }); /** * Return active goal. */ worker.port.on("GetActiveGoal", function() { if (activeGoal) { worker.port.emit("ActiveGoalLoaded", activeGoal); } }); /** * Returns the latest active goal. */ worker.port.on("GetLatestActiveGoal", function() { services.getLatestGoalFromLog(worker); }); ///////////////////////////////////////////////////////////////////////////// // GOAL: NOTES // ///////////////////////////////////////////////////////////////////////////// /** * Loads all notes regarding to the selected goal. */ worker.port.on("LoadGoalNotes", function(goal) { services.loadGoalNotes(worker, goal._id); }); /** * Adds a new note to the selected goal. */ worker.port.on("AddGoalNote", function(note) { services.addGoalNote(worker, note); }); /** * Saves changes to an existing note. */ worker.port.on("UpdateGoalNote", function(note) { services.updateGoalNote(worker, note); }); /** * Deletes an existing note. */ worker.port.on("DeleteGoalNote", function(note) { services.deleteGoalNote(worker, note._id); }); ///////////////////////////////////////////////////////////////////////////// // GOAL: SUMMARY // ///////////////////////////////////////////////////////////////////////////// /** * Loads the goal summary. */ worker.port.on("LoadGoalSummary", function(goal) { services.loadGoalSummary(worker, goal._id); }); ///////////////////////////////////////////////////////////////////////////// // TASKS // ///////////////////////////////////////////////////////////////////////////// /** * Loads all tasks. */ worker.port.on("LoadTasks", function(goal) { services.loadTasks(worker, goal._id); }); /** * Load a specific task. */ worker.port.on("LoadTask", function(taskId) { services.loadTask(worker, taskId); }); /** * Adds a new task. */ worker.port.on("AddTask", function(task) { services.addTask(worker, task); }); /** * Saves changes to an existing task. */ worker.port.on("UpdateTask", function(task) { services.updateTask(worker, task); }); /** * Deletes an existing task. */ worker.port.on("DeleteTask", function(task) { services.deleteTask(worker, task._id); }); /** * Sets active task. */ worker.port.on("SetActiveTask", function(task) { if (task != null) { var msg = "The task '" + task.title + "' has been selected!"; console.log(msg); notify("Task selected", msg); addLogEntry({ "action": "task_selected", "parameters": [ { "key": "taskId", "value": task._id }, { "key": "goalId", "value": activeGoal._id } ] }); } else { var msg = "The task '" + activeTask.title + "' has been deselected!"; console.log(msg); notify("Task deselected", msg); addLogEntry({ "action": "task_deselected", "parameters": [ { "key": "taskId", "value": activeTask._id } ] }); } // Set new active task activeTask = task; // Reset local storage ss.storage.bookmarks = []; ss.storage.history = []; ss.storage.tabs = []; ss.storage.suggestions = null; // Remove notification layer on bookmarked pages hideBookmarkNotifications(); // Remove all highlighted pages in search results hideBookmarksInSearchResults(); hideVisitedPagesInSearchResults(); // Hide search support windows hideSearchSupportWindows(); // Toggle the context menu toggleBrowserTopMenu(); }); /** * Return active task. */ worker.port.on("GetActiveTask", function() { if (activeTask) { worker.port.emit("ActiveTaskLoaded", activeTask); } }); /** * Returns the latest active task. */ worker.port.on("GetLatestActiveTask", function() { services.getLatestTaskFromLog(worker); }); ///////////////////////////////////////////////////////////////////////////// // TASK: NOTES // ///////////////////////////////////////////////////////////////////////////// /** * Loads all notes regarding to the selected task. */ worker.port.on("LoadNotes", function(task) { services.loadNotes(worker, task._id); }); /** * Adds a new note to the selected task. */ worker.port.on("AddNote", function(note) { services.addNote(worker, note); }); /** * Saves changes to an existing note. */ worker.port.on("UpdateNote", function(note) { services.updateNote(worker, note); }); /** * Deletes an existing note. */ worker.port.on("DeleteNote", function(note) { services.deleteNote(worker, note._id); }); ///////////////////////////////////////////////////////////////////////////// // TASK: BOOKMARKS // ///////////////////////////////////////////////////////////////////////////// /** * Loads all bookmarks regarding to the selected task. */ worker.port.on("LoadBookmarks", function(task) { services.loadBookmarks(worker, task._id); }); /** * Adds a new bookmark to the selected task. */ worker.port.on("AddBookmark", function(bookmark) { services.addBookmark(worker, bookmark); }); /** * Saves changes to an existing bookmark. */ worker.port.on("UpdateBookmark", function(bookmark) { services.updateBookmark(worker, bookmark); }); /** * Deletes an existing bookmark. */ worker.port.on("DeleteBookmark", function(bookmark) { services.deleteBookmark(worker, bookmark._id); }); /** * Be aware of all bookmarks from the active task */ worker.port.on("SetActiveTaskBookmarks", function(bookmarks) { // Set task bookmarks ss.storage.bookmarks = bookmarks; }); ///////////////////////////////////////////////////////////////////////////// // TASK: HISTORY // ///////////////////////////////////////////////////////////////////////////// /** * Loads history of selected task. */ worker.port.on("LoadHistory", function(task) { services.getBrowsingHistory(worker, task._id); }); /** * Be aware of the browsing history */ worker.port.on("SetActiveTaskHistory", function(history) { // Set active task history ss.storage.history = history; }); /** * Clear the browse history of a given task. */ worker.port.on("ClearBrowseHistory", function(taskId) { services.removeBrowseHistory(worker, taskId); }); ///////////////////////////////////////////////////////////////////////////// // TASK: SEARCH HISTORY // ///////////////////////////////////////////////////////////////////////////// /** * Loads history of selected task. */ worker.port.on("LoadSearchHistory", function(task) { services.getSearchQueriesByTask(worker, task._id); }); /** * Clear the search history of a given task. */ worker.port.on("ClearSearchHistory", function(taskId) { services.removeSearchHistory(worker, taskId); }); ///////////////////////////////////////////////////////////////////////////// // TASK: TABS // ///////////////////////////////////////////////////////////////////////////// /** * Loads the stored tabs of a given task. */ worker.port.on("LoadTabs", function(task) { // Load all tabs services.getTabsFromLog(worker, task._id); }); /** * Restores the given tabs. */ worker.port.on("StoreTabs", function() { for (let tab of tabs) { // Save tab saveTab(tab); } // (Re-)Load all tabs services.getTabsFromLog(worker, activeTask._id); }); /** * Restores the given tabs. */ worker.port.on("RestoreTab", function(tab) { let opened = false; for (let t of tabs) { if (t.url === JSON.parse(tab).url) { opened = true; } } if (!opened) { tabs.open({ url: JSON.parse(tab).url, inBackground: true, isPinned: (JSON.parse(tab).pinned === 'true') }); addLogEntry({ "action": "tab_restored", "parameters": [ { "key": "goalId", "value": activeGoal._id }, { "key": "taskId", "value": activeTask._id }, { "key": "tabUrl", "value": JSON.parse(tab).url } ] }); } }); /** * Deletes an existing tab. */ worker.port.on("DeleteTab", function(tab) { // Delete a tab services.deleteLogEntry(worker, tab._id); // Reload all tabs services.getTabsFromLog(worker, activeTask._id); }); /** * Be aware of all bookmarks from the active task */ worker.port.on("SetActiveTaskTabs", function(tabs) { ss.storage.tabs = tabs; }); ///////////////////////////////////////////////////////////////////////////// // TASK: SCREENSHOTS // ///////////////////////////////////////////////////////////////////////////// /** * Loads all screenshots regarding to the selected task. */ worker.port.on("LoadScreenshots", function(task) { services.loadScreenshots(worker, task._id); }); /** * Deletes an existing screenshot. */ worker.port.on("DeleteScreenshot", function(screenshot) { services.deleteScreenshot(worker, screenshot._id); }); /** * Downloads an existing screenshot. */ worker.port.on("OpenScreenshot", function(screenshot) { tabs.open({ url: data.url(screenshot.image), inBackground: false }); }); ///////////////////////////////////////////////////////////////////////////// // TASK: ATTACHMENT // ///////////////////////////////////////////////////////////////////////////// /** * Loads all attachments regarding to the selected task. */ worker.port.on("LoadAttachments", function(task) { services.loadAttachments(worker, task._id); }); /** * Adds a new attachment to the selected task. */ worker.port.on("AddAttachment", function(task, data, filename, filetype) { services.addAttachment(worker, task._id, data, filename, filetype); }); /** * Deletes an existing attachment. */ worker.port.on("DeleteAttachment", function(attachment) { services.deleteAttachment(worker, attachment._id); }); /** * Downloads an existing attachment. */ /*worker.port.on("DownloadAttachment", function(attachment) { if (attachment != null && attachment.filename != null) { notify("Attachment Download", "Downloading the file '" + attachment.filename + "' to your desktop.") services.downloadAttachment(worker, attachment); } });*/ ///////////////////////////////////////////////////////////////////////////// // TASK: LOG // ///////////////////////////////////////////////////////////////////////////// /** * Loads all log entries. */ worker.port.on("LoadLogEntries", function() { services.getAllLogEntries(worker); }); /** * Adds a new log entry. */ worker.port.on("AddLogEntry", function(entry) { addLogEntry(entry); }); /** * Deletes an existing log entry. */ worker.port.on("DeleteLogEntry", function(id) { services.deleteLogEntry(worker, id); }); ///////////////////////////////////////////////////////////////////////////// // HELP // ///////////////////////////////////////////////////////////////////////////// /** * Opens the help page of this addon. */ worker.port.on("ShowHelp", function(queries) { var pageUrl = data.url("help.html"); tabs.open(pageUrl); }); }, onShow: function () { // console.log("Showing sidebar"); sidebarStatus = 'visible'; }, onHide: function () { // console.log("Hiding sidebar"); sidebarStatus = 'hidden'; }, onDetach: function () { // console.log("Detaching sidebar"); } }); /* * THIS HACK ALLOWS US TO SET THE WIDTH OF THE SIDEBAR! */ const { WindowTracker } = require('sdk/deprecated/window-utils'); const { isBrowser, getMostRecentBrowserWindow, windows, isWindowPrivate } = require('sdk/window/utils'); WindowTracker({ onTrack: function (window) { if (!isBrowser(window)) return; let sidebar = window.document.getElementById('sidebar'); sidebar.setAttribute('style', 'min-width: 350px; width: 350px; max-width: 500px;'); } }); }