aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-10-23 23:09:36 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-10-23 23:09:36 +0200
commite0c0b5d7642b1a83de3763febaaba102ab37d1bf (patch)
tree6f6b00cc32f4a9cd4cc30ddef90c90cd6ca497d1
parentdf33c6920d9dd3765202b86614b660d2c8f85db2 (diff)
downloadbugzilla-triage-e0c0b5d7642b1a83de3763febaaba102ab37d1bf.tar.gz
Jetpack-SDK currently provides clipboard and selection libraries.
So there is no need to do our own.
-rw-r--r--lib/clipboard.js127
-rw-r--r--lib/rhbzpage.js1
-rw-r--r--tests/test-clipboard.js51
3 files changed, 0 insertions, 179 deletions
diff --git a/lib/clipboard.js b/lib/clipboard.js
deleted file mode 100644
index 608bbc0..0000000
--- a/lib/clipboard.js
+++ /dev/null
@@ -1,127 +0,0 @@
-// Released under the MIT/X11 license
-// http://www.opensource.org/licenses/mit-license.php
-var Cc = require("chrome").Cc;
-var Ci = require("chrome").Ci;
-
-/**
- * returns content of the system clipboard
- * @return string with the content of the clipboard or "" if empty.
- * originally from
- * https://developer.mozilla.org/en/Using_the_Clipboard
- * https://wiki.mozilla.org/Labs/Jetpack/JEP/10
- */
-
-function getClipboard() {
- var clip = Cc["@mozilla.org/widget/clipboard;1"].
- getService(Ci.nsIClipboard);
- if (!clip) {
- throw new Error("No access to the clipboard!");
- }
- return clip;
-}
-
-function createTransferable() {
- var trans = Cc["@mozilla.org/widget/transferable;1"].
- createInstance(Ci.nsITransferable);
- if (!trans) {
- throw new Error("No access to the transfer object during the set of clipboard!");
- }
- return trans;
-}
-
-var getMethod = exports.get = function getMethod( flavor ) {
- var pastetext = "", mimeType = "", stuff = {};
- var len = 0, clipId = 0, clip = {}, trans = {};
-
- // flavor argument is optional
- if (flavor === undefined) {
- flavor = "plain";
- }
-
- if (flavor === "plain") {
- mimeType = "text/unicode";
- } else if (favor === "html") {
- mimeType = "text/html";
- } else {
- throw new Error("Unsupported flavor '" + flavor + "'!");
- }
-
- clip = getClipboard();
-
- trans = createTransferable();
-
- trans.addDataFlavor(mimeType);
- clip.getData(trans, clip.kGlobalClipboard);
-
- var str = {};
- var strLength = {};
-
- trans.getTransferData(mimeType, str, strLength);
-
- if (str) {
- str = str.value.QueryInterface(Ci.nsISupportsString);
- pastetext = str.data.substring(0, strLength.value / 2);
- }
- return pastetext;
-};
-
-var setMethod = exports.set = function setMethod(content, flavor) {
- var mimeType = "", stuff = {};
- var len = 0, clipId = 0, clip = {}, trans = {};
-
- // flavor argument is optional
- if (flavor === undefined) {
- flavor = "plain";
- }
-
- if (flavor === "plain") {
- mimeType = "text/unicode";
- } else if (favor === "html") {
- mimeType = "text/html";
- } else {
- throw new Error("Unsupported flavor '" + flavor + "'!");
- }
-
- stuff = Cc["@mozilla.org/supports-string;1"].
- createInstance(Ci.nsISupportsString);
- if (!stuff) {
- return false;
- }
- stuff.data = content;
- len = content.length * 2;
-
- clip = getClipboard();
-
- trans = createTransferable();
-
- trans.addDataFlavor(mimeType);
- trans.setTransferData(mimeType, stuff, content.length * 2);
-
- clip.setData(trans, null, clip.kGlobalClipboard);
- return true;
-};
-
-var flavorsMethod = exports.getCurrentFlavors = function flavorsMethod(test) {
- // currently the only possible flavors in Jetpack-prototype are "plain" and
- // "html", i.e., "text/plain" (or text/unicode?) and "text/html" (or
- // application/xml+xhtml?)
- var possibleTypes = {
- "text/unicode": "plain",
- "text/plain": "plain",
- "text/html": "html"
- };
- var flavorArray = [];
- var clip = getClipboard();
-
- for (var flavor in possibleTypes) {
- var presentFlavor = clip.hasDataMatchingFlavors(
- [flavor],
- 1,
- clip.kGlobalClipboard
- );
- if (presentFlavor) {
- flavorArray.push(possibleTypes[flavor]);
- }
- }
- return flavorArray;
-}; \ No newline at end of file
diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js
index 0d9aad0..630aeb1 100644
--- a/lib/rhbzpage.js
+++ b/lib/rhbzpage.js
@@ -6,7 +6,6 @@ var util = require("util");
var xrpc = require("xmlrpc");
var apiUtils = require("api-utils");
var self = require("self");
-var clip = require("clipboard");
var Color = require("color").Color;
var BZPage = require("bzpage").BZPage;
var Request = require("request").Request;
diff --git a/tests/test-clipboard.js b/tests/test-clipboard.js
deleted file mode 100644
index e1d5828..0000000
--- a/tests/test-clipboard.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/*global exports: false, require: false */
-/*jslint plusplus: false */
-// Released under the MIT/X11 license
-// http://www.opensource.org/licenses/mit-license.php
-
-// TODO: add some failing tests as well
-"use strict";
-var clip = require("clipboard");
-
-var testString = "When in the Course of human events it becomes necessary for one people to dissolve the political bands which have connected them with another and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.\n";
-var pushkinTestString = "Byl pozdní večer první máj!\n\nАРИОН.\n\nНас было много на челне;\nИные парус напрягали,\nДругие дружно упирали\nВ глубь мощны веслы. В тишине\nНа руль склонясь, наш кормщик умный\nВ молчаньи правил грузный чолн;\nА я — беспечной веры полн —\nПловцам я пел … Вдруг лоно волн\nИзмял с налету вихорь шумный …\nПогиб и кормщик и пловец! –\nЛишь я, таинственный певец,\nНа берег выброшен грозою,\nЯ гимны прежние пою\nИ ризу влажную мою\nСушу на солнце под скалою.\n";
-
-// TODO: VERY insufficient test, needs to be extended
-exports.ensureClipboardASCII = function ensureClipboard(test) {
- var text = "";
- var req = clip.set(testString);
- if (req) {
- text = clip.get();
- if (!text) {
- throw "Cannot read a string from the clipboard";
- }
- } else {
- throw "Cannot copy string to the clipboard";
- }
- test.assertEqual(text, testString,
- "checking set and get clipboard methods (ASCII)");
-};
-
-exports.ensureClipboardUnicode = function ensureClipboard(test) {
- var text = "";
- var req = clip.set(pushkinTestString);
- if (req) {
- text = clip.get();
- if (!text) {
- throw "Cannot read a string from the clipboard";
- }
- } else {
- throw "Cannot copy string to the clipboard";
- }
- test.assertEqual(text, pushkinTestString,
- "checking set and get clipboard methods (Unicode)");
-};
-
-exports.ensureClipboardGetFlavors = function ensureClipboardGetFlavors(test) {
- clip.set(pushkinTestString);
- var available = clip.getCurrentFlavors();
- test.assertEqual(JSON.stringify(available),'["plain"]',
- "checking getFlavors method");
-};
-
-// TODO: test for some weird mimeType which is not supported