KEYCLOAK-4014 Add source for all js libs

This commit is contained in:
Stian Thorgersen 2016-12-02 08:57:50 +01:00
parent 8621733e17
commit 6fdc470b0b
4 changed files with 3533 additions and 0 deletions

View file

@ -0,0 +1,25 @@
/**!
* AngularJS file upload shim for angular XHR HTML5 browsers
* @author Danial <danial.farid@gmail.com>
* @version 1.1.10
*/
if (window.XMLHttpRequest) {
if (window.FormData) {
// allow access to Angular XHR private field: https://github.com/angular/angular.js/issues/1934
XMLHttpRequest = (function(origXHR) {
return function() {
var xhr = new origXHR();
xhr.send = (function(orig) {
return function() {
if (arguments[0] instanceof FormData && arguments[0].__setXHR_) {
var formData = arguments[0];
formData.__setXHR_(xhr);
}
orig.apply(xhr, arguments);
}
})(xhr.send);
return xhr;
}
})(XMLHttpRequest);
}
}

View file

@ -0,0 +1,215 @@
/**!
* AngularJS file upload shim for HTML5 FormData
* @author Danial <danial.farid@gmail.com>
* @version 1.1.10
*/
(function() {
if (window.XMLHttpRequest) {
if (window.FormData) {
// allow access to Angular XHR private field: https://github.com/angular/angular.js/issues/1934
XMLHttpRequest = (function(origXHR) {
return function() {
var xhr = new origXHR();
xhr.send = (function(orig) {
return function() {
if (arguments[0] instanceof FormData && arguments[0].__setXHR_) {
var formData = arguments[0];
formData.__setXHR_(xhr);
}
orig.apply(xhr, arguments);
}
})(xhr.send);
return xhr;
}
})(XMLHttpRequest);
} else {
XMLHttpRequest = (function(origXHR) {
return function() {
var xhr = new origXHR();
var origSend = xhr.send;
xhr.__requestHeaders = [];
xhr.open = (function(orig) {
xhr.upload = {
addEventListener: function(t, fn, b) {
if (t == 'progress') {
xhr.__progress = fn;
}
}
};
return function(m, url, b) {
orig.apply(xhr, [m, url, b]);
xhr.__url = url;
}
})(xhr.open);
xhr.getResponseHeader = (function(orig) {
return function(h) {
return xhr.__fileApiXHR ? xhr.__fileApiXHR.getResponseHeader(h) : orig.apply(xhr, [h]);
}
})(xhr.getResponseHeader);
xhr.getAllResponseHeaders = (function(orig) {
return function() {
return xhr.__fileApiXHR ? xhr.__fileApiXHR.getAllResponseHeaders() : orig.apply(xhr);
}
})(xhr.getAllResponseHeaders);
xhr.abort = (function(orig) {
return function() {
return xhr.__fileApiXHR ? xhr.__fileApiXHR.abort() : (orig == null ? null : orig.apply(xhr));
}
})(xhr.abort);
xhr.send = function() {
if (arguments[0] != null && arguments[0].__isShim && arguments[0].__setXHR_) {
var formData = arguments[0];
if (arguments[0].__setXHR_) {
var formData = arguments[0];
formData.__setXHR_(xhr);
}
var config = {
url: xhr.__url,
complete: function(err, fileApiXHR) {
Object.defineProperty(xhr, 'status', {get: function() {return fileApiXHR.status}});
Object.defineProperty(xhr, 'statusText', {get: function() {return fileApiXHR.statusText}});
Object.defineProperty(xhr, 'readyState', {get: function() {return 4}});
Object.defineProperty(xhr, 'response', {get: function() {return fileApiXHR.response}});
Object.defineProperty(xhr, 'responseText', {get: function() {return fileApiXHR.responseText}});
xhr.__fileApiXHR = fileApiXHR;
xhr.onreadystatechange();
},
progress: function(e) {
xhr.__progress(e);
},
headers: xhr.__requestHeaders
}
config.data = {};
config.files = {}
for (var i = 0; i < formData.data.length; i++) {
var item = formData.data[i];
if (item.val != null && item.val.name != null && item.val.size != null && item.val.type != null) {
config.files[item.key] = item.val;
} else {
config.data[item.key] = item.val;
}
}
setTimeout(function() {
xhr.__fileApiXHR = FileAPI.upload(config);
}, 1);
} else {
origSend.apply(xhr, arguments);
}
}
return xhr;
}
})(XMLHttpRequest);
}
}
if (!window.FormData) {
var hasFlash = false;
try {
var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
if (fo) hasFlash = true;
} catch(e) {
if (navigator.mimeTypes["application/x-shockwave-flash"] != undefined) hasFlash = true;
}
var wrapFileApi = function(elem) {
if (!elem.__isWrapped && (elem.getAttribute('ng-file-select') != null || elem.getAttribute('data-ng-file-select') != null)) {
var wrap = document.createElement('div');
wrap.innerHTML = '<div class="js-fileapi-wrapper" style="position:relative; overflow:hidden"></div>';
wrap = wrap.firstChild;
var parent = elem.parentNode;
parent.insertBefore(wrap, elem);
parent.removeChild(elem);
wrap.appendChild(elem);
if (!hasFlash) {
wrap.appendChild(document.createTextNode('Flash is required'));
}
elem.__isWrapped = true;
}
};
var changeFnWrapper = function(fn) {
return function(evt) {
var files = FileAPI.getFiles(evt);
if (!evt.target) {
evt.target = {};
}
evt.target.files = files;
evt.target.files.item = function(i) {
return evt.target.files[i] || null;
}
fn(evt);
};
};
var isFileChange = function(elem, e) {
return (e.toLowerCase() === 'change' || e.toLowerCase() === 'onchange') && elem.getAttribute('type') == 'file';
}
if (HTMLInputElement.prototype.addEventListener) {
HTMLInputElement.prototype.addEventListener = (function(origAddEventListener) {
return function(e, fn, b, d) {
if (isFileChange(this, e)) {
wrapFileApi(this);
origAddEventListener.apply(this, [e, changeFnWrapper(fn), b, d]);
} else {
origAddEventListener.apply(this, [e, fn, b, d]);
}
}
})(HTMLInputElement.prototype.addEventListener);
}
if (HTMLInputElement.prototype.attachEvent) {
HTMLInputElement.prototype.attachEvent = (function(origAttachEvent) {
return function(e, fn) {
if (isFileChange(this, e)) {
wrapFileApi(this);
origAttachEvent.apply(this, [e, changeFnWrapper(fn)]);
} else {
origAttachEvent.apply(this, [e, fn]);
}
}
})(HTMLInputElement.prototype.attachEvent);
}
window.FormData = FormData = function() {
return {
append: function(key, val, name) {
this.data.push({
key: key,
val: val,
name: name
});
},
data: [],
__isShim: true
};
};
(function () {
//load FileAPI
if (!window.FileAPI || !FileAPI.upload) {
var base = '', script = document.createElement('script'), allScripts = document.getElementsByTagName('script'), i, index, src;
if (window.FileAPI && window.FileAPI.jsPath) {
base = window.FileAPI.jsPath;
} else {
for (i = 0; i < allScripts.length; i++) {
src = allScripts[i].src;
index = src.indexOf('angular-file-upload-shim.js')
if (index == -1) {
index = src.indexOf('angular-file-upload-shim.min.js');
}
if (index > -1) {
base = src.substring(0, index);
break;
}
}
}
if (!window.FileAPI || FileAPI.staticPath == null) {
FileAPI = {
staticPath: base
}
}
script.setAttribute('src', base + "FileAPI.min.js");
document.getElementsByTagName('head')[0].appendChild(script);
}
})();
}})();

View file

@ -0,0 +1,156 @@
/**!
* AngularJS file upload/drop directive with http post and progress
* @author Danial <danial.farid@gmail.com>
* @version 1.1.10
*/
(function() {
var angularFileUpload = angular.module('angularFileUpload', []);
angularFileUpload.service('$upload', ['$http', '$rootScope', '$timeout', function($http, $rootScope, $timeout) {
this.upload = function(config) {
config.method = config.method || 'POST';
config.headers = config.headers || {};
config.headers['Content-Type'] = undefined;
config.transformRequest = config.transformRequest || $http.defaults.transformRequest;
var formData = new FormData();
if (config.data) {
for (var key in config.data) {
var val = config.data[key];
if (!config.formDataAppender) {
if (typeof config.transformRequest == 'function') {
val = config.transformRequest(val);
} else {
for (var i = 0; i < config.transformRequest.length; i++) {
var fn = config.transformRequest[i];
if (typeof fn == 'function') {
val = fn(val);
}
}
}
formData.append(key, val);
} else {
config.formDataAppender(formData, key, val);
}
}
}
config.transformRequest = angular.identity;
formData.append(config.fileFormDataName || 'file', config.file, config.file.name);
formData['__setXHR_'] = function(xhr) {
config.__XHR = xhr;
xhr.upload.addEventListener('progress', function(e) {
if (config.progress) {
$timeout(function() {
config.progress(e);
});
}
}, false);
//fix for firefox not firing upload progress end
xhr.upload.addEventListener('load', function(e) {
if (e.lengthComputable) {
$timeout(function() {
config.progress(e);
});
}
}, false);
};
config.data = formData;
var promise = $http(config);
promise.progress = function(fn) {
config.progress = fn;
return promise;
};
promise.abort = function() {
if (config.__XHR) {
$timeout(function() {
config.__XHR.abort();
});
}
return promise;
};
promise.then = (function(promise, origThen) {
return function(s, e, p) {
config.progress = p || config.progress;
origThen.apply(promise, [s, e, p]);
return promise;
};
})(promise, promise.then);
return promise;
};
}]);
angularFileUpload.directive('ngFileSelect', [ '$parse', '$http', '$timeout', function($parse, $http, $timeout) {
return function(scope, elem, attr) {
var fn = $parse(attr['ngFileSelect']);
elem.bind('change', function(evt) {
var files = [], fileList, i;
fileList = evt.target.files;
if (fileList != null) {
for (i = 0; i < fileList.length; i++) {
files.push(fileList.item(i));
}
}
$timeout(function() {
fn(scope, {
$files : files,
$event : evt
});
});
});
elem.bind('click', function(){
this.value = null;
});
};
} ]);
angularFileUpload.directive('ngFileDropAvailable', [ '$parse', '$http', '$timeout', function($parse, $http, $timeout) {
return function(scope, elem, attr) {
if ('draggable' in document.createElement('span')) {
var fn = $parse(attr['ngFileDropAvailable']);
$timeout(function() {
fn(scope);
});
}
};
} ]);
angularFileUpload.directive('ngFileDrop', [ '$parse', '$http', '$timeout', function($parse, $http, $timeout) {
return function(scope, elem, attr) {
if ('draggable' in document.createElement('span')) {
var fn = $parse(attr['ngFileDrop']);
elem[0].addEventListener("dragover", function(evt) {
evt.stopPropagation();
evt.preventDefault();
elem.addClass(attr['ngFileDragOverClass'] || "dragover");
}, false);
elem[0].addEventListener("dragleave", function(evt) {
elem.removeClass(attr['ngFileDragOverClass'] || "dragover");
}, false);
elem[0].addEventListener("drop", function(evt) {
evt.stopPropagation();
evt.preventDefault();
elem.removeClass(attr['ngFileDragOverClass'] || "dragover");
var files = [], fileList = evt.dataTransfer.files, i;
if (fileList != null) {
for (i = 0; i < fileList.length; i++) {
files.push(fileList.item(i));
}
}
$timeout(function() {
fn(scope, {
$files : files,
$event : evt
});
});
}, false);
}
};
} ]);
})();