diff options
-rw-r--r-- | extensions/Bitly/template/en/default/hook/global/header-start.html.tmpl | 12 | ||||
-rw-r--r-- | extensions/Bitly/template/en/default/hook/list/list-links.html.tmpl | 17 | ||||
-rw-r--r-- | extensions/Bitly/web/js/bitly.js | 118 | ||||
-rw-r--r-- | extensions/Bitly/web/styles/bitly.css | 13 | ||||
-rw-r--r-- | js/jquery/plugins/bPopup/bPopup-min.js | 7 |
5 files changed, 63 insertions, 104 deletions
diff --git a/extensions/Bitly/template/en/default/hook/global/header-start.html.tmpl b/extensions/Bitly/template/en/default/hook/global/header-start.html.tmpl index ba698aa2c..d41320b29 100644 --- a/extensions/Bitly/template/en/default/hook/global/header-start.html.tmpl +++ b/extensions/Bitly/template/en/default/hook/global/header-start.html.tmpl @@ -6,8 +6,10 @@ # defined by the Mozilla Public License, v. 2.0. #%] -[% RETURN UNLESS template.name == 'list/list.html.tmpl' %] - -[% style_urls.push('extensions/Bitly/web/styles/bitly.css') %] -[% javascript_urls.push('extensions/Bitly/web/js/bitly.js') %] -[% yui.push('container', 'connection', 'json') %] +[% + RETURN UNLESS template.name == 'list/list.html.tmpl'; + jquery.push('bPopup'); + style_urls.push('extensions/Bitly/web/styles/bitly.css'); + javascript_urls.push('extensions/Bitly/web/js/bitly.js'); + generate_api_token = 1; +%] diff --git a/extensions/Bitly/template/en/default/hook/list/list-links.html.tmpl b/extensions/Bitly/template/en/default/hook/list/list-links.html.tmpl index 836c017ed..e0dcdc708 100644 --- a/extensions/Bitly/template/en/default/hook/list/list-links.html.tmpl +++ b/extensions/Bitly/template/en/default/hook/list/list-links.html.tmpl @@ -8,17 +8,18 @@ [% RETURN UNLESS user.id && Bugzilla.params.bitly_token %] -<div id="bitly_overlay"> - <div class="bd"> - <select id="bitly_type" onchange="YAHOO.bitly.execute()"> +<div id="bitly-overlay"> + <div> + <select id="bitly-type"> <option value="shorten">Share a link to this search</option> <option value="list">Share a link to this list of [% terms.bugs %]</option> </select> - <input id="bitly_url" readonly placeholder="Generating short link..."> - </div> - <div class="ft"> - <button id="bitly_close" class="notransition">Close</button> + <input id="bitly-url" readonly placeholder="Generating short link..."> </div> + <button id="bitly-close" class="notransition">Close</button> </div> -<a id="bitly_shorten" href="#" onclick="YAHOO.bitly.toggle();return false">Short URL</a> +<a id="bitly-shorten" href="#" + data-url="[% urlbase _ "buglist.cgi?" _ + cgi.new(urlquerypart).canonicalise_query('list_id','query_format') FILTER html %]" +>Short URL</a> | [%# using nbsp because tt always trims trailing whitespace from templates %] diff --git a/extensions/Bitly/web/js/bitly.js b/extensions/Bitly/web/js/bitly.js index 62c49b650..6784c83e9 100644 --- a/extensions/Bitly/web/js/bitly.js +++ b/extensions/Bitly/web/js/bitly.js @@ -5,96 +5,48 @@ * This Source Code Form is "Incompatible With Secondary Licenses", as * defined by the Mozilla Public License, v. 2.0. */ -(function() { +$(function() { 'use strict'; - var Dom = YAHOO.util.Dom; - YAHOO.namespace('bitly'); - var bitly = YAHOO.bitly; + var popup, urls = []; - bitly.dialog = false; - bitly.url = { shorten: '', list: '' }; + function execute() { + var type = $('#bitly-type').val(); - bitly.shorten = function() { - if (this.dialog) { - this.dialog.show(); - var el = Dom.get('bitly_url'); - el.select(); - el.focus(); + if (urls[type]) { + $('#bitly-url').val(urls[type]).select().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(); + $('#bitly-url').val(''); + var request = 'rest/bitly/' + type + + '?url=' + encodeURIComponent($('#bitly-shorten').data('url')) + + '&Bugzilla_api_token=' + encodeURIComponent(BUGZILLA.api_token); + $.ajax(request) + .done(function(data) { + urls[type] = data.url; + $('#bitly-url').val(urls[type]).select().focus(); + }) + .error(function(data) { + $('#bitly-url').val(data.responseJSON.message); + }); + } + + $('#bitly-shorten') + .click(function(event) { + event.preventDefault(); + popup = $('#bitly-overlay').bPopup({ + speed: 100, + followSpeed: 100, + modalColor: '#fff' + }, execute); }); - 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; - } + $('#bitly-type') + .change(execute); - 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-close') + .click(function(event) { + event.preventDefault(); + popup.close(); }); - }; - - 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(); - } - }; -})(); +}); diff --git a/extensions/Bitly/web/styles/bitly.css b/extensions/Bitly/web/styles/bitly.css index 110a6bef4..e856cbb5d 100644 --- a/extensions/Bitly/web/styles/bitly.css +++ b/extensions/Bitly/web/styles/bitly.css @@ -5,18 +5,15 @@ * This Source Code Form is "Incompatible With Secondary Licenses", as * defined by the Mozilla Public License, v. 2.0. */ -#bitly_overlay { - position: absolute; +#bitly-overlay { + display: none; background: #eee; - border: 1px solid black; + border: 1px solid #000; padding: 5px; - margin: 10px; - visibility: collapse; - box-shadow: 3px 3px 6px #888; - -moz-box-shadow: 3px 3px 6px #888; + width: 400px; } -#bitly_url { +#bitly-url { margin: 2px 0; display: block; width: 100%; diff --git a/js/jquery/plugins/bPopup/bPopup-min.js b/js/jquery/plugins/bPopup/bPopup-min.js new file mode 100644 index 000000000..34ef6f61b --- /dev/null +++ b/js/jquery/plugins/bPopup/bPopup-min.js @@ -0,0 +1,7 @@ +/*================================================================================ + * @name: bPopup - if you can't get it up, use bPopup + * @author: (c)Bjoern Klinggaard (twitter@bklinggaard) + * @demo: http://dinbror.dk/bpopup + * @version: 0.11.0.min + ================================================================================*/ + (function(c){c.fn.bPopup=function(A,E){function L(){a.contentContainer=c(a.contentContainer||b);switch(a.content){case "iframe":var d=c('<iframe class="b-iframe" '+a.iframeAttr+"></iframe>");d.appendTo(a.contentContainer);t=b.outerHeight(!0);u=b.outerWidth(!0);B();d.attr("src",a.loadUrl);l(a.loadCallback);break;case "image":B();c("<img />").load(function(){l(a.loadCallback);F(c(this))}).attr("src",a.loadUrl).hide().appendTo(a.contentContainer);break;default:B(),c('<div class="b-ajax-wrapper"></div>').load(a.loadUrl,a.loadData,function(d,b,e){l(a.loadCallback,b);F(c(this))}).hide().appendTo(a.contentContainer)}}function B(){a.modal&&c('<div class="b-modal '+e+'"></div>').css({backgroundColor:a.modalColor,position:"fixed",top:0,right:0,bottom:0,left:0,opacity:0,zIndex:a.zIndex+v}).appendTo(a.appendTo).fadeTo(a.speed,a.opacity);C();b.data("bPopup",a).data("id",e).css({left:"slideIn"==a.transition||"slideBack"==a.transition?"slideBack"==a.transition?f.scrollLeft()+w:-1*(x+u):m(!(!a.follow[0]&&n||g)),position:a.positionStyle||"absolute",top:"slideDown"==a.transition||"slideUp"==a.transition?"slideUp"==a.transition?f.scrollTop()+y:z+-1*t:p(!(!a.follow[1]&&q||g)),"z-index":a.zIndex+v+1}).each(function(){a.appending&&c(this).appendTo(a.appendTo)});G(!0)}function r(){a.modal&&c(".b-modal."+b.data("id")).fadeTo(a.speed,0,function(){c(this).remove()});a.scrollBar||c("html").css("overflow","auto");c(".b-modal."+e).unbind("click");f.unbind("keydown."+e);k.unbind("."+e).data("bPopup",0<k.data("bPopup")-1?k.data("bPopup")-1:null);b.undelegate(".bClose, ."+a.closeClass,"click."+e,r).data("bPopup",null);clearTimeout(H);G();return!1}function I(d){y=k.height();w=k.width();h=D();if(h.x||h.y)clearTimeout(J),J=setTimeout(function(){C();d=d||a.followSpeed;var e={};h.x&&(e.left=a.follow[0]?m(!0):"auto");h.y&&(e.top=a.follow[1]?p(!0):"auto");b.dequeue().each(function(){g?c(this).css({left:x,top:z}):c(this).animate(e,d,a.followEasing)})},50)}function F(d){var c=d.width(),e=d.height(),f={};a.contentContainer.css({height:e,width:c});e>=b.height()&&(f.height=b.height());c>=b.width()&&(f.width=b.width());t=b.outerHeight(!0);u=b.outerWidth(!0);C();a.contentContainer.css({height:"auto",width:"auto"});f.left=m(!(!a.follow[0]&&n||g));f.top=p(!(!a.follow[1]&&q||g));b.animate(f,250,function(){d.show();h=D()})}function M(){k.data("bPopup",v);b.delegate(".bClose, ."+a.closeClass,"click."+e,r);a.modalClose&&c(".b-modal."+e).css("cursor","pointer").bind("click",r);N||!a.follow[0]&&!a.follow[1]||k.bind("scroll."+e,function(){if(h.x||h.y){var d={};h.x&&(d.left=a.follow[0]?m(!g):"auto");h.y&&(d.top=a.follow[1]?p(!g):"auto");b.dequeue().animate(d,a.followSpeed,a.followEasing)}}).bind("resize."+e,function(){I()});a.escClose&&f.bind("keydown."+e,function(a){27==a.which&&r()})}function G(d){function c(e){b.css({display:"block",opacity:1}).animate(e,a.speed,a.easing,function(){K(d)})}switch(d?a.transition:a.transitionClose||a.transition){case "slideIn":c({left:d?m(!(!a.follow[0]&&n||g)):f.scrollLeft()-(u||b.outerWidth(!0))-200});break;case "slideBack":c({left:d?m(!(!a.follow[0]&&n||g)):f.scrollLeft()+w+200});break;case "slideDown":c({top:d?p(!(!a.follow[1]&&q||g)):f.scrollTop()-(t||b.outerHeight(!0))-200});break;case "slideUp":c({top:d?p(!(!a.follow[1]&&q||g)):f.scrollTop()+y+200});break;default:b.stop().fadeTo(a.speed,d?1:0,function(){K(d)})}}function K(d){d?(M(),l(E),a.autoClose&&(H=setTimeout(r,a.autoClose))):(b.hide(),l(a.onClose),a.loadUrl&&(a.contentContainer.empty(),b.css({height:"auto",width:"auto"})))}function m(a){return a?x+f.scrollLeft():x}function p(a){return a?z+f.scrollTop():z}function l(a,e){c.isFunction(a)&&a.call(b,e)}function C(){z=q?a.position[1]:Math.max(0,(y-b.outerHeight(!0))/2-a.amsl);x=n?a.position[0]:(w-b.outerWidth(!0))/2;h=D()}function D(){return{x:w>b.outerWidth(!0),y:y>b.outerHeight(!0)}}c.isFunction(A)&&(E=A,A=null);var a=c.extend({},c.fn.bPopup.defaults,A);a.scrollBar||c("html").css("overflow","hidden");var b=this,f=c(document),k=c(window),y=k.height(),w=k.width(),N=/OS 6(_\d)+/i.test(navigator.userAgent),v=0,e,h,q,n,g,z,x,t,u,J,H;b.close=function(){r()};b.reposition=function(a){I(a)};return b.each(function(){c(this).data("bPopup")||(l(a.onOpen),v=(k.data("bPopup")||0)+1,e="__b-popup"+v+"__",q="auto"!==a.position[1],n="auto"!==a.position[0],g="fixed"===a.positionStyle,t=b.outerHeight(!0),u=b.outerWidth(!0),a.loadUrl?L():B())})};c.fn.bPopup.defaults={amsl:50,appending:!0,appendTo:"body",autoClose:!1,closeClass:"b-close",content:"ajax",contentContainer:!1,easing:"swing",escClose:!0,follow:[!0,!0],followEasing:"swing",followSpeed:500,iframeAttr:'scrolling="no" frameborder="0"',loadCallback:!1,loadData:!1,loadUrl:!1,modal:!0,modalClose:!0,modalColor:"#000",onClose:!1,onOpen:!1,opacity:.7,position:["auto","auto"],positionStyle:"absolute",scrollBar:!0,speed:250,transition:"fadeIn",transitionClose:!1,zIndex:9997}})(jQuery); |