summaryrefslogtreecommitdiffstats
path: root/extensions/Bitly/web/js
diff options
context:
space:
mode:
authorByron Jones <glob@mozilla.com>2014-09-01 08:04:02 +0200
committerByron Jones <glob@mozilla.com>2014-09-01 08:04:18 +0200
commit1f6f7f13093e0c3c51fe43fa9c4eb1330256ad93 (patch)
treef6da8ad340802f15f42e9ea4b17b136b9e16c951 /extensions/Bitly/web/js
parent2251b986b5ffef72b2ce06e6f90652c3ff598a38 (diff)
downloadbugzilla-1f6f7f13093e0c3c51fe43fa9c4eb1330256ad93.tar.gz
bugzilla-1f6f7f13093e0c3c51fe43fa9c4eb1330256ad93.tar.xz
Bug 1056162: add bit.ly support to bmo
Diffstat (limited to 'extensions/Bitly/web/js')
-rw-r--r--extensions/Bitly/web/js/bitly.js100
1 files changed, 100 insertions, 0 deletions
diff --git a/extensions/Bitly/web/js/bitly.js b/extensions/Bitly/web/js/bitly.js
new file mode 100644
index 000000000..62c49b650
--- /dev/null
+++ b/extensions/Bitly/web/js/bitly.js
@@ -0,0 +1,100 @@
+/* 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/.
+ *
+ * This Source Code Form is "Incompatible With Secondary Licenses", as
+ * defined by the Mozilla Public License, v. 2.0. */
+
+(function() {
+ 'use strict';
+ var Dom = YAHOO.util.Dom;
+ YAHOO.namespace('bitly');
+ var bitly = YAHOO.bitly;
+
+ bitly.dialog = false;
+ bitly.url = { shorten: '', list: '' };
+
+ bitly.shorten = function() {
+ if (this.dialog) {
+ this.dialog.show();
+ var el = Dom.get('bitly_url');
+ el.select();
+ el.focus();
+ return;
+ }
+ this.dialog = new YAHOO.widget.Overlay('bitly_overlay', {
+ visible: true,
+ close: false,
+ underlay: 'shadow',
+ width: '400px',
+ context: [ 'bitly_shorten', 'bl', 'tl', ['windowResize'], [0, -10] ]
+ });
+ this.dialog.render(document.body);
+
+ YAHOO.util.Event.addListener('bitly_close', 'click', function() {
+ YAHOO.bitly.dialog.hide();
+ });
+ YAHOO.util.Event.addListener('bitly_url', 'keypress', function(o) {
+ if (o.keyCode == 27 || o.keyCode == 13)
+ YAHOO.bitly.dialog.hide();
+ });
+ this.execute();
+ Dom.get('bitly_url').focus();
+ };
+
+ bitly.execute = function() {
+ Dom.get('bitly_url').value = '';
+
+ var type = Dom.get('bitly_type').value;
+ if (this.url[type]) {
+ this.set(this.url[type]);
+ return;
+ }
+
+ var url = 'rest/bitly/' + type + '?url=' + encodeURIComponent(document.location);
+ YAHOO.util.Connect.initHeader("Accept", "application/json");
+ YAHOO.util.Connect.asyncRequest('GET', url, {
+ success: function(o) {
+ var response = YAHOO.lang.JSON.parse(o.responseText);
+ if (response.error) {
+ bitly.set(response.message);
+ }
+ else {
+ bitly.url[type] = response.url;
+ bitly.set(response.url);
+ }
+ },
+ failure: function(o) {
+ try {
+ var response = YAHOO.lang.JSON.parse(o.responseText);
+ if (response.error) {
+ bitly.set(response.message);
+ }
+ else {
+ bitly.set(o.statusText);
+ }
+ } catch (ex) {
+ bitly.set(o.statusText);
+ }
+ }
+ });
+ };
+
+ bitly.set = function(value) {
+ var el = Dom.get('bitly_url');
+ el.value = value;
+ el.select();
+ el.focus();
+ };
+
+ bitly.toggle = function() {
+ if (this.dialog
+ && YAHOO.util.Dom.get('bitly_overlay').style.visibility == 'visible')
+ {
+ this.dialog.hide();
+ }
+ else {
+ this.shorten();
+ }
+ };
+})();