diff --git a/app/directives/external-account/external-link-data.directive.jade b/app/directives/external-account/external-link-data.directive.jade index 77a486ffe..83dc151b0 100644 --- a/app/directives/external-account/external-link-data.directive.jade +++ b/app/directives/external-account/external-link-data.directive.jade @@ -102,4 +102,4 @@ p.link-title(data-ellipsis, ng-bind="account.title", ng-hide="account.status === 'PENDING'") p.link-title(ng-show="account.status === 'PENDING'") Loading data. This will take a few minutes. - a.link-url(ng-href="{{account.URL}}", ng-bind="account.URL") + a.link-url(ng-href="{{account.URL | urlProtocol}}", ng-bind="account.URL") diff --git a/app/filters/filters.spec.js b/app/filters/filters.spec.js index 9e4440289..0485c152e 100644 --- a/app/filters/filters.spec.js +++ b/app/filters/filters.spec.js @@ -3,7 +3,7 @@ describe('filters', function() { beforeEach(function() { bard.appModule('topcoder'); - bard.inject(this, 'CONSTANTS', 'roleFilter', 'percentageFilter', 'ordinalFilter', 'displayLocationFilter', 'listRolesFilter', 'trackFilter', 'challengeLinksFilter', 'externalLinkColorFilter', 'emptyFilter', 'ternaryFilter'); + bard.inject(this, 'CONSTANTS', 'roleFilter', 'percentageFilter', 'ordinalFilter', 'displayLocationFilter', 'listRolesFilter', 'trackFilter', 'challengeLinksFilter', 'externalLinkColorFilter', 'emptyFilter', 'ternaryFilter', 'urlProtocolFilter'); domain = CONSTANTS.domain; }); @@ -135,4 +135,19 @@ describe('filters', function() { expect(ternaryFilter(true, 'm', 'n')).to.be.equal('m'); }); }); + + describe('urlProtocolFilter', function() { + it('should add http to the url ', function() { + expect(urlProtocolFilter('google.com')).to.be.equal('http://google.com'); + }); + it('should add http to the url ', function() { + expect(urlProtocolFilter('www.google.com')).to.be.equal('http://www.google.com'); + }); + it('should not add anything to the url ', function() { + expect(urlProtocolFilter('http://google.com')).to.be.equal('http://google.com'); + }); + it('should not add anything to the url ', function() { + expect(urlProtocolFilter('https://google.com')).to.be.equal('https://google.com'); + }); + }); }); diff --git a/app/filters/url-protocol.filter.js b/app/filters/url-protocol.filter.js new file mode 100644 index 000000000..9a4f051cb --- /dev/null +++ b/app/filters/url-protocol.filter.js @@ -0,0 +1,23 @@ +(function() { + 'use strict'; + + angular.module('topcoder').filter('urlProtocol', urlProtocol); + + function urlProtocol() { + return function(link) { + if (!link) { + return link; + } + var result; + var startingUrl = "http://"; + var httpsStartingUrl = "https://"; + if(link.indexOf(startingUrl) === 0||link.indexOf(httpsStartingUrl) === 0) { + result = link; + } else { + result = startingUrl + link; + } + return result; + }; + } + +})(); diff --git a/app/index.jade b/app/index.jade index ed2cf125e..cb1d415d5 100644 --- a/app/index.jade +++ b/app/index.jade @@ -232,6 +232,7 @@ html script(src="filters/track.filter.js") script(src="filters/truncate.filter.js") script(src="filters/underscore-strip.filter.js") + script(src="filters/url-protocol.filter.js") script(src="layout/layout.module.js") script(src="layout/header/header.controller.js") script(src="my-challenges/my-challenges.module.js")