Moved vendored js/css into public/vendor and documented sources (#1484) (#2241)

* Cleaning up public/ and documenting js/css libs.

This commit mostly addresses #1484 by moving vendor'ed plugins into a
vendor/ directory and documenting their upstream source and license in
vendor/librejs.html.

This also proves gitea is using only open source js/css libraries which
helps toward reaching #1524.

* Removing unused css file.

The version of this file in use is located at:
  vendor/plugins/highlight/github.css

* Cleaned up librejs.html and added javascript header

A SafeJS function was added to templates/helper.go to allow keeping
comments inside of javascript.

A javascript comment was added in the header of templates/base/head.tmpl
to mark all non-inline source as free.

The librejs.html file was updated to meet the current librejs spec. I
have now verified that the librejs plugin detects most of the scripts
included in gitea and suspect the non-free detections are the result of
a bug in the plugin. I believe this commit is enough to meet the C0.0
requirement of #1534.

* Updating SafeJS function per lint suggestion

* Added VERSIONS file, per request
This commit is contained in:
Michael Lustfield 2017-08-23 09:58:05 -05:00 committed by Kim "BKC" Carlbäcker
parent 64b7068846
commit a915a09e4f
1339 changed files with 813 additions and 126 deletions

View file

@ -1456,7 +1456,7 @@ $(document).ready(function () {
// Emojify
emojify.setConfig({
img_dir: suburl + '/img/emoji',
img_dir: suburl + '/plugins/emojify/images',
ignore_emoticons: true
});
var hasEmoji = document.getElementsByClassName('has-emoji');

File diff suppressed because one or more lines are too long

View file

@ -1,45 +0,0 @@
(function () {
var re = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-]*)?\??(?:[\-\+:=&;%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g;
function textNodesUnder(node) {
var textNodes = [];
if(typeof document.createTreeWalker === 'function') {
// Efficient TreeWalker
var currentNode, walker;
walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, null, false);
while(currentNode = walker.nextNode()) {
textNodes.push(currentNode);
}
} else {
// Less efficient recursive function
for(node = node.firstChild; node; node = node.nextSibling) {
if(node.nodeType === 3) {
textNodes.push(node);
} else {
textNodes = textNodes.concat(textNodesUnder(node));
}
}
}
return textNodes;
}
function processNode(node) {
re.lastIndex = 0;
var results = re.exec(node.textContent);
if(results !== null) {
if($(node).parents().filter('pre>code').length === 0) {
$(node).replaceWith(
$('<span />').html(
node.nodeValue.replace(re, '<a href="$1">$1</a>')
)
);
}
}
}
jQuery.fn.autolink = function () {
this.each(function () {
textNodesUnder(this).forEach(processNode);
});
return this;
};
})();

File diff suppressed because one or more lines are too long

View file

@ -1,2 +0,0 @@
/*! loadCSS rel=preload polyfill. [c]2017 Filament Group, Inc. MIT License */
!function(a){if(a.loadCSS){var b=loadCSS.relpreload={};if(b.support=function(){try{return a.document.createElement("link").relList.supports("preload")}catch(b){return!1}},b.poly=function(){for(var b=a.document.getElementsByTagName("link"),c=0;c<b.length;c++){var d=b[c];"preload"===d.rel&&"style"===d.getAttribute("as")&&(a.loadCSS(d.href,d,d.getAttribute("media")),d.rel=null)}},!b.support()){b.poly();var c=a.setInterval(b.poly,300);a.addEventListener&&a.addEventListener("load",function(){b.poly(),a.clearInterval(c)}),a.attachEvent&&a.attachEvent("onload",function(){a.clearInterval(c)})}}}(this);

File diff suppressed because one or more lines are too long

View file

@ -1,399 +0,0 @@
/*
* Copyright (c) 2011, Terrence Lee <kill889@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
var gitGraph = function (canvas, rawGraphList, config) {
if (!canvas.getContext) {
return;
}
if (typeof config === "undefined") {
config = {
unitSize: 20,
lineWidth: 3,
nodeRadius: 4
};
}
var flows = [];
var graphList = [];
var ctx = canvas.getContext("2d");
var init = function () {
var maxWidth = 0;
var i;
var l = rawGraphList.length;
var row;
var midStr;
for (i = 0; i < l; i++) {
midStr = rawGraphList[i].replace(/\s+/g, " ").replace(/^\s+|\s+$/g, "");
maxWidth = Math.max(midStr.replace(/(\_|\s)/g, "").length, maxWidth);
row = midStr.split("");
graphList.unshift(row);
}
canvas.width = maxWidth * config.unitSize;
canvas.height = graphList.length * config.unitSize;
ctx.lineWidth = config.lineWidth;
ctx.lineJoin = "round";
ctx.lineCap = "round";
};
var genRandomStr = function () {
var chars = "0123456789ABCDEF";
var stringLength = 6;
var randomString = '', rnum, i;
for (i = 0; i < stringLength; i++) {
rnum = Math.floor(Math.random() * chars.length);
randomString += chars.substring(rnum, rnum + 1);
}
return randomString;
};
var findFlow = function (id) {
var i = flows.length;
while (i-- && flows[i].id !== id) {}
return i;
};
var findColomn = function (symbol, row) {
var i = row.length;
while (i-- && row[i] !== symbol) {}
return i;
};
var findBranchOut = function (row) {
if (!row) {
return -1
}
var i = row.length;
while (i-- &&
!(row[i - 1] && row[i] === "/" && row[i - 1] === "|") &&
!(row[i - 2] && row[i] === "_" && row[i - 2] === "|")) {}
return i;
}
var genNewFlow = function () {
var newId;
do {
newId = genRandomStr();
} while (findFlow(newId) !== -1);
return {id:newId, color:"#" + newId};
};
//draw method
var drawLineRight = function (x, y, color) {
ctx.strokeStyle = color;
ctx.beginPath();
ctx.moveTo(x, y + config.unitSize / 2);
ctx.lineTo(x + config.unitSize, y + config.unitSize / 2);
ctx.stroke();
};
var drawLineUp = function (x, y, color) {
ctx.strokeStyle = color;
ctx.beginPath();
ctx.moveTo(x, y + config.unitSize / 2);
ctx.lineTo(x, y - config.unitSize / 2);
ctx.stroke();
};
var drawNode = function (x, y, color) {
ctx.strokeStyle = color;
drawLineUp(x, y, color);
ctx.beginPath();
ctx.arc(x, y, config.nodeRadius, 0, Math.PI * 2, true);
ctx.fill();
};
var drawLineIn = function (x, y, color) {
ctx.strokeStyle = color;
ctx.beginPath();
ctx.moveTo(x + config.unitSize, y + config.unitSize / 2);
ctx.lineTo(x, y - config.unitSize / 2);
ctx.stroke();
};
var drawLineOut = function (x, y, color) {
ctx.strokeStyle = color;
ctx.beginPath();
ctx.moveTo(x, y + config.unitSize / 2);
ctx.lineTo(x + config.unitSize, y - config.unitSize / 2);
ctx.stroke();
};
var draw = function (graphList) {
var colomn, colomnIndex, prevColomn, condenseIndex;
var x, y;
var color;
var nodePos, outPos;
var tempFlow;
var prevRowLength = 0;
var flowSwapPos = -1;
var lastLinePos;
var i, k, l;
var condenseCurrentLength, condensePrevLength = 0, condenseNextLength = 0;
var inlineIntersect = false;
//initiate for first row
for (i = 0, l = graphList[0].length; i < l; i++) {
if (graphList[0][i] !== "_" && graphList[0][i] !== " ") {
flows.push(genNewFlow());
}
}
y = canvas.height - config.unitSize * 0.5;
//iterate
for (i = 0, l = graphList.length; i < l; i++) {
x = config.unitSize * 0.5;
currentRow = graphList[i];
nextRow = graphList[i + 1];
prevRow = graphList[i - 1];
flowSwapPos = -1;
condenseCurrentLength = currentRow.filter(function (val) {
return (val !== " " && val !== "_")
}).length;
if (nextRow) {
condenseNextLength = nextRow.filter(function (val) {
return (val !== " " && val !== "_")
}).length;
} else {
condenseNextLength = 0;
}
//pre process begin
//use last row for analysing
if (prevRow) {
if (!inlineIntersect) {
//intersect might happen
for (colomnIndex = 0; colomnIndex < prevRowLength; colomnIndex++) {
if (prevRow[colomnIndex + 1] &&
(prevRow[colomnIndex] === "/" && prevRow[colomnIndex + 1] === "|") ||
((prevRow[colomnIndex] === "_" && prevRow[colomnIndex + 1] === "|") &&
(prevRow[colomnIndex + 2] === "/"))) {
flowSwapPos = colomnIndex;
//swap two flow
tempFlow = {id:flows[flowSwapPos].id, color:flows[flowSwapPos].color};
flows[flowSwapPos].id = flows[flowSwapPos + 1].id;
flows[flowSwapPos].color = flows[flowSwapPos + 1].color;
flows[flowSwapPos + 1].id = tempFlow.id;
flows[flowSwapPos + 1].color = tempFlow.color;
}
}
}
if (condensePrevLength < condenseCurrentLength &&
((nodePos = findColomn("*", currentRow)) !== -1 &&
(findColomn("_", currentRow) === -1))) {
flows.splice(nodePos - 1, 0, genNewFlow());
}
if (prevRowLength > currentRow.length &&
(nodePos = findColomn("*", prevRow)) !== -1) {
if (findColomn("_", currentRow) === -1 &&
findColomn("/", currentRow) === -1 &&
findColomn("\\", currentRow) === -1) {
flows.splice(nodePos + 1, 1);
}
}
} //done with the previous row
prevRowLength = currentRow.length; //store for next round
colomnIndex = 0; //reset index
condenseIndex = 0;
condensePrevLength = 0;
while (colomnIndex < currentRow.length) {
colomn = currentRow[colomnIndex];
if (colomn !== " " && colomn !== "_") {
++condensePrevLength;
}
if (colomn === " " &&
currentRow[colomnIndex + 1] &&
currentRow[colomnIndex + 1] === "_" &&
currentRow[colomnIndex - 1] &&
currentRow[colomnIndex - 1] === "|") {
currentRow.splice(colomnIndex, 1);
currentRow[colomnIndex] = "/";
colomn = "/";
}
//create new flow only when no intersetc happened
if (flowSwapPos === -1 &&
colomn === "/" &&
currentRow[colomnIndex - 1] &&
currentRow[colomnIndex - 1] === "|") {
flows.splice(condenseIndex, 0, genNewFlow());
}
//change \ and / to | when it's in the last position of the whole row
if (colomn === "/" || colomn === "\\") {
if (!(colomn === "/" && findBranchOut(nextRow) === -1)) {
if ((lastLinePos = Math.max(findColomn("|", currentRow),
findColomn("*", currentRow))) !== -1 &&
(lastLinePos < colomnIndex - 1)) {
while (currentRow[++lastLinePos] === " ") {}
if (lastLinePos === colomnIndex) {
currentRow[colomnIndex] = "|";
}
}
}
}
if (colomn === "*" &&
prevRow &&
prevRow[condenseIndex + 1] === "\\") {
flows.splice(condenseIndex + 1, 1);
}
if (colomn !== " ") {
++condenseIndex;
}
++colomnIndex;
}
condenseCurrentLength = currentRow.filter(function (val) {
return (val !== " " && val !== "_")
}).length;
//do some clean up
if (flows.length > condenseCurrentLength) {
flows.splice(condenseCurrentLength, flows.length - condenseCurrentLength);
}
colomnIndex = 0;
//a little inline analysis and draw process
while (colomnIndex < currentRow.length) {
colomn = currentRow[colomnIndex];
prevColomn = currentRow[colomnIndex - 1];
if (currentRow[colomnIndex] === " ") {
currentRow.splice(colomnIndex, 1);
x += config.unitSize;
continue;
}
//inline interset
if ((colomn === "_" || colomn === "/") &&
currentRow[colomnIndex - 1] === "|" &&
currentRow[colomnIndex - 2] === "_") {
inlineIntersect = true;
tempFlow = flows.splice(colomnIndex - 2, 1)[0];
flows.splice(colomnIndex - 1, 0, tempFlow);
currentRow.splice(colomnIndex - 2, 1);
colomnIndex = colomnIndex - 1;
} else {
inlineIntersect = false;
}
color = flows[colomnIndex].color;
switch (colomn) {
case "_" :
drawLineRight(x, y, color);
x += config.unitSize;
break;
case "*" :
drawNode(x, y, color);
break;
case "|" :
drawLineUp(x, y, color);
break;
case "/" :
if (prevColomn &&
(prevColomn === "/" ||
prevColomn === " ")) {
x -= config.unitSize;
}
drawLineOut(x, y, color);
x += config.unitSize;
break;
case "\\" :
drawLineIn(x, y, color);
break;
}
++colomnIndex;
}
y -= config.unitSize;
}
};
init();
draw(graphList);
};

View file

@ -1,192 +0,0 @@
/*!
* jQuery Plugin: Are-You-Sure (Dirty Form Detection)
* https://github.com/codedance/jquery.AreYouSure/
*
* Copyright (c) 2012-2014, Chris Dance and PaperCut Software http://www.papercut.com/
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* Author: chris.dance@papercut.com
* Version: 1.9.0
* Date: 13th August 2014
*/
(function($) {
$.fn.areYouSure = function(options) {
var settings = $.extend(
{
'message' : 'You have unsaved changes!',
'dirtyClass' : 'dirty',
'change' : null,
'silent' : false,
'addRemoveFieldsMarksDirty' : false,
'fieldEvents' : 'change keyup propertychange input',
'fieldSelector': ":input:not(input[type=submit]):not(input[type=button])"
}, options);
var getValue = function($field) {
if ($field.hasClass('ays-ignore')
|| $field.hasClass('aysIgnore')
|| $field.attr('data-ays-ignore')
|| $field.attr('name') === undefined) {
return null;
}
if ($field.is(':disabled')) {
return 'ays-disabled';
}
var val;
var type = $field.attr('type');
if ($field.is('select')) {
type = 'select';
}
switch (type) {
case 'checkbox':
case 'radio':
val = $field.is(':checked');
break;
case 'select':
val = '';
$field.find('option').each(function(o) {
var $option = $(this);
if ($option.is(':selected')) {
val += $option.val();
}
});
break;
default:
val = $field.val();
}
return val;
};
var storeOrigValue = function($field) {
$field.data('ays-orig', getValue($field));
};
var checkForm = function(evt) {
var isFieldDirty = function($field) {
var origValue = $field.data('ays-orig');
if (undefined === origValue) {
return false;
}
return (getValue($field) != origValue);
};
var $form = ($(this).is('form'))
? $(this)
: $(this).parents('form');
// Test on the target first as it's the most likely to be dirty
if (isFieldDirty($(evt.target))) {
setDirtyStatus($form, true);
return;
}
$fields = $form.find(settings.fieldSelector);
if (settings.addRemoveFieldsMarksDirty) {
// Check if field count has changed
var origCount = $form.data("ays-orig-field-count");
if (origCount != $fields.length) {
setDirtyStatus($form, true);
return;
}
}
// Brute force - check each field
var isDirty = false;
$fields.each(function() {
$field = $(this);
if (isFieldDirty($field)) {
isDirty = true;
return false; // break
}
});
setDirtyStatus($form, isDirty);
};
var initForm = function($form) {
var fields = $form.find(settings.fieldSelector);
$(fields).each(function() { storeOrigValue($(this)); });
$(fields).unbind(settings.fieldEvents, checkForm);
$(fields).bind(settings.fieldEvents, checkForm);
$form.data("ays-orig-field-count", $(fields).length);
setDirtyStatus($form, false);
};
var setDirtyStatus = function($form, isDirty) {
var changed = isDirty != $form.hasClass(settings.dirtyClass);
$form.toggleClass(settings.dirtyClass, isDirty);
// Fire change event if required
if (changed) {
if (settings.change) settings.change.call($form, $form);
if (isDirty) $form.trigger('dirty.areYouSure', [$form]);
if (!isDirty) $form.trigger('clean.areYouSure', [$form]);
$form.trigger('change.areYouSure', [$form]);
}
};
var rescan = function() {
var $form = $(this);
var fields = $form.find(settings.fieldSelector);
$(fields).each(function() {
var $field = $(this);
if (!$field.data('ays-orig')) {
storeOrigValue($field);
$field.bind(settings.fieldEvents, checkForm);
}
});
// Check for changes while we're here
$form.trigger('checkform.areYouSure');
};
var reinitialize = function() {
initForm($(this));
}
if (!settings.silent && !window.aysUnloadSet) {
window.aysUnloadSet = true;
$(window).bind('beforeunload', function() {
$dirtyForms = $("form").filter('.' + settings.dirtyClass);
if ($dirtyForms.length == 0) {
return;
}
// Prevent multiple prompts - seen on Chrome and IE
if (navigator.userAgent.toLowerCase().match(/msie|chrome/)) {
if (window.aysHasPrompted) {
return;
}
window.aysHasPrompted = true;
window.setTimeout(function() {window.aysHasPrompted = false;}, 900);
}
return settings.message;
});
}
return this.each(function(elem) {
if (!$(this).is('form')) {
return;
}
var $form = $(this);
$form.submit(function() {
$form.removeClass(settings.dirtyClass);
});
$form.bind('reset', function() { setDirtyStatus($form, false); });
// Add a custom events
$form.bind('rescan.areYouSure', rescan);
$form.bind('reinitialize.areYouSure', reinitialize);
$form.bind('checkform.areYouSure', checkForm);
initForm($form);
});
};
})(jQuery);

View file

@ -1,2 +0,0 @@
/*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
!function(a){"use strict";var b=function(b,c,d){function e(a){return h.body?a():void setTimeout(function(){e(a)})}function f(){i.addEventListener&&i.removeEventListener("load",f),i.media=d||"all"}var g,h=a.document,i=h.createElement("link");if(c)g=c;else{var j=(h.body||h.getElementsByTagName("head")[0]).childNodes;g=j[j.length-1]}var k=h.styleSheets;i.rel="stylesheet",i.href=b,i.media="only x",e(function(){g.parentNode.insertBefore(i,c?g:g.nextSibling)});var l=function(a){for(var b=i.href,c=k.length;c--;)if(k[c].href===b)return a();setTimeout(function(){l(a)})};return i.addEventListener&&i.addEventListener("load",f),i.onloadcssdefined=l,l(f),i};"undefined"!=typeof exports?exports.loadCSS=b:a.loadCSS=b}("undefined"!=typeof global?global:this);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long