Files
galaxy/static/scripts/utils/utils.js
T
2017-12-04 08:55:46 -05:00

1 line
4.3 KiB
JavaScript

define("utils/utils",["exports","utils/localization"],function(e,t){"use strict";function r(e){return'<iframe src="'+e+'" frameborder="0" style="width: 100%; height: 100%;"/>'}function n(e,t){for(var r in e){var i=e[r];if(_.isObject(i)){var a=t(i);a&&(e[r]=a),n(i,t)}}}function i(e){var t,r,n,i;return r=/(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim,t=e.replace(r,'<a href="$1" target="_blank">$1</a>'),n=/(^|[^\/])(www\.[\S]+(\b|$))/gim,t=t.replace(n,'$1<a href="http://$2" target="_blank">$2</a>'),i=/(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim,t=t.replace(i,'<a href="mailto:$1">$1</a>')}function a(e){return JSON.parse(JSON.stringify(e)||null)}function s(e){return/^[\],:{}\s]*$/.test(e.replace(/\\["\\\/bfnrtu]/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))}function u(e){return $("<div/>").text(e).html()}function o(e){if(e instanceof Array||(e=[e]),0===e.length)return!0;for(var t in e)if(["__null__","__undefined__",null,void 0].indexOf(e[t])>-1)return!0;return!1}function l(e){if($.isArray(e)){var t=(e=e.toString().replace(/,/g,", ")).lastIndexOf(", ");return-1!=t&&(e=e.substr(0,t)+" or "+e.substr(t+2)),e}return""}function c(e){top.__utils__get__=top.__utils__get__||{};var t=JSON.stringify(e);e.cache&&top.__utils__get__[t]?(e.success&&e.success(top.__utils__get__[t]),window.console.debug("utils.js::get() - Fetching from cache ["+e.url+"].")):f({url:e.url,data:e.data,success:function(r){top.__utils__get__[t]=r,e.success&&e.success(r)},error:function(t,r){e.error&&e.error(t,r)}})}function f(e){var t={contentType:"application/json",type:e.type||"GET",data:e.data||{},url:e.url};"GET"==t.type||"DELETE"==t.type?($.isEmptyObject(t.data)||(t.url+=-1==t.url.indexOf("?")?"?":"&",t.url+=$.param(t.data,!0)),t.data=null):(t.dataType="json",t.url=t.url,t.data=JSON.stringify(t.data)),$.ajax(t).done(function(t){if("string"==typeof t)try{t=t.replace("Infinity,",'"Infinity",'),t=jQuery.parseJSON(t)}catch(e){console.debug(e)}e.success&&e.success(t)}).fail(function(t){var r=null;try{r=jQuery.parseJSON(t.responseText)}catch(e){r=t.responseText}e.error&&e.error(r,t.status)}).always(function(){e.complete&&e.complete()})}function d(e,t){var r=$('<div class="'+e+'"></div>');r.appendTo(":eq(0)");var n=r.css(t);return r.remove(),n}function p(e){$('link[href^="'+e+'"]').length||$('<link href="'+Galaxy.root+e+'" rel="stylesheet">').appendTo("head")}function g(e,t){return e?_.defaults(e,t):t}function y(e,t){for(var r=1,n=0;n<t;n++)r*=10;return Math.round(e*r)/r}function h(e,t,r){r=void 0!==r?r:1;var n="";if(e>=j)e/=j,n="TB";else if(e>=G)e/=G,n="GB";else if(e>=O)e/=O,n="MB";else if(e>=T)e/=T,n="KB";else{if(!(e>0))return t?"0 b":"<strong>-</strong>";n="b"}var i="b"==n?e:y(e,r);return t?i+" "+n:"<strong>"+i+"</strong> "+n}function m(){return top.__utils__uid__=top.__utils__uid__||0,"uid-"+top.__utils__uid__++}function b(){var e=new Date,t=(e.getHours()<10?"0":"")+e.getHours(),r=(e.getMinutes()<10?"0":"")+e.getMinutes();return e.getDate()+"/"+(e.getMonth()+1)+"/"+e.getFullYear()+", "+t+":"+r}function v(e){e.script&&""!==e.script&&$("<script/>",{type:"text/javascript"}).text(e.script).appendTo("head"),e.styles&&""!==e.styles&&$("<style/>",{type:"text/css"}).text(e.styles).appendTo("head")}function w(e){return decodeURIComponent(window.location.search.replace(new RegExp("^(?:.*[&\\?]"+encodeURIComponent(e).replace(/[\.\+\*]/g,"\\$&")+"(?:\\=([^&]*))?)?.*$","i"),"$1"))}function x(e){window.document.title=e?"Galaxy "+(window.Galaxy.config.brand?" | "+window.Galaxy.config.brand:"")+" | "+(0,S.default)(e):"Galaxy "+(window.Galaxy.config.brand?" | "+window.Galaxy.config.brand:"")}Object.defineProperty(e,"__esModule",{value:!0}),e.iframe=r,e.deepeach=n,e.linkify=i,e.clone=a,e.isJSON=s,e.sanitize=u,e.isEmpty=o,e.textify=l,e.get=c,e.request=f,e.cssGetAttribute=d,e.cssLoadFile=p,e.merge=g,e.roundToDecimalPlaces=y,e.bytesToString=h,e.uid=m,e.time=b,e.appendScriptStyle=v,e.getQueryString=w,e.setWindowTitle=x;var S=function(e){return e&&e.__esModule?e:{default:e}}(t),T=1024,O=T*T,G=O*T,j=G*T;e.default={cssLoadFile:p,cssGetAttribute:d,get:c,merge:g,iframe:r,bytesToString:h,uid:m,time:b,request:f,sanitize:u,textify:l,isEmpty:o,deepeach:n,isJSON:s,clone:a,linkify:i,appendScriptStyle:v,getQueryString:w,setWindowTitle:x}});