diff --git a/.eslintignore b/.eslintignore index d4041fe..74776ac 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,7 +3,7 @@ coverage/** dist/** # Ignore symlink to build folder -docs/assets/** +docs/** # Ignore HTML templates generated code src/** diff --git a/docs/url.js b/docs/url.js index 4eeff23..679eb15 100644 --- a/docs/url.js +++ b/docs/url.js @@ -394,6 +394,8 @@ })(typeof self !== 'undefined' ? self : this); },{}],2:[function(require,module,exports){ +/* global Diff2HtmlUI */ + /* * Example URLs: * @@ -410,20 +412,20 @@ * https://bitbucket.org/atlassian/amps/pull-requests/236 */ -$(document).ready(function () { +$(document).ready(function() { // Improves browser compatibility require('whatwg-fetch'); var $container = $('.container'); - var $url = $("#url"); - var $outputFormat = $("#diff-url-options-output-format"); - var $showFiles = $("#diff-url-options-show-files"); - var $matching = $("#diff-url-options-matching"); - var $wordThreshold = $("#diff-url-options-match-words-threshold"); - var $matchingMaxComparisons = $("#diff-url-options-matching-max-comparisons"); + var $url = $('#url'); + var $outputFormat = $('#diff-url-options-output-format'); + var $showFiles = $('#diff-url-options-show-files'); + var $matching = $('#diff-url-options-matching'); + var $wordThreshold = $('#diff-url-options-match-words-threshold'); + var $matchingMaxComparisons = $('#diff-url-options-matching-max-comparisons'); var hash = window.location.hash - .replace(/^(#!?\/?)/, ""); + .replace(/^(#!?\/?)/, ''); var search = window.location.search; @@ -433,9 +435,9 @@ $(document).ready(function () { } else if (search) { try { var url = search - .split("?")[1] - .split("diff=")[1] - .split("&")[0]; + .split('?')[1] + .split('diff=')[1] + .split('&')[0]; $url.val(url); draw(prepareUrl(url)); } catch (_ignore) { @@ -449,7 +451,7 @@ $(document).ready(function () { .add($matching) .add($wordThreshold) .add($matchingMaxComparisons) - .change(function () { + .change(function() { fastDraw(); }); @@ -460,12 +462,12 @@ $(document).ready(function () { } function bind() { - $("#url-btn").click(function (e) { + $('#url-btn').click(function(e) { e.preventDefault(); fastDraw(); }); - $url.on("paste", function(e) { + $url.on('paste', function(e) { fastDraw(); }); } @@ -484,43 +486,41 @@ $(document).ready(function () { var bitbucketPrUrl = /^https?:\/\/(?:www\.)?bitbucket\.org\/(.*?)\/(.*?)\/pull-requests\/(.*?)(?:\/.*)?$/; function genericUrlGen(provider, userName, projectName, type, value) { - return "https://" + provider + ".com/" + userName + "/" + projectName + "/" + type + "/" + value + ".diff"; + return 'https://' + provider + '.com/' + userName + '/' + projectName + '/' + type + '/' + value + '.diff'; } function bitbucketUrlGen(userName, projectName, type, value) { - var baseUrl = "https://bitbucket.org/api/2.0/repositories/"; + var baseUrl = 'https://bitbucket.org/api/2.0/repositories/'; - if (type == "pullrequests") { - return baseUrl + userName + "/" + projectName + "/pullrequests/" + value + "/diff"; + if (type === 'pullrequests') { + return baseUrl + userName + '/' + projectName + '/pullrequests/' + value + '/diff'; } - return baseUrl + userName + "/" + projectName + "/diff/" + value; + return baseUrl + userName + '/' + projectName + '/diff/' + value; } var values; var finalUrl; if ((values = githubPath.exec(url))) { - finalUrl = genericUrlGen("github", values[1], values[2], "commit", values[3]); + finalUrl = genericUrlGen('github', values[1], values[2], 'commit', values[3]); } else if ((values = githubCommitUrl.exec(url))) { - finalUrl = genericUrlGen("github", values[1], values[2], "commit", values[3]); + finalUrl = genericUrlGen('github', values[1], values[2], 'commit', values[3]); } else if ((values = githubPrUrl.exec(url))) { - finalUrl = genericUrlGen("github", values[1], values[2], "pull", values[3]); - + finalUrl = genericUrlGen('github', values[1], values[2], 'pull', values[3]); } else if ((values = gitlabPath.exec(url))) { - finalUrl = genericUrlGen("gitlab", values[1], values[2], "commit", values[3]); + finalUrl = genericUrlGen('gitlab', values[1], values[2], 'commit', values[3]); } else if ((values = gitlabCommitUrl.exec(url))) { - finalUrl = genericUrlGen("gitlab", values[1], values[2], "commit", values[3]); + finalUrl = genericUrlGen('gitlab', values[1], values[2], 'commit', values[3]); } else if ((values = gitlabPrUrl.exec(url))) { - finalUrl = genericUrlGen("gitlab", values[1], values[2], "merge_requests", values[3]); - + finalUrl = genericUrlGen('gitlab', values[1], values[2], 'merge_requests', values[3]); } else if ((values = bitbucketPath.exec(url))) { - finalUrl = bitbucketUrlGen(values[1], values[2], "commit", values[3]); + finalUrl = bitbucketUrlGen(values[1], values[2], 'commit', values[3]); } else if ((values = bitbucketCommitUrl.exec(url))) { - finalUrl = bitbucketUrlGen(values[1], values[2], "commit", values[3]); + finalUrl = bitbucketUrlGen(values[1], values[2], 'commit', values[3]); } else if ((values = bitbucketPrUrl.exec(url))) { - finalUrl = bitbucketUrlGen(values[1], values[2], "pullrequests", values[3]); + finalUrl = bitbucketUrlGen(values[1], values[2], 'pullrequests', values[3]); } else { - console.info("Could not parse url, using the provided url."); + console.info('Could not parse url, using the provided url.'); finalUrl = url; } @@ -529,24 +529,24 @@ $(document).ready(function () { function draw(url) { var outputFormat = $outputFormat.val(); - var showFiles = $showFiles.is(":checked"); + var showFiles = $showFiles.is(':checked'); var matching = $matching.val(); var wordThreshold = $wordThreshold.val(); var matchingMaxComparisons = $matchingMaxComparisons.val(); var fullUrl = 'https://crossorigin.me/' + url; fetch(fullUrl) - .then(function (res) { - return res.text() + .then(function(res) { + return res.text(); }) - .then(function (data) { + .then(function(data) { var container = '#url-diff-container'; var diff2htmlUi = new Diff2HtmlUI({diff: data}); - if (outputFormat == 'side-by-side') { - $container.css({"width": "1400px"}); + if (outputFormat === 'side-by-side') { + $container.css({'width': '1400px'}); } else { - $container.css({"width": ""}); + $container.css({'width': ''}); } diff2htmlUi.draw(container, { diff --git a/docs/url.min.js b/docs/url.min.js index f534be3..50294c4 100644 --- a/docs/url.min.js +++ b/docs/url.min.js @@ -1 +1 @@ -!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o-1?upcased:method}function Request(input,options){options=options||{};var body=options.body;if(Request.prototype.isPrototypeOf(input)){if(input.bodyUsed)throw new TypeError("Already read");this.url=input.url,this.credentials=input.credentials,options.headers||(this.headers=new Headers(input.headers)),this.method=input.method,this.mode=input.mode,body||(body=input._bodyInit,input.bodyUsed=!0)}else this.url=input;if(this.credentials=options.credentials||this.credentials||"omit",(options.headers||!this.headers)&&(this.headers=new Headers(options.headers)),this.method=normalizeMethod(options.method||this.method||"GET"),this.mode=options.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&body)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(body)}function decode(body){var form=new FormData;return body.trim().split("&").forEach(function(bytes){if(bytes){var split=bytes.split("="),name=split.shift().replace(/\+/g," "),value=split.join("=").replace(/\+/g," ");form.append(decodeURIComponent(name),decodeURIComponent(value))}}),form}function headers(xhr){var head=new Headers,pairs=(xhr.getAllResponseHeaders()||"").trim().split("\n");return pairs.forEach(function(header){var split=header.trim().split(":"),key=split.shift().trim(),value=split.join(":").trim();head.append(key,value)}),head}function Response(bodyInit,options){options||(options={}),this.type="default",this.status=options.status,this.ok=this.status>=200&&this.status<300,this.statusText=options.statusText,this.headers=options.headers instanceof Headers?options.headers:new Headers(options.headers),this.url=options.url||"",this._initBody(bodyInit)}if(!self.fetch){Headers.prototype.append=function(name,value){name=normalizeName(name),value=normalizeValue(value);var list=this.map[name];list||(list=[],this.map[name]=list),list.push(value)},Headers.prototype["delete"]=function(name){delete this.map[normalizeName(name)]},Headers.prototype.get=function(name){var values=this.map[normalizeName(name)];return values?values[0]:null},Headers.prototype.getAll=function(name){return this.map[normalizeName(name)]||[]},Headers.prototype.has=function(name){return this.map.hasOwnProperty(normalizeName(name))},Headers.prototype.set=function(name,value){this.map[normalizeName(name)]=[normalizeValue(value)]},Headers.prototype.forEach=function(callback,thisArg){Object.getOwnPropertyNames(this.map).forEach(function(name){this.map[name].forEach(function(value){callback.call(thisArg,value,name,this)},this)},this)};var support={blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self},methods=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];Request.prototype.clone=function(){return new Request(this)},Body.call(Request.prototype),Body.call(Response.prototype),Response.prototype.clone=function(){return new Response(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new Headers(this.headers),url:this.url})},Response.error=function(){var response=new Response(null,{status:0,statusText:""});return response.type="error",response};var redirectStatuses=[301,302,303,307,308];Response.redirect=function(url,status){if(-1===redirectStatuses.indexOf(status))throw new RangeError("Invalid status code");return new Response(null,{status:status,headers:{location:url}})},self.Headers=Headers,self.Request=Request,self.Response=Response,self.fetch=function(input,init){return new Promise(function(resolve,reject){function responseURL(){return"responseURL"in xhr?xhr.responseURL:/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())?xhr.getResponseHeader("X-Request-URL"):void 0}var request;request=Request.prototype.isPrototypeOf(input)&&!init?input:new Request(input,init);var xhr=new XMLHttpRequest;xhr.onload=function(){var status=1223===xhr.status?204:xhr.status;if(100>status||status>599)return void reject(new TypeError("Network request failed"));var options={status:status,statusText:xhr.statusText,headers:headers(xhr),url:responseURL()},body="response"in xhr?xhr.response:xhr.responseText;resolve(new Response(body,options))},xhr.onerror=function(){reject(new TypeError("Network request failed"))},xhr.ontimeout=function(){reject(new TypeError("Network request failed"))},xhr.open(request.method,request.url,!0),"include"===request.credentials&&(xhr.withCredentials=!0),"responseType"in xhr&&support.blob&&(xhr.responseType="blob"),request.headers.forEach(function(value,name){xhr.setRequestHeader(name,value)}),xhr.send("undefined"==typeof request._bodyInit?null:request._bodyInit)})},self.fetch.polyfill=!0}}("undefined"!=typeof self?self:this)},{}],2:[function(require){$(document).ready(function(){function fastDraw(){var url=$url.val(),preparedUrl=prepareUrl(url);draw(preparedUrl)}function bind(){$("#url-btn").click(function(e){e.preventDefault(),fastDraw()}),$url.on("paste",function(){fastDraw()})}function prepareUrl(url){function genericUrlGen(provider,userName,projectName,type,value){return"https://"+provider+".com/"+userName+"/"+projectName+"/"+type+"/"+value+".diff"}function bitbucketUrlGen(userName,projectName,type,value){var baseUrl="https://bitbucket.org/api/2.0/repositories/";return"pullrequests"==type?baseUrl+userName+"/"+projectName+"/pullrequests/"+value+"/diff":baseUrl+userName+"/"+projectName+"/diff/"+value}var values,finalUrl,githubPath=/^github\/(.*?)\/(.*?)\/(.*?)$/,githubCommitUrl=/^https?:\/\/(?:www\.)?github\.com\/(.*?)\/(.*?)\/commit\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/,githubPrUrl=/^https?:\/\/(?:www\.)?github\.com\/(.*?)\/(.*?)\/pull\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/,gitlabPath=/^gitlab\/(.*?)\/(.*?)\/(.*?)$/,gitlabCommitUrl=/^https?:\/\/(?:www\.)?gitlab\.com\/(.*?)\/(.*?)\/commit\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/,gitlabPrUrl=/^https?:\/\/(?:www\.)?gitlab\.com\/(.*?)\/(.*?)\/merge_requests\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/,bitbucketPath=/^bitbucket\/(.*?)\/(.*?)\/(.*?)$/,bitbucketCommitUrl=/^https?:\/\/(?:www\.)?bitbucket\.org\/(.*?)\/(.*?)\/commits\/(.*?)(?:\/raw)?(?:\/.*)?$/,bitbucketPrUrl=/^https?:\/\/(?:www\.)?bitbucket\.org\/(.*?)\/(.*?)\/pull-requests\/(.*?)(?:\/.*)?$/;return(values=githubPath.exec(url))?finalUrl=genericUrlGen("github",values[1],values[2],"commit",values[3]):(values=githubCommitUrl.exec(url))?finalUrl=genericUrlGen("github",values[1],values[2],"commit",values[3]):(values=githubPrUrl.exec(url))?finalUrl=genericUrlGen("github",values[1],values[2],"pull",values[3]):(values=gitlabPath.exec(url))?finalUrl=genericUrlGen("gitlab",values[1],values[2],"commit",values[3]):(values=gitlabCommitUrl.exec(url))?finalUrl=genericUrlGen("gitlab",values[1],values[2],"commit",values[3]):(values=gitlabPrUrl.exec(url))?finalUrl=genericUrlGen("gitlab",values[1],values[2],"merge_requests",values[3]):(values=bitbucketPath.exec(url))?finalUrl=bitbucketUrlGen(values[1],values[2],"commit",values[3]):(values=bitbucketCommitUrl.exec(url))?finalUrl=bitbucketUrlGen(values[1],values[2],"commit",values[3]):(values=bitbucketPrUrl.exec(url))?finalUrl=bitbucketUrlGen(values[1],values[2],"pullrequests",values[3]):(console.info("Could not parse url, using the provided url."),finalUrl=url),finalUrl}function draw(url){var outputFormat=$outputFormat.val(),showFiles=$showFiles.is(":checked"),matching=$matching.val(),wordThreshold=$wordThreshold.val(),matchingMaxComparisons=$matchingMaxComparisons.val(),fullUrl="https://crossorigin.me/"+url;fetch(fullUrl).then(function(res){return res.text()}).then(function(data){var container="#url-diff-container",diff2htmlUi=new Diff2HtmlUI({diff:data});$container.css("side-by-side"==outputFormat?{width:"1400px"}:{width:""}),diff2htmlUi.draw(container,{outputFormat:outputFormat,showFiles:showFiles,matching:matching,matchWordsThreshold:wordThreshold,matchingMaxComparisons:matchingMaxComparisons,synchronisedScroll:!0}),diff2htmlUi.fileListCloseable(container,!1),diff2htmlUi.highlightCode(container)})}require("whatwg-fetch");var $container=$(".container"),$url=$("#url"),$outputFormat=$("#diff-url-options-output-format"),$showFiles=$("#diff-url-options-show-files"),$matching=$("#diff-url-options-matching"),$wordThreshold=$("#diff-url-options-match-words-threshold"),$matchingMaxComparisons=$("#diff-url-options-matching-max-comparisons"),hash=window.location.hash.replace(/^(#!?\/?)/,""),search=window.location.search;if(hash)$url.val(hash),draw(prepareUrl(hash));else if(search)try{var url=search.split("?")[1].split("diff=")[1].split("&")[0];$url.val(url),draw(prepareUrl(url))}catch(_ignore){}bind(prepareUrl),$outputFormat.add($showFiles).add($matching).add($wordThreshold).add($matchingMaxComparisons).change(function(){fastDraw()})})},{"whatwg-fetch":1}]},{},[2]); \ No newline at end of file +!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o-1?upcased:method}function Request(input,options){options=options||{};var body=options.body;if(Request.prototype.isPrototypeOf(input)){if(input.bodyUsed)throw new TypeError("Already read");this.url=input.url,this.credentials=input.credentials,options.headers||(this.headers=new Headers(input.headers)),this.method=input.method,this.mode=input.mode,body||(body=input._bodyInit,input.bodyUsed=!0)}else this.url=input;if(this.credentials=options.credentials||this.credentials||"omit",(options.headers||!this.headers)&&(this.headers=new Headers(options.headers)),this.method=normalizeMethod(options.method||this.method||"GET"),this.mode=options.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&body)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(body)}function decode(body){var form=new FormData;return body.trim().split("&").forEach(function(bytes){if(bytes){var split=bytes.split("="),name=split.shift().replace(/\+/g," "),value=split.join("=").replace(/\+/g," ");form.append(decodeURIComponent(name),decodeURIComponent(value))}}),form}function headers(xhr){var head=new Headers,pairs=(xhr.getAllResponseHeaders()||"").trim().split("\n");return pairs.forEach(function(header){var split=header.trim().split(":"),key=split.shift().trim(),value=split.join(":").trim();head.append(key,value)}),head}function Response(bodyInit,options){options||(options={}),this.type="default",this.status=options.status,this.ok=this.status>=200&&this.status<300,this.statusText=options.statusText,this.headers=options.headers instanceof Headers?options.headers:new Headers(options.headers),this.url=options.url||"",this._initBody(bodyInit)}if(!self.fetch){Headers.prototype.append=function(name,value){name=normalizeName(name),value=normalizeValue(value);var list=this.map[name];list||(list=[],this.map[name]=list),list.push(value)},Headers.prototype["delete"]=function(name){delete this.map[normalizeName(name)]},Headers.prototype.get=function(name){var values=this.map[normalizeName(name)];return values?values[0]:null},Headers.prototype.getAll=function(name){return this.map[normalizeName(name)]||[]},Headers.prototype.has=function(name){return this.map.hasOwnProperty(normalizeName(name))},Headers.prototype.set=function(name,value){this.map[normalizeName(name)]=[normalizeValue(value)]},Headers.prototype.forEach=function(callback,thisArg){Object.getOwnPropertyNames(this.map).forEach(function(name){this.map[name].forEach(function(value){callback.call(thisArg,value,name,this)},this)},this)};var support={blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self},methods=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];Request.prototype.clone=function(){return new Request(this)},Body.call(Request.prototype),Body.call(Response.prototype),Response.prototype.clone=function(){return new Response(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new Headers(this.headers),url:this.url})},Response.error=function(){var response=new Response(null,{status:0,statusText:""});return response.type="error",response};var redirectStatuses=[301,302,303,307,308];Response.redirect=function(url,status){if(-1===redirectStatuses.indexOf(status))throw new RangeError("Invalid status code");return new Response(null,{status:status,headers:{location:url}})},self.Headers=Headers,self.Request=Request,self.Response=Response,self.fetch=function(input,init){return new Promise(function(resolve,reject){function responseURL(){return"responseURL"in xhr?xhr.responseURL:/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())?xhr.getResponseHeader("X-Request-URL"):void 0}var request;request=Request.prototype.isPrototypeOf(input)&&!init?input:new Request(input,init);var xhr=new XMLHttpRequest;xhr.onload=function(){var status=1223===xhr.status?204:xhr.status;if(100>status||status>599)return void reject(new TypeError("Network request failed"));var options={status:status,statusText:xhr.statusText,headers:headers(xhr),url:responseURL()},body="response"in xhr?xhr.response:xhr.responseText;resolve(new Response(body,options))},xhr.onerror=function(){reject(new TypeError("Network request failed"))},xhr.ontimeout=function(){reject(new TypeError("Network request failed"))},xhr.open(request.method,request.url,!0),"include"===request.credentials&&(xhr.withCredentials=!0),"responseType"in xhr&&support.blob&&(xhr.responseType="blob"),request.headers.forEach(function(value,name){xhr.setRequestHeader(name,value)}),xhr.send("undefined"==typeof request._bodyInit?null:request._bodyInit)})},self.fetch.polyfill=!0}}("undefined"!=typeof self?self:this)},{}],2:[function(require){$(document).ready(function(){function fastDraw(){var url=$url.val(),preparedUrl=prepareUrl(url);draw(preparedUrl)}function bind(){$("#url-btn").click(function(e){e.preventDefault(),fastDraw()}),$url.on("paste",function(){fastDraw()})}function prepareUrl(url){function genericUrlGen(provider,userName,projectName,type,value){return"https://"+provider+".com/"+userName+"/"+projectName+"/"+type+"/"+value+".diff"}function bitbucketUrlGen(userName,projectName,type,value){var baseUrl="https://bitbucket.org/api/2.0/repositories/";return"pullrequests"===type?baseUrl+userName+"/"+projectName+"/pullrequests/"+value+"/diff":baseUrl+userName+"/"+projectName+"/diff/"+value}var values,finalUrl,githubPath=/^github\/(.*?)\/(.*?)\/(.*?)$/,githubCommitUrl=/^https?:\/\/(?:www\.)?github\.com\/(.*?)\/(.*?)\/commit\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/,githubPrUrl=/^https?:\/\/(?:www\.)?github\.com\/(.*?)\/(.*?)\/pull\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/,gitlabPath=/^gitlab\/(.*?)\/(.*?)\/(.*?)$/,gitlabCommitUrl=/^https?:\/\/(?:www\.)?gitlab\.com\/(.*?)\/(.*?)\/commit\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/,gitlabPrUrl=/^https?:\/\/(?:www\.)?gitlab\.com\/(.*?)\/(.*?)\/merge_requests\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/,bitbucketPath=/^bitbucket\/(.*?)\/(.*?)\/(.*?)$/,bitbucketCommitUrl=/^https?:\/\/(?:www\.)?bitbucket\.org\/(.*?)\/(.*?)\/commits\/(.*?)(?:\/raw)?(?:\/.*)?$/,bitbucketPrUrl=/^https?:\/\/(?:www\.)?bitbucket\.org\/(.*?)\/(.*?)\/pull-requests\/(.*?)(?:\/.*)?$/;return(values=githubPath.exec(url))?finalUrl=genericUrlGen("github",values[1],values[2],"commit",values[3]):(values=githubCommitUrl.exec(url))?finalUrl=genericUrlGen("github",values[1],values[2],"commit",values[3]):(values=githubPrUrl.exec(url))?finalUrl=genericUrlGen("github",values[1],values[2],"pull",values[3]):(values=gitlabPath.exec(url))?finalUrl=genericUrlGen("gitlab",values[1],values[2],"commit",values[3]):(values=gitlabCommitUrl.exec(url))?finalUrl=genericUrlGen("gitlab",values[1],values[2],"commit",values[3]):(values=gitlabPrUrl.exec(url))?finalUrl=genericUrlGen("gitlab",values[1],values[2],"merge_requests",values[3]):(values=bitbucketPath.exec(url))?finalUrl=bitbucketUrlGen(values[1],values[2],"commit",values[3]):(values=bitbucketCommitUrl.exec(url))?finalUrl=bitbucketUrlGen(values[1],values[2],"commit",values[3]):(values=bitbucketPrUrl.exec(url))?finalUrl=bitbucketUrlGen(values[1],values[2],"pullrequests",values[3]):(console.info("Could not parse url, using the provided url."),finalUrl=url),finalUrl}function draw(url){var outputFormat=$outputFormat.val(),showFiles=$showFiles.is(":checked"),matching=$matching.val(),wordThreshold=$wordThreshold.val(),matchingMaxComparisons=$matchingMaxComparisons.val(),fullUrl="https://crossorigin.me/"+url;fetch(fullUrl).then(function(res){return res.text()}).then(function(data){var container="#url-diff-container",diff2htmlUi=new Diff2HtmlUI({diff:data});$container.css("side-by-side"===outputFormat?{width:"1400px"}:{width:""}),diff2htmlUi.draw(container,{outputFormat:outputFormat,showFiles:showFiles,matching:matching,matchWordsThreshold:wordThreshold,matchingMaxComparisons:matchingMaxComparisons,synchronisedScroll:!0}),diff2htmlUi.fileListCloseable(container,!1),diff2htmlUi.highlightCode(container)})}require("whatwg-fetch");var $container=$(".container"),$url=$("#url"),$outputFormat=$("#diff-url-options-output-format"),$showFiles=$("#diff-url-options-show-files"),$matching=$("#diff-url-options-matching"),$wordThreshold=$("#diff-url-options-match-words-threshold"),$matchingMaxComparisons=$("#diff-url-options-matching-max-comparisons"),hash=window.location.hash.replace(/^(#!?\/?)/,""),search=window.location.search;if(hash)$url.val(hash),draw(prepareUrl(hash));else if(search)try{var url=search.split("?")[1].split("diff=")[1].split("&")[0];$url.val(url),draw(prepareUrl(url))}catch(_ignore){}bind(prepareUrl),$outputFormat.add($showFiles).add($matching).add($wordThreshold).add($matchingMaxComparisons).change(function(){fastDraw()})})},{"whatwg-fetch":1}]},{},[2]); \ No newline at end of file diff --git a/website/templates/pages/url/url.js b/website/templates/pages/url/url.js index 12a4009..b5763ed 100644 --- a/website/templates/pages/url/url.js +++ b/website/templates/pages/url/url.js @@ -1,3 +1,5 @@ +/* global Diff2HtmlUI */ + /* * Example URLs: * @@ -14,20 +16,20 @@ * https://bitbucket.org/atlassian/amps/pull-requests/236 */ -$(document).ready(function () { +$(document).ready(function() { // Improves browser compatibility require('whatwg-fetch'); var $container = $('.container'); - var $url = $("#url"); - var $outputFormat = $("#diff-url-options-output-format"); - var $showFiles = $("#diff-url-options-show-files"); - var $matching = $("#diff-url-options-matching"); - var $wordThreshold = $("#diff-url-options-match-words-threshold"); - var $matchingMaxComparisons = $("#diff-url-options-matching-max-comparisons"); + var $url = $('#url'); + var $outputFormat = $('#diff-url-options-output-format'); + var $showFiles = $('#diff-url-options-show-files'); + var $matching = $('#diff-url-options-matching'); + var $wordThreshold = $('#diff-url-options-match-words-threshold'); + var $matchingMaxComparisons = $('#diff-url-options-matching-max-comparisons'); var hash = window.location.hash - .replace(/^(#!?\/?)/, ""); + .replace(/^(#!?\/?)/, ''); var search = window.location.search; @@ -37,9 +39,9 @@ $(document).ready(function () { } else if (search) { try { var url = search - .split("?")[1] - .split("diff=")[1] - .split("&")[0]; + .split('?')[1] + .split('diff=')[1] + .split('&')[0]; $url.val(url); draw(prepareUrl(url)); } catch (_ignore) { @@ -53,7 +55,7 @@ $(document).ready(function () { .add($matching) .add($wordThreshold) .add($matchingMaxComparisons) - .change(function () { + .change(function() { fastDraw(); }); @@ -64,12 +66,12 @@ $(document).ready(function () { } function bind() { - $("#url-btn").click(function (e) { + $('#url-btn').click(function(e) { e.preventDefault(); fastDraw(); }); - $url.on("paste", function(e) { + $url.on('paste', function(e) { fastDraw(); }); } @@ -88,43 +90,41 @@ $(document).ready(function () { var bitbucketPrUrl = /^https?:\/\/(?:www\.)?bitbucket\.org\/(.*?)\/(.*?)\/pull-requests\/(.*?)(?:\/.*)?$/; function genericUrlGen(provider, userName, projectName, type, value) { - return "https://" + provider + ".com/" + userName + "/" + projectName + "/" + type + "/" + value + ".diff"; + return 'https://' + provider + '.com/' + userName + '/' + projectName + '/' + type + '/' + value + '.diff'; } function bitbucketUrlGen(userName, projectName, type, value) { - var baseUrl = "https://bitbucket.org/api/2.0/repositories/"; + var baseUrl = 'https://bitbucket.org/api/2.0/repositories/'; - if (type == "pullrequests") { - return baseUrl + userName + "/" + projectName + "/pullrequests/" + value + "/diff"; + if (type === 'pullrequests') { + return baseUrl + userName + '/' + projectName + '/pullrequests/' + value + '/diff'; } - return baseUrl + userName + "/" + projectName + "/diff/" + value; + return baseUrl + userName + '/' + projectName + '/diff/' + value; } var values; var finalUrl; if ((values = githubPath.exec(url))) { - finalUrl = genericUrlGen("github", values[1], values[2], "commit", values[3]); + finalUrl = genericUrlGen('github', values[1], values[2], 'commit', values[3]); } else if ((values = githubCommitUrl.exec(url))) { - finalUrl = genericUrlGen("github", values[1], values[2], "commit", values[3]); + finalUrl = genericUrlGen('github', values[1], values[2], 'commit', values[3]); } else if ((values = githubPrUrl.exec(url))) { - finalUrl = genericUrlGen("github", values[1], values[2], "pull", values[3]); - + finalUrl = genericUrlGen('github', values[1], values[2], 'pull', values[3]); } else if ((values = gitlabPath.exec(url))) { - finalUrl = genericUrlGen("gitlab", values[1], values[2], "commit", values[3]); + finalUrl = genericUrlGen('gitlab', values[1], values[2], 'commit', values[3]); } else if ((values = gitlabCommitUrl.exec(url))) { - finalUrl = genericUrlGen("gitlab", values[1], values[2], "commit", values[3]); + finalUrl = genericUrlGen('gitlab', values[1], values[2], 'commit', values[3]); } else if ((values = gitlabPrUrl.exec(url))) { - finalUrl = genericUrlGen("gitlab", values[1], values[2], "merge_requests", values[3]); - + finalUrl = genericUrlGen('gitlab', values[1], values[2], 'merge_requests', values[3]); } else if ((values = bitbucketPath.exec(url))) { - finalUrl = bitbucketUrlGen(values[1], values[2], "commit", values[3]); + finalUrl = bitbucketUrlGen(values[1], values[2], 'commit', values[3]); } else if ((values = bitbucketCommitUrl.exec(url))) { - finalUrl = bitbucketUrlGen(values[1], values[2], "commit", values[3]); + finalUrl = bitbucketUrlGen(values[1], values[2], 'commit', values[3]); } else if ((values = bitbucketPrUrl.exec(url))) { - finalUrl = bitbucketUrlGen(values[1], values[2], "pullrequests", values[3]); + finalUrl = bitbucketUrlGen(values[1], values[2], 'pullrequests', values[3]); } else { - console.info("Could not parse url, using the provided url."); + console.info('Could not parse url, using the provided url.'); finalUrl = url; } @@ -133,24 +133,24 @@ $(document).ready(function () { function draw(url) { var outputFormat = $outputFormat.val(); - var showFiles = $showFiles.is(":checked"); + var showFiles = $showFiles.is(':checked'); var matching = $matching.val(); var wordThreshold = $wordThreshold.val(); var matchingMaxComparisons = $matchingMaxComparisons.val(); var fullUrl = 'https://crossorigin.me/' + url; fetch(fullUrl) - .then(function (res) { - return res.text() + .then(function(res) { + return res.text(); }) - .then(function (data) { + .then(function(data) { var container = '#url-diff-container'; var diff2htmlUi = new Diff2HtmlUI({diff: data}); - if (outputFormat == 'side-by-side') { - $container.css({"width": "1400px"}); + if (outputFormat === 'side-by-side') { + $container.css({'width': '1400px'}); } else { - $container.css({"width": ""}); + $container.css({'width': ''}); } diff2htmlUi.draw(container, {