mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
1 line
4.4 KiB
JavaScript
1 line
4.4 KiB
JavaScript
define("utils/utils",["exports","utils/localization","underscore"],function(e,t,r){"use strict";function n(e){return'<iframe src="'+e+'" frameborder="0" style="width: 100%; height: 100%;"/>'}function i(e,t){for(var r in e){var n=e[r];if(T.isObject(n)){var a=t(n);a&&(e[r]=a),i(n,t)}}}function a(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 s(e){return JSON.parse(JSON.stringify(e)||null)}function u(e){return/^[\],:{}\s]*$/.test(e.replace(/\\["\\\/bfnrtu]/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))}function o(e){return $("<div/>").text(e).html()}function l(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 c(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 f(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+"].")):d({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 d(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=$.parseJSON(t)}catch(e){console.debug(e)}e.success&&e.success(t)}).fail(function(t){var r=null;try{r=$.parseJSON(t.responseText)}catch(e){r=t.responseText}e.error&&e.error(r,t.status)}).always(function(){e.complete&&e.complete()})}function p(e,t){var r=$('<div class="'+e+'"></div>');r.appendTo(":eq(0)");var n=r.css(t);return r.remove(),n}function _(e){$('link[href^="'+e+'"]').length||$('<link href="'+Galaxy.root+e+'" rel="stylesheet">').appendTo("head")}function g(e,t){return e?T.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>=E)e/=E,n="GB";else if(e>=G)e/=G,n="MB";else if(e>=O)e/=O,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 v(){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 m(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=n,e.deepeach=i,e.linkify=a,e.clone=s,e.isJSON=u,e.sanitize=o,e.isEmpty=l,e.textify=c,e.get=f,e.request=d,e.cssGetAttribute=p,e.cssLoadFile=_,e.merge=g,e.roundToDecimalPlaces=y,e.bytesToString=h,e.uid=v,e.time=b,e.appendScriptStyle=m,e.getQueryString=w,e.setWindowTitle=x;var S=function(e){return e&&e.__esModule?e:{default:e}}(t),T=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(r),O=1024,G=O*O,E=G*O,j=E*O;e.default={cssLoadFile:_,cssGetAttribute:p,get:f,merge:g,iframe:n,bytesToString:h,uid:v,time:b,request:d,sanitize:o,textify:c,isEmpty:l,deepeach:i,isJSON:u,clone:s,linkify:a,appendScriptStyle:m,getQueryString:w,setWindowTitle:x}}); |