Files
galaxy/static/scripts/utils/utils.js
T

3 lines
3.3 KiB
JavaScript

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