TagSpaces is an offline, open source, document manager with tagging support
Toolbarbuton js library added
uggrock1ab62cf61362
diff --git a/addonlibs/toolbarbutton-jplib-master/.gitignore b/addonlibs/toolbarbutton-jplib-master/.gitignorenew file mode 100644index 000000000..057cab783--- /dev/null+++ b/addonlibs/toolbarbutton-jplib-master/.gitignore@@ -0,0 +1,3 @@+.DS_Store+.project+.settingsdiff --git a/addonlibs/toolbarbutton-jplib-master/README.md b/addonlibs/toolbarbutton-jplib-master/README.mdnew file mode 100644index 000000000..3a15ce114--- /dev/null+++ b/addonlibs/toolbarbutton-jplib-master/README.md@@ -0,0 +1,12 @@+# Toolbar Buttons Package for Mozilla's Add-on SDK+by Erik Vold++The toolbarbutton module in this package allows one to easily create toolbar+buttons with Mozilla's Add-on SDK.++## Dependencies++The `toolbarbutton` package depends on the following packages:++* [Vold Utils](https://github.com/erikvold/vold-utils-jplib)+* [API Utils](https://github.com/mozilla/addon-sdk/) *built in to the Add-on SDKdiff --git a/addonlibs/toolbarbutton-jplib-master/docs/toolbarbutton.md b/addonlibs/toolbarbutton-jplib-master/docs/toolbarbutton.mdnew file mode 100644index 000000000..87f4cf2fb--- /dev/null+++ b/addonlibs/toolbarbutton-jplib-master/docs/toolbarbutton.md@@ -0,0 +1,84 @@+The `toolbarbutton` API provides a simple way to create+[toolbar buttons](https://developer.mozilla.org/en/XUL/toolbarbutton), which+can perform an action when clicked.++## Example ##++ // create toolbarbutton+ var tbb = require("toolbarbutton").ToolbarButton({+ id: "TBB-TEST",+ label: "TBB TEST",+ onCommand: function () {+ tbb.destroy(); // kills the toolbar button+ }+ });++ if (require('self').loadReason == "install") {+ tbb.moveTo({+ toolbarID: "nav-bar",+ forceMove: false // only move from palette+ });+ }++<api name="ToolbarButton">+@class++Module exports `ToolbarButton` constructor allowing users to create a+toolbar button.++<api name="ToolbarButton">+@constructor+Creates a toolbarbutton.++@param options {Object}+ Options for the toolbarbutton, with the following parameters:++@prop id {String}+A id for the toolbar button, this should be namespaced.++@prop label {String}+A label for the toolbar button.++@prop image {String}+A image url for the toolbar button.++@prop [onCommand] {Function}+ A option function that is invoked when the toolbar button is pressed.++@prop [panel] {Panel}+ A optional panel.+</api>++<api name="destroy">+@method+Removes the toolbar button from all open windows and no longer adds the+toolbar button to new windows.+</api>++<api name="moveTo">+@method+Moves the toolbar button on all open windows to the desired location.++@param options {Object}+Options which describe the position to move the toolbar button to, with the+following parameters:++@prop toolbarID {String}+The id of the toolbar which you want to add the toolbar button to.++Example toolbar IDs:++- **toolbar-menubar**: The menu bar.+- **nav-bar**: The navigation bar.+- **TabsToolbar**: The tabs bar.+- **addon-bar**: The addon bar.++@prop insertbefore {String}+The id of the element which the toolbar button should be inserted before.++@prop forceMove {Boolean}+If `forceMove` is `false`, then the move will only occur if the toolbar button+is not already being used. If `true`, then the move will happen no matter where+the toolbar button is.+</api>+</api>diff --git a/addonlibs/toolbarbutton-jplib-master/lib/toolbarbutton.js b/addonlibs/toolbarbutton-jplib-master/lib/toolbarbutton.jsnew file mode 100644index 000000000..5aa2326ee--- /dev/null+++ b/addonlibs/toolbarbutton-jplib-master/lib/toolbarbutton.js@@ -0,0 +1,192 @@+'use strict';++const { unload } = require("unload+");+const { listen } = require("listen");+const winUtils = require("window-utils");++const browserURL = "chrome://browser/content/browser.xul";+const NS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";++exports.ToolbarButton = function ToolbarButton(options) {+ var unloaders = [],+ toolbarID = "",+ insertbefore = "",+ destroyed = false,+ destoryFuncs = [];++ var delegate = {+ onTrack: function (window) {+ if (browserURL != window.location || destroyed)+ return;++ let doc = window.document;+ let $ = function(id) doc.getElementById(id);++ options.tooltiptext = options.tooltiptext || '';++ // create toolbar button+ let tbb = doc.createElementNS(NS_XUL, "toolbarbutton");+ tbb.setAttribute("id", options.id);+ tbb.setAttribute("type", "button");+ if (options.image) tbb.setAttribute("image", options.image);+ tbb.setAttribute("class", "toolbarbutton-1 chromeclass-toolbar-additional");+ tbb.setAttribute("label", options.label);+ tbb.setAttribute('tooltiptext', options.tooltiptext);+ tbb.addEventListener("command", function() {+ if (options.onCommand)+ options.onCommand({}); // TODO: provide something?++ if (options.panel) {+ options.panel.show(tbb);+ }+ }, true);++ // add toolbarbutton to palette+ ($("navigator-toolbox") || $("mail-toolbox")).palette.appendChild(tbb);++ // find a toolbar to insert the toolbarbutton into+ if (toolbarID) {+ var tb = $(toolbarID);+ }+ if (!tb) {+ var tb = toolbarbuttonExists(doc, options.id);+ }++ // found a toolbar to use?+ if (tb) {+ let b4;++ // find the toolbarbutton to insert before+ if (insertbefore) {+ b4 = $(insertbefore);+ }+ if (!b4) {+ let currentset = tb.getAttribute("currentset").split(",");+ let i = currentset.indexOf(options.id) + 1;++ // was the toolbarbutton id found in the curent set?+ if (i > 0) {+ let len = currentset.length;+ // find a toolbarbutton to the right which actually exists+ for (; i < len; i++) {+ b4 = $(currentset[i]);+ if (b4) break;+ }+ }+ }++ tb.insertItem(options.id, b4, null, false);+ }++ var saveTBNodeInfo = function(e) {+ toolbarID = tbb.parentNode.getAttribute("id") || "";+ insertbefore = (tbb.nextSibling || "")+ && tbb.nextSibling.getAttribute("id").replace(/^wrapper-/i, "");+ };++ window.addEventListener("aftercustomization", saveTBNodeInfo, false);++ // add unloader to unload+'s queue+ var unloadFunc = function() {+ tbb.parentNode.removeChild(tbb);+ window.removeEventListener("aftercustomization", saveTBNodeInfo, false);+ };+ var index = destoryFuncs.push(unloadFunc) - 1;+ listen(window, window, "unload", function() {+ destoryFuncs[index] = null;+ }, false);+ unloaders.push(unload(unloadFunc, window));+ },+ onUntrack: function (window) {}+ };+ var tracker = winUtils.WindowTracker(delegate);++ function setIcon(aOptions) {+ options.image = aOptions.image || aOptions.url;+ getToolbarButtons(function(tbb) {+ tbb.image = options.image;+ }, options.id);+ return options.image;+ }++ return {+ destroy: function() {+ if (destroyed) return;+ destroyed = true;++ if (options.panel)+ options.panel.destroy();++ // run unload functions+ destoryFuncs.forEach(function(f) f && f());+ destoryFuncs.length = 0;++ // remove unload functions from unload+'s queue+ unloaders.forEach(function(f) f());+ unloaders.length = 0;+ },+ moveTo: function(pos) {+ if (destroyed) return;++ // record the new position for future windows+ toolbarID = pos.toolbarID;+ insertbefore = pos.insertbefore;++ // change the current position for open windows+ for each (var window in winUtils.windowIterator()) {+ if (browserURL != window.location) return;++ let doc = window.document;+ let $ = function (id) doc.getElementById(id);++ // if the move isn't being forced and it is already in the window, abort+ if (!pos.forceMove && $(options.id)) return;++ var tb = $(toolbarID);+ var b4 = $(insertbefore);++ // TODO: if b4 dne, but insertbefore is in currentset, then find toolbar to right++ if (tb) tb.insertItem(options.id, b4, null, false);+ };+ },+ get label() options.label,+ set label(value) {+ options.label = value;+ getToolbarButtons(function(tbb) {+ tbb.label = value;+ }, options.id);+ return value;+ },+ setIcon: setIcon,+ get image() options.image,+ set image(value) setIcon({image: value}),+ get tooltiptext() options.tooltiptext,+ set tooltiptext(value) {+ options.tooltiptext = value;+ getToolbarButtons(function(tbb) {+ tbb.setAttribute('tooltiptext', value);+ }, options.id);+ },+ };+};++function getToolbarButtons(callback, id) {+ let buttons = [];+ for each (var window in winUtils.windowIterator()) {+ if (browserURL != window.location) continue;+ let tbb = window.document.getElementById(id);+ if (tbb) buttons.push(tbb);+ }+ if (callback) buttons.forEach(callback);+ return buttons;+}++function toolbarbuttonExists(doc, id) {+ var toolbars = doc.getElementsByTagNameNS(NS_XUL, "toolbar");+ for (var i = toolbars.length - 1; ~i; i--) {+ if ((new RegExp("(?:^|,)" + id + "(?:,|$)")).test(toolbars[i].getAttribute("currentset")))+ return toolbars[i];+ }+ return false;+}diff --git a/addonlibs/toolbarbutton-jplib-master/package.json b/addonlibs/toolbarbutton-jplib-master/package.jsonnew file mode 100644index 000000000..040c540c7--- /dev/null+++ b/addonlibs/toolbarbutton-jplib-master/package.json@@ -0,0 +1,9 @@+{+ "name": "toolbarbutton",+ "description": "Toolbar Buttons for Jetpacks",+ "keywords": ["toolbar", "toolbarbutton", "button", "ui"],+ "author": "Erik Vold",+ "version": "1.1.1",+ "license": "MIT/X11",+ "dependencies": ["api-utils", "vold-utils"]+}diff --git a/addonlibs/toolbarbutton-jplib-master/tests/black.png b/addonlibs/toolbarbutton-jplib-master/tests/black.pngnew file mode 100644index 000000000..ee11b0980Binary files /dev/null and b/addonlibs/toolbarbutton-jplib-master/tests/black.png differdiff --git a/addonlibs/toolbarbutton-jplib-master/tests/test-toolbarbutton.js b/addonlibs/toolbarbutton-jplib-master/tests/test-toolbarbutton.jsnew file mode 100644index 000000000..3503493cb--- /dev/null+++ b/addonlibs/toolbarbutton-jplib-master/tests/test-toolbarbutton.js@@ -0,0 +1,111 @@+/* This Source Code Form is subject to the terms of the Mozilla Public+ * License, v. 2.0. If a copy of the MPL was not distributed with this+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */+'use strict';++const windowUtils = require("window-utils");+const toolbarbutton = require("toolbarbutton");++const NS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";++const TEST_ICON_URL = module.uri.replace(/[^\.\\\/]*\.js$/, "test.png");+const TEST_ICON_BLACK_URL = module.uri.replace(/[^\.\\\/]*\.js$/, "black.png");++function $(id) windowUtils.activeBrowserWindow.document.getElementById(id);++function createToolbarButton(options, test) {+ test.assertEqual(!$(options.id), true);+ var tbb = toolbarbutton.ToolbarButton(options);+ test.assertEqual(!$(options.id), true);+ tbb.moveTo(options);+ return tbb;+}++function buttonExists(button, options, test) {+ test.assertEqual(!button, false, 'test button');+ test.assertEqual(button.parentNode, $(options.toolbarID), 'test parent');+ test.assertEqual(button.id, options.id, 'test id');+ if (options.label)+ test.assertEqual(button.label, options.label, 'test label');+ if (options.image)+ test.assertEqual(button.image, options.image);+ else+ test.assertEqual(button.image, "");+}++exports.testTBBExists = function(test) {+ var options = {+ id: "test-tbb",+ label: "test",+ toolbarID: "nav-bar",+ forceMove: true+ };++ var tbb = createToolbarButton(options, test);+ buttonExists($(options.id), options, test);+ tbb.destroy();+ test.assertEqual(!$(options.id), true);+ var tbb = createToolbarButton(options, test);+ tbb.destroy();+};++exports.testTBBDoesNotExist = function(test) {+ var options = {+ id: "test-tbb2",+ label: "test"+ };+ var tbb = createToolbarButton(options, test);+ var tbbEle = $(options.id);+ test.assertEqual(!tbbEle, true, 'toolbar button dne');+ tbb.destroy();+};++exports.testTBBLabelChange = function(test) {+ test.waitUntilDone();++ var options = {+ id: "test-tbb3",+ label: "test",+ toolbarID: "nav-bar",+ forceMove: true+ };++ let tbb = createToolbarButton(options, test);+ buttonExists($(options.id), options, test);+ tbb.label = 'test change';+ test.assertEqual($(options.id).label, 'test change', 'the label is changed');+ test.assertEqual(tbb.label, 'test change', 'the label is changed');++ tbb.destroy();+ test.done();+};++exports.testTBBPropertyChange = function(test) {+ test.waitUntilDone();++ var options = {+ id: "test-tbb4",+ label: "test",+ toolbarID: "nav-bar",+ forceMove: true,+ image: TEST_ICON_URL,+ tooltiptext: 'a'+ };++ let tbb = createToolbarButton(options, test);+ buttonExists($(options.id), options, test);+ test.assertEqual($(options.id).image, TEST_ICON_URL, 'the image is correct');+ test.assertEqual(tbb.image, TEST_ICON_URL, 'the image is correct');+ test.assertEqual(tbb.tooltiptext, 'a', 'the tooltiptext is correct');+ tbb.setIcon({url: TEST_ICON_BLACK_URL});+ test.assertEqual($(options.id).image, TEST_ICON_BLACK_URL, 'the image is changed');+ test.assertEqual(tbb.image, TEST_ICON_BLACK_URL, 'the image is changed');+ tbb.tooltiptext = 'b';+ test.assertEqual($(options.id).getAttribute('tooltiptext'), 'b', 'the tooltiptext is changed');+ test.assertEqual(tbb.tooltiptext, 'b', 'the tooltiptext is changed');++ tbb.destroy();+ test.done();+};++diff --git a/addonlibs/toolbarbutton-jplib-master/tests/test.png b/addonlibs/toolbarbutton-jplib-master/tests/test.pngnew file mode 100644index 000000000..5469a500aBinary files /dev/null and b/addonlibs/toolbarbutton-jplib-master/tests/test.png differ