diff options
author | Matěj Cepl <mcepl@redhat.com> | 2010-06-11 21:52:52 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2010-06-11 21:52:52 +0200 |
commit | 54426f47a1149e5b833653660db3b208c78e67f1 (patch) | |
tree | ae28e0a5887e643e4a19045d8f3e07c45e12b744 /lib/puvodni | |
parent | e8d6c71ee96a96230aadd5504e3f312774896920 (diff) | |
download | bugzilla-triage-54426f47a1149e5b833653660db3b208c78e67f1.tar.gz |
Last unused files archived.
Diffstat (limited to 'lib/puvodni')
-rw-r--r-- | lib/puvodni/clipboard.js | 125 | ||||
-rw-r--r-- | lib/puvodni/offline-support.js | 153 | ||||
-rw-r--r-- | lib/puvodni/skip-process-bug.js | 46 |
3 files changed, 324 insertions, 0 deletions
diff --git a/lib/puvodni/clipboard.js b/lib/puvodni/clipboard.js new file mode 100644 index 0000000..0051a55 --- /dev/null +++ b/lib/puvodni/clipboard.js @@ -0,0 +1,125 @@ +// Released under the MIT/X11 license +// http://www.opensource.org/licenses/mit-license.php + +/** + * 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/puvodni/offline-support.js b/lib/puvodni/offline-support.js new file mode 100644 index 0000000..4849bd3 --- /dev/null +++ b/lib/puvodni/offline-support.js @@ -0,0 +1,153 @@ +/*jslint onevar: false, browser: true, evil: true, laxbreak: true, undef: true, nomen: true, eqeqeq: true, bitwise: true, maxerr: 1000, immed: false, white: false, plusplus: false, regexp: false, undef: false */ +/*global jetpack */ +// Released under the MIT/X11 license +// http://www.opensource.org/licenses/mit-license.php +"use strict"; + +/* Offline supporting functions */ +/** + * + * @todo FIXME this probably makes a closure and a memory leak name='changeform' + * investigate + * https://developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion + * + * <form method="post" action="process_bug.cgi" autocomplete="off"> + * + * Reading + * http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.13 + * random notes: - 17.13.3 provides all steps necessary - enctype != + * application/x-www-form-urlencoded => SHOULD fails (no further questions + * needed) - http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1. is + * nice explanation (albeit quite dated) - on multiple values + * http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.6.1 - + * příliš jednoduché + * http://www.innovation.ch/java/HTTPClient/emulating_forms.html - + */ +RHBugzillaPage.prototype.serializeForm = function(form) { + let serialForm = { + dataOut : "", + name : form.name, + method : form.method, + acceptCharset : form.acceptCharset, + action : form.action, // TODO shouldn't we get a non-relative URL? + enctype : form.enctype, + cookie : this.doc.cookie, + autocomplete : form.getAttribute("autocomplete"), + bugNo : this.bugNo + }; + + function genURIElement(sName, sValue) { + return encodeURIComponent(sName) + "=" + encodeURIComponent(sValue); + } + + /** + * @param o + * control to be serialized + * @return String with the serialized control + */ + function serializeControl(element) { + let val = element.value; + // console.log("val.toSource() = " + val.toSource()); + /* + * on HTMLSelectElement we have an attribute 'type' of type DOMString, + * readonly The type of this form control. This is the string + * "select-multiple" when the multiple attribute is true and the string + * "select-one" when false. + */ + if ((val == null) || (val == undefined) || (val == "")) { + return; + } else if (val instanceof Array) { + return val.map(function(x) { + return genURIElement(element.name, x.value); + }).join("&"); + } else if (val instanceof String) { + return genURIElement(element.name, val); + } else { // assume HTMLCollection + return Array.map(val, function(x) { + return genURIElement(element.name, x.value); + }).join("&"); + } + } + + serialForm.dataOut = Array.filter(form.elements,function(el) { + return !el.disabled && el.name && + // FIXME shouldn't I just add && el.value here? + (el.checked || /select|textarea/i.test(el.nodeName) || + /text|hidden|password|search/i.test(el.type)); + }).map(serializeControl).join("&"); + return serialForm; +}; + +//RHBugzillaPage.prototype.submitCallback = function(evt) { +// console.log("Submit Callback!"); +// if (jetpack.__parent__.navigator.onLine) { +// let serForm = this +// .serializeForm(jetpack.tabs.focused.contentWindow.document.forms +// .namedItem("changeform")); +//// console.log("serForm:\n" + serForm.toSource()); +// } else { +// let serForm = this +// .serializeForm(jetpack.tabs.focused.contentWindow.document.forms +// .namedItem("changeform")); +// myStorage.forms[this.bugNo] = serForm; +// evt.stopPropagation(); +// evt.preventDefault(); +// } +//}; + +/** + * + * + * Yes, this is correct, this is NOT method of RHBugzillaPage! + */ +/*function onlineCallback() { + function deserializeAndSend(formData) { + // FIXME notImplemented + // is it enough to just + // run XMLHttpRequest? Probably yes, this is just a form + // and this is just a HTTP request + // it is probably better to get already processed + // application/x-www-form-urlencoded + // see http://htmlhelp.com/reference/html40/forms/form.html for details + // and also https://developer.mozilla.org/en/AJAX/Getting_Started + // what's? + // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference\ + // /Global_Functions/encodeURI & co. + // this seems to be also interesting + // https://developer.mozilla.org/en/Code_snippets/Post_data_to_window + console.error("Sending bugs not implemented yet!"); + return ""; // FIXME check other HTTP headers to be set + + let bugID = formData.bugNo; + let req = new XMLHttpRequest(); + req.open("POST", formData.action, true); + // FIXME co očekávám za odpověď? req.overrideMimeType("text/xml"); + // * Accept-Encoding + // * Accept-Language + // * Accept (MIME types) + req.setRequestHeader("Connection", "keep-alive"); + req.setRequestHeader("Keep-Alive", 300); + req.setRequestHeader("Content-Type", formData.enctype); + req.setRequestHeader("Referer", bugURL + bugID); + req.setRequestHeader("Accept-Charset", formData.acceptCharset); + req.setRequestHeader("Cookie", formData.cookie); + req.onreadystatechange = function(aEvt) { + if (req.readyState == 4) { + if (req.status == 200) { + console.log("Sent form for bug " + bugID); + delete myStorage.forms[bugID]; + } else { + console.error("Sending form for bug " + bugID + "failed!"); + } + } + }; + req.send(formData.data); + } + + if (myStorage.forms.length > 0) { + myStorage.forms.forEach(function(x) { + deserializeAndSend(x); + }); + } +} +*/
\ No newline at end of file diff --git a/lib/puvodni/skip-process-bug.js b/lib/puvodni/skip-process-bug.js new file mode 100644 index 0000000..3f82578 --- /dev/null +++ b/lib/puvodni/skip-process-bug.js @@ -0,0 +1,46 @@ +jetpack.future.import("pageMods"); + +// http://maymay.net/blog/2008/06/15/\ +// ridiculously-simple-javascript-version-string-to-object-parser/ +function parseVersionString (str) { + if (typeof(str) != 'string') { return false; } + var x = str.split('.'); + // parse from string or default to 0 if can't parse + var maj = parseInt(x[0]) || 0; + var min = parseInt(x[1]) || 0; + var pat = parseInt(x[2]) || 0; + return { + major: maj, + minor: min, + patch: pat + }; +} + +var callback = function(document){ + var stemURL = "https://HOSTNAME/show_bug.cgi?id="; + var titleStr = $("title",document).text(); + var REArr = RegExp("[0-9]+").exec(titleStr); + var REHostname = RegExp("\/\/([^/]+)\/").exec(document.location.toString()); + if (REArr) { + var bugNo = REArr[0]; + var hostname = REHostname[1]; + console.log("bugNo = " + bugNo + ", hostname = " + hostname); + var currentFFVersion = parseVersionString(jetpack.__parent__.navigator.vendorSub); + console.log("currentFFVersion = " + currentFFVersion.toSource()); + if ((currentFFVersion.major >= 3) && (currentFFVersion.minor >= 6)) { + var emailsSent = $("#bugzilla-body > dl:first",document).text(); + emailsSent = emailsSent.replace(/^(\s*)$/mg,""); + jetpack.notifications.show(emailsSent); + } + document.location = stemURL.replace("HOSTNAME",hostname) + bugNo; + } +}; + +var options = {}; +options.matches = [ + "https://bugzilla.redhat.com/process_bug.cgi", + "https://bugzilla.redhat.com/post_bug.cgi", + "https://bugzilla.mozilla.org/post_bug.cgi", + "https://bugzilla.mozilla.org/process_bug.cgi" + ]; +jetpack.pageMods.add(callback, options); |